/* Kurai and the Lull — page, screens and touch controls.
   The game itself is drawn on the canvas (js/render.js). */

:root {
  --navy: #1c2b55;
  --navy-deep: #0b1226;
  --teal: #2fe0c8;
  --brass: #f5d76e;
  --ash: #b9b3c9;
  --danger: #ff6b5e;
  --text: #dfe6f5;
  --dim: #8792ad;
  --sat: env(safe-area-inset-top, 0px);
  --sar: env(safe-area-inset-right, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0; height: 100%;
  background: #000; color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  overflow: hidden; overscroll-behavior: none;
  -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent;
  touch-action: none;
}
body { position: fixed; inset: 0; }

#game { position: absolute; inset: 0; width: 100%; height: 100%; display: block; background: #000; }

button { font: inherit; color: inherit; touch-action: none; -webkit-user-select: none; user-select: none; }

/* ---------- top bar */
/* Above the screens too: sound can be switched off on the title and during a pause. */
#topbar {
  position: absolute; z-index: 50; display: flex; gap: 8px;
  top: calc(10px + var(--sat)); right: calc(10px + var(--sar));
  transition: opacity .15s;
}
body:not(.playing) #btnPause { display: none; }   /* nothing to pause; the pause screen has its own buttons */
/* The run has just ended: nothing may look as if it could still be pressed. */
body.ending #topbar, body.ending #touch { opacity: 0; pointer-events: none; }
body.silent #topbar { display: none; }
body.ending #touch * { pointer-events: none; }
.chip {
  width: 44px; height: 44px; border-radius: 50%;
  border: 1.5px solid rgba(223, 230, 245, .28); background: rgba(8, 12, 24, .55);
  color: var(--text); font-weight: 700; font-size: 15px; letter-spacing: 1px; cursor: pointer;
}
.chip.off { color: var(--dim); text-decoration: line-through; }
.chip:focus-visible, .go:focus-visible { outline: 2px solid var(--teal); outline-offset: 3px; }

/* ---------- hint line */
#hint {
  position: absolute; z-index: 20; left: 50%; transform: translateX(-50%);
  top: calc(86px + var(--sat)); width: min(92vw, 520px);
  text-align: center; pointer-events: none;
  font-size: 16px; font-weight: 500; color: var(--text);
  text-shadow: 0 0 6px #000, 0 0 14px #000, 0 1px 2px #000;
  opacity: 0; transition: opacity .5s;
}
#hint.show { opacity: 1; }
body:not(.playing) #hint { visibility: hidden; }   /* a screen is up: its words are not mixed with the last message */
#hint.warn { color: #ffd9b0; }

/* ---------- touch controls */
#touch[hidden] { display: none; }
#touch { position: absolute; inset: 0; z-index: 10; pointer-events: none; transition: opacity .15s; }
#stickZone { position: absolute; left: 0; top: 0; width: 50%; height: 100%; pointer-events: auto; }
#stick {
  position: absolute; width: 124px; height: 124px; margin: -62px 0 0 -62px; border-radius: 50%;
  left: calc(86px + var(--sal)); top: calc(100% - 96px - var(--sab));
  border: 2px solid rgba(47, 224, 200, .32); background: rgba(47, 224, 200, .05);
  pointer-events: none;
}
#knob {
  position: absolute; left: 50%; top: 50%; width: 54px; height: 54px; margin: -27px 0 0 -27px; border-radius: 50%;
  background: rgba(47, 224, 200, .32); border: 2px solid rgba(47, 224, 200, .6);
}
.pad {
  position: absolute; pointer-events: auto; border-radius: 50%;
  border: 2px solid rgba(223, 230, 245, .35); background: rgba(8, 12, 24, .5);
  color: var(--text); font-weight: 700; letter-spacing: .5px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1.1;
}
.pad small { font-weight: 500; font-size: 10px; color: var(--dim); letter-spacing: 1px; text-transform: uppercase; }
.pad.down { background-color: rgba(223, 230, 245, .22); }
#btnRun   { width: 92px; height: 92px; font-size: 16px; right: calc(18px + var(--sar));  bottom: calc(26px + var(--sab));  border-color: rgba(255, 107, 94, .6); }
#btnRun.down { background-color: rgba(255, 107, 94, .3); }
#btnAct   { width: 80px; height: 80px; font-size: 14px; right: calc(118px + var(--sar)); bottom: calc(18px + var(--sab));  border-color: rgba(47, 224, 200, .35); color: var(--dim); }
#btnAct.ready { border-color: var(--teal); color: #fff; background-color: rgba(47, 224, 200, .25); box-shadow: 0 0 18px rgba(47, 224, 200, .45); }
#btnLight { width: 64px; height: 64px; font-size: 11px; right: calc(26px + var(--sar));  bottom: calc(130px + var(--sab)); border-color: rgba(245, 215, 110, .5); }
#btnLight.off { color: var(--dim); border-color: rgba(223, 230, 245, .25); }
/* When the art lead supplies button drawings (see ART.md), the lettering steps aside. */
#touch .pad.has-art, #topbar .chip.has-art { background-color: transparent; background-size: 100% 100%; background-position: 0 0; background-repeat: no-repeat; border: 0; box-shadow: none; }
#touch #btnRun.has-art.down, #touch .pad.has-art.ready, #touch .pad.has-art.off, #topbar .chip.has-art.off { background-position: 100% 0; }
#touch .pad.has-art > *, #topbar .chip.has-art { font-size: 0; }
/* Under a bell the HIDE button becomes OUT: dim while the rim settles, lit once a tap will be obeyed. */
#btnAct.out { opacity: .45; }
#btnAct.out.ready { opacity: 1; }
#stick.has-art, #knob.has-art { background: center / contain no-repeat; border: 0; }

