:root {
  color-scheme: dark;
  --paper: #f6f4eb;
  --ink: #111222;
  --panel: #18192d;
  --muted: #8d8ea4;
  --red: #ff355d;
  --cyan: #78f6df;
  --yellow: #ffd166;
}

* { box-sizing: border-box; }

html, body { width: 100%; height: 100%; }

body {
  margin: 0;
  overflow: hidden;
  background: var(--ink);
  color: var(--paper);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}

button, a { color: inherit; font: inherit; }
button { border: 0; }

.game-shell {
  position: relative;
  width: 100%;
  height: 100%;
  height: 100svh;
  overflow: hidden;
  isolation: isolate;
  background: #111222;
}

#game {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  cursor: crosshair;
  touch-action: none;
}

.hud {
  position: absolute;
  z-index: 5;
  top: 0;
  left: 0;
  width: 100%;
  height: 68px;
  display: grid;
  grid-template-columns: 1fr auto auto 1fr;
  align-items: center;
  gap: clamp(18px, 5vw, 64px);
  padding: max(10px, env(safe-area-inset-top)) clamp(15px, 3vw, 34px) 8px;
  pointer-events: none;
}

.wordmark {
  justify-self: start;
  display: inline-flex;
  align-items: center;
  gap: 9px;
  color: var(--paper);
  text-decoration: none;
  font-size: .76rem;
  font-weight: 950;
  letter-spacing: .18em;
  pointer-events: auto;
}

.wordmark i {
  width: 15px;
  height: 15px;
  display: block;
  border-radius: 4px 4px 7px 7px;
  background: var(--cyan);
  box-shadow: 0 0 18px #78f6df66;
  rotate: 45deg;
}

.time-block, .best-block { display: grid; justify-items: center; min-width: 62px; }
.hud small { color: var(--muted); font-size: .52rem; font-weight: 900; letter-spacing: .19em; }
.hud strong { font-size: 1rem; font-weight: 900; letter-spacing: -.035em; font-variant-numeric: tabular-nums; }
.time-block strong::after, .best-block strong::after { content: "s"; margin-left: 1px; color: var(--muted); font-size: .62em; }

