/* ── CSS Custom Properties ── */
:root {
  --gold: #B8860B;
  --gold-light: #F0C040;
  --gold-bg: #F9F5E7;
  --gold-border: #F0E8C0;
  --white: #FFFFFF;
  --bg: #F5F5F5;
  --text: #1A1A2E;
  --text-secondary: #666666;
  --text-muted: #AAAAAA;
  --green: #16A34A;
  --green-bg: #F0FDF4;
  --green-border: #86efac;
  --orange: #EA580C;
  --red: #DC2626;
  --blue: #2563EB;
  --purple: #7C3AED;
  --purple-bg: #F3E8FF;
  --purple-border: #D4A0FF;
  --border: #E2E8F0;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 2px 8px rgba(0,0,0,0.08);
  --nav-height: 60px;
}

/* ── Reset + Base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; background: var(--bg); color: var(--text); }
body { display: flex; flex-direction: column; }
button { cursor: pointer; border: none; background: none; font: inherit; }
input, select { font: inherit; }
.hidden { display: none !important; }

/* ── App container ── */
#app { flex: 1; overflow: hidden; position: relative; max-width: 480px; margin: 0 auto; width: 100%; background: var(--white); }

/* ── Views ── */
.view { display: flex; flex-direction: column; height: calc(100vh - var(--nav-height)); overflow-y: auto; }
.view.hidden { display: none !important; }
.view-body { padding: 16px; display: flex; flex-direction: column; gap: 12px; }

/* ── Headers ── */
.view-header { padding: 16px; flex-shrink: 0; }
.gold-header { background: var(--gold); color: white; }
.gold-header h1, .gold-header h2 { color: white; font-size: 20px; }
.gold-header .subtitle { color: rgba(255,255,255,0.8); font-size: 13px; }
.gold-header .search-input { background: rgba(255,255,255,0.2); border: none; color: white; border-radius: var(--radius-sm); padding: 8px 12px; width: 100%; margin-top: 8px; font-size: 14px; }
.gold-header .search-input::placeholder { color: rgba(255,255,255,0.7); }
.header-row { display: flex; justify-content: space-between; align-items: center; }
.greeting-text { font-size: 12px; color: rgba(255,255,255,0.8); }
.header-date { font-size: 18px; color: white; font-weight: bold; }

