:root {
  color-scheme: light;
  --bg: #e9dfc4;
  --panel: #e2d5b4;
  --panel-2: #efe5cb;
  --line: #625b40;
  --text: #302e22;
  --muted: #655f48;
  --shadow: #8e8463;
  --good: #355e49;
  --caution: #65511b;
  --danger: #a02f2b;
  --shadow: #8e8463;
  --good: #355e49;
  --caution: #65511b;
  --danger: #a02f2b;
  --yellow: #edc767;
  --dark: #302e22;
  --light: #f5ecd0;
  --stage: #c6b980;
  --dark: #302e22;
  --light: #f5ecd0;
  --stage: #c6b980;
}
/* game.js overrides these variables with the active room's palette. */
/* game.js overrides these variables with the active room's palette. */

* { box-sizing: border-box; }

html { background: var(--bg); }

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100svh;
  color: var(--text);
  background: var(--bg);
  font-family: ui-monospace, "Cascadia Mono", "SFMono-Regular", Consolas, monospace;
}

button, kbd { font: inherit; }

button {
  min-height: 42px;
  border: 2px solid var(--line);
  border-radius: 0;
  padding: .65rem .9rem;
  color: var(--text);
  background: var(--panel-2);
  box-shadow: 0 3px 0 var(--shadow);
  cursor: pointer;
}

button:hover { border-color: var(--good); }
button:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--shadow); }
button:focus-visible, canvas:focus-visible { outline: 3px solid var(--yellow); outline-offset: 3px; }
button.primary { color: var(--dark); border-color: var(--dark); background: var(--yellow); font-weight: 900; }
button.danger { border-color: var(--danger); color: var(--danger); }
button:disabled { opacity: .45; cursor: default; }
a.button-link { display: inline-flex; align-items: center; min-height: 42px; box-sizing: border-box; border: 2px solid var(--line); padding: .65rem .9rem; color: var(--text); background: var(--panel-2); box-shadow: 0 3px 0 var(--shadow); text-decoration: none; }
a.button-link:focus-visible { outline: 3px solid var(--yellow); outline-offset: 3px; }
#record-button[aria-pressed="true"] { border-color: var(--danger); color: var(--danger); font-weight: 900; }
.replay-message { margin: .4rem 0 0; color: var(--muted); font-size: .8rem; overflow-wrap: anywhere; user-select: all; }
.replay-message[hidden] { display: none; }
.cleared-offer { display: flex; flex-wrap: wrap; align-items: center; gap: .65rem; margin-top: .6rem; padding: .5rem .75rem; border: 2px solid var(--line); background: var(--panel); }
.cleared-offer[hidden] { display: none; }
#clip-video { display: block; width: 100%; max-height: 60dvh; background: var(--dark); }

.game-shell { width: min(1100px, 100%); margin: 0 auto; padding: clamp(.75rem, 2vw, 1.5rem); }

.topbar { display: flex; align-items: end; justify-content: space-between; gap: 1.5rem; }
.eyebrow { margin: 0 0 .6rem; color: var(--muted); font-size: .65rem; font-weight: 900; letter-spacing: .13em; }
h1 { margin: 0; font-size: clamp(2rem, 4vw, 3.2rem); line-height: .95; letter-spacing: -.06em; text-transform: uppercase; }
.goal { max-width: 34rem; margin: 0; color: var(--muted); text-align: right; }
.goal span { color: var(--good); }

.scoreboard {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  margin-top: 1rem;
  border: 2px solid var(--line);
  border-bottom: 0;
  background: var(--panel);
}

.scoreboard p { margin: 0; padding: .55rem .85rem; border-right: 1px solid var(--line); }
.scoreboard p:last-child { border-right: 0; }
.scoreboard span { display: block; color: var(--muted); font-size: .68rem; letter-spacing: .1em; text-transform: uppercase; }
.scoreboard strong { color: var(--text); font-size: 1.2rem; }
.danger-stat strong { white-space: nowrap; }
.danger-stat [data-danger-tier="0"], .danger-stat [data-danger-tier="1"] { color: var(--good); }
.danger-stat [data-danger-tier="2"], .danger-stat [data-danger-tier="3"], .danger-stat [data-danger-tier="4"], .danger-stat [data-danger-tier="5"] { color: var(--caution); }
.danger-stat [data-danger-tier="6"], .danger-stat [data-danger-tier="7"], .danger-stat [data-danger-tier="8"] { color: var(--danger); }

