/* ── Tokens ── */
:root {
  --blue: #1cb0f6;
  --blue-dim: #d4f0fd;
  --gold: #ffa41b;
  --bg: #f0f4f8;
  --card: #ffffff;
  --text: #1a1a2e;
  --roman: #4a7fa5;
  --muted: #8a96a8;
  --border: #e2e8f0;
  --shadow-sm: 0 1px 4px rgba(0,0,0,0.06);
  --shadow-md: 0 3px 12px rgba(0,0,0,0.09);
  --r: 18px;
}

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
}

/* ════════════════════════════════
   HOME VIEW
════════════════════════════════ */
.home-header {
  background: var(--blue);
  padding: 2.5rem 1.5rem 2rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  color: white;
}

.home-flag { font-size: 2.8rem; line-height: 1; }

.home-title {
  font-size: 1.7rem;
  font-weight: 900;
  letter-spacing: -0.02em;
  line-height: 1.1;
  color: white;
}

.home-sub {
  font-size: 1rem;
  opacity: 0.85;
  font-weight: 400;
  margin-top: 2px;
}

/* ── Search bar ── */
.search-bar-wrap {
  background: white;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
}

.search-bar {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  background: var(--bg);
  border: 1.5px solid var(--border);
  border-radius: 14px;
  padding: 0.55rem 0.9rem;
  max-width: 600px;
  margin: 0 auto;
  transition: border-color 0.15s;
}
.search-bar:focus-within {
  border-color: var(--blue);
  background: white;
}

.search-icon { color: var(--muted); flex-shrink: 0; }

.search-input {
  flex: 1;
  border: none;
  background: transparent;
  font-size: 0.95rem;
  color: var(--text);
  outline: none;
  min-width: 0;
}
.search-input::placeholder { color: var(--muted); }
.search-input::-webkit-search-cancel-button { display: none; }

.search-clear {
  border: none;
  background: var(--border);
  color: var(--muted);
  border-radius: 50%;
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  padding: 0;
}
.search-clear:hover { background: var(--muted); color: white; }

/* ── Today card ── */
.today-card {
  background: var(--blue);
  border-radius: var(--r);
  padding: 1.2rem 1.1rem 1.2rem 1.3rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  cursor: pointer;
  margin-bottom: 1.4rem;
  transition: opacity 0.15s;
  -webkit-user-select: none;
  user-select: none;
}
.today-card:active { opacity: 0.88; }

.today-left { display: flex; flex-direction: column; gap: 0.25rem; }

.today-badge {
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.75);
}

.today-emoji { font-size: 2rem; line-height: 1; margin: 0.2rem 0; }

.today-title {
  font-size: 1.35rem;
  font-weight: 900;
  color: white;
  letter-spacing: -0.02em;
}

.today-meta {
  font-size: 0.78rem;
  color: rgba(255,255,255,0.7);
  font-weight: 500;
}

.today-arrow { color: rgba(255,255,255,0.8); flex-shrink: 0; }

/* ── Search results ── */
.search-count {
  font-size: 0.8rem;
  color: var(--muted);
  font-weight: 600;
  margin-bottom: 1rem;
}

.search-empty {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--muted);
  font-size: 0.95rem;
}

.search-word-list,
.search-sent-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.search-topic-badge {
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--blue);
  background: var(--blue-dim);
  padding: 0.15rem 0.5rem;
  border-radius: 20px;
  display: inline-block;
  margin-bottom: 0.35rem;
  width: fit-content;
}

.search-word-row {
  background: var(--card);
  border: none;
  border-radius: 14px;
  box-shadow: var(--shadow-sm);
  padding: 0.8rem 0.9rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  cursor: pointer;
  text-align: left;
  width: 100%;
  transition: box-shadow 0.15s;
}
.search-word-row:active { box-shadow: none; }

.search-word-body {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  flex: 1;
  min-width: 0;
}

.search-word-thai  { font-size: 1.25rem; font-weight: 700; color: var(--text); }
.search-word-roman { font-size: 0.75rem; color: var(--roman); font-style: italic; font-weight: 600; }
.search-word-english { font-size: 0.78rem; color: var(--muted); font-weight: 600; }

