/* Classical Thai poetry page */
:root {
  --bg: #e2ebe8;
  --card: #f4faf7;
  --text: #0f172a;
  --muted: #5b6b7c;
  --border: #b5c9c2;
  --accent: #0f5c4c;
  --accent-soft: #d1fae5;
  --ink: #134e4a;
  --gold: #b45309;
  --thai: #9f1239;
  --shadow: 0 10px 32px rgba(15, 23, 42, 0.12);
  --font-display: 'Outfit', 'Segoe UI', sans-serif;
  --font-thai: 'Sarabun', 'Segoe UI', sans-serif;
  --font-verse: 'Sarabun', 'Outfit', serif;
}
html.dark body, body.dark {
  --bg: #0b1220;
  --card: #111827;
  --text: #e5eef7;
  --muted: #94a3b8;
  --border: #1e293b;
  --accent: #34d399;
  --accent-soft: #064e3b;
  --ink: #6ee7b7;
  --gold: #fbbf24;
  --thai: #fb7185;
  --shadow: 0 8px 28px rgba(0, 0, 0, 0.4);
  color-scheme: dark;
}
* { box-sizing: border-box; }
body.poetry-page {
  font-family: var(--font-display);
  margin: 0;
  padding: 16px;
  padding-bottom: calc(88px + env(safe-area-inset-bottom, 0px));
  background:
    radial-gradient(1000px 420px at 0% 0%, rgba(15, 92, 76, 0.22), transparent 55%),
    radial-gradient(800px 360px at 100% 0%, rgba(180, 83, 9, 0.14), transparent 50%),
    linear-gradient(180deg, #c5d9d2 0%, var(--bg) 42%, #d5e3de 100%);
  color: var(--text);
}
html.dark body.poetry-page, body.dark.poetry-page {
  background:
    radial-gradient(900px 400px at 0% 0%, rgba(16, 185, 129, 0.12), transparent 55%),
    radial-gradient(700px 320px at 100% 0%, rgba(251, 191, 36, 0.08), transparent 50%),
    linear-gradient(180deg, #0b1220 0%, #0f172a 100%);
}
.wrap { max-width: 920px; margin: 0 auto; }

.tm-hero-poetry {
  background:
    radial-gradient(900px 380px at 8% -20%, rgba(52, 211, 153, 0.35), transparent 55%),
    radial-gradient(700px 320px at 100% 10%, rgba(251, 191, 36, 0.22), transparent 52%),
    linear-gradient(145deg, #022c22 0%, #064e3b 40%, #0f766e 72%, #92400e 100%) !important;
}
.tm-hero h1 .th {
  display: block;
  font-family: var(--font-thai);
  font-size: 0.55em;
  font-weight: 700;
  opacity: 0.92;
  margin-top: 4px;
}
.tm-lead .th {
  display: block;
  font-family: var(--font-thai);
  margin-top: 4px;
  opacity: 0.9;
}

.sc-panel {
  background: linear-gradient(160deg, #ecfdf5 0%, #fff 50%, #fff 100%);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 18px;
  margin-top: 14px;
  box-shadow: var(--shadow);
}
html.dark body.poetry-page .sc-panel, body.dark.poetry-page .sc-panel {
  background: linear-gradient(160deg, #064e3b 0%, #0f172a 50%, #111827 100%);
}
.sc-head h2 { margin: 0 0 4px; font-size: 1.15rem; font-weight: 800; }
.sc-sub { margin: 0; color: var(--muted); font-weight: 600; font-size: 0.9rem; }
.po-direction-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-left: 5px solid var(--gold);
}
.po-direction-panel h2 .th { color: var(--thai); font-family: var(--font-thai); }
.po-direction {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  min-width: min(100%, 360px);
}
.po-direction button {
  display: grid;
  gap: 2px;
  padding: 11px 14px;
  border: 1px solid var(--border);
  border-radius: 13px;
  color: var(--text);
  background: var(--card);
  font: inherit;
  cursor: pointer;
}
.po-direction button strong { font-size: .9rem; }
.po-direction button span { color: var(--muted); font-size: .68rem; }
.po-direction button.active {
  color: #fff;
  border-color: var(--gold);
  background: linear-gradient(135deg, var(--accent), var(--gold));
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--gold) 28%, transparent);
}
.po-direction button.active span { color: rgba(255,255,255,.84); }
.sc-search {
  width: 100%;
  min-height: 44px;
  margin: 12px 0 8px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  font: inherit;
  font-weight: 600;
}
html.dark .sc-search, body.dark .sc-search { background: #1e293b; }
.sc-cats {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 8px 0 12px;
}
.sc-cat {
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  border-radius: 999px;
  padding: 8px 12px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  font-size: 0.85rem;
}
.sc-cat.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.sc-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
}
.sc-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  text-align: left;
  padding: 14px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: var(--card);
  color: inherit;
  cursor: pointer;
  font-family: inherit;
  min-height: 120px;
  transition: transform 0.15s ease, border-color 0.15s ease;
}
.sc-card:hover, .sc-card:focus-visible {
  transform: translateY(-2px);
  border-color: var(--accent);
  outline: none;
}
.sc-card.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 92, 76, 0.2);
}
.sc-card-emoji { font-size: 1.6rem; }
.sc-card-primary { font-weight: 800; font-size: 0.95rem; }
.sc-card-secondary { color: var(--thai); font-weight: 700; font-size: 0.88rem; }
.sc-card.th-first .sc-card-primary,
.po-hub-card.th-first .sc-card-primary { font-family: var(--font-thai); font-size: 1.02rem; }
.sc-card.th-first .sc-card-secondary,
.po-hub-card.th-first .sc-card-secondary { color: var(--muted); }
.sc-card.en-first .sc-card-secondary,
.po-hub-card.en-first .sc-card-secondary { font-family: var(--font-thai); }
.sc-card-meta { font-size: 0.75rem; color: var(--muted); font-weight: 600; }
.sc-meta { margin: 12px 0 0; color: var(--muted); font-weight: 600; font-size: 0.88rem; }

