:root {
    --bg: #0f0f0f;
    --bg-card: #1a1916;
    --fg: #f0ebe3;
    --muted: #7a756b;
    --accent: #d4a24c;
    --accent-bright: #f0b94d;
    --border: #2a2822;
    --toggle-bg: #2a2822;
  }

  :root[data-theme="light"] {
    --bg: #f5f0e8;
    --bg-card: #fff;
    --fg: #1a1710;
    --muted: #8c8578;
    --accent: #b8832a;
    --accent-bright: #c9902f;
    --border: #ddd8ce;
    --toggle-bg: #e8e2d8;
  }

  * {
    box-sizing: border-box;
  }

  body {
    font-family: 'Space Grotesk', sans-serif;
    background: var(--bg);
    color: var(--fg);
    min-height: 100vh;
    margin: 0;
    overflow-x: hidden;
  }

  .bg-layer {
    position: fixed;
    inset: 0;
    z-index: 0;
    background: 
      radial-gradient(ellipse 100% 80% at 30% 0%, rgba(212, 162, 76, 0.06) 0%, transparent 50%),
      radial-gradient(ellipse 80% 60% at 70% 100%, rgba(212, 162, 76, 0.04) 0%, transparent 50%);
    pointer-events: none;
  }

  .noise-overlay {
    position: fixed;
    inset: 0;
    z-index: 0;
    opacity: 0.03;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)'/%3E%3C/svg%3E");
    pointer-events: none;
  }

  .main-container {
    position: relative;
    z-index: 1;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 2rem 1rem;
  }

  .title {
    font-family: 'Fraunces', serif;
    font-size: clamp(1.4rem, 4vw, 2.2rem);
    font-weight: 500;
    margin-bottom: 0.5rem;
    letter-spacing: -0.02em;
    color: var(--fg);
  }

  .subtitle {
    color: var(--muted);
    font-size: 0.9rem;
    margin-bottom: 2.5rem;
  }

  .word-display {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 2rem 3.5rem;
    margin-bottom: 1.5rem;
    min-width: 300px;
    text-align: center;
    position: relative;
    overflow: hidden;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
  }

  .word-display::before {
    content: '';
    position: absolute;
    top: 0;
    left: 20%;
    right: 20%;
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--accent), transparent);
    opacity: 0.6;
  }

  .generated-word {
    font-family: 'Fraunces', serif;
    font-size: clamp(2.5rem, 10vw, 4rem);
    font-weight: 500;
    color: var(--accent-bright);
    letter-spacing: 0.01em;
    min-height: 1.2em;
    line-height: 1;
  }

  .generated-word.appear {
    animation: wordReveal 0.35s cubic-bezier(0.22, 1, 0.36, 1);
  }

  @keyframes wordReveal {
    0% {
      opacity: 0;
      transform: translateY(15px);
      filter: blur(4px);
    }
    100% {
      opacity: 1;
      transform: translateY(0);
      filter: blur(0);
    }
  }

  .word-meta {
    font-size: 0.75rem;
    color: var(--muted);
    margin-top: 1rem;
    font-family: 'Space Grotesk', sans-serif;
    letter-spacing: 0.05em;
  }

  .word-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.6rem;
  }

  .copy-btn {
    position: relative;
    background: none;
    border: none;
    color: var(--muted);
    width: 2rem;
    height: 2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 0.9rem;
    flex-shrink: 0;
    align-self: center;
    transition: color 0.15s ease;
  }

  .copy-btn:hover {
    color: var(--accent);
  }

  .copy-btn.copied {
    color: var(--accent);
  }

  .copy-tooltip {
    position: absolute;
    bottom: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%) translateY(4px);
    background: var(--fg);
    color: var(--bg);
    font-size: 0.7rem;
    font-family: 'Space Grotesk', sans-serif;
    padding: 0.25rem 0.6rem;
    border-radius: 6px;
    white-space: nowrap;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.15s ease, transform 0.15s ease;
  }

  .copy-tooltip::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 4px solid transparent;
    border-top-color: var(--fg);
  }

  .copy-btn.copied .copy-tooltip {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }

  .phonetic {
    font-family: 'Space Grotesk', sans-serif;
    font-style: italic;
    color: var(--muted);
    font-size: 0.85rem;
    margin-top: 0.75rem;
    opacity: 0;
    transition: opacity 0.3s ease 0.1s;
  }

  .phonetic.visible {
    opacity: 1;
  }

  .generate-btn {
    background: var(--accent);
    border: none;
    color: var(--bg);
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 600;
    font-size: 0.95rem;
    padding: 0.8rem 2rem;
    border-radius: 50px;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.22, 1, 0.36, 1);
    position: relative;
    overflow: hidden;
  }

  .generate-btn::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(180deg, rgba(255,255,255,0.15) 0%, transparent 50%);
    pointer-events: none;
  }

  .generate-btn:hover {
    background: var(--accent-bright);
    transform: translateY(-2px);
    box-shadow: 0 8px 32px rgba(212, 162, 76, 0.3);
  }

  .generate-btn:active {
    transform: translateY(0) scale(0.98);
  }

  .generate-btn:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 3px;
  }

  .history-section {
    margin-top: 2.5rem;
    width: 100%;
    max-width: 480px;
  }

  .history-header {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1rem;
  }

  .history-line {
    flex: 1;
    height: 1px;
    background: var(--border);
  }

  .history-title {
    font-size: 0.7rem;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.12em;
  }

  .history-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    justify-content: center;
  }

  .history-item {
    background: transparent;
    border: 1px solid var(--border);
    padding: 0.35rem 0.9rem;
    border-radius: 20px;
    font-size: 0.85rem;
    color: var(--muted);
    font-family: 'Fraunces', serif;
    transition: all 0.2s ease;
    cursor: default;
  }

  .history-item:hover {
    border-color: var(--accent);
    color: var(--fg);
  }

  .history-item {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
  }

  .history-copy-btn {
    position: relative;
    background: none;
    border: none;
    padding: 0;
    color: var(--muted);
    font-size: 0.75rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    opacity: 1;
    transition: opacity 0.15s ease, color 0.15s ease;
    line-height: 1;
  }

  .history-item:hover .history-copy-btn {
    opacity: 1;
  }

  .history-copy-btn:hover {
    color: var(--accent);
  }

  .history-copy-btn.copied {
    color: var(--accent);
    opacity: 1;
  }

  @keyframes historyPop {
    0% {
      opacity: 0;
      transform: scale(0.85);
    }
    100% {
      opacity: 1;
      transform: scale(1);
    }
  }

  .history-item.latest {
    color: var(--fg);
    border-color: var(--accent);
    background: rgba(212, 162, 76, 0.1);
    animation: historyPop 0.25s cubic-bezier(0.22, 1, 0.36, 1);
  }

  .empty-state {
    color: var(--muted);
    font-style: italic;
    font-size: 0.85rem;
    font-family: 'Space Grotesk', sans-serif;
  }

  .keyboard-hint {
    margin-top: 1rem;
    font-size: 0.7rem;
    color: var(--muted);
    opacity: 0.6;
  }

  .keyboard-hint kbd {
    background: var(--bg-card);
    border: 1px solid var(--border);
    color: var(--fg);
    padding: 0.15rem 0.4rem;
    border-radius: 4px;
    font-family: inherit;
    font-size: 0.65rem;
  }

  @media (prefers-reduced-motion: reduce) {
    .generated-word.appear,
    .history-item.latest {
      animation: none;
    }
    .generate-btn {
      transition: none;
    }
  }

  /* ── Theme Toggle ── */
  .theme-toggle {
    position: fixed;
    bottom: 1.25rem;
    right: 1.25rem;
    z-index: 100;
    background: var(--toggle-bg);
    border: 1px solid var(--border);
    border-radius: 50px;
    width: 2.5rem;
    height: 2.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 1rem;
    transition: background 0.2s ease, border-color 0.2s ease, transform 0.15s ease;
  }

  .theme-toggle:hover {
    transform: scale(1.1);
    border-color: var(--accent);
  }

  .theme-toggle .bi {
    color: var(--accent);
    font-size: 1rem;
    line-height: 1;
  }

  .theme-icon { display: none; }
  .theme-icon--dark  { display: block; }
  [data-theme="light"] .theme-icon--dark  { display: none; }
  [data-theme="light"] .theme-icon--light { display: block; }

  /* ── Footer ── */
  .site-footer {
    margin-top: 3rem;
    font-size: 0.75rem;
    color: var(--muted);
    display: flex;
    align-items: center;
    gap: 0.6rem;
  }

  .site-footer a {
    color: var(--muted);
    text-decoration: none;
    transition: color 0.15s ease;
  }

  .site-footer a:hover {
    color: var(--accent);
  }

  .footer-sep {
    opacity: 0.4;
  }

  /* ── How It Works page ── */
  .hiw-container {
    justify-content: flex-start;
    padding-top: 3rem;
    padding-bottom: 3rem;
  }

  .hiw-back {
    width: 100%;
    max-width: 640px;
    margin-bottom: 1.5rem;
  }

  .back-link {
    font-size: 0.8rem;
    color: var(--muted);
    text-decoration: none;
    transition: color 0.15s ease;
  }

  .back-link:hover {
    color: var(--accent);
  }

  .hiw-content {
    width: 100%;
    max-width: 640px;
    margin-top: 2rem;
    display: flex;
    flex-direction: column;
    gap: 2rem;
  }

  .hiw-section {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 1.5rem 2rem;
  }

  .hiw-heading {
    font-family: 'Fraunces', serif;
    font-size: 1.1rem;
    font-weight: 500;
    color: var(--accent-bright);
    margin-bottom: 0.75rem;
  }

  .hiw-section p,
  .hiw-section ul {
    font-size: 0.9rem;
    color: var(--fg);
    line-height: 1.7;
    margin-bottom: 0.5rem;
  }

  .hiw-section ul {
    padding-left: 1.25rem;
  }

  .hiw-section li {
    margin-bottom: 0.3rem;
  }

  .hiw-section strong {
    color: var(--fg);
  }

  .hiw-section em {
    color: var(--accent);
    font-style: normal;
  }

  .hiw-table-wrap {
    overflow-x: auto;
  }

  .hiw-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
    margin-top: 0.5rem;
  }

  .hiw-table th,
  .hiw-table td {
    text-align: left;
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid var(--border);
  }

  .hiw-table th {
    color: var(--muted);
    font-weight: 600;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.07em;
  }

  .hiw-table tr:last-child td {
    border-bottom: none;
  }

  .hiw-code {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.75rem 1rem;
    font-size: 0.82rem;
    color: var(--accent);
    font-family: 'Space Grotesk', monospace;
    margin-top: 0.75rem;
    white-space: pre;
    overflow-x: auto;
  }

  .hiw-section code {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 0.1rem 0.4rem;
    font-size: 0.82rem;
    color: var(--accent);
    font-family: 'Space Grotesk', monospace;
  }

  /* ── Examples page ── */
  .examples-note {
    font-size: 0.8rem;
    color: var(--muted);
    font-style: italic;
    margin-bottom: 1rem;
  }

  .examples-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
  }

  .examples-grid span {
    font-family: 'Fraunces', serif;
    font-size: 0.95rem;
    color: var(--fg);
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 0.3rem 0.9rem;
    transition: border-color 0.15s ease, color 0.15s ease;
  }

  .examples-grid span:hover {
    border-color: var(--accent);
    color: var(--accent-bright);
  }

  /* ── Index SEO Section ── */
  .seo-section {
    width: 100%;
    max-width: 640px;
    margin-top: 3.5rem;
    display: flex;
    flex-direction: column;
    gap: 2.5rem;
  }

  .seo-heading {
    font-family: 'Fraunces', serif;
    font-size: 1.15rem;
    font-weight: 500;
    color: var(--fg);
    margin-bottom: 1rem;
  }

  .seo-intro p {
    font-size: 0.9rem;
    color: var(--muted);
    line-height: 1.7;
    margin-bottom: 0.6rem;
    text-align: justify;
  }

  .seo-intro strong {
    color: var(--fg);
  }

  .seo-features {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
  }

  .seo-feature {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 1.1rem 1.25rem;
  }

  .seo-feature-icon {
    font-size: 1.2rem;
    color: var(--accent);
    display: block;
    margin-bottom: 0.5rem;
  }

  .seo-feature h3 {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--fg);
    margin-bottom: 0.3rem;
  }

  .seo-feature p {
    font-size: 0.8rem;
    color: var(--muted);
    line-height: 1.5;
    margin: 0;
  }

  .seo-cards {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
  }

  .seo-card {
    display: flex;
    align-items: center;
    gap: 1rem;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 1rem 1.25rem;
    text-decoration: none;
    color: var(--fg);
    transition: border-color 0.15s ease;
  }

  .seo-card:hover {
    border-color: var(--accent);
    color: var(--fg);
  }

  .seo-card-icon {
    font-size: 1.4rem;
    color: var(--accent);
    flex-shrink: 0;
  }

  .seo-card strong {
    display: block;
    font-size: 0.9rem;
    margin-bottom: 0.2rem;
  }

  .seo-card span {
    font-size: 0.8rem;
    color: var(--muted);
  }

  .faq-item {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    margin-bottom: 0.6rem;
    overflow: hidden;
  }

  .faq-question {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--fg);
    padding: 1rem 1.25rem;
    cursor: pointer;
    list-style: none;
    display: flex;
    justify-content: space-between;
    align-items: center;
    user-select: none;
  }

  .faq-question::-webkit-details-marker { display: none; }

  .faq-question::after {
    content: '\002B';
    font-size: 1rem;
    color: var(--muted);
  }

  details[open] .faq-question::after {
    content: '\2212';
  }

  .faq-answer {
    font-size: 0.85rem;
    color: var(--muted);
    line-height: 1.7;
    padding: 0 1.25rem 1rem;
    margin: 0;
  }

  @media (max-width: 480px) {
    .seo-features {
      grid-template-columns: 1fr;
    }
  }