/* Starling — Nocturne. One dark room, one warm light. */

:root {
  --bg: #070b14; --ink: #ece5d3; --ink-2: #9aa3b8; --ink-3: #5d6578; --accent: #f0b45e; --accent-2: #c4dcff;
  --rule: rgba(236,229,211,0.22); --card: rgba(7,11,20,0.66); --card-blur: 12px;
  --font-display: "Cormorant Garamond", "Iowan Old Style", Georgia, serif;
  --font-body: "EB Garamond", "Iowan Old Style", Georgia, serif;
  --sat: env(safe-area-inset-top, 0px); --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px); --sar: env(safe-area-inset-right, 0px);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
html { background: var(--bg); }
body {
  height: 100dvh; overflow: hidden; background: var(--bg); color: var(--ink); font-family: var(--font-body); font-size: 17px;
  -webkit-font-smoothing: antialiased; overscroll-behavior: none; -webkit-text-size-adjust: 100%;
}
button, input { font: inherit; color: inherit; }
button:focus-visible, input:focus-visible, .btn.is-focus { outline: 2px solid var(--accent); outline-offset: 2px; }
::selection { background: rgba(240,180,94,0.35); }

.stage { position: fixed; inset: 0; overflow: hidden; touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
#field { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

/* ---------- HUD ---------- */
.hud { position: absolute; inset: 0; pointer-events: none; color: var(--ink); text-shadow: 0 1px 2px rgba(0,0,0,.7); }
.hud[hidden] { display: none; }
.hud-l { position: absolute; left: calc(14px + var(--sal)); top: calc(10px + var(--sat)); display: flex; flex-direction: column; gap: 2px; }
.hud-c { position: absolute; left: 50%; top: calc(10px + var(--sat)); transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 4px; white-space: nowrap; }
.hud-r { position: absolute; right: calc(14px + var(--sar)); top: calc(10px + var(--sat)); display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.hud-label { font-size: 11px; letter-spacing: .18em; text-transform: uppercase; color: var(--ink-2); }
.hud-score { font-family: var(--font-display); font-size: 30px; font-weight: 600; line-height: 1; font-variant-numeric: tabular-nums; }
.hud-mult { font-size: 12px; color: var(--accent); letter-spacing: .1em; }
.hud-night { font-size: 12px; letter-spacing: .16em; text-transform: uppercase; color: var(--ink-2); }
.hud-wind { display: flex; align-items: center; gap: 6px; font-size: 11px; letter-spacing: .14em; text-transform: uppercase; color: var(--ink-2); }
.hud-wind[hidden] { display: none; }
.hud-wind i { display: block; width: 40px; height: 2px; background: linear-gradient(90deg, transparent, var(--ink-2)); transform-origin: center; transition: transform .3s; }
.hud-oil { display: block; width: 80px; height: 4px; margin-top: 6px; background: rgba(255,255,255,.14); border-radius: 2px; overflow: hidden; }
.hud-oil-fill { display: block; height: 100%; width: 50%; background: var(--accent); box-shadow: 0 0 8px var(--accent); transition: width .2s; }
.hud-oil-fill.is-ready { animation: oilpulse 1.4s ease-in-out infinite; }
@keyframes oilpulse { 50% { filter: brightness(1.5); } }
.hud-lanterns, .hud-straw { display: flex; gap: 5px; }
.hud-lanterns i, .hud-straw i { display: block; width: 10px; height: 14px; border-radius: 2px 2px 4px 4px; background: var(--accent); box-shadow: 0 0 10px var(--accent); transition: background .3s, box-shadow .3s; }
.hud-lanterns i.off { background: transparent; box-shadow: none; border: 1px solid var(--ink-2); opacity: .5; }
.hud-lanterns i.carried { animation: swing .5s ease-in-out infinite alternate; }
@keyframes swing { from { transform: rotate(-12deg); } to { transform: rotate(12deg); } }
.hud-straw i { width: 8px; height: 8px; border-radius: 50%; background: var(--ink); box-shadow: none; }
.hud-straw i.off { background: transparent; border: 1px solid var(--ink-2); opacity: .5; }
.hud-roost { position: absolute; left: 50%; top: calc(58px + var(--sat)); transform: translateX(-50%); width: min(60vw, 320px); display: flex; flex-direction: column; align-items: center; gap: 4px; }
.hud-roost[hidden] { display: none; }
.hud-roost-name { font-family: var(--font-display); font-size: 15px; letter-spacing: .12em; text-transform: uppercase; color: var(--accent-2); }
.hud-roost-bar { display: block; width: 100%; height: 3px; background: rgba(255,255,255,.14); border-radius: 2px; overflow: hidden; }
.hud-roost-bar i { display: block; height: 100%; width: 100%; background: var(--accent-2); box-shadow: 0 0 8px var(--accent-2); transition: width .25s; }
.hud-hint { position: absolute; left: 0; right: 0; bottom: calc(10px + var(--sab)); margin: 0; text-align: center; font-size: 12.5px; color: var(--ink-2); opacity: .85; transition: opacity .6s; }
.hud-hint.is-gone { opacity: 0; }
.hud-wave { position: absolute; left: 50%; top: 38%; transform: translateX(-50%); margin: 0; font-family: var(--font-display); font-size: 26px; font-style: italic; color: var(--ink); opacity: 0; transition: opacity .4s; pointer-events: none; }
.hud-wave.is-on { opacity: .9; }
body.has-banner .hud-wave { opacity: 0; }
body.has-banner .hud-c, body.has-banner .hud-roost { opacity: 0; transition: opacity .3s; }

.touch-ui { display: none; }
body.touch .touch-ui { display: block; }
.touch-btn { position: absolute; pointer-events: auto; border: 1px solid rgba(236,229,211,.35); background: rgba(7,11,20,.45); color: var(--ink); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); }
.touch-btn--pause { top: calc(44px + var(--sat)); right: calc(14px + var(--sar)); width: 44px; height: 44px; border-radius: 10px; font-size: 13px; font-weight: 700; letter-spacing: .1em; }
.touch-btn--flare { bottom: calc(28px + var(--sab)); right: calc(22px + var(--sar)); width: 84px; height: 84px; border-radius: 50%; font-size: 14px; letter-spacing: .14em; text-transform: uppercase; box-shadow: 0 0 0 6px rgba(240,180,94,.12), 0 0 24px rgba(240,180,94,.2); transition: box-shadow .2s, transform .1s; }
.touch-btn--flare.is-ready { border-color: var(--accent); box-shadow: 0 0 0 6px rgba(240,180,94,.25), 0 0 34px rgba(240,180,94,.45); }
.touch-btn--flare:active { transform: scale(.94); }
.when-paused { display: none; }
body.paused .when-paused { display: inline; }
body.paused .when-playing { display: none; }
body.paused .touch-btn--flare { display: none; }
body.has-screen .hud-l, body.has-screen .hud-c, body.has-screen .hud-r, body.has-screen .hud-roost, body.has-screen .hud-hint { opacity: .35; transition: opacity .3s; }
body.lefthand .touch-btn--flare { right: auto; left: calc(22px + var(--sal)); }
body.touch .hud-hint { bottom: calc(14px + var(--sab)); }

/* ---------- overlays ---------- */
.banner { position: absolute; left: 0; right: 0; top: max(18vh, calc(80px + var(--sat))); text-align: center; pointer-events: none; animation: banner 1.2s ease-out both; text-shadow: 0 2px 8px rgba(0,0,0,.8); }
.banner[hidden] { display: none; }
.banner .kicker { margin: 0; font-size: 13px; letter-spacing: .3em; text-transform: uppercase; color: var(--accent); }
.banner .name { margin: 2px 0 8px; font-family: var(--font-display); font-size: clamp(34px, min(9vw, 12vh), 68px); font-weight: 600; font-style: italic; line-height: 1; }
.banner .line { margin: 0 auto; max-width: 42ch; padding: 0 20px; font-size: 15px; line-height: 1.45; color: var(--ink-2); }
@keyframes banner { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
.banner.is-out { animation: bannerout .8s ease-in both; }
@keyframes bannerout { to { opacity: 0; transform: translateY(-10px); } }

.toast { position: absolute; left: 50%; bottom: max(30vh, 220px); transform: translateX(-50%); margin: 0; max-width: min(88vw, 56ch); padding: 8px 16px; text-align: center; font-size: 16px; font-style: italic; line-height: 1.4; color: var(--ink); background: rgba(7,11,20,.55); border-radius: 3px; pointer-events: none; animation: toast .35s ease-out both; }
.toast[hidden] { display: none; }
@keyframes toast { from { opacity: 0; transform: translate(-50%, 6px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* ---------- screens ---------- */
.screens { position: absolute; inset: 0; pointer-events: none; }
.screen { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; padding: calc(16px + var(--sat)) calc(16px + var(--sar)) calc(16px + var(--sab)) calc(16px + var(--sal)); pointer-events: auto; overflow-y: auto; -webkit-overflow-scrolling: touch; animation: screenin .35s ease-out both; }
.screen[hidden] { display: none; }
@keyframes screenin { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.card { display: flex; flex-direction: column; width: min(100%, 520px); max-height: 100%; overflow-y: auto; overscroll-behavior: contain; background: var(--card); backdrop-filter: blur(var(--card-blur)); -webkit-backdrop-filter: blur(var(--card-blur)); border: 1px solid var(--rule); border-radius: 3px; padding: 26px 30px; box-shadow: 0 30px 60px rgba(0,0,0,.35); }
.card.wide { width: min(100%, 680px); }
.kicker { margin: 0 0 4px; font-size: 12px; letter-spacing: .24em; text-transform: uppercase; color: var(--accent); }
.card .name { margin: 0 0 14px; font-family: var(--font-display); font-size: 40px; line-height: 1; font-weight: 500; font-style: italic; }
.line { margin: 0 0 12px; font-size: 17px; line-height: 1.5; }
.line.small { font-size: 14px; color: var(--ink-2); }
.line b { color: var(--accent); font-weight: 500; }
.lines p { margin: 0 0 12px; font-size: 17.5px; line-height: 1.5; opacity: 0; animation: linein .9s ease-out forwards; }
.lines p:nth-child(2) { animation-delay: .5s; } .lines p:nth-child(3) { animation-delay: 1s; } .lines p:nth-child(4) { animation-delay: 1.5s; }
@keyframes linein { to { opacity: 1; } }
.voice { display: flex; align-items: center; gap: 8px; margin: 14px 0 0; font-size: 12.5px; color: var(--ink-2); }
.voice i { display: inline-block; width: 22px; height: 10px; background: repeating-linear-gradient(90deg, var(--accent) 0 2px, transparent 2px 4px); opacity: .3; }
.voice.is-speaking i { opacity: .9; animation: wave 1.2s linear infinite; }
@keyframes wave { to { background-position: 4px 0; } }

.actions { display: flex; flex-direction: column; gap: 8px; margin-top: 20px; }
.card > .actions, .card .entry ~ .actions, .card .board ~ .actions { position: sticky; bottom: -26px; margin: 20px -30px -26px; padding: 14px 30px 26px; background: linear-gradient(to bottom, rgba(7,11,20,0), rgba(7,11,20,.94) 40%); flex-shrink: 0; }
.actions--row { flex-direction: row; justify-content: flex-end; flex-wrap: wrap; }
.actions .row { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 4px; }
.btn { display: inline-block; padding: 12px 16px; border: 1px solid var(--rule); border-radius: 3px; background: transparent; text-align: left; cursor: pointer; font-size: 16px; transition: background .15s, border-color .15s, transform .15s; }
.actions:not(.actions--row) > .btn { width: 100%; }
.btn:hover { border-color: rgba(240,180,94,.55); }
.btn.is-focus, .btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; background: rgba(240,180,94,0.1); }
.btn:active { transform: translateY(1px); }
.btn--primary { border-color: var(--accent); background: rgba(240,180,94,0.16); }
.btn { position: relative; }
.btn--primary { padding-right: 34px; }
.btn--primary::after { content: "→"; position: absolute; right: 14px; top: 50%; transform: translateY(-50%); color: var(--accent); }
.btn--quiet { border-color: transparent; color: var(--ink-2); padding: 10px 12px; font-size: 15px; }
.btn--quiet:hover, .btn--quiet.is-focus, .btn--quiet:focus-visible { color: var(--ink); }
.btn[disabled] { opacity: .4; cursor: default; }
.btn small { display: block; margin: 2px 0 0; font-size: 12.5px; color: var(--ink-2); font-style: italic; }
.btn--quiet small { display: inline; margin-left: 6px; }
.link { background: none; border: 0; padding: 0; color: var(--accent); text-decoration: underline; cursor: pointer; font-size: inherit; }

/* title */
.screen--title { align-items: flex-end; padding-bottom: calc(5vh + var(--sab)); }
.title-card { width: min(100%, 560px); }
.eyebrow { margin: 0 0 8px; font-size: 12px; letter-spacing: .22em; text-transform: uppercase; color: var(--ink-2); }
.word { margin: 0; font-family: var(--font-display); font-weight: 600; font-size: clamp(50px, 11vw, 92px); line-height: .95; letter-spacing: .06em; text-shadow: 0 2px 20px rgba(0,0,0,.6); }
.tag { margin: 14px 0 0; font-family: var(--font-display); font-style: italic; font-size: 22px; line-height: 1.3; text-shadow: 0 1px 8px rgba(0,0,0,.7); }
.tag--sub { margin-top: 6px; font-family: var(--font-body); font-style: italic; font-size: 16px; color: var(--ink-2); }
.title-card .actions { max-width: 340px; }
.title-card .actions .btn { background: rgba(7,11,20,.55); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); }
.title-card .actions .btn--primary { background: rgba(240,180,94,0.2); }
.title-card .actions .btn--quiet { background: transparent; }
.foot { margin: 14px 0 0; font-size: 13px; color: var(--ink-2); text-shadow: 0 1px 4px rgba(0,0,0,.8); }
.soundtoggle { position: absolute; top: calc(12px + var(--sat)); right: calc(14px + var(--sar)); min-width: 44px; min-height: 44px; padding: 8px 12px; border: 1px solid var(--rule); border-radius: 999px; background: rgba(7,11,20,.55); font-size: 13px; cursor: pointer; }
.soundtoggle[aria-pressed="true"] { color: var(--ink-2); text-decoration: line-through; }
.build { position: absolute; left: calc(14px + var(--sal)); bottom: calc(10px + var(--sab)); margin: 0; font-size: 12px; color: var(--ink-3); }
.build a { color: var(--ink-3); }

/* nights */
.nights { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.nights .btn { display: grid; grid-template-columns: 34px 1fr auto; gap: 10px; align-items: baseline; width: 100%; padding: 10px 14px; }
.nights .btn i { font-family: var(--font-display); font-style: normal; font-size: 20px; color: var(--accent); }
.nights .btn b { font-weight: 500; }
.nights .btn small { display: block; margin: 0; font-size: 13px; color: var(--ink-2); }
.nights .btn em { font-style: normal; font-size: 13px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.nights .btn[disabled] { opacity: .35; }
.nights .btn--primary::after { display: none; }

/* long / settings */
.mods, .settings { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.mods label, .settings label { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border: 1px solid var(--rule); border-radius: 3px; cursor: pointer; }
.mods label b, .settings label b { font-weight: 500; white-space: nowrap; }
.mods label span, .settings label span { font-size: 14px; color: var(--ink-2); }
.mods input, .settings input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--accent); }
.settings input[type=range] { flex: 1; accent-color: var(--accent); min-width: 0; }
.settings label:has(input[type=range]) { justify-content: space-between; }
.settings label:has(input[type=range]) > input { margin-left: 14px; }

/* result */
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 18px; margin: 0 0 16px; padding: 0; list-style: none; }
.stats li { display: flex; justify-content: space-between; gap: 10px; padding: 6px 0; border-bottom: 1px solid var(--rule); font-size: 14.5px; }
.stats li b { font-family: var(--font-display); font-size: 19px; font-weight: 600; font-variant-numeric: tabular-nums; }
.stats li.total b { color: var(--accent); }
.result .lines p { font-style: italic; font-size: 16.5px; }
.board { margin: 12px 0 0; padding: 0; list-style: none; }
.board li { display: grid; grid-template-columns: 28px 1fr auto auto; gap: 10px; padding: 6px 0; border-bottom: 1px solid var(--rule); font-size: 15px; font-variant-numeric: tabular-nums; color: var(--ink-2); }
.board li b { font-weight: 500; letter-spacing: .08em; }
.board li.you { color: var(--ink); }
.board li.you b { color: var(--accent); }
.board li em { font-style: normal; font-size: 13px; color: var(--ink-3); }
.board li.empty { display: block; text-align: center; color: var(--ink-3); font-style: italic; }
.board--tall { min-height: 200px; }
.entry { margin: 4px 0 8px; }
.entry label { display: block; font-size: 13px; letter-spacing: .14em; text-transform: uppercase; color: var(--ink-2); margin-bottom: 6px; }
.entry-row { display: flex; gap: 8px; }
.entry-row .btn { white-space: nowrap; }
.entry input { flex: 0 0 96px; min-width: 0; padding: 10px 12px; border: 1px solid var(--rule); border-radius: 3px; background: rgba(0,0,0,.3); font-family: var(--font-display); font-size: 24px; letter-spacing: .3em; text-transform: uppercase; text-align: center; }
.entry-note { margin: 6px 0 0; font-size: 13px; color: var(--ink-2); min-height: 1.2em; }
.entry-note:empty { display: none; }
.entry[hidden] { display: none; }

/* board tabs */
.tabs { display: flex; gap: 6px; margin: 0 0 8px; }
.tabs--small .tab { font-size: 12px; padding: 5px 10px; }
.tab { padding: 7px 12px; border: 1px solid var(--rule); border-radius: 999px; background: transparent; cursor: pointer; font-size: 14px; color: var(--ink-2); }
.tab.is-on { color: var(--ink); border-color: var(--accent); background: rgba(240,180,94,0.12); }

/* almanac & howto */
.almanac { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.almanac li { padding: 12px 14px; border: 1px solid var(--rule); border-radius: 3px; }
.almanac li h3 { margin: 0 0 4px; font-family: var(--font-display); font-size: 22px; font-weight: 500; }
.almanac li h3 small { font-family: var(--font-body); font-size: 11px; letter-spacing: .16em; text-transform: uppercase; color: var(--accent); margin-left: 8px; }
.almanac li p { margin: 0; font-size: 14.5px; line-height: 1.45; color: var(--ink-2); }
.almanac li.unseen { opacity: .4; }
.almanac li.unseen p { font-style: italic; }
.almanac li .sigil { float: right; width: 34px; height: 34px; margin: 0 0 6px 8px; }
.howto { margin: 0; display: grid; grid-template-columns: max-content 1fr; gap: 8px 16px; }
.howto dt { font-family: var(--font-display); font-size: 20px; font-weight: 500; color: var(--accent); }
.howto dd { margin: 0; font-size: 15px; line-height: 1.45; color: var(--ink-2); }
.controls { margin-top: 16px; display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; font-size: 13.5px; color: var(--ink-2); }
.controls h4 { margin: 0 0 4px; font-size: 11px; letter-spacing: .18em; text-transform: uppercase; color: var(--ink); }
.controls p { margin: 0 0 3px; }
kbd { font: 11px/1 ui-monospace, Menlo, monospace; padding: 2px 5px; border: 1px solid var(--rule); border-bottom-width: 2px; border-radius: 4px; color: var(--ink); }

/* ending */
.ending .lines p { font-size: 18px; }

/* ---------- boot ---------- */
body.booting .screens { opacity: 0; }
.screens { transition: opacity .6s; }

/* ---------- small screens ---------- */
@media (max-width: 720px) {
  body { font-size: 16px; }
  .card { padding: 20px 20px; width: 100%; }
  .card .name { font-size: 32px; }
  .word { font-size: clamp(46px, 15vw, 76px); }
  .tag { font-size: 18px; }
  .stats { grid-template-columns: 1fr; gap: 0; }
  .hud-score { font-size: 24px; }
  .hud-oil { width: 60px; }
  .hud-c { top: calc(10px + var(--sat)); }
  .hud-night { font-size: 10px; }
  .almanac { grid-template-columns: 1fr; }
  .controls { grid-template-columns: 1fr; }
  .howto { grid-template-columns: 1fr; gap: 2px 0; }
  .howto dd { margin-bottom: 8px; }
  .screen--title { padding-bottom: calc(3vh + var(--sab)); }
  .title-card .actions { max-width: none; }
  .actions .row { gap: 4px; }
  .actions .row .btn { flex: 1 1 40%; text-align: center; }
  .btn { padding: 11px 14px; }
  .soundtoggle span:last-child { display: none; }
  .soundtoggle { padding: 8px 10px; }
  .build { display: none; }
}
@media (max-height: 600px) and (pointer: fine) {
  .word { font-size: 40px; }
  .tag--sub, .foot { display: none; }
  .actions { margin-top: 10px; gap: 5px; }
  .btn { padding: 8px 12px; font-size: 14px; }
  .card { padding: 14px 18px; }
  .card .name { font-size: 26px; margin-bottom: 8px; }
  .lines p { font-size: 15px; margin-bottom: 6px; }
}
@media (prefers-reduced-motion: reduce) {
  .lines p { animation-duration: .01s; animation-delay: 0s !important; }
  .banner, .screen, .toast { animation-duration: .01s; }
}
body.reduce-motion * { animation-duration: .01s !important; animation-delay: 0s !important; transition-duration: .01s !important; }
@media (pointer: coarse) {
  .tab { min-height: 44px; }
  .link { display: inline-block; padding: 10px 0; }
  .btn { min-height: 44px; }
}