/* ── Buttons ── */
.btn-primary { background: var(--gold); color: white; padding: 12px 24px; border-radius: var(--radius); font-size: 15px; font-weight: 600; letter-spacing: 0.3px; transition: opacity 0.15s; }
.btn-primary:active { opacity: 0.85; }
.btn-secondary { background: var(--gold-bg); color: var(--gold); border: 1.5px solid var(--gold-border); padding: 10px 16px; border-radius: var(--radius); font-size: 13px; font-weight: 500; }
.btn-secondary.small { padding: 6px 12px; font-size: 12px; }
.btn-danger { background: #FEE2E2; color: var(--red); border-radius: var(--radius); padding: 12px; font-size: 14px; font-weight: 600; }
.text-btn { color: var(--text-secondary); font-size: 13px; padding: 4px 0; }
.full-width { width: 100%; }

/* ── PIN ── */
.pin-input { font-size: 24px; letter-spacing: 8px; text-align: center; border: 2px solid var(--border); border-radius: var(--radius); padding: 14px 20px; width: 180px; }
.pin-input:focus { outline: none; border-color: var(--gold); }
.error-msg { color: var(--red); font-size: 13px; margin-top: 8px; }
.success-msg { color: var(--green); font-size: 13px; margin-top: 8px; }

/* ── Home stats ── */
.stats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat-card { background: white; border-radius: var(--radius); padding: 16px; text-align: center; border: 1.5px solid var(--border); }
.stat-card.gold-border { border-color: var(--gold-light); }
.stat-card.green-border { border-color: var(--green-border); }
.stat-number { font-size: 28px; font-weight: bold; }
.gold-text { color: var(--gold); }
.green-text { color: var(--green); }
.stat-label { font-size: 11px; color: var(--text-muted); margin-top: 2px; }
.streak-card { background: white; border-radius: var(--radius); padding: 14px; border: 1.5px solid var(--border); }
.streak-label { font-size: 12px; color: var(--text-secondary); margin-bottom: 8px; }
.streak-dots { display: flex; gap: 4px; }
.streak-dot { flex: 1; height: 6px; border-radius: 3px; }
.streak-dot.done { background: var(--gold-light); }
.streak-dot.empty { background: var(--border); }
.mode-row { display: flex; gap: 8px; }
.mode-row .btn-secondary { flex: 1; }

/* ── Study view ── */
.study-header { display: flex; justify-content: space-between; align-items: center; padding: 10px 16px; background: var(--gold-bg); border-bottom: 1px solid var(--gold-border); flex-shrink: 0; }
.progress-bar-thin { height: 3px; background: var(--gold-border); flex-shrink: 0; }
.progress-fill { height: 100%; background: var(--gold); transition: width 0.3s ease; }

/* ── Flashcard ── */
.flashcard { background: white; border: 2px solid var(--gold-light); border-radius: 18px; padding: 28px 20px; text-align: center; box-shadow: 0 4px 16px rgba(184,134,11,0.1); cursor: pointer; transition: transform 0.15s; }
.flashcard:active { transform: scale(0.98); }
.flashcard-lang { font-size: 10px; color: var(--gold); letter-spacing: 1px; text-transform: uppercase; margin-bottom: 12px; }
.flashcard-thai { font-size: 36px; color: var(--text); margin-bottom: 8px; line-height: 1.3; }
.flashcard-rtgs { font-size: 14px; color: var(--text-muted); margin-bottom: 16px; }
.flashcard-divider { border: none; border-top: 1px solid var(--gold-border); margin: 12px 0; }
.flashcard-meaning { font-size: 18px; font-weight: bold; color: var(--text); margin-bottom: 10px; }
.phonetic-tags { display: flex; justify-content: center; gap: 8px; flex-wrap: wrap; }
.tag { border-radius: 6px; padding: 3px 10px; font-size: 12px; }
.tag-zh { background: #FFF8E1; border: 1px solid var(--gold-light); color: var(--gold); }
.tag-zhuyin { background: var(--purple-bg); border: 1px solid var(--purple-border); color: var(--purple); }
.card-hint { font-size: 11px; color: var(--text-muted); margin-top: 8px; }
.rating-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.rating-btn { border-radius: var(--radius-sm); padding: 10px 4px; font-size: 11px; font-weight: bold; display: flex; flex-direction: column; align-items: center; gap: 2px; }
.rating-btn .next-time { font-size: 9px; opacity: 0.7; font-weight: normal; }
.rating-btn.again { background: #FEE2E2; color: var(--red); }
.rating-btn.hard { background: #FFF7ED; color: var(--orange); }
.rating-btn.good { background: var(--green-bg); color: var(--green); }
.rating-btn.easy { background: #EFF6FF; color: var(--blue); }

/* ── Quiz ── */
.quiz-question { background: white; border-radius: var(--radius); padding: 24px 16px; text-align: center; box-shadow: var(--shadow); }
.quiz-prompt { font-size: 11px; color: var(--text-muted); margin-bottom: 10px; }
.quiz-thai { font-size: 32px; margin-bottom: 6px; }
.quiz-rtgs { font-size: 13px; color: var(--text-muted); }
.quiz-options { display: flex; flex-direction: column; gap: 8px; }
.quiz-option { background: white; border: 2px solid var(--border); border-radius: var(--radius); padding: 12px 14px; font-size: 13px; display: flex; align-items: center; gap: 10px; text-align: left; transition: border-color 0.2s, background 0.2s; }
.quiz-option .option-letter { width: 24px; height: 24px; border-radius: 50%; background: var(--bg); display: flex; align-items: center; justify-content: center; font-size: 11px; flex-shrink: 0; }
.quiz-option.correct { border-color: var(--green); background: var(--green-bg); }
.quiz-option.correct .option-letter { background: var(--green); color: white; }
.quiz-option.wrong { border-color: var(--red); background: #FEF2F2; }
.quiz-option.wrong .option-letter { background: var(--red); color: white; }
.quiz-next-btn { background: var(--gold); color: white; padding: 12px; border-radius: var(--radius); font-size: 14px; font-weight: bold; width: 100%; }

/* ── Session complete ── */
.session-complete { text-align: center; padding: 32px 16px; }
.session-complete .big-emoji { font-size: 60px; margin-bottom: 16px; }
.session-complete h2 { font-size: 22px; margin-bottom: 8px; }
.session-complete p { color: var(--text-secondary); margin-bottom: 24px; }

/* ── Word list ── */
.category-tabs { display: flex; gap: 8px; padding: 10px 14px; overflow-x: auto; scrollbar-width: none; background: white; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.category-tabs::-webkit-scrollbar { display: none; }
.cat-tab { white-space: nowrap; padding: 5px 12px; border-radius: 20px; font-size: 12px; border: 1.5px solid transparent; flex-shrink: 0; }
.cat-tab.active { background: var(--gold); color: white; }
.cat-tab:not(.active) { background: var(--gold-bg); color: var(--gold); border-color: var(--gold-border); }
.word-list { display: flex; flex-direction: column; gap: 6px; }
.word-item { display: flex; align-items: center; padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius); gap: 10px; background: white; cursor: pointer; }
.word-item:active { background: var(--gold-bg); }
.status-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.status-dot.mastered { background: var(--green); }
.status-dot.review { background: var(--gold-light); }
.status-dot.learning { background: var(--orange); }
.status-dot.new { background: var(--border); }
.word-item-body { flex: 1; min-width: 0; }
.word-item-thai { font-size: 16px; }
.word-item-sub { font-size: 11px; color: var(--text-muted); }
.word-item-state { font-size: 10px; color: var(--text-muted); white-space: nowrap; }

/* ── Word detail ── */
.word-detail-card { background: var(--gold-bg); border: 1.5px solid var(--gold-border); border-radius: var(--radius); padding: 24px; text-align: center; margin-bottom: 12px; }
.word-detail-thai { font-size: 40px; margin-bottom: 8px; }
.word-detail-rtgs { font-size: 15px; color: var(--text-muted); margin-bottom: 16px; }
.word-detail-meaning { font-size: 22px; font-weight: bold; margin-bottom: 12px; }
.word-detail-meta { font-size: 11px; color: var(--text-muted); }
.word-detail-section { background: white; border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; }
.word-detail-row { display: flex; justify-content: space-between; align-items: center; padding: 6px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.word-detail-row:last-child { border-bottom: none; }

/* ── Forms ── */
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group label { font-size: 13px; color: var(--text-secondary); font-weight: 500; }
.form-group input, .form-group select { border: 1.5px solid var(--border); border-radius: var(--radius-sm); padding: 10px 12px; font-size: 14px; }
.form-group input:focus, .form-group select:focus { outline: none; border-color: var(--gold); }

/* ── Settings ── */
.settings-section-label { font-size: 10px; color: var(--gold); font-weight: bold; letter-spacing: 0.8px; text-transform: uppercase; margin-bottom: 6px; }
.settings-card { background: white; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; margin-bottom: 16px; }
.settings-row { display: flex; justify-content: space-between; align-items: center; padding: 12px 14px; border-bottom: 1px solid var(--border); }
.settings-row:last-child { border-bottom: none; }
.settings-title { font-size: 13px; font-weight: 500; }
.settings-hint { font-size: 11px; color: var(--text-muted); margin-top: 2px; }
.counter { display: flex; align-items: center; gap: 10px; }
.counter-btn { width: 28px; height: 28px; border-radius: 50%; background: var(--border); font-size: 16px; display: flex; align-items: center; justify-content: center; }
.counter-btn.gold { background: var(--gold); color: white; }
.counter span { min-width: 24px; text-align: center; font-weight: bold; color: var(--gold); }
/* Toggle switch */
.toggle { position: relative; display: inline-block; width: 36px; height: 20px; }
.toggle input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; inset: 0; background: var(--border); border-radius: 20px; transition: background 0.2s; }
.slider::before { content: ''; position: absolute; width: 14px; height: 14px; background: white; border-radius: 50%; top: 3px; left: 3px; transition: transform 0.2s; }
.toggle input:checked + .slider { background: var(--gold); }
.toggle input:checked + .slider::before { transform: translateX(16px); }
.sync-card { display: flex; justify-content: space-between; align-items: center; background: var(--gold-bg); border: 1.5px solid var(--gold-border); border-radius: var(--radius); padding: 12px 14px; }

/* ── Utility / layout fixes ── */
.word-list-empty { text-align: center; color: var(--text-muted); padding: 24px; }
.word-detail-phonetics { justify-content: center; gap: 8px; display: flex; flex-wrap: wrap; margin-bottom: 8px; }
.card-hint-category { color: var(--gold); margin-top: 8px; }

/* ── Bottom nav ── */
#bottom-nav { height: var(--nav-height); display: flex; background: white; border-top: 1px solid var(--border); max-width: 480px; margin: 0 auto; width: 100%; flex-shrink: 0; }
.nav-item { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: 18px; color: var(--text-muted); padding: 6px; }
.nav-item span { font-size: 9px; }
.nav-item.active { color: var(--gold); }
#nav-logo { display: none; }

/* ── Speak / TTS button ── */
.speak-btn { background: var(--gold-bg); border: 1.5px solid var(--gold-border); border-radius: 50%; width: 40px; height: 40px; font-size: 20px; display: inline-flex; align-items: center; justify-content: center; margin: 6px auto; cursor: pointer; transition: background 0.15s, transform 0.1s; flex-shrink: 0; }
.speak-btn:active { background: var(--gold); transform: scale(0.9); }
.speak-btn-lg { width: 48px; height: 48px; font-size: 24px; margin: 12px auto; display: flex; }

/* ── Desktop responsive (≥ 768px) ── */
@media (min-width: 768px) {
  /* App wider on desktop */
  #app { max-width: 680px; box-shadow: 0 0 30px rgba(0,0,0,0.07); }

  /* Nav becomes left sidebar when visible */
  body.nav-visible { padding-left: 220px; }
  body.nav-visible #app { max-width: 760px; }

  body.nav-visible #bottom-nav {
    position: fixed;
    left: 0; top: 0; bottom: 0;
    height: 100vh; width: 220px;
    flex-direction: column;
    justify-content: flex-start;
    align-items: stretch;
    padding: 28px 12px 24px;
    gap: 4px;
    max-width: 220px;
    margin: 0;
    border-top: none;
    border-right: 1px solid var(--border);
    box-shadow: 2px 0 12px rgba(0,0,0,0.05);
  }

  /* Nav logo — desktop only */
  #nav-logo {
    display: block;
    font-size: 15px;
    font-weight: bold;
    color: var(--gold);
    padding: 0 8px 18px;
    border-bottom: 1px solid var(--gold-border);
    margin-bottom: 10px;
    letter-spacing: 0.3px;
  }

  /* Nav items: horizontal (icon + text side by side) */
  .nav-item {
    flex-direction: row;
    justify-content: flex-start;
    gap: 12px;
    padding: 12px 16px;
    border-radius: var(--radius);
    font-size: 20px;
    flex: none;
    width: 100%;
  }
  .nav-item span { font-size: 14px; font-weight: 500; }
  .nav-item.active { background: var(--gold-bg); }

  /* View full height (no bottom nav offset) */
  .view { height: 100vh; }
  .view-body { padding: 20px 28px; gap: 16px; }

  /* Bigger flashcard */
  .flashcard { padding: 44px 36px; }
  .flashcard-thai { font-size: 54px; }
  .flashcard-meaning { font-size: 22px; }

  /* Bigger quiz */
  .quiz-thai { font-size: 46px; }
  .quiz-question { padding: 32px 24px; }
  .quiz-option { padding: 14px 18px; font-size: 15px; }

  /* Rating buttons bigger */
  .rating-grid { gap: 10px; }
  .rating-btn { padding: 14px 6px; font-size: 13px; }
  .rating-btn .next-time { font-size: 11px; }

  /* Word detail bigger */
  .word-detail-thai { font-size: 56px; }
  .word-detail-meaning { font-size: 26px; }

  /* Home stats */
  .stat-number { font-size: 36px; }

  /* Headers taller */
  .view-header { padding: 20px 28px; }
  .gold-header h1, .gold-header h2 { font-size: 24px; }
  .header-date { font-size: 22px; }
}