.search-sent-row {
  background: var(--card);
  border: none;
  border-radius: 14px;
  box-shadow: var(--shadow-sm);
  padding: 0.9rem 1rem;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.25rem;
  cursor: pointer;
  text-align: left;
  width: 100%;
  transition: box-shadow 0.15s;
}
.search-sent-row:active { box-shadow: none; }
.search-sent-thai    { font-size: 1.05rem; font-weight: 600; color: var(--text); line-height: 1.4; }
.search-sent-english { font-size: 0.82rem; color: var(--muted); font-weight: 500; }

/* ── Home main ── */
.home-main {
  padding: 1.2rem 1rem 5rem;
  max-width: 600px;
  margin: 0 auto;
}

.home-intro {
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 1rem;
  padding-left: 2px;
}

/* ── Subject grid ── */
.subject-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.subject-card {
  background: var(--card);
  border: none;
  border-radius: var(--r);
  box-shadow: var(--shadow-md);
  padding: 1.4rem 1rem 1.2rem;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.35rem;
  cursor: pointer;
  text-align: left;
  width: 100%;
  transition: transform 0.13s, box-shadow 0.13s;
  -webkit-user-select: none;
  user-select: none;
}
.subject-card:active {
  transform: scale(0.97);
  box-shadow: var(--shadow-sm);
}

.subject-card-emoji {
  font-size: 2rem;
  line-height: 1;
  margin-bottom: 0.2rem;
}
.subject-card-title {
  font-size: 1rem;
  font-weight: 800;
  color: var(--text);
  line-height: 1.2;
}
.subject-card-count {
  font-size: 0.72rem;
  color: var(--muted);
  font-weight: 500;
}

/* ════════════════════════════════
   SUBJECT VIEW
════════════════════════════════ */
.subject-header {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 0 0.75rem;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
}

.subject-header-title {
  font-size: 0.95rem;
  font-weight: 800;
  color: var(--text);
  flex: 1;
  text-align: center;
}

.icon-btn {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  border: none;
  background: transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text);
  transition: background 0.15s;
  flex-shrink: 0;
}
.icon-btn:hover, .icon-btn:active { background: var(--bg); }

.print-icon-btn { color: var(--gold); }

/* ── Topic hero ── */
.subject-main {
  max-width: 600px;
  margin: 0 auto;
  padding: 1.2rem 1rem 5rem;
  display: flex;
  flex-direction: column;
  gap: 1.4rem;
}

.topic-hero {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  background: var(--card);
  border-radius: var(--r);
  padding: 1.3rem 1.4rem;
  box-shadow: var(--shadow-md);
}

.topic-emoji { font-size: 2.4rem; line-height: 1; }

.topic-title {
  font-size: 1.5rem;
  font-weight: 900;
  color: var(--text);
  letter-spacing: -0.02em;
}

/* ── Section label ── */
.section-label {
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 0.65rem;
  padding-left: 2px;
}