.stage {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  border: 2px solid var(--line);
  background: var(--stage);
  box-shadow: 6px 6px 0 var(--shadow);
}

canvas { display: block; width: 100%; height: 100%; touch-action: none; image-rendering: pixelated; }

.start-panel {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 1rem;
  padding: 2rem;
  text-align: center;
  background: var(--dark);
}
.start-panel[hidden] { display: none; }
.start-panel p { margin: 0; color: var(--light); font-size: clamp(.65rem, 1.5vw, .9rem); }
.start-panel .start-heading { color: var(--yellow); font-size: clamp(1.2rem, 4vw, 3rem); line-height: 1.05; font-weight: 900; letter-spacing: -.04em; }
.start-panel button { justify-self: center; min-width: 11rem; }

.controls { display: flex; justify-content: space-between; align-items: center; gap: 1rem; padding-top: .85rem; }
.key-legend { display: flex; flex-wrap: wrap; gap: .45rem 1rem; margin: 0; color: var(--muted); font-size: .72rem; }
.key-legend span { white-space: nowrap; }
kbd { display: inline-block; min-width: 1.45rem; padding: .1rem .28rem; border: 1px solid var(--line); border-bottom-width: 2px; color: var(--text); background: var(--panel-2); text-align: center; }
.button-row { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: .5rem; }
.fine-print { color: var(--muted); margin: 1rem 0 0; font-size: .68rem; text-align: center; }

.touch-controls { display: none; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .75rem; padding-top: .75rem; }
/* Keep iOS long presses on game controls from selecting text or showing callouts. */
.touch-controls, .touch-controls * {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
.touch-move { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); grid-template-rows: repeat(2, 1fr); gap: .5rem; height: clamp(144px, 45vw, 200px); }
.touch-controls button { min-width: 0; min-height: 68px; padding: .5rem; font-size: 1.5rem; font-weight: 900; touch-action: none; }
.touch-jump { align-self: stretch; color: var(--dark); border-color: var(--dark); background: var(--yellow); }
/* A double-tap-held arrow is sprinting; it borrows the jump button's colors. */
.touch-controls button[data-sprint] { color: var(--dark); border-color: var(--dark); background: var(--yellow); }
.touch-controls button[data-sprint]::after { content: " RUN"; font-size: .8rem; }
.touch-only { display: none; }

dialog { width: min(30rem, calc(100% - 2rem)); padding: 0; border: 2px solid var(--line); color: var(--text); background: var(--panel); box-shadow: 0 20px 80px var(--shadow); }
dialog::backdrop { background: rgba(4, 4, 8, .78); }
dialog form { padding: 1.3rem; }
dialog h2 { margin: .2rem 0 .6rem; }
dialog p { color: var(--muted); }
.dialog-actions { display: flex; justify-content: flex-end; gap: .65rem; margin-top: 1.3rem; }