.hud-actions { justify-self: end; display: flex; gap: 7px; pointer-events: auto; }
.icon-button {
  width: 34px;
  height: 34px;
  border: 1px solid #ffffff20;
  border-radius: 50%;
  background: #ffffff0b;
  color: #d8d7e1;
  font-size: .8rem;
  font-weight: 900;
  cursor: pointer;
  backdrop-filter: blur(8px);
  transition: transform 140ms ease, background 140ms ease, color 140ms ease;
}
.icon-button:hover { transform: scale(1.07); background: #ffffff18; color: white; }
.icon-button.muted { color: var(--red); }

.pattern-label {
  position: absolute;
  z-index: 4;
  top: 82px;
  left: 50%;
  translate: -50% -8px;
  color: #d7d5e1;
  font-size: .55rem;
  font-weight: 950;
  letter-spacing: .28em;
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease, translate 180ms ease;
}
.pattern-label.show { opacity: .7; translate: -50% 0; }

.touch-hint {
  position: absolute;
  z-index: 3;
  bottom: max(17px, env(safe-area-inset-bottom));
  left: 50%;
  translate: -50% 0;
  color: #77798f;
  font-size: .48rem;
  font-weight: 900;
  letter-spacing: .2em;
  opacity: 0;
  pointer-events: none;
  transition: opacity 300ms ease;
}

.overlay {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 24px;
  background: #111222bf;
  backdrop-filter: blur(11px);
  transition: opacity 240ms ease, visibility 240ms ease;
}
.overlay.hidden { opacity: 0; visibility: hidden; pointer-events: none; }

.card { width: min(100%, 420px); text-align: center; }
.eyebrow { margin: 0 0 15px; color: var(--cyan); font-size: .58rem; font-weight: 950; letter-spacing: .28em; }
.card h1 {
  margin: 0;
  color: var(--paper);
  font-size: clamp(4rem, 17vw, 7rem);
  font-weight: 1000;
  line-height: .75;
  letter-spacing: -.1em;
}
.card h1 span { color: var(--red); }
.message { margin: 28px 0 0; color: #a9a9b8; font-size: 1rem; line-height: 1.55; }
.message b { color: var(--paper); font-weight: 850; }

.results {
  width: min(100%, 310px);
  margin: 25px auto 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  border: 1px solid #ffffff16;
  border-radius: 15px;
  overflow: hidden;
}
.results[hidden] { display: none; }
.results div { display: grid; gap: 4px; padding: 13px; }
.results div + div { border-left: 1px solid #ffffff16; }
.results small { color: #7f8094; font-size: .48rem; font-weight: 900; letter-spacing: .15em; }
.results strong { font-size: 1.1rem; font-variant-numeric: tabular-nums; }

.play-button {
  width: min(100%, 310px);
  margin-top: 26px;
  padding: 0 8px 0 22px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-radius: 99px;
  background: var(--paper);
  color: var(--ink);
  font-size: .72rem;
  font-weight: 950;
  letter-spacing: .17em;
  cursor: pointer;
  box-shadow: 0 14px 40px #0005;
  transition: transform 150ms ease, background 150ms ease;
}
.play-button i {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--red);
  color: white;
  font-size: 1.25rem;
  font-style: normal;
}
.play-button:hover { transform: translateY(-2px); background: white; }

.secondary-actions { display: flex; justify-content: center; gap: 9px; margin-top: 14px; }
.secondary-actions button {
  padding: 8px 11px;
  background: transparent;
  color: #85869a;
  font-size: .51rem;
  font-weight: 900;
  letter-spacing: .13em;
  cursor: pointer;
}
.secondary-actions button:hover { color: var(--cyan); }
.seed-label { margin: 6px 0 0; color: #55566c; font: 800 .47rem ui-monospace, SFMono-Regular, Consolas, monospace; letter-spacing: .08em; }
.controls { margin: 21px 0 0; color: #5e5f73; font-size: .48rem; font-weight: 800; letter-spacing: .07em; }
kbd { padding: 2px 5px; border: 1px solid #ffffff1c; border-radius: 4px; font: inherit; }

.pause-card {
  position: absolute;
  z-index: 12;
  inset: 0;
  place-content: center;
  justify-items: center;
  gap: 10px;
  background: #10111ed6;
  backdrop-filter: blur(10px);
}
.pause-card:not([hidden]) { display: grid; }
.pause-card small { color: var(--cyan); font-size: .55rem; font-weight: 950; letter-spacing: .25em; }
.pause-card strong { font-size: clamp(1.5rem, 6vw, 2.6rem); letter-spacing: -.05em; }
.pause-card button { margin-top: 15px; padding: 12px 28px; border-radius: 99px; background: var(--paper); color: var(--ink); font-size: .62rem; font-weight: 950; letter-spacing: .15em; cursor: pointer; }

.debug-panel {
  position: absolute;
  z-index: 20;
  right: 12px;
  bottom: 12px;
  width: min(310px, calc(100% - 24px));
  padding: 12px;
  border: 1px solid #ffffff20;
  border-radius: 12px;
  background: #111222e8;
}
.debug-panel b { display: block; margin-bottom: 8px; color: var(--cyan); font-size: .55rem; letter-spacing: .18em; }
.debug-panel div { display: flex; flex-wrap: wrap; gap: 5px; }
.debug-panel button { padding: 6px 8px; border-radius: 5px; background: #292a40; color: #cccbd7; font-size: .48rem; cursor: pointer; }

@media (pointer: coarse) {
  #game { cursor: none; }
  .touch-hint { opacity: 1; }
  .controls { display: none; }
  .hud { gap: 9px; grid-template-columns: 1fr auto auto auto; }
  .wordmark span { display: none; }
  .wordmark i { width: 13px; height: 13px; }
}

@media (max-width: 520px) {
  .hud { height: 60px; padding-inline: 13px; }
  .best-block { display: none; }
  .hud { grid-template-columns: 1fr auto 1fr; }
  .hud-actions { grid-column: 3; }
  .pattern-label { top: 70px; }
  .secondary-actions { margin-top: 10px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: .001ms !important; }
}