/* ── Breakdown button ── */
.breakdown-btn {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  border: 1.5px solid var(--border);
  background: var(--card);
  color: var(--muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.breakdown-btn:hover  { background: #f3f4f6; border-color: #9aa5b4; color: var(--text); }
.breakdown-btn:active { transform: scale(0.93); }

/* ── Sentence actions group ── */
.sentence-actions {
  display: flex;
  gap: 0.4rem;
  flex-shrink: 0;
}

/* ── Audio button ── */
.audio-btn {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  border: 1.5px solid var(--border);
  background: var(--card);
  color: var(--blue);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s, border-color 0.15s;
}
.audio-btn:hover  { background: var(--blue-dim); border-color: var(--blue); }
.audio-btn:active { background: var(--blue-dim); border-color: var(--blue); transform: scale(0.93); }

/* ── Word grid ── */
.word-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.65rem;
}

.word-card {
  background: var(--card);
  border-radius: var(--r);
  box-shadow: var(--shadow-sm);
  padding: 0.9rem 0.9rem 0.85rem;
  border-top: 3px solid var(--blue-dim);
}

.word-card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.4rem;
  margin-bottom: 0.2rem;
}

.word-thai {
  font-size: 1.45rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.25;
  flex: 1;
}

.word-roman {
  font-size: 0.78rem;
  color: var(--roman);
  font-style: italic;
  font-weight: 600;
  margin-bottom: 0.12rem;
}

.word-english {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
}

/* ── Sentences ── */
.sentences {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.sentence-card {
  background: var(--card);
  border-radius: var(--r);
  box-shadow: var(--shadow-sm);
  padding: 1.1rem 1.1rem 1rem;
}

.sentence-top {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  margin-bottom: 0.5rem;
}

.sentence-thai {
  font-size: 1.15rem;
  font-weight: 500;
  color: var(--text);
  line-height: 1.6;
  flex: 1;
}

.sentence-thai .hl {
  font-weight: 800;
  color: var(--blue);
}

.sentence-roman {
  font-size: 0.8rem;
  color: var(--roman);
  font-style: italic;
  font-weight: 500;
  margin-bottom: 0.25rem;
  border-top: 1px solid var(--border);
  padding-top: 0.4rem;
}

.sentence-english {
  font-size: 0.84rem;
  color: var(--muted);
  font-weight: 500;
}

/* ════════════════════════════════
   BREAKDOWN MODAL
════════════════════════════════ */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 200;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.22s ease;
}
.modal-backdrop.open { opacity: 1; }

.modal-sheet {
  background: var(--card);
  border-radius: 24px 24px 0 0;
  width: 100%;
  max-width: 600px;
  max-height: 85vh;
  overflow-y: auto;
  padding: 1.2rem 1.2rem 2.5rem;
  transform: translateY(40px);
  transition: transform 0.25s ease;
}
.modal-backdrop.open .modal-sheet { transform: translateY(0); }

.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 1.2rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}

.modal-sentence {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.5;
  flex: 1;
}

.modal-close {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: 1.5px solid var(--border);
  background: var(--bg);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  flex-shrink: 0;
  transition: background 0.15s;
}
.modal-close:hover { background: #f3f4f6; color: var(--text); }

.modal-words {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.modal-word-row {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  background: var(--bg);
  border-radius: 14px;
  padding: 0.75rem 0.9rem;
}

.modal-word-main {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  flex: 1;
  min-width: 0;
}

.modal-word-thai {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.2;
}

.modal-word-roman {
  font-size: 0.78rem;
  color: var(--roman);
  font-style: italic;
  font-weight: 600;
}

.modal-word-english {
  font-size: 0.82rem;
  color: var(--muted);
  font-weight: 600;
  flex: 1;
  text-align: right;
  min-width: 0;
}

/* ════════════════════════════════
   RESPONSIVE — tablet / desktop
════════════════════════════════ */
@media (min-width: 540px) {
  .subject-grid { grid-template-columns: repeat(3, 1fr); }
  .word-grid { grid-template-columns: repeat(3, 1fr); }
  .home-main { padding: 1.5rem 1.5rem 5rem; }
  .subject-main { padding: 1.5rem 1.5rem 5rem; }
}

@media (min-width: 760px) {
  .subject-grid { grid-template-columns: repeat(4, 1fr); }
  .word-grid { grid-template-columns: repeat(4, 1fr); }
}

/* ════════════════════════════════
   PRINT
════════════════════════════════ */
@media print {
  #view-home { display: none !important; }
  .subject-header { display: none !important; }
  .audio-btn, .breakdown-btn, .sentence-actions, .modal-backdrop { display: none !important; }

  body { background: white; }

  .subject-main {
    max-width: 100%;
    padding: 1cm 1.2cm 1.5cm;
  }

  .topic-hero, .word-card, .sentence-card {
    box-shadow: none;
    border: 1px solid #ddd;
    break-inside: avoid;
  }

  .word-grid, .sentences { break-inside: avoid; }

  .sentence-thai .hl { color: #0d7ab8; font-weight: 800; }

  @page { size: A4; margin: 1cm 1.2cm; }
}