.po-hub-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  text-align: left;
  padding: 0 0 12px;
  overflow: hidden;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: #fff;
  color: inherit;
  cursor: pointer;
  font-family: inherit;
  transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
}
html.dark .po-hub-card, body.dark .po-hub-card { background: #0f172a; }
.po-hub-card:hover, .po-hub-card:focus-visible {
  transform: translateY(-3px);
  box-shadow: var(--shadow);
  border-color: var(--accent);
  outline: none;
}
.po-hub-card.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 92, 76, 0.2);
}
.po-hub-img-wrap {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  overflow: hidden;
  background: #134e4a;
}
.po-hub-img-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.po-hub-emoji {
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  font-size: 3rem;
}
.po-hub-emoji-sm {
  font-size: 1.05rem;
  padding: 8px 12px 0;
}
.po-hub-card .sc-card-primary,
.po-hub-card .sc-card-secondary,
.po-hub-card .sc-card-meta {
  padding: 0 12px;
}

.po-forms {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
  margin-top: 10px;
}
.po-form {
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 0;
  overflow: hidden;
  background: var(--accent-soft);
}
.po-form.is-audio {
  cursor: pointer;
  transition: border-color 0.15s ease, transform 0.15s ease, box-shadow 0.15s ease;
}
.po-form.is-audio:hover,
.po-form.is-audio:focus-within {
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}
.po-form-img {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 10;
  overflow: hidden;
  background: #134e4a;
}
.po-form-img img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.po-form-body {
  padding: 10px 12px 12px;
}
.po-form strong { display: block; font-size: 1rem; }
.po-form em {
  display: block;
  font-style: normal;
  font-family: var(--font-thai);
  color: var(--thai);
  font-weight: 700;
  margin: 2px 0 6px;
}
.po-form span { font-size: 0.78rem; color: var(--muted); font-weight: 600; line-height: 1.35; }
.po-form.th-first strong { font-family: var(--font-thai); font-size: 1.06rem; }
.po-form.th-first em { color: var(--muted); font-family: var(--font-display); }
.po-form.en-first em { font-family: var(--font-thai); }
.po-form span b, .po-form span i { display: block; font-style: normal; }
.po-form span i { margin-top: 3px; opacity: .82; }
.po-form-audio {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}
.po-form-play {
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 10px;
  background: var(--surface, #fff);
  color: var(--ink);
  font-size: 0.72rem;
  font-weight: 800;
  cursor: pointer;
}
.po-form-play.secondary { opacity: 0.9; }
.po-form-play.pair {
  color: #fff;
  border-color: var(--accent);
  background: var(--accent);
}
.po-form-play:hover { border-color: var(--accent); }

.po-detail { display: none; margin-top: 14px; scroll-margin-top: 16px; }
.po-detail.open { display: block; animation: poIn 0.28s ease; }
.po-actions button, .po-vocab button { scroll-margin-top: 72px; }
.po-hero-img {
  width: 100%;
  max-height: 360px;
  object-fit: cover;
  border-radius: 16px;
  border: 1px solid var(--border);
  margin: 0 0 12px;
  display: block;
}
.po-section-title {
  margin: 16px 0 8px;
  font-weight: 800;
  font-size: 1rem;
}
.po-gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
  margin-bottom: 12px;
}
.po-gal-item {
  margin: 0;
  border-radius: 14px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: #fff;
}
html.dark .po-gal-item, body.dark .po-gal-item { background: #0f172a; }
.po-gal-item img {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  display: block;
}
.po-gal-item figcaption {
  padding: 8px 10px;
  font-size: 0.85rem;
}
.po-gal-item .en { display: block; font-weight: 700; }
.po-gal-item .th {
  display: block;
  font-family: var(--font-thai);
  color: var(--thai);
}
.po-related {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 16px;
}
.po-related a {
  text-decoration: none;
  padding: 8px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--card);
  color: inherit;
  font-weight: 700;
  font-size: 0.85rem;
}
.po-related a:hover { border-color: var(--accent); }
@keyframes poIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}
.po-detail-head {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 10px;
}
.po-detail-head h3 {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 800;
}
.po-detail-head h3 .th {
  display: block;
  font-family: var(--font-thai);
  color: var(--thai);
  font-size: 0.85em;
  margin-top: 2px;
}
.po-title-primary, .po-title-secondary { display: block; }
.po-detail-head h3 .po-title-primary { display: inline; }
.po-detail-head h3 .po-title-secondary {
  margin-top: 2px;
  color: var(--thai);
  font-size: .85em;
}
.po-detail-head h3.th-first .po-title-primary { font-family: var(--font-thai); }
.po-detail-head h3.th-first .po-title-secondary {
  color: var(--muted);
  font-family: var(--font-display);
}
.po-detail-head h3.en-first .po-title-secondary { font-family: var(--font-thai); }
.po-era {
  display: inline-block;
  margin-top: 6px;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--gold);
}
.po-bio {
  margin: 0 0 12px;
  line-height: 1.55;
  font-weight: 600;
  color: var(--text);
}
.po-bio .th {
  display: block;
  margin-top: 8px;
  font-family: var(--font-thai);
  color: var(--muted);
  font-weight: 600;
}
.po-bio-primary, .po-bio-secondary { display: block; }
.po-bio-secondary { margin-top: 8px; color: var(--muted); }
.po-bio.th-first .po-bio-primary { font-family: var(--font-thai); }
.po-bio.en-first .po-bio-secondary { font-family: var(--font-thai); }
.po-works {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 0 0 14px;
  padding: 0;
  list-style: none;
}
.po-works li {
  border: 1px solid var(--border);
  background: var(--card);
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 0.78rem;
  font-weight: 700;
}