.visually-hidden { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

@media (hover: none), (pointer: coarse), (max-width: 760px) {
  .touch-controls { display: grid; }
  .controls { align-items: stretch; flex-direction: column; }
  .button-row { justify-content: stretch; }
  .button-row button { flex: 1 1 42%; }
  .wide-only { display: none; }
  .key-legend .touch-only { display: inline; }
}

/* A phone in portrait is width-bound: the game only gets bigger sideways. */
.rotate-hint { display: none; }
@media (orientation: portrait) and (pointer: coarse) {
  .start-panel .rotate-hint { display: block; color: var(--yellow); }
}

/* A phone held sideways: the game fills the screen height with the arrows over its left edge and
   JUMP over its right. Everything else moves below it, a scroll away. */
@media (orientation: landscape) and (pointer: coarse) and (max-height: 540px) {
  .game-shell { position: relative; display: flex; flex-direction: column; width: 100%; box-sizing: border-box;
    padding: 0 max(1rem, env(safe-area-inset-right)) 1rem max(1rem, env(safe-area-inset-left)); }
  /* The stage and the controls over it share one height: the screen's, or less if 16:9 at that height is too wide. */
  .stage { order: -1; align-self: center; width: auto; height: min(100dvh, (100vw - max(1rem, env(safe-area-inset-left)) - max(1rem, env(safe-area-inset-right))) * 9 / 16); border-width: 0 2px; box-shadow: none; }
  .scoreboard { border-bottom: 2px solid var(--line); }
  .touch-controls { position: absolute; inset: 0 0 auto; height: min(100dvh, (100vw - max(1rem, env(safe-area-inset-left)) - max(1rem, env(safe-area-inset-right))) * 9 / 16); box-sizing: border-box;
    display: flex; justify-content: space-between; align-items: flex-end; padding: .75rem max(.75rem, env(safe-area-inset-right)) max(.75rem, env(safe-area-inset-bottom)) max(.75rem, env(safe-area-inset-left));
    pointer-events: none; }
  .touch-controls button { pointer-events: auto; min-height: 0; opacity: .72; }
  .touch-move { width: 9rem; height: 9rem; gap: .4rem; }
  .touch-jump { align-self: flex-end; width: 7.5rem; height: 7.5rem; font-size: 1.2rem; }
}

@media (max-width: 850px) {
  .scoreboard { grid-template-columns: repeat(6, minmax(0, 1fr)); }
  .scoreboard p { min-width: 0; padding: .45rem .6rem; }
  .scoreboard p:nth-child(-n+3) { grid-column: span 2; border-bottom: 1px solid var(--line); }
  .scoreboard p:nth-child(n+4) { grid-column: span 3; }
  .scoreboard p:nth-child(3), .scoreboard p:nth-child(5) { border-right: 0; }
}

@media (max-width: 620px) {
  .topbar { display: block; }
  .goal { margin-top: .7rem; text-align: left; font-size: .78rem; }
  .scoreboard strong { font-size: clamp(.85rem, 4vw, 1.05rem); }
}

@media (forced-colors: active) {
  .danger-stat [data-danger-tier] { color: CanvasText; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .001ms !important; animation-duration: .001ms !important; }
  button:active { transform: none; }
}

/* Options: difficulty, character, sound and the sandbox, one section each. */
#options-dialog { width: min(34rem, calc(100% - 2rem)); max-height: calc(100dvh - 2rem); overflow: auto; }
.options-section { display: grid; gap: .5rem; padding: .9rem 0; border-top: 2px solid var(--line); }
.options-section[hidden] { display: none; }
.options-section > label, .options-section h3 { margin: 0; font-size: .72rem; font-weight: 900; letter-spacing: .08em; text-transform: uppercase; }
.options-row { display: flex; flex-wrap: wrap; align-items: center; gap: .6rem; }
.options-row span { font-size: .8rem; color: var(--muted); }
#options-dialog select { font: inherit; min-height: 44px; padding: .5rem; border: 2px solid var(--line); color: var(--text); background: var(--panel-2); max-width: 100%; }
#options-dialog select:focus-visible { outline: 3px solid var(--good); outline-offset: 3px; }
#options-dialog [role="switch"][aria-checked="false"] { color: var(--muted); }
/* Options can outgrow short screens; keep Done in reach while the sections scroll. */
#options-dialog .dialog-actions { position: sticky; bottom: 0; margin: 0 -1.3rem -1.3rem; padding: .9rem 1.3rem 1.3rem; border-top: 2px solid var(--line); background: var(--panel); }
.sprite-options canvas, #builder-preview { image-rendering: pixelated; }
.sprite-options { display: grid; grid-template-columns: repeat(auto-fill, minmax(4.4rem, 1fr)); gap: .4rem; }
.sprite-options button { display: grid; justify-items: center; gap: .2rem; min-height: 0; padding: .35rem .2rem; font-size: .7rem; box-shadow: none; }
.sprite-options button[aria-pressed="true"] { border-color: var(--good); background: var(--panel); outline: 2px solid var(--good); }
.sprite-options canvas { width: 30px; height: 38px; }

#builder-dialog { width: min(32rem, calc(100% - 2rem)); max-height: calc(100dvh - 2rem); overflow: auto; }
.builder { display: flex; flex-wrap: wrap; align-items: flex-start; gap: 1rem; }
.builder-parts { display: grid; gap: .7rem; flex: 1 1 16rem; min-width: 0; }
.builder-parts fieldset { margin: 0; padding: 0; border: 0; display: flex; flex-wrap: wrap; gap: .35rem; }
.builder-parts legend { margin-bottom: .3rem; font-size: .72rem; font-weight: 900; letter-spacing: .08em; text-transform: uppercase; }
.builder-parts button { min-height: 36px; padding: .3rem .6rem; font-size: .8rem; box-shadow: none; }
.builder-parts button[aria-pressed="true"] { border-color: var(--good); outline: 2px solid var(--good); }
.builder-parts .swatch { width: 36px; padding: 0; }
/* The person at 3x, pixels kept square. */
#builder-preview { width: 90px; height: 114px; border: 2px solid var(--line); }


#daily-dialog { width: min(34rem, calc(100% - 2rem)); max-height: calc(100dvh - 2rem); overflow: auto; }
.daily-actions { margin-top: .4rem; }
.daily-message { min-height: 1.2em; margin: .6rem 0 0; font-size: .82rem; overflow-wrap: anywhere; white-space: pre-line; }
.daily-tag { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; margin-top: .9rem; }
.daily-tag label { font-weight: 900; font-size: .8rem; }
.daily-tag input {
  flex: 1 1 7rem; min-width: 0; min-height: 42px; padding: .4rem .6rem;
  font: inherit; font-weight: 900; letter-spacing: .12em; text-transform: uppercase;
  border: 2px solid var(--line); border-radius: 0; color: var(--text); background: var(--panel-2);
}
.daily-tag input:focus-visible { outline: 3px solid var(--good); outline-offset: 3px; }
.daily-notify label { flex-basis: 100%; }
.daily-notify input { letter-spacing: normal; text-transform: none; font-weight: 400; flex-basis: 12rem; }
.daily-notify select {
  min-height: 42px; padding: .4rem .5rem; font: inherit; font-weight: 700;
  border: 2px solid var(--line); border-radius: 0; color: var(--text); background: var(--panel-2);
}
.daily-notify select:focus-visible { outline: 3px solid var(--good); outline-offset: 3px; }
.daily-boards { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; margin-top: 1rem; }
/* In the dialog the day's board takes the full width; streaks and the podium share the row below. */
#daily-dialog .daily-boards section:first-child { grid-column: 1 / -1; }
.daily-title-row { display: flex; align-items: center; gap: .5rem; }
.daily-title-row h2 { flex: 1; margin: 0; text-align: center; }
.daily-nav { min-width: 42px; min-height: 42px; padding: 0; font-size: 1.3rem; line-height: 1; }
.daily-boards h3 { margin: 0 0 .4rem; font-size: .78rem; letter-spacing: .08em; text-transform: uppercase; }
.daily-list { margin: 0; padding: 0; list-style: none; border-top: 2px solid var(--line); font-size: .82rem; }
.daily-list li { display: flex; justify-content: space-between; gap: .5rem; padding: .3rem 0; border-bottom: 1px solid var(--shadow); }
.daily-list li span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 700; }
.daily-list li span:last-child { white-space: nowrap; color: var(--muted); }
.daily-list li.empty span:first-child { white-space: normal; font-weight: 400; }
.daily-list li.mine { color: var(--good); }
.daily-list li.mine span:last-child { color: var(--good); }

