:root {
  --bg: #0d0907;
  --ink: #f4ead8;
  --gold: #f2b631;
  --red: #d9432f;
  --blue: #2f6fd9;
  --green: #5cbf4a;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: "Press Start 2P", ui-monospace, monospace;
  overscroll-behavior: none;
}

/* Stop double-tap zoom, text selection and long-press menus while mashing. */
#game {
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-width: 860px;
  height: 100vh;
  height: 100dvh;
  margin: 0 auto;
  padding: max(12px, env(safe-area-inset-top)) 16px max(10px, env(safe-area-inset-bottom));
}

header { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; }
h1 { font-size: clamp(12px, 3.4vw, 20px); line-height: 1.5; color: var(--gold); }
.clock { text-align: right; font-variant-numeric: tabular-nums; }
#time { font-size: clamp(22px, 7vw, 40px); }
.best { margin-top: 6px; font-size: 9px; opacity: .65; }

#stage {
  position: relative;
  flex: 1 1 0;
  min-height: 0;
  border: 4px solid var(--ink);
  background: #000;
}
#screen {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: 62% 30%;
}
#prompt {
  position: absolute;
  inset: auto 8px 12px;
  text-align: center;
  font-size: clamp(10px, 2.8vw, 15px);
  line-height: 1.8;
  text-shadow: 2px 2px 0 #000, -2px -2px 0 #000, 2px -2px 0 #000, -2px 2px 0 #000;
  white-space: pre-line;
  pointer-events: none;
}
#prompt.warn { color: var(--red); }

/* One line that keeps its newest letters in view. */
#word {
  display: flex;
  justify-content: safe center;
  overflow: hidden;
  white-space: nowrap;
  font-size: clamp(20px, 6vw, 34px);
  line-height: 1.2;
  color: var(--gold);
  flex: none;
}
#word.long { justify-content: flex-end; }

.meter { display: flex; align-items: center; gap: 10px; font-size: 9px; }
.track { flex: 1; height: 18px; border: 3px solid var(--ink); }
#fill { height: 100%; width: 100%; background: var(--green); transform-origin: left; transform: scaleX(0); }
#fill.mid { background: var(--gold); }
#fill.low { background: var(--red); }

.pads { display: flex; justify-content: space-between; gap: 16px; }
.pad {
  flex: 1;
  height: clamp(100px, 22vh, 170px);
  border: 4px solid var(--ink);
  border-radius: 18px;
  color: var(--ink);
  font: inherit;
  cursor: pointer;
  background: var(--red);
  box-shadow: 0 8px 0 #000, inset 0 -8px 0 rgba(0,0,0,.25);
  touch-action: none;
}
.pad[data-side="1"] { background: var(--blue); }
.pad b { display: block; font-size: 40px; }
.pad small { display: block; margin-top: 12px; font-size: 9px; opacity: .8; }
.pad.down { transform: translateY(6px); box-shadow: 0 2px 0 #000; filter: brightness(1.2); }
.pad.next { outline: 4px solid var(--gold); outline-offset: 2px; }
.pad.wrong { animation: shake .2s; }
@keyframes shake { 25% { translate: -6px 0; } 75% { translate: 6px 0; } }

footer { font-size: 7px; opacity: .4; text-align: center; }

#results {
  position: fixed;
  inset: 0;
  display: flex;
  overflow-y: auto;
  padding: 16px;
  background: rgba(0,0,0,.85);
}
.panel {
  width: 100%;
  max-width: 460px;
  margin: auto;
  padding: 20px 16px;
  border: 4px solid var(--ink);
  background: var(--bg);
  text-align: center;
}
.label { font-size: 10px; opacity: .7; }
#final { margin: 12px 0; font-size: 38px; color: var(--gold); }
h2 { font-size: 13px; line-height: 1.7; }
#note { margin: 10px 0; font-size: 9px; line-height: 1.7; opacity: .75; }
#card { display: block; width: 100%; margin-bottom: 14px; aspect-ratio: 1200 / 630; }

.primary, .links a, .links button {
  font: inherit;
  color: var(--ink);
  border: 3px solid var(--ink);
  background: transparent;
  cursor: pointer;
  text-decoration: none;
}
.primary { width: 100%; padding: 15px; font-size: 13px; background: var(--red); }
.primary.alt { background: var(--blue); }
.primary:disabled { opacity: .35; cursor: default; }
.links { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin: 12px 0; }
.links a, .links button { padding: 10px; font-size: 9px; }

/* Landscape phones: picture on the left of the pads' thumbs. */
@media (orientation: landscape) and (max-height: 520px) {
  #game {
    display: grid;
    max-width: none;
    grid-template-columns: 22vw 1fr 22vw;
    grid-template-rows: auto minmax(0, 1fr) auto auto;
    gap: 8px 12px;
  }
  header { grid-column: 1 / -1; }
  .clock { display: flex; align-items: baseline; gap: 12px; }
  #stage { grid-area: 2 / 2; }
  #word { grid-area: 3 / 2; min-width: 0; font-size: 20px; }
  .meter { grid-area: 4 / 2; }
  .pads { display: contents; }
  .pad { height: 100%; }
  .pad[data-side="0"] { grid-area: 2 / 1 / 5 / 2; }
  .pad[data-side="1"] { grid-area: 2 / 3 / 5 / 4; }
  footer { display: none; }
}