.po-verse {
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 14px;
  margin: 0 0 12px;
  background: linear-gradient(165deg, rgba(15, 92, 76, 0.06), transparent 55%), var(--card);
}
.po-verse-title {
  margin: 0 0 8px;
  font-size: 0.95rem;
  font-weight: 800;
}
.po-verse-title .th {
  display: block;
  font-family: var(--font-thai);
  color: var(--thai);
  font-size: 0.9em;
}
.po-verse-title .po-title-secondary {
  margin-top: 2px;
  color: var(--thai);
  font-size: .9em;
}
.po-verse.th-first .po-verse-title .po-title-primary {
  font-family: var(--font-thai);
  font-size: 1.05em;
}
.po-verse.th-first .po-verse-title .po-title-secondary {
  color: var(--muted);
  font-family: var(--font-display);
}
.po-verse.en-first .po-verse-title .po-title-secondary { font-family: var(--font-thai); }
.po-form-chip {
  display: inline-block;
  margin-bottom: 8px;
  padding: 3px 8px;
  border-radius: 8px;
  background: var(--accent-soft);
  color: var(--ink);
  font-size: 0.72rem;
  font-weight: 800;
}
.po-lines {
  font-family: var(--font-verse);
  font-size: clamp(1.15rem, 3.5vw, 1.4rem);
  font-weight: 700;
  line-height: 1.7;
  color: var(--ink);
  white-space: pre-line;
  margin: 8px 0;
}
html.dark .po-lines, body.dark .po-lines { color: var(--accent); }
.po-en {
  margin: 8px 0;
  color: var(--muted);
  font-weight: 600;
  line-height: 1.5;
  white-space: pre-line;
  border-left: 3px solid var(--gold);
  padding-left: 10px;
}
.po-poem-primary {
  margin: 8px 0;
  color: var(--ink);
  font-family: var(--font-verse);
  font-size: clamp(1.12rem, 3.5vw, 1.4rem);
  font-weight: 700;
  line-height: 1.7;
  white-space: pre-line;
}
.po-verse.en-first .po-poem-primary { font-family: var(--font-display); }
.po-poem-secondary {
  margin: 8px 0;
  padding-left: 10px;
  border-left: 3px solid var(--gold);
  color: var(--muted);
  font-weight: 600;
  line-height: 1.55;
  white-space: pre-line;
}
.po-verse.en-first .po-poem-secondary {
  font-family: var(--font-thai);
  font-size: 1.02rem;
}
.po-verse.th-first .po-poem-secondary { font-family: var(--font-display); }
.po-note {
  margin: 8px 0 0;
  font-size: 0.8rem;
  color: var(--muted);
  font-weight: 600;
  line-height: 1.4;
}
.po-vocab {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}
.po-vocab button {
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  border-radius: 10px;
  padding: 6px 10px;
  font-family: inherit;
  font-weight: 700;
  cursor: pointer;
  font-size: 0.82rem;
}
html.dark .po-vocab button, body.dark .po-vocab button { background: #1e293b; }
.po-vocab button .th { font-family: var(--font-thai); color: var(--thai); }
.po-vocab .word-primary, .po-vocab .word-secondary { display: block; }
.po-vocab .word-secondary { margin-top: 2px; color: var(--muted); font-size: .88em; }
.po-vocab button.th-first .word-primary { color: var(--thai); font-family: var(--font-thai); }
.po-vocab button.en-first .word-secondary { color: var(--thai); font-family: var(--font-thai); }
.po-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}
.po-actions button, .sc-tool {
  min-height: 44px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--accent);
  color: #fff;
  font-weight: 800;
  font-family: inherit;
  padding: 8px 14px;
  cursor: pointer;
}
.po-actions button.secondary, .sc-tool.secondary {
  background: var(--card);
  color: var(--text);
}