.daily-strip { margin-top: 1rem; padding: .9rem 1rem 1rem; border: 2px solid var(--line); background: var(--panel); }
.daily-strip[hidden] { display: none; }
.daily-strip-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .5rem .75rem; }
.daily-strip-head h2 { margin: 0; font-size: 1rem; letter-spacing: .02em; }
.daily-strip-head .daily-countdown { margin-right: auto; }
.daily-countdown { color: var(--muted); font-size: .78rem; white-space: nowrap; }
p.daily-countdown { margin: -.4rem 0 .4rem; }
.daily-strip .daily-boards { margin-top: .75rem; }

@media (max-width: 520px) {
  .daily-boards { grid-template-columns: 1fr; }
}

#sandbox-dialog { width: min(40rem, calc(100% - 2rem)); max-height: calc(100dvh - 2rem); overflow: auto; }
.sandbox-traps { display: grid; grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr)); gap: .8rem; }
.sandbox-traps fieldset { margin: 0; padding: .5rem .6rem .6rem; border: 2px solid var(--line); }
.sandbox-traps legend { padding: 0 .3rem; font-size: .72rem; font-weight: 900; letter-spacing: .08em; text-transform: uppercase; }
.sandbox-traps label { display: flex; align-items: center; gap: .45rem; min-height: 30px; font-size: .85rem; }
.sandbox-traps input { width: 1.1rem; height: 1.1rem; margin: 0; accent-color: var(--good); }
.sandbox-options { display: flex; flex-wrap: wrap; align-items: center; gap: .6rem; margin-top: 1rem; }
.sandbox-options > label { font-weight: 900; font-size: .8rem; }
.sandbox-options select {
  min-height: 42px; padding: .4rem .5rem; font: inherit; font-weight: 700;
  border: 2px solid var(--line); border-radius: 0; color: var(--text); background: var(--panel-2);
}
.sandbox-traps input:focus-visible, .sandbox-options select:focus-visible { outline: 3px solid var(--good); outline-offset: 3px; }
