:root {
  color-scheme: light dark;
  --page: #e8e3d3;
  --board: #fffdf4;
  --ink: #171a16;
  --muted: #4a4e44;
  --grid: rgba(23, 26, 22, 0.07);
  --green: #1bd94b;
  --green-light: #6bff89;
  --green-dark: #087d28;
  --score-green: var(--green-dark);
  --red: #f23838;
  --red-light: #ff7373;
  --red-dark: #991515;
  --status: var(--red-dark);
  --yellow: #f4d44d;
  --shadow: #171a16;
}

@media (prefers-color-scheme: dark) {
  :root {
    --page: #11130f;
    --board: #171a16;
    --ink: #f6f2df;
    --muted: #c0c4b6;
    --grid: rgba(246, 242, 223, 0.06);
    --score-green: #6bff89;
    --status: var(--red-light);
    --shadow: #000;
  }
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--page);
}

body {
  min-width: 280px;
  min-height: 100dvh;
  margin: 0;
  overflow-x: hidden;
  background: var(--page);
  color: var(--ink);
  font-family: "Courier New", Courier, monospace;
  overscroll-behavior-y: contain;
}

button {
  font: inherit;
}

.page-shell {
  display: flex;
  width: 100%;
  min-height: 100dvh;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  padding: max(18px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right))
    max(18px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
}

.game-header {
  display: flex;
  width: min(90vw, 920px);
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  border-bottom: 3px solid var(--ink);
  padding-bottom: 8px;
}

.mode-picker {
  width: min(90vw, 920px);
  border: 3px solid var(--ink);
  padding: 10px;
  background: var(--board);
  box-shadow: 4px 4px 0 var(--shadow);
}

.mode-picker__title {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 900;
  letter-spacing: 0.14em;
}

.mode-options {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 7px;
}

.mode-option {
  min-width: 0;
  padding: 8px 5px;
  cursor: pointer;
  border: 2px solid var(--ink);
  border-radius: 0;
  background: transparent;
  color: var(--ink);
  line-height: 1.05;
}

.mode-option span,
.mode-option small {
  display: block;
}

.mode-option span {
  font-size: clamp(0.64rem, 2.5vw, 0.9rem);
  font-weight: 900;
}

.mode-option small {
  margin-top: 4px;
  color: var(--muted);
  font-size: clamp(0.48rem, 1.8vw, 0.63rem);
}

.mode-option:hover:not(:disabled) {
  background: color-mix(in srgb, var(--green) 18%, transparent);
}

.mode-option[aria-pressed="true"] {
  background: var(--ink);
  color: var(--board);
}

.mode-option[aria-pressed="true"] small {
  color: color-mix(in srgb, var(--board) 72%, var(--muted));
}

.mode-option:disabled {
  cursor: not-allowed;
  opacity: 0.62;
}

.mode-option:focus-visible {
  outline: 4px solid var(--yellow);
  outline-offset: 3px;
}

.eyebrow,
.game-header h1,
.score-panel p,
.game-overlay p,
.game-overlay h2,
.round-status,
footer p {
  margin: 0;
}

.eyebrow {
  margin-bottom: 4px;
  color: var(--muted);
  font-size: clamp(0.62rem, 2.5vw, 0.8rem);
  font-weight: 700;
  letter-spacing: 0.12em;
}

.game-header h1 {
  font-size: clamp(1.7rem, 7vw, 3.6rem);
  line-height: 0.83;
  letter-spacing: -0.08em;
}

.score-panel {
  flex: none;
  border-left: 3px solid var(--ink);
  padding-left: 14px;
  font-size: clamp(0.72rem, 2.6vw, 1rem);
  font-weight: 700;
  line-height: 1.5;
  white-space: nowrap;
}

.score-panel output {
  display: inline-block;
  min-width: 2.5ch;
  color: var(--score-green);
  font-weight: 900;
  text-align: right;
}

