/* Mobile-first workout reader — light theme */
:root {
  --bg0: #f0f3f7;
  --bg1: #ffffff;
  --bg2: #e8edf3;
  --surface: #ffffff;
  --border: rgba(15, 23, 42, 0.1);
  --text: #1e293b;
  --muted: #64748b;
  --accent: #0d9488;
  --accent-dim: rgba(13, 148, 136, 0.12);
  --warm: #d97706;
  --warm-dim: rgba(217, 119, 6, 0.1);
  --radius: 14px;
  --radius-sm: 10px;
  --font: "Noto Sans Thai", system-ui, -apple-system, sans-serif;
  --font-display: "Sora", var(--font);
  --shadow: 0 8px 30px rgba(15, 23, 42, 0.08);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100dvh;
  font-family: var(--font);
  font-size: 1.0625rem;
  line-height: 1.65;
  color: var(--text);
  background: var(--bg0);
  background-image:
    radial-gradient(ellipse 120% 70% at 50% -25%, rgba(13, 148, 136, 0.08), transparent 50%),
    radial-gradient(ellipse 70% 45% at 100% 20%, rgba(217, 119, 6, 0.06), transparent 45%);
  padding-bottom: calc(4.5rem + var(--safe-bottom));
}

.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  padding: calc(0.75rem + var(--safe-top)) 1rem 1rem;
  background: linear-gradient(180deg, rgba(240, 243, 247, 0.96) 0%, rgba(240, 243, 247, 0.82) 65%, transparent 100%);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.site-header__inner {
  max-width: 40rem;
  margin: 0 auto;
}

.site-header__badge {
  display: inline-block;
  font-family: var(--font-display);
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
  background: var(--accent-dim);
  border: 1px solid rgba(13, 148, 136, 0.22);
  padding: 0.28rem 0.65rem;
  border-radius: 999px;
  margin-bottom: 0.5rem;
}

.site-header__sub {
  margin: 0.35rem 0 0;
  font-size: 0.78rem;
  color: var(--muted);
  line-height: 1.45;
  max-width: 22rem;
}

.main {
  max-width: 40rem;
  margin: 0 auto;
  padding: 0 1rem 2rem;
}

.state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--muted);
}

.state--error {
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  color: var(--text);
}

.state--error p {
  margin: 0 0 0.75rem;
  font-size: 0.95rem;
}

.state--error p:last-child {
  margin-bottom: 0;
}

.state__cmd {
  margin: 0.75rem 0;
  padding: 0.85rem 1rem;
  background: var(--bg2);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  overflow-x: auto;
  font-size: 0.8rem;
}

.state__cmd code {
  font-family: ui-monospace, monospace;
  color: var(--warm);
}

.spinner {
  width: 36px;
  height: 36px;
  margin: 0 auto 1rem;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* Markdown body */
.prose {
  padding-top: 0.25rem;
}

.prose > h1:first-of-type {
  font-family: var(--font-display);
  font-size: clamp(1.65rem, 5.5vw, 2.05rem);
  font-weight: 700;
  margin: 0.25rem 0 1.25rem;
  padding-bottom: 0.85rem;
  letter-spacing: -0.03em;
  line-height: 1.15;
  color: var(--text);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 0 rgba(13, 148, 136, 0.35);
}

.prose h1:not(:first-of-type) {
  font-family: var(--font-display);
  font-size: clamp(1.35rem, 4vw, 1.6rem);
  font-weight: 700;
  margin: 2rem 0 1rem;
  letter-spacing: -0.02em;
}

.prose h2 {
  font-family: var(--font-display);
  font-size: 1.05rem;
  font-weight: 600;
  margin: 2.25rem 0 1rem;
  padding: 0.65rem 1rem;
  background: linear-gradient(135deg, var(--surface) 0%, var(--bg2) 100%);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  border-left: 4px solid var(--accent);
  box-shadow: var(--shadow);
}

.prose h3 {
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 600;
  margin: 1.75rem 0 0.75rem;
  padding: 0.5rem 0 0.5rem 0.85rem;
  border-left: 3px solid var(--warm);
  color: var(--text);
  background: linear-gradient(90deg, var(--warm-dim), transparent);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

.prose h4 {
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--accent);
  margin: 1.35rem 0 0.5rem;
  text-transform: none;
}

.prose h5 {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--muted);
  margin: 1rem 0 0.4rem;
}

.prose p {
  margin: 0 0 0.85rem;
  color: var(--text);
}

.prose p:last-child {
  margin-bottom: 0;
}

.prose hr {
  border: none;
  height: 1px;
  margin: 1.75rem 0;
  background: linear-gradient(90deg, transparent, var(--border), transparent);
}

.prose strong {
  color: var(--text);
  font-weight: 600;
}

.prose ul,
.prose ol {
  margin: 0 0 1rem;
  padding-left: 1.35rem;
}

.prose li {
  margin-bottom: 0.35rem;
}

.prose code {
  font-family: ui-monospace, "Cascadia Code", monospace;
  font-size: 0.88em;
  background: var(--bg2);
  padding: 0.12em 0.4em;
  border-radius: 6px;
  border: 1px solid var(--border);
}

.prose pre {
  margin: 0.75rem 0 1rem;
  padding: 1rem 1.1rem;
  background: var(--bg1);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.prose pre code {
  display: block;
  padding: 0;
  border: none;
  background: none;
  font-size: 0.82rem;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
  color: #334155;
}

.table-wrap {
  margin: 1rem 0 1.25rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--surface);
}

.prose table {
  width: 100%;
  min-width: 520px;
  border-collapse: collapse;
  font-size: 0.82rem;
}

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

.prose th {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  background: var(--bg2);
}

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

.prose tbody tr:nth-child(even) td {
  background: rgba(15, 23, 42, 0.035);
}

.to-top {
  position: fixed;
  right: max(1rem, env(safe-area-inset-right));
  bottom: calc(1rem + var(--safe-bottom));
  z-index: 30;
  width: 3rem;
  height: 3rem;
  border-radius: 50%;
  border: 1px solid rgba(13, 148, 136, 0.35);
  background: rgba(255, 255, 255, 0.92);
  color: var(--accent);
  font-size: 1.15rem;
  line-height: 1;
  cursor: pointer;
  box-shadow: var(--shadow);
  backdrop-filter: blur(8px);
  transition: transform 0.2s, opacity 0.2s;
}

.to-top:active {
  transform: scale(0.94);
}

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

@media (min-width: 480px) {
  body {
    font-size: 1.075rem;
  }

  .prose pre code {
    font-size: 0.85rem;
  }
}
