/* Copyright (c) 2026 Aqta Technologies Limited. All rights reserved. */
#bedtime { max-width: 880px; align-items: stretch; gap: 22px; color: #22334B; }

/* Top bar */
.story-bar, .story-actions, .story-bar-right { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; }
.story-bar { justify-content: space-between; }
.story-bar-right { justify-content: flex-end; }
.story-read-toggle { display: inline-flex; align-items: center; gap: 10px; }
.story-switch { position: relative; flex: none; width: 44px; height: 26px; border-radius: 13px; background: #B9C4D0; transition: background .2s; }
.story-switch::after { content: ''; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #FFFDFA; box-shadow: 0 1px 2px rgba(34, 51, 75, .3); transition: transform .2s; }
.story-read-toggle[aria-checked="true"] .story-switch { background: #246471; }
.story-read-toggle[aria-checked="true"] .story-switch::after { transform: translateX(18px); }

.story-title { font-size: clamp(1.8rem, 4vw, 2.7rem); line-height: 1.12; text-wrap: balance; }
.story-lead { font-size: 1.25rem; line-height: 1.5; font-weight: 500; }
.story-note { font-size: 1.125rem; line-height: 1.5; color: #41536B; }

/* Story chooser */
.story-covers { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 230px), 1fr)); gap: 16px; }
.story-cover-card { display: flex; flex-direction: column; gap: 6px; padding: 10px 10px 16px; text-align: left; background: #FFFDFA; border: 2px solid #8E9BAA; border-radius: 16px; color: #22334B; font: inherit; cursor: pointer; }
.story-cover-card strong { font-size: 1.3rem; line-height: 1.25; padding: 6px 6px 0; }
.story-cover-card > span:last-child { font-size: 1.125rem; line-height: 1.4; font-weight: 500; color: #41536B; padding: 0 6px; }
.story-cover-card:hover { border-color: #246471; }
.story-cover-card:focus-visible { outline: 3px solid #0A7C8C; outline-offset: 4px; }
.story-cover { position: relative; display: block; width: 100%; aspect-ratio: 3 / 2; overflow: hidden; border-radius: 10px; background: #E7EDF4; }
.story-saved { padding: 14px 16px; background: #E7EDF4; border-radius: 14px; }
.story-saved .story-note { flex-basis: 100%; margin: 0; color: #22334B; font-weight: 700; }

/* Setup */
.story-intro { display: grid; grid-template-columns: 1.15fr 1fr; align-items: center; gap: 28px; }
.story-intro p { max-width: 40ch; line-height: 1.55; font-size: 1.2rem; }
.story-intro .story-note { margin-top: 10px; font-size: 1.05rem; }
.story-selection { border: 0; padding: 0; min-width: 0; }
.story-selection legend { font-size: 1.3rem; font-weight: 800; margin-bottom: 12px; }
.story-options { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.story-options-character { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.story-option { position: relative; display: flex; flex-direction: column; gap: 8px; align-items: center; justify-content: flex-end; padding: 12px 12px 16px; min-height: 56px; border: 3px solid #B9C4D0; border-radius: 16px; background: #FFFDFA; cursor: pointer; font-size: 1.2rem; font-weight: 700; text-align: center; transition: transform .15s, border-color .15s; }
.story-option:has(input:checked) { background: #E0EDF0; border-color: #246471; transform: translateY(-2px); box-shadow: 0 6px 0 -2px #CFE0E4; }
.story-option input { position: absolute; z-index: 1; top: 10px; left: 10px; width: 26px; height: 26px; accent-color: #246471; }
.story-choice-picture { position: relative; display: block; width: 100%; height: 132px; overflow: hidden; border-radius: 10px; }
.story-choice-image { display: block; width: 100%; height: 100%; object-fit: contain; }
.story-choice-setting .story-choice-image, .story-choice-window .story-choice-image { object-fit: cover; }
.story-choice-window .story-choice-image { object-position: 88% 18%; transform: scale(1.9); transform-origin: 84% 22%; }
.story-choice-flowers .story-choice-image, .story-choice-pond .story-choice-image { position: absolute; width: 200%; max-width: none; object-fit: cover; }
.story-choice-flowers .story-choice-image { left: 0; }
.story-choice-pond .story-choice-image { right: 0; }
.story-heart { position: absolute; right: 18%; top: 12%; width: 30px; height: 28px; }
.story-heart::before, .story-heart::after { content: ''; position: absolute; top: 0; width: 16px; height: 25px; background: #F28AA0; border-radius: 16px 16px 0 0; }
.story-heart::before { left: 14px; transform: rotate(-45deg); transform-origin: 0 100%; }
.story-heart::after { left: 0; transform: rotate(45deg); transform-origin: 100% 100%; }
.story-option:focus-within, #bedtime button:focus-visible { outline: 3px solid #0A7C8C; outline-offset: 4px; }
.story-option:hover { border-color: #246471; }

/* Pages */
.story-progress { display: flex; align-items: center; gap: 14px; color: #41536B; font-size: 1rem; font-variant-numeric: tabular-nums; }
.story-dots { display: inline-flex; gap: 6px; }
.story-dots span { width: 10px; height: 10px; border-radius: 50%; background: #CBD3DC; }
.story-dots .is-read { background: #8FB4BB; }
.story-dots .is-here { background: #246471; transform: scale(1.25); }
.story-spread { width: 100%; max-width: 760px; align-self: center; overflow: hidden; border-radius: 16px; background: #FFFDFA; border: 1px solid #D9D2C3; }
.story-picture { position: relative; isolation: isolate; width: 100%; aspect-ratio: 3 / 2; overflow: hidden; border-radius: 12px; background: #E7EDF4; }
.story-spread > .story-picture { border-radius: 0; }
.story-backdrop { display: block; width: 100%; height: 100%; object-fit: cover; user-select: none; -webkit-user-select: none; }
.story-hero { position: absolute; left: 10%; bottom: 12%; width: 27%; height: 48%; }
.story-hero-image, .story-prop-image { display: block; width: 100%; height: 100%; object-fit: contain; object-position: center bottom; pointer-events: none; user-select: none; -webkit-user-select: none; }
.story-prop { position: absolute; display: block; }
.story-tap { padding: 0; margin: 0; border: 0; background: transparent; color: inherit; font: inherit; cursor: pointer; -webkit-tap-highlight-color: transparent; touch-action: manipulation; min-width: 48px; min-height: 48px; }
#bedtime .story-tap { min-height: 48px; max-width: none; }
.story-hero-button { transform-origin: 50% 100%; animation: story-breathe 5s ease-in-out infinite; }
.story-hero-button.is-tapped { animation: story-hop .6s ease-out; }
.story-spot { position: absolute; border-radius: 50%; }
.story-spot.is-tapped::after, .story-spot.is-found::after, .story-prop.is-found::after, .story-star.is-found::before { content: ''; position: absolute; inset: -4px; border-radius: 50%; border: 4px solid rgba(255, 236, 170, .95); box-shadow: 0 0 18px 6px rgba(255, 220, 120, .55); animation: story-ring 1.2s ease-out both; }
.story-spot.is-found::after, .story-prop.is-found::after, .story-star.is-found::before { animation: story-ring-stay 1.2s ease-out both; }
.story-prop-blanket.is-tapped { animation: story-wiggle .6s ease-in-out; }
.story-prop-lantern .story-prop-image { transition: filter .5s; animation: story-flicker 4s ease-in-out infinite; }
.story-prop-lantern.is-glowing .story-prop-image { filter: brightness(1.2) drop-shadow(0 0 14px rgba(255, 205, 90, .95)) drop-shadow(0 0 34px rgba(255, 190, 70, .7)); }
.story-star { position: absolute; display: block; width: max(48px, 10%); aspect-ratio: 1; height: auto; border-radius: 50%; transform: translate(-50%, -50%); }
.story-star::after { content: ''; position: absolute; inset: 2px; border-radius: 50%; background: radial-gradient(circle, #FFFDF2 0 14%, #FFE7A0 26%, rgba(255, 214, 110, .45) 40%, rgba(255, 214, 110, 0) 62%), linear-gradient(transparent 47%, rgba(255, 243, 200, .95) 47% 53%, transparent 53%), linear-gradient(90deg, transparent 47%, rgba(255, 243, 200, .95) 47% 53%, transparent 53%); filter: drop-shadow(0 0 6px rgba(255, 226, 140, .9)); animation: story-twinkle 3s ease-in-out infinite; }
.story-star.is-tapped::after { animation: story-sparkle .8s ease-out; }
.story-star-cover { left: 77%; top: 21%; }
.story-star-thumb { left: 50%; top: 50%; width: 48px; pointer-events: none; }
.story-route { position: absolute; top: 8%; left: 6%; display: block; width: 26%; height: 27%; overflow: hidden; border: 4px solid #FFFDFA; border-radius: 8px; }
.story-route-image { position: absolute; width: 200%; max-width: none; height: 100%; object-fit: cover; }
.story-route-flowers .story-route-image { left: 0; }
.story-route-pond .story-route-image { right: 0; }
.story-cover .story-hero { left: 6%; bottom: 8%; width: 32%; height: 56%; }

.story-words { user-select: text; min-width: 0; padding: clamp(20px, 3vw, 36px); }
.story-words h2 { font-size: 1.45rem; line-height: 1.25; margin-bottom: 18px; }
.story-words p { font-weight: 500; font-size: 1.3rem; line-height: 1.65; max-width: 50ch; padding: 2px 8px; margin-left: -8px; border-radius: 8px; transition: background .3s; }
.story-words p + p { margin-top: 16px; }
.story-words p.is-reading { background: #FFF3CF; }
.story-words ::selection { background: #DCEAEC; color: #22334B; }
.story-large .story-words p { font-size: 1.65rem; }
.story-large .story-words h2 { font-size: 1.8rem; }
.story-find { display: flex; align-items: center; gap: 12px; margin: 0; padding: 12px 16px; border-radius: 14px; background: #FFF6DC; border: 2px dashed #E3B24B; font-size: 1.25rem; font-weight: 700; color: #22334B; }
.story-find-mark { flex: none; width: 30px; height: 30px; border-radius: 50%; border: 4px solid #C98A12; position: relative; }
.story-find-mark::after { content: ''; position: absolute; right: -10px; bottom: -8px; width: 12px; height: 4px; background: #C98A12; border-radius: 2px; transform: rotate(45deg); }
.story-find.is-found { background: #E3F2EC; border-style: solid; border-color: #6CC4A1; }
.story-find.is-found .story-find-mark { border-color: #2E8B6A; background: #2E8B6A; }
.story-find.is-found .story-find-mark::after { display: none; }

/* Bottom controls stay in reach while reading */
.story-dock { position: sticky; bottom: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 0 -12px; padding: 12px 12px calc(12px + env(safe-area-inset-bottom)); background: rgba(239, 248, 252, .96); border-top: 1px solid #D5DEE7; -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px); }
.story-voice { display: flex; gap: 10px; }
.story-voice[hidden] { display: none; }
.story-play, .story-again, .story-turn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
.story-icon { display: inline-flex; }
.story-size-short { display: none; font-weight: 800; }
#bedtime .story-dock button { min-height: 56px; min-width: 56px; }
#bedtime .story-turn { min-width: 96px; }
#bedtime button { min-height: 52px; max-width: 100%; white-space: normal; font-size: 1.05rem; }
#bedtime .journey-button { background: #246471; color: #FFFDFA; border-color: #246471; }

@keyframes story-breathe { 0%, 100% { transform: scale(1, 1); } 50% { transform: scale(1.015, .985); } }
@keyframes story-hop { 0% { transform: translateY(0); } 40% { transform: translateY(-9%); } 70% { transform: translateY(0) scale(1.03, .97); } 100% { transform: none; } }
@keyframes story-wiggle { 0%, 100% { transform: rotate(0); } 30% { transform: rotate(-4deg); } 60% { transform: rotate(3deg); } }
@keyframes story-flicker { 0%, 100% { filter: brightness(1); } 50% { filter: brightness(1.08); } }
@keyframes story-twinkle { 0%, 100% { transform: scale(1); opacity: .9; } 50% { transform: scale(1.18); opacity: 1; } }
@keyframes story-sparkle { 0% { transform: scale(1); } 40% { transform: scale(1.8); } 100% { transform: scale(1); } }
@keyframes story-ring { 0% { opacity: 0; transform: scale(.6); } 30% { opacity: 1; } 100% { opacity: 0; transform: scale(1.15); } }
@keyframes story-ring-stay { 0% { opacity: 0; transform: scale(.6); } 100% { opacity: 1; transform: scale(1); } }
@media (prefers-reduced-motion: reduce) {
  .story-hero-button, .story-hero-button.is-tapped, .story-prop-lantern .story-prop-image, .story-star::after, .story-prop-blanket.is-tapped, .story-spot::after, .story-prop::after, .story-star::before { animation: none !important; }
  .story-option, .story-switch, .story-switch::after, .story-words p { transition: none; }
  .story-option:has(input:checked) { transform: none; }
}

@media (max-width: 600px) {
  #bedtime { gap: 16px; }
  .story-bar { flex-wrap: nowrap; }
  .story-bar-right { flex-wrap: nowrap; }
  .story-bar .quiet-button { padding-left: 12px; padding-right: 12px; }
  .story-size-long { display: none; }
  .story-size-short { display: inline; }
  #bedtime .story-size { min-width: 52px; }
  .story-intro { grid-template-columns: 1fr; gap: 12px; }
  .story-options { gap: 10px; }
  .story-option { padding: 10px 7px 12px; font-size: 1.125rem; }
  .story-option input { width: 22px; height: 22px; top: 8px; left: 8px; }
  .story-choice-picture { height: 104px; }
  .story-choice-character { padding-top: 18px; }
  .story-words { padding: 18px 18px 22px; }
  .story-words p { font-size: 1.2rem; }
  .story-large .story-words p { font-size: 1.5rem; }
  .story-dock { gap: 8px; }
  .story-voice { gap: 8px; }
  #bedtime .story-turn { min-width: 0; flex: 1 1 0; }
  .story-play span:last-child, .story-again span:last-child { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
}
@media (max-width: 360px) {
  .story-bar { gap: 8px; }
  .story-read-toggle { gap: 6px; }
  .story-choice-picture { height: 88px; }
}
#bedtime > .story-actions { margin-top: 0; }
#bedtime > .story-dock { margin-top: auto; }
:root:has(#bedtime:not([hidden])) { scroll-padding-bottom: 110px; }
#bedtime .story-tap[data-find] { z-index: 3; }
/* Wide and short-landscape screens: picture and words side by side, so both fit on screen. */
@media (min-width: 960px), (orientation: landscape) and (max-height: 620px) and (min-width: 640px) {
  #bedtime[data-step="page"] { max-width: 1180px; }
  #bedtime[data-step="page"] .story-spread { max-width: none; display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); align-items: center; }
  #bedtime[data-step="page"] .story-spread > .story-picture { align-self: center; }
  #bedtime[data-step="page"] .story-words p { font-size: 1.25rem; }
  #bedtime[data-step="page"].story-large .story-words p { font-size: 1.55rem; }
}
@media (orientation: landscape) and (max-height: 620px) {
  #bedtime { gap: 12px; }
  #bedtime[data-step="page"] > .story-title { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  #bedtime .story-words { padding: 14px 18px; }
  #bedtime .story-words h2 { margin-bottom: 8px; font-size: 1.25rem; }
  #bedtime[data-step="page"] .story-words p { font-size: 1.15rem; line-height: 1.5; }
  #bedtime .story-words p + p { margin-top: 8px; }
  .story-dock { padding-top: 8px; padding-bottom: calc(8px + env(safe-area-inset-bottom)); }
}

/* Phone readability pass, 20 November 2026: story text and controls stay at 18px or more. */
#bedtime button, .story-note, .story-intro .story-note, .story-progress, .story-cover-card > span:last-child { font-size: 1.125rem; }
#bedtime[data-step="page"] .story-words p { font-size: 1.2rem; }
/* Thai helper lines inside story controls stay readable and do not crowd the art. */
#bedtime .th-help { font-size: 1.125rem; font-weight: 500; }
#bedtime .story-title .th-help { margin-top: 4px; }
#bedtime button:has(> .th-help) { flex-direction: column; gap: 0; }
#bedtime .journey-button .th-help, .journey-button .th-help { color: inherit; opacity: .92; }