.game-board {
  container-type: size;
  position: relative;
  width: 90vw;
  height: 90vw;
  flex: none;
  overflow: hidden;
  border: clamp(4px, 0.65vw, 8px) solid var(--ink);
  background: var(--board);
  box-shadow: 8px 8px 0 var(--shadow);
  isolation: isolate;
  touch-action: manipulation;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.game-running .game-board {
  touch-action: none;
}

.board-grid,
.scanlines,
.target-layer,
.game-overlay {
  position: absolute;
  inset: 0;
}

.board-grid {
  z-index: -2;
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 5% 5%;
}

.scanlines {
  z-index: 8;
  pointer-events: none;
  background: repeating-linear-gradient(
    to bottom,
    transparent 0,
    transparent 3px,
    rgba(0, 0, 0, 0.025) 4px
  );
  mix-blend-mode: multiply;
}

.timer-track {
  position: absolute;
  z-index: 9;
  top: 0;
  right: 0;
  left: 0;
  height: max(5px, 0.75cqw);
  background: color-mix(in srgb, var(--ink) 16%, transparent);
  pointer-events: none;
}

.timer-fill {
  width: 100%;
  height: 100%;
  background: var(--yellow);
  transform-origin: left;
}

.target-layer {
  z-index: 2;
}

.target {
  position: absolute;
  width: 5%;
  height: 5%;
  min-width: 14px;
  min-height: 14px;
  margin: 0;
  padding: 0;
  cursor: crosshair;
  border: 0;
  border-top: max(2px, 0.55cqw) solid var(--target-light);
  border-right: max(2px, 0.55cqw) solid var(--target-dark);
  border-bottom: max(2px, 0.55cqw) solid var(--target-dark);
  border-left: max(2px, 0.55cqw) solid var(--target-light);
  border-radius: 0;
  background: var(--target-color);
  box-shadow: max(1px, 0.3cqw) max(1px, 0.3cqw) 0 rgba(0, 0, 0, 0.35);
  forced-color-adjust: none;
}

.target--green {
  --target-color: var(--green);
  --target-light: var(--green-light);
  --target-dark: var(--green-dark);
}

.target--red {
  --target-color: var(--red);
  --target-light: var(--red-light);
  --target-dark: var(--red-dark);
}

.target:focus-visible,
.start-button:focus-visible {
  outline: 4px solid var(--yellow);
  outline-offset: 3px;
}

.target--hit {
  filter: brightness(1.4);
  transform: scale(0.72);
  transition: transform 80ms steps(2, end);
}

.target:disabled {
  cursor: default;
}

.game-overlay {
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  padding: 8%;
  background: var(--board);
  background: color-mix(in srgb, var(--board) 91%, transparent);
  text-align: center;
}

.game-overlay[hidden] {
  display: none;
}

.status-code {
  margin-bottom: 4cqw;
  color: var(--status);
  font-size: clamp(0.65rem, 2.5cqw, 1rem);
  font-weight: 900;
  letter-spacing: 0.15em;
}

.game-overlay h2 {
  margin-bottom: 4cqw;
  font-size: clamp(1.7rem, 8cqw, 5rem);
  line-height: 0.92;
  letter-spacing: -0.08em;
}

.game-overlay p:not(.status-code) {
  max-width: 52ch;
  color: var(--muted);
  font-size: clamp(0.65rem, 2.5cqw, 1rem);
  line-height: 1.55;
}

.start-button {
  margin-top: 5cqw;
  padding: clamp(10px, 2.4cqw, 20px) clamp(14px, 5cqw, 42px);
  cursor: pointer;
  border: 3px solid var(--ink);
  border-radius: 0;
  background: var(--green);
  box-shadow: 5px 5px 0 var(--ink);
  color: #07130a;
  font-size: clamp(0.8rem, 3cqw, 1.25rem);
  font-weight: 900;
  letter-spacing: 0.08em;
}

.start-button:hover {
  background: var(--green-light);
}

.start-button:active {
  box-shadow: 2px 2px 0 var(--ink);
  transform: translate(3px, 3px);
}

.round-status {
  position: absolute;
  z-index: 4;
  right: 2%;
  bottom: 1.5%;
  padding: 2px 6px;
  background: color-mix(in srgb, var(--board) 86%, transparent);
  color: var(--muted);
  font-size: clamp(0.55rem, 2cqw, 0.9rem);
  font-weight: 700;
  letter-spacing: 0.08em;
  pointer-events: none;
}

.ad-slot {
  display: grid;
  width: min(90vw, 728px);
  min-height: 74px;
  grid-template-rows: auto 1fr;
  place-items: center;
  border: 2px dashed var(--muted);
  color: var(--muted);
  font-size: clamp(0.6rem, 2.4vw, 0.75rem);
  letter-spacing: 0.12em;
  text-align: center;
}

.ad-label {
  margin: 4px 0;
  font-size: 0.56rem;
  font-weight: 700;
  letter-spacing: 0.12em;
}

.ad-choice-button {
  padding: 0;
  border: 0;
  border-bottom: 1px solid currentcolor;
  background: transparent;
  color: inherit;
  cursor: pointer;
  font: inherit;
  letter-spacing: inherit;
}

.ad-choice-button:focus-visible,
.ad-consent button:focus-visible {
  outline: 3px solid var(--yellow);
  outline-offset: 2px;
}

.ad-mount {
  display: grid;
  width: 100%;
  min-height: 50px;
  place-items: center;
}

.ad-consent {
  display: grid;
  max-width: 520px;
  gap: 8px;
  padding: 8px;
  letter-spacing: normal;
}

.ad-consent p {
  margin: 0;
  font-size: 0.68rem;
  line-height: 1.3;
}

.ad-consent__actions {
  display: flex;
  justify-content: center;
  gap: 8px;
}

.ad-consent button {
  padding: 5px 8px;
  border: 2px solid var(--ink);
  background: var(--board);
  color: var(--ink);
  cursor: pointer;
  font-size: 0.64rem;
  font-weight: 900;
}

.ad-consent a {
  color: inherit;
  text-underline-offset: 0.15em;
}

.ad-slot--active {
  border-color: transparent;
}

.ad-frame {
  display: block;
  max-width: 100%;
  border: 0;
}

.ad-slot--compact .ad-frame {
  width: 320px;
  height: 50px;
}

.ad-slot--leaderboard .ad-frame {
  width: 728px;
  height: 90px;
}

footer {
  width: min(90vw, 920px);
  color: var(--muted);
  font-size: clamp(0.55rem, 2.2vw, 0.72rem);
  letter-spacing: 0.08em;
  text-align: center;
}

footer a {
  color: inherit;
  text-underline-offset: 0.2em;
}

footer a:hover,
footer a:focus-visible {
  color: var(--ink);
}

.legal-page {
  display: block;
  width: min(90vw, 760px);
  min-height: 100dvh;
  margin: 0 auto;
  padding: max(24px, env(safe-area-inset-top)) 0
    max(36px, env(safe-area-inset-bottom));
  line-height: 1.55;
}

.legal-page h1 {
  border-bottom: 3px solid var(--ink);
  padding-bottom: 10px;
  font-size: clamp(1.7rem, 7vw, 3.2rem);
  line-height: 0.95;
  letter-spacing: -0.06em;
}

.legal-page h2 {
  margin-top: 2rem;
  font-size: 1rem;
  letter-spacing: 0.04em;
}

.legal-page p,
.legal-page li {
  font-size: 0.9rem;
}

.legal-page a {
  color: var(--score-green);
  font-weight: 700;
}

.legal-page__back {
  display: inline-block;
  margin-bottom: 1rem;
}

@media (orientation: landscape) {
  .page-shell {
    display: grid;
    grid-template-areas:
      "header board"
      "modes board"
      "footer board"
      ". board"
      "ad board";
    grid-template-columns: minmax(140px, 1fr) 90svh;
    grid-template-rows: auto auto auto 1fr auto;
    align-items: center;
    justify-content: center;
    gap: min(2.4vw, 28px);
    padding: max(5svh, env(safe-area-inset-top))
      max(3vw, env(safe-area-inset-right))
      max(5svh, env(safe-area-inset-bottom))
      max(3vw, env(safe-area-inset-left));
  }

  .game-header {
    grid-area: header;
    width: 100%;
  }

  .game-header h1 {
    font-size: clamp(1.6rem, 4.2vw, 3.3rem);
  }

  .mode-picker {
    grid-area: modes;
    width: 100%;
  }

  .mode-options {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .mode-option span {
    font-size: clamp(0.64rem, 1.3vw, 0.85rem);
  }

  .mode-option small {
    font-size: clamp(0.48rem, 0.85vw, 0.6rem);
  }

  .game-board {
    grid-area: board;
    width: 90svh;
    height: 90svh;
  }

  .ad-slot {
    grid-area: ad;
    width: 100%;
    min-height: 110px;
  }

  footer {
    grid-area: footer;
    width: 100%;
  }
}

@media (orientation: landscape) and (max-aspect-ratio: 6/5) {
  .page-shell {
    display: flex;
    padding-top: 3svh;
    padding-bottom: max(3svh, env(safe-area-inset-bottom));
  }

  .game-board {
    width: 90svh;
    height: 90svh;
  }

  .mode-picker {
    width: min(90vw, 920px);
  }

  .mode-options {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

@media (orientation: landscape) and (max-height: 500px) {
  .page-shell {
    grid-template-areas:
      "header board"
      "modes board";
    grid-template-rows: auto 1fr;
  }

  .game-header {
    align-self: end;
  }

  .eyebrow {
    display: none;
  }

  .game-header h1 {
    font-size: clamp(1.35rem, 4vw, 2rem);
  }

  .mode-picker {
    align-self: start;
    padding: 7px;
  }

  .mode-picker__title {
    margin-bottom: 5px;
    font-size: 0.62rem;
  }

  .mode-options {
    gap: 4px;
  }

  .mode-option {
    padding: 6px 3px;
  }

  .ad-slot,
  footer {
    display: none;
  }
}

@media (orientation: portrait) and (max-width: 500px) {
  .page-shell {
    gap: 12px;
    padding-top: max(12px, env(safe-area-inset-top));
  }

  .mode-picker {
    padding: 7px;
  }

  .game-header h1 {
    font-size: clamp(1.35rem, 6vw, 1.75rem);
  }

  .mode-picker__title {
    margin-bottom: 5px;
  }

  .mode-options {
    gap: 4px;
  }

  .mode-option {
    padding: 7px 3px;
  }

}

@media (orientation: portrait) and (max-width: 355px) {
  .ad-slot {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .target--hit {
    transition: none;
  }
}
