:root {
  --bg: #cfe8f3;
  --card: #eef8fc;
  --text: #0c4a6e;
  --muted: #5b7a8c;
  --border: #9ec8d9;
  --accent: #0284c7;
  --accent-soft: #e0f2fe;
  --you: #0369a1;
  --other: #0d9488;
  --thai: #be123c;
  --shadow: 0 10px 32px rgba(12, 74, 110, 0.14);
  --font-display: "Outfit", "Segoe UI", sans-serif;
  --font-thai: "Sarabun", "Segoe UI", sans-serif;
}
html.dark body,
body.dark {
  --bg: #0b1a24;
  --card: #0f2430;
  --text: #e0f2fe;
  --muted: #94a3b8;
  --border: #1e3a4a;
  --accent: #38bdf8;
  --accent-soft: #0c4a6e;
  --you: #7dd3fc;
  --other: #5eead4;
  --thai: #fb7185;
  --shadow: 0 8px 28px rgba(0, 0, 0, 0.45);
  color-scheme: dark;
}
* { box-sizing: border-box; }
body {
  font-family: var(--font-display);
  margin: 0;
  padding: 16px;
  padding-bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  background:
    radial-gradient(1000px 420px at 0% 0%, rgba(56, 189, 248, 0.35), transparent 55%),
    radial-gradient(800px 360px at 100% 0%, rgba(45, 212, 191, 0.22), transparent 50%),
    linear-gradient(180deg, #b8dff0 0%, var(--bg) 45%, #d4ebe8 100%);
  color: var(--text);
}
.wrap { max-width: 920px; margin: 0 auto; }
.tm-hero-swim {
  background:
    radial-gradient(900px 380px at 8% -20%, rgba(56, 189, 248, 0.5), transparent 55%),
    radial-gradient(700px 320px at 100% 10%, rgba(20, 184, 166, 0.35), transparent 52%),
    linear-gradient(145deg, #0c4a6e 0%, #0369a1 42%, #0e7490 72%, #0f766e 100%) !important;
}
.tm-hero h1 .th {
  display: block;
  font-family: var(--font-thai);
  font-size: 0.72em;
  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 {
  margin-top: 14px;
  padding: 14px 12px 12px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: linear-gradient(160deg, #e0f2fe 0%, #fff 55%, #ccfbf1 100%);
  box-shadow: var(--shadow);
}
html.dark .sc-panel,
body.dark .sc-panel {
  background: linear-gradient(160deg, #0c4a6e 0%, #0f172a 55%, #134e4a 100%);
  border-color: #334155;
}
.sc-head h2 { margin: 0 0 4px; font-size: 1.15rem; }
.sc-sub { margin: 0; color: var(--muted); font-size: 0.9rem; }
.sc-cats {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 12px 0;
}
.sc-cat {
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  border-radius: 999px;
  padding: 6px 12px;
  font-weight: 700;
  font-size: 0.82rem;
  cursor: pointer;
}
html.dark .sc-cat, body.dark .sc-cat { background: #0f172a; }
.sc-cat.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.sc-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px;
}
.sc-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  text-align: left;
  padding: 12px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: color-mix(in srgb, #fff 88%, var(--accent));
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
html.dark .sc-card, body.dark .sc-card {
  background: color-mix(in srgb, #0f172a 80%, var(--accent));
}
.sc-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.sc-card-picto {
  width: 100%;
  height: 100px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 6px;
}
.sc-card-picto svg { width: 140px; height: 84px; }
.sc-card-emoji { font-size: 1.4rem; }
.sc-card-en { font-weight: 800; font-size: 0.92rem; }
.sc-card-th { font-family: var(--font-thai); font-size: 0.88rem; color: var(--thai); }
.sc-card-meta { font-size: 0.72rem; color: var(--muted); }
.sc-meta { margin: 10px 0 0; color: var(--muted); font-size: 0.85rem; }

.sc-back {
  border: 0;
  background: transparent;
  color: var(--accent);
  font-weight: 800;
  cursor: pointer;
  margin-bottom: 10px;
  padding: 0;
}
.sc-scene-head {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 8px;
}
.sc-scene-emoji { font-size: 2.4rem; }
.swim-hero-picto {
  width: 168px;
  height: 100px;
  flex-shrink: 0;
}
.swim-hero-picto svg { width: 100%; height: 100%; }
.sc-scene-titles h2 { margin: 0; font-size: 1.35rem; }
.sc-scene-th {
  margin: 2px 0 0;
  font-family: var(--font-thai);
  color: var(--thai);
  font-weight: 700;
}
.sc-scene-roman {
  margin: 2px 0 0;
  font-size: 0.85rem;
  color: var(--muted);
}
.swim-overview {
  margin: 10px 0 12px;
  padding: 12px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: color-mix(in srgb, var(--accent) 8%, #fff);
  line-height: 1.45;
}
html.dark .swim-overview, body.dark .swim-overview {
  background: color-mix(in srgb, var(--accent) 14%, #0f172a);
}
.swim-overview .th {
  display: block;
  margin-top: 6px;
  font-family: var(--font-thai);
  color: var(--thai);
}
.sc-tip {
  padding: 10px 12px;
  border-radius: 12px;
  background: #fef3c7;
  border: 1px solid #fcd34d;
  margin-bottom: 12px;
  font-size: 0.92rem;
}
html.dark .sc-tip, body.dark .sc-tip {
  background: #422006;
  border-color: #a16207;
  color: #fde68a;
}
.sc-tip .th {
  display: block;
  margin-top: 4px;
  font-family: var(--font-thai);
}
.sc-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 8px;
}
.sc-tool {
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  border-radius: 999px;
  padding: 8px 12px;
  font-weight: 700;
  font-size: 0.82rem;
  cursor: pointer;
}
html.dark .sc-tool, body.dark .sc-tool { background: #0f172a; }
.sc-tool[aria-pressed="true"],
.sc-tool.accent {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.sc-tool.secondary { opacity: 0.9; }
.sc-status {
  min-height: 1.2em;
  font-size: 0.85rem;
  color: var(--muted);
  margin: 0 0 10px;
}
.sc-status.err { color: #be123c; }

.swim-section-title {
  margin: 16px 0 8px;
  font-size: 1rem;
}
.swim-tech {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 8px;
}
.swim-tech-card {
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: 14px;
  padding: 12px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: color-mix(in srgb, var(--accent) 7%, #fff);
}
html.dark .swim-tech-card, body.dark .swim-tech-card {
  background: color-mix(in srgb, var(--accent) 12%, #0f172a);
}
.swim-tech-card.playing { box-shadow: 0 0 0 2px var(--accent); }
.swim-tech-ico {
  display: flex;
  align-items: center;
  justify-content: center;
}
.swim-tech-ico svg { width: 140px; height: 84px; }
.swim-tech-label {
  font-size: 0.68rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--accent);
}
.swim-tech-en { font-weight: 800; margin-top: 2px; }
.swim-tech-th {
  font-family: var(--font-thai);
  color: var(--thai);
  font-weight: 700;
  font-size: 0.92rem;
}
.swim-tech-detail {
  margin-top: 4px;
  font-size: 0.9rem;
  line-height: 1.4;
  color: var(--text);
}
.swim-tech-detail .th {
  display: block;
  margin-top: 4px;
  font-family: var(--font-thai);
  color: var(--muted);
}

.swim-steps {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 8px;
  counter-reset: step;
}
.swim-step {
  display: grid;
  grid-template-columns: 40px 120px 1fr;
  gap: 12px;
  align-items: center;
  padding: 12px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: #fff;
  counter-increment: step;
}
html.dark .swim-step, body.dark .swim-step { background: #0f172a; }
.swim-step.playing { box-shadow: 0 0 0 2px var(--accent); }
.swim-step-num {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 800;
  background: var(--accent-soft);
  color: var(--accent);
}
.swim-step-num::before { content: counter(step); }
.swim-step-picto svg { width: 120px; height: 72px; }
.swim-step-en { font-weight: 700; }
.swim-step-th {
  font-family: var(--font-thai);
  color: var(--thai);
  font-size: 0.9rem;
}

.swim-mistakes {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 10px;
}
.swim-mistake {
  padding: 8px 12px;
  border-radius: 12px;
  border-left: 4px solid #f97316;
  background: color-mix(in srgb, #fb923c 12%, #fff);
  font-size: 0.9rem;
}
html.dark .swim-mistake, body.dark .swim-mistake {
  background: color-mix(in srgb, #fb923c 16%, #0f172a);
}
.swim-mistake .th {
  display: block;
  margin-top: 2px;
  font-family: var(--font-thai);
  color: var(--thai);
}

.sc-chat {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 12px;
}
.sc-bubble {
  padding: 10px 12px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: #fff;
  cursor: pointer;
}
html.dark .sc-bubble, body.dark .sc-bubble { background: #0f172a; }
.sc-bubble.playing { box-shadow: 0 0 0 2px var(--accent); }
.sc-en { font-weight: 700; }
.sc-th {
  font-family: var(--font-thai);
  color: var(--thai);
  margin-top: 2px;
}
.sc-scene-links {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 12px;
}
.sc-scene-links a {
  color: var(--accent);
  font-weight: 700;
  text-decoration: none;
}
.sc-footer {
  margin: 18px 0 80px;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  color: var(--muted);
  font-size: 0.85rem;
}
.sc-footer a { color: var(--accent); text-decoration: none; font-weight: 700; }

.mobile-dock {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 4px;
  padding: 8px 8px calc(8px + env(safe-area-inset-bottom, 0px));
  background: color-mix(in srgb, var(--card) 92%, transparent);
  border-top: 1px solid var(--border);
  backdrop-filter: blur(10px);
  z-index: 40;
}
.dock-link, .dock-menu {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  text-decoration: none;
  color: var(--text);
  background: transparent;
  border: 0;
  font: inherit;
  cursor: pointer;
  padding: 4px;
}
.dock-ico { font-size: 1.1rem; }
.dock-th { font-family: var(--font-thai); font-size: 0.62rem; }
.dock-lbl { font-size: 0.62rem; font-weight: 700; }
.dock-link.primary { color: var(--accent); }
.sc-menu-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  display: none;
  align-items: flex-end;
  justify-content: center;
  z-index: 50;
}
.sc-menu-overlay.open { display: flex; }
.sc-menu-sheet {
  width: min(480px, 100%);
  background: var(--card);
  border-radius: 18px 18px 0 0;
  padding: 16px;
  border: 1px solid var(--border);
}
.sc-menu-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 10px 0;
}
.sc-menu-grid a {
  padding: 10px;
  border-radius: 12px;
  border: 1px solid var(--border);
  text-decoration: none;
  color: var(--text);
  background: #fff;
}
html.dark .sc-menu-grid a, body.dark .sc-menu-grid a { background: #0f172a; }
.sc-menu-grid .th {
  display: block;
  font-family: var(--font-thai);
  font-weight: 700;
}
.sc-menu-grid .en { font-size: 0.8rem; color: var(--muted); }
.sc-menu-close {
  width: 100%;
  border: 0;
  border-radius: 12px;
  padding: 12px;
  font-weight: 800;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
}

@media (max-width: 640px) {
  .sc-card-picto { height: 88px; }
  .sc-card-picto svg { width: 120px; height: 72px; }
  .swim-hero-picto { width: 140px; height: 84px; }
  .swim-tech-card { grid-template-columns: 1fr; }
  .swim-tech-ico svg { width: 160px; height: 96px; }
  .swim-step { grid-template-columns: 32px 96px 1fr; }
  .swim-step-picto svg { width: 96px; height: 58px; }
}
