:root {
  color-scheme: dark;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  background: #0a0d12;
  color: #f2e8c9;
  --ink: #10141b;
  --paper: #f2e8c9;
  --rust: #b54a35;
  --moss: #6f8b56;
  --water: #5d8799;
  --focus: #ffd66b;
  --touch-readout-height: 2.8rem;
  --touch-control-size: 3.2rem;
  --touch-control-gap: 0.35rem;
  --touch-control-padding: 0.55rem;
  --touch-navigation-height: calc(
    var(--touch-control-size) + var(--touch-control-size) + var(--touch-control-size)
    + var(--touch-control-gap) + var(--touch-control-gap)
    + var(--touch-control-padding) + var(--touch-control-padding)
  );
  --touch-shell-height-reserve: calc(var(--touch-readout-height) + var(--touch-navigation-height));
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  margin: 0;
}

body {
  display: grid;
  place-items: center;
  min-height: 100dvh;
  overflow: hidden;
  background: radial-gradient(circle at 50% 30%, #27313d 0%, #0a0d12 70%);
}

button {
  border: 2px solid var(--paper);
  border-radius: 0;
  padding: 0.7rem 0.9rem;
  background: var(--ink);
  color: var(--paper);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

button:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

button:active {
  translate: 0 1px;
}

input {
  accent-color: var(--focus);
  font: inherit;
}

input[type="text"] {
  min-width: 7rem;
  border: 1px solid var(--paper);
  border-radius: 0;
  padding: 0.35rem;
  background: #05070a;
  color: var(--paper);
}

input[type="range"] {
  width: min(100%, 16rem);
}

.game-shell {
  position: relative;
  display: grid;
  grid-template-rows: auto minmax(2.8rem, auto);
  width: min(100vw, calc((100dvh - 3.2rem) * 12 / 7));
  max-width: 72rem;
  max-height: 100dvh;
  overflow: hidden;
  background: var(--ink);
  box-shadow: 0 0 0 2px #46515f, 0 1.5rem 5rem #000c;
  user-select: none;
}

.game-stage {
  position: relative;
  width: 100%;
  aspect-ratio: 12 / 7;
  overflow: hidden;
  touch-action: none;
}

[data-game-canvas] {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
}

.field-readout {
  position: relative;
  z-index: 3;
  display: grid;
  grid-template-columns: minmax(10rem, 1.15fr) minmax(0, 1.15fr) minmax(0, 0.7fr);
  min-height: 2.8rem;
  border-top: 1px solid #f2e8c966;
  background: #05070a;
  pointer-events: none;
}

.game-caption,
.game-objective,
.game-status {
  min-width: 0;
  padding: 0.45rem 0.65rem;
  color: var(--paper);
  font-size: clamp(0.62rem, 1.4vw, 0.8rem);
  line-height: 1.35;
}

.game-objective,
.game-status {
  border-right: 1px solid #f2e8c933;
}

.game-status {
  color: #f2d08b;
}

.game-objective {
  color: #f2e8c9;
}

.readout-label {
  display: block;
  margin-bottom: 0.1rem;
  color: #d59667;
  font-size: 0.58rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.game-overlay {
  position: absolute;
  z-index: 6;
  inset: 0;
  display: grid;
  align-content: center;
  justify-items: start;
  gap: 0.75rem;
  padding: clamp(1.25rem, 6vw, 4rem);
  background: linear-gradient(90deg, #10141bf7 0%, #10141bdc 55%, #10141b99 100%);
}

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

.game-overlay h1,
.game-overlay h2,
.game-overlay p {
  max-width: 38rem;
  margin: 0;
}

.game-overlay h1 {
  font-size: clamp(1.6rem, 5vw, 3.25rem);
  line-height: 1.02;
}

.game-kicker {
  color: #d59667;
  text-transform: uppercase;
  letter-spacing: 0.12em;
}

.play-guide {
  width: min(100%, 48rem);
  margin: 0.2rem 0 0.35rem;
  padding: 0.85rem 1rem;
  border: 1px solid #f2e8c966;
  background: #05070acc;
}

.play-guide__eyebrow {
  color: #d59667;
  font-size: 0.68rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.play-guide h2 {
  font-size: clamp(1rem, 2.5vw, 1.35rem);
  line-height: 1.1;
}

.play-guide__steps {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.75rem;
  width: min(100%, 48rem);
  margin: 0.7rem 0 0;
  padding: 0;
  list-style: none;
}

.play-guide__steps li {
  display: grid;
  align-content: start;
  gap: 0.28rem;
  padding-top: 0.45rem;
  border-top: 1px solid #f2e8c933;
}

.play-guide__steps strong {
  color: #f2d08b;
  font-size: 0.68rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.play-guide__steps span,
.play-guide__controls,
.play-guide__note {
  color: #c7bca9;
  font-size: 0.7rem;
  line-height: 1.45;
}

.play-guide__controls,
.play-guide__note {
  margin-top: 0.7rem !important;
}

.play-guide__controls strong {
  color: #f2e8c9;
}

.game-panel {
  overflow: auto;
}

.game-panel ol {
  width: min(100%, 42rem);
  max-height: 45vh;
  overflow: auto;
  margin: 0;
  padding: 0.5rem 0.5rem 0.5rem 2rem;
  background: #05070acc;
}

.game-panel label {
  display: grid;
  grid-template-columns: minmax(8rem, auto) minmax(0, 1fr);
  align-items: center;
  gap: 0.75rem;
  width: min(100%, 34rem);
}

.game-panel label:has(input[type="checkbox"]) {
  display: flex;
  gap: 0.55rem;
}

.game-panel h3 {
  margin: 0.75rem 0 0;
}

.binding-grid,
.tableau-list {
  display: grid;
  gap: 0.45rem;
  width: min(100%, 36rem);
  padding: 0.65rem;
  border: 1px solid #f2e8c966;
  background: #05070acc;
}

.binding-grid label {
  grid-template-columns: minmax(9rem, 1fr) minmax(7rem, 0.7fr);
}

.tableau-list button {
  text-align: left;
}

:root[data-high-contrast="true"] {
  --ink: #000;
  --paper: #fff;
  --focus: #ff0;
}

:root[data-reduced-motion="true"] *,
:root[data-reduced-motion="true"] *::before,
:root[data-reduced-motion="true"] *::after {
  scroll-behavior: auto !important;
  transition-duration: 0.001ms !important;
  animation-duration: 0.001ms !important;
}

.cutscene-overlay {
  position: absolute;
  z-index: 8;
  inset: 0;
  background: #05070a;
}

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

.cutscene-overlay img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  image-rendering: pixelated;
}

.cutscene-copy {
  position: absolute;
  inset: auto 3% 4% 3%;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.35rem 1rem;
  align-items: end;
  padding: 0.65rem;
  border: 1px solid #f2e8c966;
  background: #10141be8;
}

.cutscene-copy h2,
.cutscene-copy p {
  margin: 0;
}

.cutscene-copy h2 {
  grid-column: 1;
  font-size: clamp(0.9rem, 2.5vw, 1.25rem);
}

.cutscene-copy p {
  grid-column: 1;
  font-size: clamp(0.6rem, 1.8vw, 0.85rem);
}

.cutscene-copy button {
  grid-column: 2;
  grid-row: 1 / span 2;
}

.touch-controls {
  display: none;
  position: relative;
  z-index: 4;
  justify-content: space-between;
  align-items: end;
  gap: 0.75rem;
  padding: var(--touch-control-padding);
  border-top: 1px solid #f2e8c933;
  background: #05070a;
  touch-action: none;
}

.touch-controls button {
  min-width: var(--touch-control-size);
  min-height: var(--touch-control-size);
  padding: 0.35rem;
  opacity: 0.86;
}

.touch-pad {
  display: grid;
  grid-template-columns: repeat(3, var(--touch-control-size));
  grid-template-rows: repeat(3, var(--touch-control-size));
}

.touch-pad button:nth-child(1) { grid-column: 2; grid-row: 1; }
.touch-pad button:nth-child(2) { grid-column: 1; grid-row: 2; }
.touch-pad button:nth-child(3) { grid-column: 2; grid-row: 3; }
.touch-pad button:nth-child(4) { grid-column: 3; grid-row: 2; }

.touch-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(4.2rem, 1fr));
  gap: var(--touch-control-gap);
}

@media (hover: none), (pointer: coarse) {
  .game-shell {
    grid-template-rows: auto minmax(2.8rem, auto) auto;
    width: min(100vw, calc((100dvh - var(--touch-shell-height-reserve)) * 12 / 7));
  }

  .field-readout {
    block-size: var(--touch-readout-height);
    min-block-size: var(--touch-readout-height);
    max-block-size: var(--touch-readout-height);
    overflow: hidden;
  }

  .game-caption,
  .game-objective,
  .game-status {
    display: grid;
    align-content: center;
    padding-block: 0.25rem;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
  }

  .readout-label {
    margin-bottom: 0;
  }

  .touch-controls {
    display: flex;
  }
}

@media (max-height: 420px) {
  :root {
    --touch-control-size: 2.6rem;
  }

  .touch-controls button {
    font-size: 0.68rem;
  }
}

@media (max-width: 720px) {
  .game-overlay[data-title-overlay] {
    position: fixed;
    inset: 0;
    align-content: start;
    overflow-y: auto;
    min-height: 100dvh;
  }

  .play-guide__steps {
    grid-template-columns: 1fr;
    gap: 0.55rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.001ms !important;
    animation-duration: 0.001ms !important;
  }
}
