:root {
  color-scheme: dark;
  --bg: #0b0e14;
  --text: #e9edf5;
  --muted: #8a93a8;
  --border: rgba(255, 255, 255, 0.08);
  --card: rgba(19, 24, 36, 0.72);
  --field: rgba(255, 255, 255, 0.04);
  --field-focus: rgba(255, 255, 255, 0.07);
  --accent-a: #7c8cff;
  --accent-b: #4fd1c5;
  --radius: 20px;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100dvh;
  background:
    radial-gradient(120% 90% at 85% -10%, rgba(124, 140, 255, 0.16), transparent 60%),
    radial-gradient(120% 90% at -10% 110%, rgba(79, 209, 197, 0.12), transparent 60%),
    var(--bg);
  background-attachment: fixed;
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.app {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 24px;
  min-height: 100dvh;
  max-width: 560px;
  margin: 0 auto;
  padding:
    calc(28px + env(safe-area-inset-top, 0px))
    calc(20px + env(safe-area-inset-right, 0px))
    calc(28px + env(safe-area-inset-bottom, 0px))
    calc(20px + env(safe-area-inset-left, 0px));
}

/* ---------- Header ---------- */

.header {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  animation: rise 0.5s cubic-bezier(0.2, 0.7, 0.3, 1) both;
}

.logo {
  width: 56px;
  height: 56px;
  filter: drop-shadow(0 8px 24px rgba(124, 140, 255, 0.35));
}

.header h1 {
  margin: 14px 0 0;
  font-size: 1.7rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

/* ---------- Card ---------- */

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  animation: rise 0.5s cubic-bezier(0.2, 0.7, 0.3, 1) 0.08s both;
}

.field-label {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

textarea {
  display: block;
  width: 100%;
  min-height: 64px;
  max-height: 180px;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--field);
  color: var(--text);
  font: inherit;
  resize: none;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s, background 0.2s;
}

textarea::placeholder {
  color: var(--muted);
  opacity: 0.7;
}

textarea:focus-visible {
  border-color: rgba(124, 140, 255, 0.55);
  background: var(--field-focus);
  box-shadow: 0 0 0 3px rgba(124, 140, 255, 0.16);
}

/* ---------- Length selector ---------- */

.length {
  margin-top: 16px;
}

.length-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.length-head .field-label {
  margin-bottom: 0;
}

.length-number {
  width: 70px;
  padding: 8px 6px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--field);
  color: var(--text);
  font: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  text-align: center;
  outline: none;
  appearance: textfield;
  -moz-appearance: textfield;
  transition: border-color 0.2s, box-shadow 0.2s, background 0.2s;
}

.length-number::-webkit-outer-spin-button,
.length-number::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.length-number:focus-visible {
  border-color: rgba(124, 140, 255, 0.55);
  background: var(--field-focus);
  box-shadow: 0 0 0 3px rgba(124, 140, 255, 0.16);
}

.presets {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 10px;
}

@media (min-width: 480px) {
  .presets {
    grid-template-columns: repeat(6, 1fr);
    gap: 6px;
  }
}

.modes {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-top: 8px;
}

.preset,
.mode-btn {
  min-height: 42px;
  padding: 0 8px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--field);
  color: var(--muted);
  font: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: color 0.2s, border-color 0.2s, background 0.2s, transform 0.12s;
}

.preset:hover,
.mode-btn:hover {
  color: var(--text);
  border-color: rgba(255, 255, 255, 0.16);
}

.preset:active,
.mode-btn:active {
  transform: translateY(1px);
}

.preset.is-active,
.mode-btn.is-active {
  border-color: transparent;
  background: linear-gradient(135deg, var(--accent-a), var(--accent-b));
  color: #0b0e14;
  box-shadow: 0 6px 18px rgba(124, 140, 255, 0.25);
}

/* ---------- Output ---------- */

.output-box {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 72px;
  margin-top: 16px;
  padding: 18px 14px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: rgba(0, 0, 0, 0.22);
}

.output {
  display: block;
  width: 100%;
  font-family: var(--font-mono);
  font-size: clamp(1.05rem, 5.4vw, 1.35rem);
  font-weight: 600;
  letter-spacing: 0.05em;
  text-align: center;
  word-break: break-all;
  user-select: all;
  -webkit-user-select: all;
}

.output[data-size="sm"] {
  font-size: clamp(0.92rem, 4.4vw, 1.15rem);
}

.output[data-size="xs"] {
  font-size: clamp(0.74rem, 3.4vw, 0.95rem);
}

.output[data-size="xxs"] {
  font-size: clamp(0.6rem, 2.9vw, 0.8rem);
}

.output.empty {
  color: var(--muted);
  opacity: 0.45;
  letter-spacing: 0.18em;
  user-select: none;
  -webkit-user-select: none;
}

.output.empty[data-size="sm"] {
  letter-spacing: 0.12em;
}

.output.empty[data-size="xs"] {
  letter-spacing: 0.08em;
}

.output.empty[data-size="xxs"] {
  letter-spacing: 0.04em;
}

/* ---------- Copy button ---------- */

.copy {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  width: 100%;
  min-height: 52px;
  margin-top: 16px;
  padding: 0 20px;
  border: 0;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--accent-a), var(--accent-b));
  color: #0b0e14;
  font: inherit;
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  box-shadow: 0 12px 32px rgba(124, 140, 255, 0.28);
  transition: transform 0.12s ease, box-shadow 0.2s, opacity 0.2s, filter 0.2s;
}

.copy:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  box-shadow: none;
}

.copy:not(:disabled):hover {
  filter: brightness(1.06);
}

.copy:not(:disabled):active {
  transform: translateY(1px) scale(0.99);
}

.copy:focus-visible,
.preset:focus-visible,
.mode-btn:focus-visible,
.length-number:focus-visible,
textarea:focus-visible {
  outline: 2px solid #b9c2ff;
  outline-offset: 2px;
}

.copy.copied {
  box-shadow: 0 12px 32px rgba(79, 209, 197, 0.35);
}

.icon {
  width: 20px;
  height: 20px;
  flex: none;
}

/* ---------- Larger screens ---------- */

@media (min-width: 600px) {
  .card {
    padding: 28px;
  }

  .header h1 {
    font-size: 2rem;
  }

  .logo {
    width: 64px;
    height: 64px;
  }
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