.sc-footer {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: center;
  align-items: center;
  margin: 18px 0 8px;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--muted);
}
.sc-footer a { color: var(--accent); text-decoration: none; }

.mobile-dock {
  display: none;
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 9998;
  grid-template-columns: repeat(5, 1fr);
  gap: 2px;
  padding: 6px 6px calc(6px + env(safe-area-inset-bottom, 0px));
  background: rgba(15, 23, 42, 0.92);
  backdrop-filter: blur(10px);
}
.dock-link, .dock-menu {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  border: 0;
  background: transparent;
  color: #e2e8f0;
  text-decoration: none;
  font-family: inherit;
  cursor: pointer;
  padding: 6px 2px;
}
.dock-link.primary { color: #6ee7b7; }
.dock-ico { font-size: 1.15rem; }
.dock-th { font-family: var(--font-thai); font-size: 0.65rem; font-weight: 700; }
.dock-lbl { font-size: 0.62rem; font-weight: 700; }
.sc-menu-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 10020;
  background: rgba(15, 23, 42, 0.55);
  align-items: flex-end;
  justify-content: center;
  padding: 12px;
}
.sc-menu-overlay.open { display: flex; }
.sc-menu-sheet {
  width: min(420px, 100%);
  background: var(--card);
  border-radius: 18px 18px 12px 12px;
  padding: 16px;
  border: 1px solid var(--border);
}
.sc-menu-sheet h3 { margin: 0 0 10px; }
.sc-menu-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.sc-menu-grid a {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  text-decoration: none;
  color: inherit;
  font-weight: 700;
}
.sc-menu-grid a .th { font-family: var(--font-thai); }
.sc-menu-grid a .en { font-size: 0.75rem; color: var(--muted); }
.sc-menu-close {
  width: 100%;
  margin-top: 12px;
  padding: 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--accent-soft);
  font-weight: 800;
  cursor: pointer;
  font-family: inherit;
}

@media (max-width: 900px) {
  .mobile-dock { display: grid; }
}
@media (max-width: 640px) {
  body.poetry-page { padding: 10px; padding-bottom: calc(88px + env(safe-area-inset-bottom, 0px)); }
  .sc-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
  .po-direction-panel { align-items: stretch; flex-direction: column; }
  .po-direction { width: 100%; min-width: 0; }
}
@media (min-width: 901px) {
  .mobile-dock { display: none !important; }
}
