:root {
  color-scheme: light;
  --paper: #e8e1d2;
  --paper-light: #f3eee3;
  --ink: #292b28;
  --charcoal: #565950;
  --moss: #59644b;
  --rust: #92594a;
  --blue: #9daeb1;
  --focus: #743c2f;
}

*, *::before, *::after { box-sizing: border-box; }

html {
  min-height: 100%;
  background: #d7d0c1;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    linear-gradient(105deg, rgba(255,255,255,.2), transparent 35%),
    var(--paper);
  font-family: Georgia, 'Times New Roman', serif;
  -webkit-font-smoothing: antialiased;
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: .22;
  background-image:
    repeating-linear-gradient(7deg, transparent 0 5px, rgba(58,55,46,.09) 6px, transparent 7px),
    repeating-linear-gradient(97deg, transparent 0 11px, rgba(255,255,255,.2) 12px, transparent 13px),
    radial-gradient(ellipse at 18% 32%, rgba(109,89,60,.12), transparent 18%),
    radial-gradient(ellipse at 77% 64%, rgba(255,255,255,.25), transparent 22%);
  mix-blend-mode: multiply;
}

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

.game-page {
  width: min(1120px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: clamp(.8rem, 2vw, 1.5rem);
  display: grid;
  align-content: center;
  gap: .7rem;
}

.game-header {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  min-height: 2rem;
  font-size: .76rem;
  letter-spacing: .12em;
  text-transform: uppercase;
}

.game-header > :last-child { justify-self: end; }
.attempt-mark { margin: 0; color: var(--charcoal); }

.header-controls { display: flex; align-items: center; gap: 1rem; }

#sound-button[aria-pressed='true'] { color: var(--ink); border-bottom-color: currentColor; }

/* Pressed state must be readable without colour: the label says so too. */
#sound-button[aria-pressed='false']::after { content: ' · off'; }

.text-control {
  width: max-content;
  padding: .35rem .2rem;
  border: 0;
  border-bottom: 1px solid transparent;
  color: var(--charcoal);
  background: transparent;
  text-decoration: none;
  cursor: pointer;
}

.text-control:hover { border-bottom-color: currentColor; color: var(--ink); }

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

.paper-frame {
  position: relative;
  overflow: hidden;
  width: 100%;
  aspect-ratio: 16 / 9;
  min-height: 340px;
  max-height: min(74vh, 700px);
  background: var(--paper-light);
  border: 0;
  clip-path: polygon(.2% .5%, 99.7% 0, 100% 99.3%, .35% 100%, 0 61%);
  box-shadow: 0 18px 52px rgba(49,45,36,.18);
}

.paper-frame::after {
  content: '';
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  box-shadow: inset 0 0 0 1px rgba(49,48,42,.24), inset 0 0 42px rgba(83,73,54,.06);
}

#effort-canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: grab;
}

.opening, .ready, .result {
  position: absolute;
  z-index: 2;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  padding: 2rem;
  text-align: center;
  background: rgba(232,225,210,.74);
  backdrop-filter: blur(2px);
}

.opening {
  inset: 0 0 0 auto;
  width: min(54%, 36rem);
  justify-items: start;
  padding-right: clamp(2rem, 5vw, 4.5rem);
  text-align: left;
  background: linear-gradient(270deg, rgba(238,229,211,.96) 69%, rgba(238,229,211,.12));
  backdrop-filter: none;
}

[hidden] { display: none !important; }

.opening-title {
  max-width: 12ch;
  margin: 0 0 1.5rem;
  font-size: clamp(1.4rem, 3.2vw, 2.65rem);
  font-weight: 400;
  letter-spacing: .04em;
}

.eyebrow {
  margin: 0 0 .65rem;
  color: var(--rust);
  font-size: .68rem;
  letter-spacing: .22em;
  text-transform: uppercase;
}

.opening-instruction, .result-line {
  margin: 0 0 1.8rem;
  color: var(--charcoal);
  font-size: clamp(1rem, 2vw, 1.25rem);
  line-height: 1.7;
  letter-spacing: .08em;
}

.opening-instruction {
  font-size: clamp(.83rem, 1.6vw, 1.05rem);
  letter-spacing: .035em;
}

.result-line { white-space: pre-line; }

.result-echo {
  margin: -1rem 0 1.8rem;
  color: var(--charcoal);
  opacity: .68;
  font-style: italic;
  font-size: clamp(.82rem, 1.5vw, .95rem);
  letter-spacing: .04em;
}

.ready {
  align-content: end;
  justify-items: start;
  padding: 2rem clamp(1.5rem, 5vw, 4rem);
  text-align: left;
  background: linear-gradient(0deg, rgba(232,225,210,.9), rgba(232,225,210,0) 55%);
  backdrop-filter: none;
}

.ready-title {
  margin: 0 0 .8rem;
  font-size: clamp(1.3rem, 2.7vw, 2.15rem);
  font-weight: 400;
}

.opening-controls {
  display: flex;
  flex-wrap: wrap;
  gap: .35rem 1.25rem;
  max-width: 44rem;
  margin: 0 0 .6rem;
  color: var(--charcoal);
  font-size: .76rem;
  line-height: 1.6;
  letter-spacing: .04em;
}

.opening-controls b { color: var(--ink); font-weight: 600; }

.bearing-hint {
  margin: 0 0 .9rem;
  max-width: 30rem;
  color: var(--charcoal);
  font-style: italic;
  font-size: .78rem;
  line-height: 1.6;
  letter-spacing: .03em;
}

.release-prompt {
  margin: 0;
  color: var(--rust);
  font-size: .72rem;
  letter-spacing: .1em;
  text-transform: uppercase;
}

.begin-button, .result-action {
  min-width: 7rem;
  padding: .65rem 1rem;
  border: 1px solid rgba(41,43,40,.5);
  border-radius: 0;
  color: var(--ink);
  background: rgba(243,238,227,.65);
  text-decoration: none;
  cursor: pointer;
  transition: background 250ms ease, color 250ms ease;
}

.begin-button:hover, .result-action:hover {
  color: var(--paper-light);
  background: var(--ink);
}

.result {
  background: rgba(232,225,210,.64);
}

.result-actions { display: flex; gap: .7rem; }

.canvas-description {
  max-width: 76ch;
  margin: .1rem auto 0;
  color: var(--charcoal);
  font-size: .82rem;
  line-height: 1.5;
  text-align: center;
}

.instructions {
  color: var(--charcoal);
  font-size: clamp(.68rem, 1.5vw, .78rem);
  letter-spacing: .04em;
  line-height: 1.65;
  text-align: center;
}

.instructions p { margin: 0; }
kbd { font-family: inherit; color: var(--ink); }
.touch-hint { display: none; }

.status {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

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

.noscript {
  position: fixed;
  inset: 1rem;
  z-index: 10;
  display: grid;
  place-content: center;
  padding: 2rem;
  color: var(--ink);
  background: var(--paper-light);
  text-align: center;
}

@media (pointer: coarse) {
  .touch-hint { display: block; }
}

@media (max-width: 650px), (max-height: 650px) {
  .game-page { align-content: start; }
  .paper-frame { min-height: 300px; max-height: 68vh; aspect-ratio: auto; }
  .canvas-description { font-size: .74rem; }
  .game-header { font-size: .67rem; }
  .opening {
    width: 60%;
    padding: 1.3rem;
  }
  .opening-title { margin-bottom: .8rem; }
  .opening-instruction { margin-bottom: 1rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    scroll-behavior: auto !important;
    transition-duration: .01ms !important;
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
  }
  body::before { opacity: .09; }
}
