/*
VOICE: a cosy storybook night; playful, warm and gentle.
IDEA: a snow globe on a mantelpiece; the 3D scene is the whole page and the UI is frosted paper labels around it.
PICTURE: the procedurally modelled tree, full-bleed, with falling snow and a fairytale castle far behind.
COLOUR and TYPE: midnight blue sky, pine green, berry red #d8283a and candle gold #f3c14b on frosted white; Mali, rounded Thai lettering.
LAYOUT: title top-left, tools top-right, the ornament tray docked at the bottom; stacked on phones.
*/
:root {
  color-scheme: dark;
  --ink: #23213a;
  --paper: rgba(255, 252, 247, 0.93);
  --red: #d8283a;
  --gold: #f3c14b;
  --pine: #1f7a4a;
  --sky: #0f1b3d;
  --shadow: 0 10px 30px rgba(5, 10, 35, 0.35);
}
* { box-sizing: border-box; min-width: 0; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--sky); }
body { font: 500 16px/1.5 Mali, "Noto Sans Thai", system-ui, sans-serif; color: var(--ink); -webkit-tap-highlight-color: transparent; }
#scene { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; outline: none; }
button, a { font: inherit; }

.title { position: fixed; top: 18px; left: 22px; color: #fff; pointer-events: none; max-width: 46vw; }
.title h1 { margin: 0; font-size: clamp(28px, 4vw, 46px); line-height: 1.05; font-weight: 700; text-wrap: balance; text-shadow: 0 3px 0 rgba(216, 40, 58, 0.55), 0 8px 24px rgba(0, 0, 0, 0.4); }
.title p { margin: 8px 0 0; font-size: 16px; text-shadow: 0 2px 10px rgba(0, 0, 0, 0.6); }
.title .count { display: inline-block; margin-top: 10px; padding: 2px 12px; border-radius: 99px; background: rgba(243, 193, 75, 0.95); color: var(--ink); font-size: 14px; font-weight: 600; text-shadow: none; }

.tools { position: fixed; top: 16px; right: 16px; display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; max-width: min(560px, 50vw); }
.tools button, .tabs button, .modal button, .modal a {
  min-height: 44px; padding: 8px 16px; border: 0; border-radius: 99px; background: var(--paper); color: var(--ink);
  box-shadow: var(--shadow); cursor: pointer; font-size: 15px; font-weight: 600; white-space: nowrap; text-decoration: none;
  transition: transform 0.15s ease, background 0.15s ease;
}
.tools button:hover, .tabs button:hover { transform: translateY(-2px); }
.tools button:active { transform: translateY(1px); }
.tools .primary { background: var(--red); color: #fff; }
.tools [aria-pressed="true"] { background: var(--gold); }
#erase[aria-pressed="true"] { background: #ff9db0; }
:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }

.dock { position: fixed; left: 50%; bottom: 14px; transform: translateX(-50%); width: min(1120px, calc(100% - 24px)); background: var(--paper); border-radius: 26px; box-shadow: var(--shadow); padding: 10px 10px 8px; }
.tabs { display: flex; gap: 6px; overflow-x: auto; padding: 2px 2px 8px; scrollbar-width: none; }
.tabs button { box-shadow: none; background: transparent; min-height: 40px; padding: 6px 14px; flex: none; }
.tabs button[aria-selected="true"] { background: var(--pine); color: #fff; }
.tray { display: flex; gap: 8px; overflow-x: auto; scroll-snap-type: x mandatory; padding: 4px 2px 6px; scrollbar-width: thin; }
.card { flex: none; width: 96px; scroll-snap-align: start; border: 2px solid transparent; border-radius: 18px; background: #fff; padding: 6px 4px 6px; cursor: pointer; text-align: center; color: var(--ink); font: inherit; font-size: 13px; line-height: 1.25; transition: transform 0.15s, border-color 0.15s; }
.card:hover { transform: translateY(-3px); }
.card img { width: 72px; height: 72px; display: block; margin: 0 auto 4px; border-radius: 14px; background: radial-gradient(circle at 50% 40%, #fff 0, #eaf1ff 70%); }
.card span { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; min-height: 2.5em; }
.card[aria-selected="true"] { border-color: var(--red); box-shadow: 0 0 0 3px rgba(243, 193, 75, 0.9); }
.card.action { background: #fff7df; }

.cozy { position: fixed; top: 196px; left: 22px; display: flex; flex-direction: column; align-items: flex-start; gap: 8px; }
.cozy button { min-height: 44px; padding: 8px 16px; border: 0; border-radius: 99px; background: rgba(255, 236, 214, 0.95); color: #6a2b1f; font-size: 15px; font-weight: 700; box-shadow: var(--shadow); cursor: pointer; white-space: nowrap; transition: transform 0.15s; }
.cozy button:hover { transform: translateX(3px); }
.cozy button[aria-pressed="true"] { background: var(--gold); }

.sheet { background: #fffaf3; border-radius: 26px; width: min(560px, 100%); max-height: min(86vh, 760px); display: flex; flex-direction: column; box-shadow: var(--shadow); overflow: hidden; }
.sheet header { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 18px 10px 22px; background: linear-gradient(#ffe9d2, #fffaf3); }
.sheet h2 { margin: 0; font-size: 24px; line-height: 1.2; color: #8a2a24; }
.sheet .sheet-close { min-height: 40px; box-shadow: none; background: #fff; }
.sheet-body { padding: 6px 22px 22px; overflow-y: auto; }
.sheet h3 { margin: 18px 0 6px; font-size: 17px; }
.lead { margin: 6px 0 12px; color: #5b4a52; }
.center { text-align: center; }
.reply { margin: 0 0 14px; padding: 12px 16px; border-radius: 18px; background: color-mix(in srgb, var(--c, #ffd9a8) 35%, #fff); border: 2px solid var(--c, #ffd9a8); }
.reply p { margin: 0 0 6px; }
.reply .tip { color: #6a4a52; font-size: 15px; }
.stack-form { display: grid; gap: 8px; }
.stack-form label { font-weight: 600; }
textarea { width: 100%; font: inherit; font-size: 16px; padding: 10px 12px; border-radius: 14px; border: 2px solid #f0d7c4; background: #fff; color: var(--ink); resize: vertical; }
textarea:focus { outline: 3px solid var(--gold); border-color: transparent; }
.btn { min-height: 44px; padding: 8px 18px; border: 0; border-radius: 99px; background: #f6e7d8; color: var(--ink); font: inherit; font-weight: 600; cursor: pointer; }
.btn.primary { background: var(--red); color: #fff; }
.btn.ghost { background: transparent; border: 2px solid #f0d7c4; text-align: left; width: 100%; }
.row { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; margin-top: 12px; }
.chips { border: 0; padding: 0; margin: 0 0 6px; display: flex; flex-wrap: wrap; gap: 8px; }
.chips legend { font-weight: 600; margin-bottom: 6px; }
.chip input { position: absolute; opacity: 0; }
.chip span { display: inline-flex; align-items: center; min-height: 40px; padding: 6px 14px; border-radius: 99px; background: #fff; border: 2px solid var(--c); cursor: pointer; }
.chip input:checked + span { background: var(--c); font-weight: 700; }
.chip input:focus-visible + span { outline: 3px solid var(--gold); }
.wish-list, .journal, .story-list, .songs { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.wish-list li { padding: 8px 12px; border-radius: 14px; background: #fff7df; }
.wish-list li::before { content: "★ "; color: #e9b43c; }
.journal li { padding: 10px 12px; border-radius: 14px; background: #fff; border: 1px solid #f3e2d4; }
.journal small { color: #8a7a80; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; }
.story p { font-size: 17px; line-height: 1.8; margin: 0 0 12px; }
.story p:first-child::first-letter { font-size: 1.6em; color: var(--red); }
.cocoa { text-align: center; }
.mug { width: min(220px, 60%); }
.steam path { fill: none; stroke: #c9b7ad; stroke-width: 4; stroke-linecap: round; opacity: 0.7; animation: rise 2.6s ease-in-out infinite; }
.steam path:nth-child(2) { animation-delay: 0.8s; }
.steam path:nth-child(3) { animation-delay: 1.6s; }
@keyframes rise { 0% { transform: translateY(8px); opacity: 0; } 50% { opacity: 0.7; } 100% { transform: translateY(-10px); opacity: 0; } }
.breathe { display: grid; place-items: center; gap: 14px; padding: 20px 0 6px; }
.orb { width: 90px; height: 90px; border-radius: 50%; background: radial-gradient(circle at 40% 40%, #ffe6a8, #ff9a4a 60%, #d8283a); box-shadow: 0 0 40px rgba(255, 154, 74, 0.7); transition: transform 4s ease-in-out; }
.orb.in, .orb.hold { transform: scale(1.8); }
.orb.out { transform: scale(1); transition-duration: 6s; }
.breathe p { font-size: 20px; font-weight: 700; margin: 30px 0 0; }
.song { width: 100%; text-align: left; border: 2px solid #f0d7c4; background: #fff; border-radius: 16px; padding: 8px 14px; cursor: pointer; font: inherit; color: var(--ink); }
.song small { display: block; color: #8a7a80; font-size: 13px; }
.song.on { border-color: var(--pine); background: #e8f6ee; }
.vol { display: flex; gap: 10px; align-items: center; justify-content: center; margin-top: 12px; font-weight: 600; }
.vol input { width: 180px; accent-color: var(--red); }

input[type=url], input[type=text] { width: 100%; font: inherit; font-size: 16px; min-height: 44px; padding: 8px 12px; border-radius: 14px; border: 2px solid #f0d7c4; background: #fff; color: var(--ink); }
.yt-search { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.yt-search a.btn { color: var(--ink); background: #fff; box-shadow: none; min-height: 40px; padding: 6px 14px; border: 2px solid #f0d7c4; }
.yt-search .btn { width: auto; display: inline-flex; align-items: center; text-decoration: none; font-size: 14px; }
.yt-row { display: flex; gap: 8px; align-items: center; }
.yt-row .song small { overflow-wrap: anywhere; }
#yt-player { position: fixed; right: 16px; bottom: 214px; width: min(340px, calc(100% - 32px)); background: var(--paper); border-radius: 18px; box-shadow: var(--shadow); overflow: hidden; z-index: 5; }
#yt-player[hidden] { display: none; }
#yt-player header { display: flex; align-items: center; gap: 8px; padding: 6px 8px 6px 14px; font-size: 14px; }
#yt-player header b { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#yt-player header a { color: var(--red); font-size: 13px; white-space: nowrap; }
#yt-player header button { color: var(--ink); min-height: 36px; border: 0; border-radius: 99px; padding: 4px 12px; background: #f6e7d8; font: inherit; cursor: pointer; }
#yt-player iframe { display: block; width: 100%; aspect-ratio: 16 / 9; border: 0; background: #000; }

.ic { display: inline-flex; width: 22px; height: 22px; flex: none; }
.ic svg { width: 100%; height: 100%; display: block; filter: drop-shadow(0 1px 0 rgba(0, 0, 0, 0.12)); }
[data-icon] { display: inline-flex; align-items: center; gap: 7px; }
.tools .primary .ic svg, .tabs [aria-selected="true"] .ic svg { filter: drop-shadow(0 0 2px rgba(255, 255, 255, 0.9)); }
.tools .icon-only { width: 46px; padding: 0; justify-content: center; }
.tools .icon-only .lb { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.tools .icon-only .ic { width: 24px; height: 24px; }
@media (max-width: 700px) { .tabs [data-icon] .ic { width: 20px; height: 20px; } }

#toast { position: fixed; left: 50%; bottom: 200px; transform: translate(-50%, 12px); background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 99px; font-size: 15px; opacity: 0; transition: opacity 0.25s, transform 0.25s; pointer-events: none; max-width: calc(100% - 32px); text-align: center; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }

.modal { position: fixed; inset: 0; display: grid; place-items: center; background: rgba(6, 10, 30, 0.7); padding: 16px; }
.modal[hidden] { display: none; }
.modal figure { margin: 0; background: var(--paper); border-radius: 24px; padding: 14px; max-width: min(760px, 100%); box-shadow: var(--shadow); text-align: center; }
.modal img { width: 100%; border-radius: 14px; display: block; }
.modal figcaption { margin: 10px 0; font-size: 14px; }
.modal .row { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.modal a { background: var(--red); color: #fff; display: inline-flex; align-items: center; }

#loading { position: fixed; inset: 0; display: grid; place-items: center; background: var(--sky); color: #fff; font-size: 22px; transition: opacity 0.5s; }
#loading.done { opacity: 0; pointer-events: none; }

@media (max-width: 700px) {
  .title { top: 12px; left: 14px; max-width: calc(100% - 28px); }
  .title h1 br { display: none; }
  .title p#hint { font-size: 14px; }
  .tools { top: auto; bottom: 196px; left: 8px; right: 8px; max-width: none; flex-wrap: nowrap; overflow-x: auto; justify-content: flex-start; padding: 4px 4px 8px; scrollbar-width: none; }
  .tools button { flex: none; font-size: 14px; padding: 8px 13px; }
  .dock { bottom: 8px; border-radius: 22px; }
  .card { width: 84px; font-size: 13px; }
  .card img { width: 64px; height: 64px; }
  #toast { bottom: 260px; }
  .title .count { display: none; }
  #yt-player { bottom: 252px; right: 8px; width: 240px; }
  .cozy { top: 96px; left: 8px; right: 8px; flex-direction: row; overflow-x: auto; padding: 4px; scrollbar-width: none; }
  .cozy button { flex: none; font-size: 14px; padding: 8px 13px; }
  .sheet h2 { font-size: 21px; }
  .sheet-body { padding: 6px 16px 18px; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