/* ---------- screens */
.screen {
  position: absolute; inset: 0; z-index: 40; display: none;
  align-items: center; justify-content: center; text-align: center;
  padding: calc(16px + var(--sat)) calc(18px + var(--sar)) calc(16px + var(--sab)) calc(18px + var(--sal));
  background: radial-gradient(ellipse at 50% 38%, rgba(18, 28, 60, .93) 0%, rgba(2, 4, 10, .97) 70%);
  background-size: cover; background-position: center;
  overflow-y: auto; touch-action: pan-y;
}
.screen.show { display: flex; }
#printPocket { margin: 0; }
#btnPrint, #savePrint {
  color: #f6dcc4; font: italic 17px Georgia, serif; text-decoration: underline;
  text-underline-offset: 4px; background: transparent; border: 0; cursor: pointer; padding: 12px;
}
#scrPrint .panel { max-width: 760px; }
#nightPrint { display: block; width: auto; height: auto; max-width: 100%; max-height: 57vh; margin: 0 auto 16px; }
#scrPrint h2 { color: #f6dcc4; }
#scrPrint .story i { color: #b7c1d4; font-family: Georgia, serif; }
#scrCaught { background: #000; }
#scrWin { background-image: radial-gradient(ellipse at 50% 110%, rgba(242, 180, 156, .5) 0%, rgba(28, 43, 85, .95) 45%, rgba(4, 7, 16, .98) 100%); }
#scrPause { background: rgba(2, 4, 10, .86); }
.screen.has-art { background-size: cover; background-position: center; }

