/* ==========================================================================
   Phone Fun — Professional UI/UX redesign
   Design system per ui-ux-pro-max: Flat Design Mobile (touch-first),
   Fredoka + Nunito typography, refined yellow theme, WCAG-AA accessibility.
   ========================================================================== */

/* ---------- Design tokens ---------- */
:root {
  /* Brand */
  --brand: #f59e0b;            /* amber 500 — primary action */
  --brand-strong: #b45309;     /* amber 700 — text on light */
  --brand-soft: #fef3c7;       /* amber 100 — tints */
  --accent: #7c3aed;           /* violet 600 — secondary highlight */
  --accent-soft: #ede9fe;
  --success: #047857;          /* emerald 700 */
  --danger: #dc2626;

  /* Light theme: yellow-warm background, dark fonts */
  --bg: #fffbeb;               /* amber 50 */
  --bg-grad: radial-gradient(120% 80% at 20% 0%, #fef9c3 0%, #fde68a 45%, #fbbf24 100%);
  --surface: rgba(255, 255, 255, 0.72);
  --surface-solid: #ffffff;
  --surface-2: rgba(255, 251, 235, 0.85);
  --border: rgba(146, 64, 14, 0.16);
  --border-strong: rgba(146, 64, 14, 0.28);
  --text: #1c1917;             /* stone 900 */
  --text-soft: #57534e;        /* stone 600 */
  --muted: #78716c;            /* stone 500 */
  --screen-bg: #0c0a09;
  --screen-text: #fbbf24;
  --screen-soft: #a16207;
  --screen-border: #292524;

  /* Keypad keys */
  --key-bg: linear-gradient(180deg, #ffffff 0%, #fef3c7 100%);
  --key-bg-hover: linear-gradient(180deg, #fffbeb 0%, #fde68a 100%);
  --key-bg-active: linear-gradient(180deg, #fde68a 0%, #fbbf24 100%);
  --key-text: #1c1917;
  --key-letters: #92400e;
  --key-shadow: 0 4px 0 rgba(180,83,9,.28), 0 6px 14px rgba(0,0,0,.10);
  --key-shadow-active: 0 1px 0 rgba(180,83,9,.28), 0 2px 6px rgba(0,0,0,.10);
  --key-border: rgba(146, 64, 14, 0.18);

  /* Effects */
  --radius-sm: 12px;
  --radius: 18px;
  --radius-lg: 26px;
  --ring: 0 0 0 3px rgba(124, 58, 237, 0.45);
  --shadow-card: 0 20px 60px rgba(120, 80, 0, 0.18), 0 2px 8px rgba(0,0,0,.06);
  --transition: 160ms cubic-bezier(0.4, 0, 0.2, 1);
}

[data-theme="dark"] {
  /* Dark theme: deep amber-black, warm gold accents */
  --bg: #0c0a09;
  --bg-grad: radial-gradient(120% 80% at 20% 0%, #1c1407 0%, #16110a 50%, #0c0a09 100%);
  --surface: rgba(251, 191, 36, 0.07);
  --surface-solid: #1c1917;
  --surface-2: rgba(251, 191, 36, 0.10);
  --border: rgba(251, 191, 36, 0.18);
  --border-strong: rgba(251, 191, 36, 0.32);
  --text: #fef3c7;
  --text-soft: #fcd34d;
  --muted: #d6d3d1;
  --screen-bg: #000000;
  --screen-text: #fbbf24;
  --screen-soft: #a8a29e;
  --screen-border: #292524;

  --key-bg: linear-gradient(180deg, #fbbf24 0%, #d97706 100%);
  --key-bg-hover: linear-gradient(180deg, #fcd34d 0%, #f59e0b 100%);
  --key-bg-active: linear-gradient(180deg, #f59e0b 0%, #b45309 100%);
  --key-text: #1c1917;
  --key-letters: #451a03;
  --key-shadow: 0 4px 0 rgba(0,0,0,.4), 0 6px 14px rgba(0,0,0,.30);
  --key-shadow-active: 0 1px 0 rgba(0,0,0,.4), 0 2px 6px rgba(0,0,0,.30);
  --key-border: rgba(251, 191, 36, 0.20);

  --ring: 0 0 0 3px rgba(251, 191, 36, 0.5);
  --shadow-card: 0 20px 60px rgba(0, 0, 0, 0.5);
}

/* ---------- Reset & base ---------- */
*, *::before, *::after { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100dvh;
  font-family: "Nunito", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg-grad);
  background-attachment: fixed;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  transition: background 0.4s ease, color 0.3s ease;
}

/* Visible focus for keyboard users (accessibility priority 1) */
:focus-visible {
  outline: none;
  box-shadow: var(--ring);
  border-radius: var(--radius-sm);
}

/* ---------- Decorative animated blobs ---------- */
.blob {
  position: fixed; border-radius: 50%; filter: blur(60px);
  opacity: 0.45; pointer-events: none; z-index: 0;
  animation: float 16s ease-in-out infinite;
}
.blob.b1 { width: 280px; height: 280px; background: #f59e0b; top: -70px; left: -70px; }
.blob.b2 { width: 220px; height: 220px; background: #fde68a; bottom: -60px; right: -50px; animation-delay: -6s; }
.blob.b3 { width: 160px; height: 160px; background: #7c3aed; top: 40%; right: -80px; opacity: 0.18; animation-delay: -3s; }
[data-theme="dark"] .blob.b1 { background: #b45309; opacity: 0.22; }
[data-theme="dark"] .blob.b2 { background: #422006; opacity: 0.3; }
[data-theme="dark"] .blob.b3 { background: #7c3aed; opacity: 0.12; }
@keyframes float {
  0%, 100% { transform: translate(0, 0) scale(1); }
  50% { transform: translate(18px, 24px) scale(1.06); }
}

/* ---------- App card ---------- */
.app {
  position: relative; z-index: 1;
  width: 100%; max-width: 400px;
  background: var(--surface);
  backdrop-filter: blur(16px) saturate(1.4);
  -webkit-backdrop-filter: blur(16px) saturate(1.4);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 22px 20px 18px;
  box-shadow: var(--shadow-card);
}

/* ---------- Header ---------- */
.app-header {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin-bottom: 18px;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand .logo {
  width: 42px; height: 42px; flex: none;
  background: linear-gradient(135deg, var(--brand) 0%, #ea580c 100%);
  border-radius: 13px;
  display: grid; place-items: center;
  box-shadow: 0 4px 12px rgba(245, 158, 11, 0.4);
}
.brand .logo svg { width: 24px; height: 24px; color: #fff; }
.brand h1 {
  font-family: "Fredoka", "Nunito", sans-serif;
  font-size: 22px; font-weight: 600; margin: 0;
  letter-spacing: -0.02em; line-height: 1.1;
}
.brand .subtitle { font-size: 12px; color: var(--muted); margin: 1px 0 0; font-weight: 500; }

.icon-btn {
  flex: none;
  width: 44px; height: 44px;
  display: grid; place-items: center;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 13px;
  color: var(--text-soft);
  cursor: pointer;
  transition: var(--transition);
}
.icon-btn:hover { background: var(--brand-soft); color: var(--brand-strong); transform: rotate(-12deg); }
.icon-btn:active { transform: scale(0.92); }
.icon-btn svg { width: 22px; height: 22px; }

/* ---------- Display / screen ---------- */
.display {
  background: var(--screen-bg);
  border: 1px solid var(--screen-border);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 16px;
  box-shadow: inset 0 2px 12px rgba(0,0,0,.5);
  min-height: 128px;
}
.number-line {
  font-family: "Fredoka", "Courier New", ui-monospace, monospace;
  font-size: 26px; font-weight: 500; letter-spacing: 1px;
  display: flex; align-items: center; gap: 1px;
  flex-wrap: wrap; min-height: 34px;
  color: var(--screen-text);
}
.number-line .area {
  color: var(--screen-soft);
  padding: 0 1px;
}
.number-line .sep { color: var(--screen-soft); margin: 0 3px; }
.number-line .word-digits { color: var(--screen-text); font-weight: 600; }
.number-line .caret {
  display: inline-block; width: 2px; height: 26px;
  background: var(--screen-text); margin-left: 3px;
  animation: blink 1.1s steps(2) infinite;
}
.number-line .placeholder {
  color: var(--screen-soft); font-size: 15px; letter-spacing: 0;
  font-weight: 400; font-family: "Nunito", sans-serif;
}
@keyframes blink { 0%, 50% { opacity: 1; } 50.01%, 100% { opacity: 0; } }

/* Result block */
.result {
  margin-top: 14px;
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  background: rgba(251, 191, 36, 0.07);
  border: 1px solid var(--screen-border);
  min-height: 60px;
}
.result .label {
  font-family: "Nunito", sans-serif;
  font-size: 10px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 1.8px; color: var(--screen-soft);
}

/* Area-code persona chip */
.persona {
  display: inline-flex; align-items: center; gap: 7px;
  margin-top: 8px;
  padding: 6px 13px;
  background: linear-gradient(135deg, rgba(251,191,36,.22), rgba(124,58,237,.18));
  border: 1px solid rgba(251,191,36,.35);
  border-radius: 999px;
  font-family: "Fredoka", sans-serif;
  font-size: 14px; font-weight: 500;
  color: var(--screen-text);
}
.persona .persona-emoji { font-size: 18px; line-height: 1; }
.persona .persona-name { letter-spacing: 0.2px; }
.result .mnemonic {
  font-family: "Fredoka", sans-serif;
  font-size: 28px; font-weight: 600; margin-top: 2px; line-height: 1.15;
  background: linear-gradient(90deg, var(--screen-text), #fef9c3);
  -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
  word-break: break-word;
}
.result .tagline {
  font-family: "Nunito", sans-serif;
  font-size: 14px; color: var(--screen-soft); font-style: italic;
  margin-top: 6px; min-height: 18px; font-weight: 500;
}

/* Candidate chips */
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.chip {
  font-family: "Fredoka", sans-serif;
  font-size: 13px; font-weight: 500;
  background: var(--surface-2); color: var(--brand-strong);
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  padding: 7px 14px;
  cursor: pointer;
  transition: var(--transition);
  min-height: 34px; display: inline-flex; align-items: center;
}
.chip:hover { background: var(--brand); color: #fff; transform: translateY(-1px); box-shadow: 0 3px 8px rgba(245,158,11,.3); }
.chip:active { transform: translateY(0); }

/* AI status pill */
.ai-status {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 11px; font-weight: 700; color: var(--screen-soft);
  margin-top: 10px;
}
.ai-status .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; flex: none; }
.ai-status.loading { color: #fcd34d; }
.ai-status.loading .dot { animation: pulse 1s infinite; }
.ai-status.done { color: var(--screen-text); }
@keyframes pulse { 0%, 100% { opacity: 0.3; } 50% { opacity: 1; } }

/* ---------- Keypad ---------- */
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.key {
  font-family: "Fredoka", sans-serif;
  appearance: none;
  border: 1px solid var(--key-border);
  background: var(--key-bg);
  color: var(--key-text);
  border-radius: var(--radius);
  min-height: 64px;                 /* touch target ≥44px + visual weight */
  padding: 12px 0 11px;
  font-size: 24px; font-weight: 600;
  cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  box-shadow: var(--key-shadow);
  transition: transform var(--transition), box-shadow var(--transition), background var(--transition);
  user-select: none;
}
.key:hover { background: var(--key-bg-hover); }
.key:active {
  transform: translateY(3px);
  box-shadow: var(--key-shadow-active);
  background: var(--key-bg-active);
}
.key .letters {
  font-family: "Nunito", sans-serif;
  font-size: 10px; font-weight: 700; letter-spacing: 1.8px;
  color: var(--key-letters); text-transform: uppercase;
}
.key.fn {
  font-size: 16px; min-height: 56px;
  background: var(--surface-2);
  box-shadow: 0 2px 8px rgba(0,0,0,.08);
}
.key.fn .icon { width: 22px; height: 22px; color: var(--brand-strong); }
[data-theme="dark"] .key.fn .icon { color: var(--screen-text); }
.key.fn .label { font-family: "Nunito"; font-size: 10px; font-weight: 700; color: var(--muted); letter-spacing: 1px; text-transform: uppercase; }

/* Action row */
.row-actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 10px; }
.row-actions .key { min-height: 50px; font-size: 13px; box-shadow: none; border: 1px solid var(--border); }
.row-actions .key .icon { width: 20px; height: 20px; }

/* ---------- Install & footer ---------- */
.install-btn {
  display: none; width: 100%; margin-top: 12px;
  background: linear-gradient(135deg, var(--brand) 0%, #ea580c 100%);
  color: #fff; border: none;
  font-family: "Fredoka", sans-serif; font-weight: 500; font-size: 15px;
  padding: 13px; border-radius: var(--radius); cursor: pointer;
  min-height: 50px;
  box-shadow: 0 4px 14px rgba(245, 158, 11, 0.4);
  transition: var(--transition);
}
.install-btn:hover { transform: translateY(-1px); box-shadow: 0 6px 18px rgba(245,158,11,.5); }
.install-btn.show { display: flex; align-items: center; justify-content: center; gap: 8px; }
.install-btn svg { width: 20px; height: 20px; }

.footnote {
  text-align: center; color: var(--muted);
  font-size: 12px; line-height: 1.7; margin-top: 14px; font-weight: 500;
}
.footnote code {
  font-family: "Courier New", monospace;
  background: var(--surface-2); padding: 2px 6px; border-radius: 6px;
  font-size: 11px; color: var(--brand-strong);
}
.footnote b { color: var(--text); }

/* ---------- Animations ---------- */
.pop { animation: pop 0.35s cubic-bezier(0.34, 1.56, 0.64, 1); }
@keyframes pop {
  0% { transform: scale(0.88); opacity: 0.4; }
  60% { transform: scale(1.05); }
  100% { transform: scale(1); opacity: 1; }
}
.flash { animation: flash 0.9s ease; }
@keyframes flash { 0% { opacity: 0.5; } 100% { opacity: 1; } }

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

/* ---------- Responsive ---------- */
@media (max-width: 380px) {
  body { padding: 8px; }
  .app { padding: 18px 14px 14px; }
  .number-line { font-size: 22px; }
  .result .mnemonic { font-size: 24px; }
}
@media (min-width: 768px) {
  .app { max-width: 420px; }
}
