/* self-hosted fonts (OFL): Thai + Latin subsets only */
@font-face { font-family: 'IBM Plex Sans Thai Looped'; font-style: normal; font-weight: 400; font-display: swap; src: url(fonts/plex-looped-400-thai.woff2) format('woff2');unicode-range: U+02D7, U+0303, U+0331, U+0E01-0E5B, U+200C-200D, U+25CC; }
@font-face { font-family: 'IBM Plex Sans Thai Looped'; font-style: normal; font-weight: 400; font-display: swap; src: url(fonts/plex-looped-400-latin.woff2) format('woff2');unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: 'IBM Plex Sans Thai Looped'; font-style: normal; font-weight: 500; font-display: swap; src: url(fonts/plex-looped-500-thai.woff2) format('woff2');unicode-range: U+02D7, U+0303, U+0331, U+0E01-0E5B, U+200C-200D, U+25CC; }
@font-face { font-family: 'IBM Plex Sans Thai Looped'; font-style: normal; font-weight: 500; font-display: swap; src: url(fonts/plex-looped-500-latin.woff2) format('woff2');unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: 'IBM Plex Sans Thai Looped'; font-style: normal; font-weight: 600; font-display: swap; src: url(fonts/plex-looped-600-thai.woff2) format('woff2');unicode-range: U+02D7, U+0303, U+0331, U+0E01-0E5B, U+200C-200D, U+25CC; }
@font-face { font-family: 'IBM Plex Sans Thai Looped'; font-style: normal; font-weight: 600; font-display: swap; src: url(fonts/plex-looped-600-latin.woff2) format('woff2');unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: 'Mali'; font-style: normal; font-weight: 700; font-display: swap; src: url(fonts/mali-700-thai.woff2) format('woff2');unicode-range: U+02D7, U+0303, U+0331, U+0E01-0E5B, U+200C-200D, U+25CC; }
@font-face { font-family: 'Mali'; font-style: normal; font-weight: 700; font-display: swap; src: url(fonts/mali-700-latin.woff2) format('woff2');unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }

/* การ์ตูนธรรมะ — tokens from the design handoff + components */
:root {
  --font-heading: 'Mali', sans-serif;
  --font-body: 'IBM Plex Sans Thai Looped', sans-serif;
  --ink: #1E1B4B; --ground: #E8F4FF; --surface: #FFFFFF; --page-ink: #1E1B4B;
  --text-secondary: #4338CA; --text-muted: #3F3D6B;
  --purple: #6C3BEF; --purple-soft: #8B5CF6; --orange: #FF8A00; --orange-deep: #C2410C;
  --green: #22C55E; --green-soft: #86EFAC; --yellow: #FFD60A; --yellow-soft: #FFE08A;
  --pink: #FF5FA2; --pink-light: #FF8FC0; --sky: #4FC3F7; --sky-soft: #B3E5FC;
  --accent: #D81B60; --badge-new: #E11D48;
  --border: 3px solid var(--ink); --border-thin: 2px solid var(--ink);
  --shadow: 0 4px 0 var(--ink); --shadow-lg: 0 5px 0 var(--ink); --shadow-pressed: 0 1px 0 var(--ink);
  --gutter: 16px;
}
[data-theme="night"] { --ground: #1E1B4B; --page-ink: #FFFFFF; }

* { box-sizing: border-box; }
html { background: var(--ground); }
body {
  margin: 0 auto; max-width: 480px; min-height: 100vh;
  background: var(--ground); color: var(--page-ink);
  font-family: var(--font-body); font-size: 15px; -webkit-tap-highlight-color: transparent;
}
body.reader { max-width: 720px; }
body.with-nav { padding-bottom: calc(88px + env(safe-area-inset-bottom)); }
h1, h2, .title-lg, .brand, .top-title, .rt, .cat-tile .name { font-family: var(--font-heading); font-weight: 700; margin: 0; }
h1 { font-size: 27px; line-height: 1.3; }
h2 { font-size: 20px; }
a { color: var(--purple); }
button { font: inherit; color: inherit; cursor: pointer; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.hscroll { overflow-x: auto; scrollbar-width: none; }
.hscroll::-webkit-scrollbar { display: none; }
[hidden] { display: none !important; }

/* layout bits */
.page { padding: 20px var(--gutter) 28px; display: flex; flex-direction: column; gap: 28px; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.stack-sm { display: flex; flex-direction: column; gap: 12px; }
.col { display: flex; flex-direction: column; gap: 6px; }
.col.tight { gap: 2px; }
.grow { flex: 1; min-width: 0; }
.grow2 { flex: 1.4; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.row-flat { display: flex; align-items: center; gap: 10px; }
.center { align-items: center; text-align: center; padding-top: 80px; }
.deco { position: absolute; pointer-events: none; }
.link { font-size: 14px; font-weight: 600; }
.link-btn { min-height: 44px; border: 0; background: none; display: flex; align-items: center; gap: 6px; font-size: 14px; font-weight: 600; color: var(--text-secondary); }
.empty { text-align: center; font-weight: 500; color: var(--text-muted); margin: 8px 0; }

/* sticker press */
.sticker, .btn, .cat-tile, .cover-card .cover, .circle-btn, .chip, .continue-card .btn {
  transition: transform .08s, box-shadow .08s;
}
.sticker:active, .btn:active, .cat-tile:active, .chip:active, .circle-btn:active, .nav-btn:active {
  transform: translateY(3px); box-shadow: var(--shadow-pressed);
}

/* header */
.top {
  height: 68px; display: flex; align-items: center; justify-content: space-between; gap: 6px;
  padding: 0 var(--gutter); position: relative; overflow: hidden;
}
.home-top { background: var(--purple); color: #fff; }
.brand { display: flex; align-items: center; gap: 10px; font-size: 22px; color: #fff; text-decoration: none; position: relative; }
.circle { width: 44px; height: 44px; flex-shrink: 0; border-radius: 50%; background: #fff; border: var(--border); display: flex; align-items: center; justify-content: center; }
.circle-btn {
  width: 44px; height: 44px; flex-shrink: 0; border-radius: 50%; background: #fff; border: var(--border);
  display: flex; align-items: center; justify-content: center; color: var(--ink); padding: 0; position: relative;
}
.circle-btn.yellow { background: var(--yellow); }
.circle-btn.ink { background: var(--ink); }
.circle-btn[aria-pressed="true"] { background: var(--yellow); }
.top-title { font-size: 19px; }

/* category colors */
.cat-jataka { --c: var(--orange); --c-ink: var(--ink); }
.cat-dhammapada { --c: var(--green); --c-ink: var(--ink); }
.cat-thera { --c: var(--purple); --c-ink: #fff; }
.cat-bg { background: var(--c); color: var(--c-ink); }
.tag { align-self: flex-start; font-size: 12px; font-weight: 600; padding: 2px 10px; border-radius: 10px; background: var(--c, var(--orange-deep)); color: var(--c-ink, #fff); }

/* search */
.search { position: relative; }
.search input {
  width: 100%; height: 52px; border: var(--border); border-radius: 26px; background: #fff; box-shadow: var(--shadow);
  padding: 0 16px 0 50px; font: inherit; font-size: 16px; color: var(--ink);
}
.search input:focus { outline: 3px solid var(--purple); outline-offset: 2px; }
.search svg { position: absolute; left: 16px; top: 13px; }

/* buttons */
.btn {
  height: 54px; padding: 0 18px; border-radius: 27px; background: #fff; border: var(--border); box-shadow: var(--shadow);
  color: var(--ink); text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font-weight: 600; font-size: 15px; white-space: nowrap;
}
.btn span { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.btn.accent { background: var(--accent); color: #fff; }
.btn.sm { height: 44px; padding: 0 20px; align-self: flex-start; margin-top: 4px; }
.btn.dashed { border-style: dashed; box-shadow: none; height: 50px; margin-top: 6px; }
.btn-row { display: flex; gap: 10px; }

/* continue card */
.continue-card { display: flex; gap: 14px; padding: 14px; background: var(--yellow); color: var(--ink); border-radius: 20px; border: var(--border); box-shadow: var(--shadow-lg); }
.cover-sm { width: 80px; height: 108px; flex-shrink: 0; border-radius: 12px; background: #fff; border: var(--border); display: flex; align-items: center; justify-content: center; overflow: hidden; }
.cover-sm img { width: 100%; height: 100%; object-fit: cover; }
.title-lg { font-size: 20px; }
.ep { font-size: 14px; font-weight: 500; }
.progress { height: 10px; border-radius: 5px; background: #fff; border: var(--border-thin); overflow: hidden; margin-top: 2px; }
.progress i { display: block; height: 100%; width: 0; background: var(--green); }
.progress.pink { height: 12px; background: #E8F4FF; }
.progress.pink i { background: var(--pink); }

/* category tiles */
.cat-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.cat-tile {
  min-height: 150px; padding: 14px; border-radius: 22px; background: var(--c); color: var(--c-ink);
  border: var(--border); box-shadow: var(--shadow-lg); text-decoration: none;
  display: flex; flex-direction: column-reverse; justify-content: space-between; gap: 10px;
}
.cat-tile .col { gap: 2px; }
.cat-tile .name { font-size: 21px; }
.cat-tile .tagline { font-size: 13px; font-weight: 500; }
.cat-tile .circle { width: 60px; height: 60px; }
/* jataka, plus a tile left alone on the last row, go full width */
.cat-tile.cat-jataka, .cat-tile:last-child:nth-child(even) { grid-column: span 2; min-height: 118px; padding: 16px 18px; flex-direction: row; align-items: center; }
.cat-jataka .name, .cat-tile:last-child:nth-child(even) .name { font-size: 24px; }
.cat-jataka .tagline, .cat-tile:last-child:nth-child(even) .tagline { font-size: 14px; }
.cat-tile.cat-jataka .circle, .cat-tile:last-child:nth-child(even) .circle { width: 76px; height: 76px; }

/* covers row */
.covers { display: flex; gap: 14px; margin: 0 calc(-1 * var(--gutter)); padding: 10px var(--gutter) 8px; }
.cover-card { width: 128px; flex-shrink: 0; text-decoration: none; color: var(--ink); display: flex; flex-direction: column; gap: 8px; }
.cover-wrap { position: relative; }
.cover { width: 128px; height: 172px; border-radius: 16px; border: var(--border); box-shadow: var(--shadow); display: flex; align-items: center; justify-content: center; object-fit: cover; }
.cover-card .t { font-size: 15px; font-weight: 600; line-height: 1.35; }
.cover-card .tag { margin-top: -4px; font-size: 11px; padding: 1px 8px; border-radius: 8px; }
.new { position: absolute; top: -8px; right: -6px; font-size: 12px; font-weight: 700; background: var(--badge-new); color: #fff; padding: 2px 9px; border-radius: 10px; border: var(--border-thin); }

/* list rows */
.row { display: flex; align-items: center; gap: 12px; padding: 10px 12px 10px 10px; background: #fff; border: var(--border); border-radius: 18px; box-shadow: var(--shadow); text-decoration: none; color: var(--ink); }
.row .grow { display: flex; flex-direction: column; gap: 3px; }
.row .t { font-size: 16px; font-weight: 600; }
.row .sub { font-size: 13px; font-weight: 500; color: var(--text-secondary); }
.thumb { width: 58px; height: 58px; flex-shrink: 0; border-radius: 14px; border: var(--border-thin); display: flex; align-items: center; justify-content: center; }
.row-cover { width: 64px; height: 86px; flex-shrink: 0; border-radius: 12px; border: var(--border); object-fit: cover; display: flex; align-items: center; justify-content: center; }
.go { width: 32px; height: 32px; flex-shrink: 0; border-radius: 50%; background: var(--yellow); border: var(--border-thin); display: flex; align-items: center; justify-content: center; color: var(--ink); }
.go.play svg { width: 14px; height: 14px; }
.badge-read { display: none; align-items: center; gap: 4px; font-size: 12px; font-weight: 700; background: var(--green-soft); border: var(--border-thin); padding: 2px 8px; border-radius: 12px; white-space: nowrap; }
.story-row.is-read .badge-read { display: flex; }
.story-row.is-read .play { display: none; }

/* series */
.banner { position: relative; padding: 8px var(--gutter) 28px; display: flex; gap: 16px; border-radius: 0 0 32px 32px; border-bottom: var(--border); overflow: hidden; }
.banner h1 { font-size: 26px; line-height: 1.25; }
.banner p { margin: 0; font-size: 14px; font-weight: 500; line-height: 1.6; }
.cover-tilt { transform: rotate(-3deg); flex-shrink: 0; }
.cover-tilt > svg { width: 116px; height: 156px; padding: 40px 30px; border-radius: 16px; border: var(--border); box-shadow: var(--shadow-lg); background: var(--yellow-soft); }
.cover-tilt .cover { width: 116px; height: 156px; box-shadow: var(--shadow-lg); }
.pill-count { align-self: flex-start; font-size: 13px; font-weight: 600; background: #fff; color: var(--ink); border: var(--border-thin); padding: 2px 10px; border-radius: 12px; }
.page > .btn-row { margin-bottom: -6px; }
.chips { display: flex; gap: 8px; margin: -6px calc(-1 * var(--gutter)) -14px; padding: 0 var(--gutter) 6px; }
.chip { height: 44px; flex-shrink: 0; padding: 0 16px; border-radius: 22px; border: var(--border); background: #fff; color: var(--ink); font-size: 14px; font-weight: 600; }
.chip[aria-pressed="true"] { background: var(--purple); color: #fff; }

/* bottom nav */
.bottom-nav {
  position: fixed; bottom: 0; left: 50%; transform: translateX(-50%); width: 100%; max-width: 480px; z-index: 10;
  height: calc(72px + env(safe-area-inset-bottom)); padding: 0 6px env(safe-area-inset-bottom);
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); background: #fff; border-top: var(--border);
}
.bottom-nav a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; text-decoration: none; color: var(--text-muted); font-size: 12px; font-weight: 500; }
.bottom-nav span { height: 32px; display: flex; align-items: center; justify-content: center; }
.bottom-nav a[aria-current] { color: var(--ink); font-weight: 700; }
.bottom-nav a[aria-current] span { width: 52px; border-radius: 16px; background: var(--yellow); border: var(--border-thin); }
.bottom-nav a[aria-current] svg { width: 24px; height: 24px; }

/* reader */
.bar { transition: transform .2s; }
.reader-top {
  position: fixed; top: 0; left: 50%; transform: translateX(-50%); width: 100%; max-width: 720px; z-index: 10;
  height: 64px; padding: 0 10px; background: var(--purple); color: #fff; border-bottom: var(--border);
}
.rt { font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding-left: 4px; }
.rs { font-size: 12px; padding-left: 4px; }
.reader-main { padding: 64px 0 116px; }
.cpage { display: block; width: 100%; height: auto; }
.placeholder { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; color: var(--ink); font-weight: 600; text-align: center; padding: 16px; }
.placeholder small { font-weight: 400; }
.reader-nav {
  position: fixed; left: 50%; bottom: calc(16px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 10;
  width: calc(100% - 24px); max-width: 696px; height: 68px; border-radius: 34px; background: #fff; color: var(--ink);
  border: var(--border); box-shadow: var(--shadow-lg); display: flex; align-items: center; gap: 8px; padding: 0 8px;
}
.reader-nav .small { font-size: 12px; font-weight: 600; }
.nav-btn { width: 48px; height: 48px; flex-shrink: 0; border-radius: 50%; border: var(--border-thin); display: flex; align-items: center; justify-content: center; color: var(--ink); }
.nav-btn.sky { background: var(--sky-soft); }
.nav-btn.accent { background: var(--accent); color: #fff; }
.nav-btn.off { opacity: .35; }
body.bars-off .reader-top { transform: translate(-50%, -110%); }
body.bars-off .reader-nav { transform: translate(-50%, 160%); }

.moral-card { position: relative; margin: 28px var(--gutter) 0; padding: 22px 20px 20px; border-radius: 22px; background: var(--yellow); color: var(--ink); border: var(--border); box-shadow: var(--shadow-lg); display: flex; flex-direction: column; gap: 10px; }
.moral-card h2 { font-size: 21px; }
.moral-card .circle { width: 46px; height: 46px; }
.moral-card .big { margin: 0; font-size: 17px; font-weight: 500; line-height: 1.7; }
.moral-card .talk { margin: 0; padding: 10px 12px; border-radius: 14px; background: #fff; border: 2px dashed var(--ink); font-size: 14px; line-height: 1.6; }
.btn-row.end { margin: 18px var(--gutter) 0; }

/* content protection (deterrent only: screenshots and devtools can't be blocked on the web) */
picture { display: block; }
body { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
input, textarea { -webkit-user-select: text; user-select: text; }
img, svg { -webkit-user-drag: none; pointer-events: none; } /* long-press / right-click hit the parent, not the image */
@media print { body { display: none !important; } }