.panel { max-width: 560px; width: 100%; margin: auto; }
.place { margin: 0 0 6px; color: var(--dim); font-size: 13px; letter-spacing: 2.5px; text-transform: uppercase; }
h1, h2 { font-family: Georgia, "Times New Roman", serif; font-weight: 400; margin: 0 0 12px; line-height: 1.05; }
h1 { font-size: clamp(40px, 9vw, 68px); }
h1 .k { color: var(--teal); letter-spacing: 2px; }
h1 .amp { font-style: italic; font-size: .42em; color: var(--dim); vertical-align: middle; margin: 0 .15em; }
h1 .l { color: var(--ash); letter-spacing: 6px; }
h2 { font-size: clamp(30px, 6.5vw, 46px); }
h2.quiet { color: var(--ash); letter-spacing: 8px; }
h2.dawn { color: #f2b49c; }
.story { margin: 0 0 16px; color: var(--text); }
.goal { margin: 0 0 18px; color: var(--brass); font-weight: 600; }
.tip { margin: 0 0 20px; color: var(--dim); white-space: pre-line; }
.rules { list-style: none; display: flex; justify-content: center; gap: 10px; padding: 0; margin: 0 0 16px; }
.rules li { flex: 1 1 0; max-width: 130px; padding: 9px 6px; border-radius: 10px; border: 1px solid rgba(223, 230, 245, .16); background: rgba(8, 12, 24, .5); }
.rules b { display: block; font-size: 17px; }
.rules i { font-style: normal; font-size: 12px; letter-spacing: 1.5px; text-transform: uppercase; color: var(--dim); }
.rules .r3 { color: var(--danger); } .rules .r2 { color: var(--brass); } .rules .r1 { color: var(--teal); }
.go {
  display: inline-block; min-width: 190px; min-height: 52px; padding: 13px 28px; margin: 4px 6px 14px;
  border-radius: 28px; border: 2px solid var(--teal); background: rgba(47, 224, 200, .14);
  color: #fff; font-size: 18px; font-weight: 700; letter-spacing: 1px; cursor: pointer;
}
.go:hover { background: rgba(47, 224, 200, .26); }
.go.ghost { border-color: rgba(223, 230, 245, .3); background: transparent; color: var(--text); font-weight: 500; }
.keys, .note { margin: 0 0 8px; font-size: 13px; color: var(--dim); }
#scrTitle .keys, #scrTitle .note, #scrWin .tip { color: #b7c1d4; text-shadow: 0 1px 3px #090c12, 0 0 6px #090c12; }

/* ---------- escaped: the time comes first, and is what a screenshot shows */
.result .escaped { margin: 0; color: #f6dcc4; font-size: clamp(13px, 2.2vw, 17px); font-weight: 600; letter-spacing: 5px; text-transform: uppercase; text-shadow: 0 1px 4px #0b0a10, 0 0 10px #0b0a10; }
.result .time {
  margin: 0 0 2px; line-height: 1; white-space: nowrap; color: #fff7ea;
  font: 700 clamp(84px, min(27vw, 34vh), 200px)/1 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-variant-numeric: tabular-nums; letter-spacing: -.02em;
  text-shadow: 0 2px 0 rgba(60, 28, 20, .55), 0 0 28px rgba(11, 10, 16, .9), 0 0 70px rgba(242, 150, 110, .45);
}
.result .time small { font-size: .42em; font-weight: 600; color: #f6dcc4; letter-spacing: 0; }
.result .best { margin: 0 0 14px; color: #f6dcc4; font-size: clamp(14px, 2.4vw, 18px); font-weight: 600; text-shadow: 0 1px 4px #0b0a10, 0 0 10px #0b0a10; }
.result .best.record { color: var(--brass); }
.result h2 { font-size: clamp(20px, 3.6vw, 28px); margin-bottom: 6px; text-shadow: 0 1px 4px #0b0a10, 0 0 12px #0b0a10; }
.result .tip { margin-bottom: 14px; font-size: 14px; }
.result .go { margin-bottom: 10px; }
.result .brand img { display: block; margin: 0 auto; height: clamp(44px, 9vh, 72px); width: auto; filter: drop-shadow(0 1px 6px rgba(11, 10, 16, .8)); }
.result .brand { margin: 0; color: #f6dcc4; font: italic 400 15px Georgia, "Times New Roman", serif; letter-spacing: 1.5px; text-shadow: 0 1px 4px #0b0a10, 0 0 10px #0b0a10; }
kbd { font: inherit; font-size: 12px; padding: 1px 6px; border-radius: 5px; border: 1px solid rgba(223, 230, 245, .3); color: var(--text); white-space: nowrap; }
.tc { display: none; }
body.touch .tc { display: block; }
body.touch .kb { display: none; }

@media (max-height: 460px) {
  h1 { font-size: 36px; margin-bottom: 4px; } h2 { font-size: 28px; }
  #scrTitle h1 img { max-height: 24vh !important; }
  #scrTitle .place { display: none; }
  .story, .goal { margin-bottom: 6px; font-size: 14px; }
  .rules { margin-bottom: 6px; } .rules li { padding: 3px 6px; } .rules b { font-size: 15px; }
  .keys { margin-bottom: 6px; }
  .go { min-height: 44px; padding: 8px 24px; margin-bottom: 6px; }
  .note { display: none; }
  .result h2 { display: none; }
  .result .best { margin-bottom: 6px; } .result .tip { margin-bottom: 6px; font-size: 13px; }
  #stick { top: calc(100% - 84px - var(--sab)); }
  #btnLight { bottom: calc(118px + var(--sab)); }
}

/* A phone held sideways leaves about 330 px of height once the browser has taken its bars. */
@media (max-height: 350px) {
  #scrTitle h1 img { max-height: 20vh !important; }
  #scrTitle .panel .go { margin-bottom: 0; }
}
/* ...and there the print sits beside its caption, so that both buttons are on screen without scrolling. */
@media (max-height: 460px) and (min-aspect-ratio: 3/2) {
  #scrPrint { padding-right: calc(62px + var(--sar)); }   /* clear of the sound button */
  #scrPrint .panel { max-width: 900px; display: grid; grid-template-columns: auto minmax(210px, 1fr); column-gap: 22px; align-content: center; align-items: center; }
  #nightPrint { grid-column: 1; grid-row: 1 / span 4; max-width: 56vw; max-height: calc(100vh - 36px - var(--sat) - var(--sab)); margin: 0; }
  #scrPrint h2, #scrPrint .story, #savePrint, #btnFold { grid-column: 2; justify-self: center; }
  #scrPrint .story { margin-bottom: 4px; }
  #savePrint { padding: 8px 12px; }
  #btnFold { margin: 0; }
}

@media (max-width: 560px) {
  #hint { top: calc(100px + var(--sat)); font-size: 15px; }
  .place { letter-spacing: 1.5px; font-size: 11px; }
}
/* A narrow phone held upright: the title starts below the sound button instead of running under it. */
@media (max-width: 480px) and (orientation: portrait) {
  #scrTitle { padding-top: calc(58px + var(--sat)); }
}
@media (max-width: 480px) and (max-height: 600px) and (orientation: portrait) {
  #scrTitle .place, #scrTitle .note { display: none; }
}
