:root {
  color-scheme: light;
  --cream: #f7eeda;
  --cream-light: #faf3df;
  --paper: #f1e6d0;
  --paper-sunk: #e8dcc2;
  --oak: #2a1f17;
  --ink: #3b2e22;
  --copper: #9c4e20;
  --amber: #c8852e;
  --rule: #d3c3a2;
  --moss: #4f6247;
  --shadow: rgba(42, 31, 23, 0.1);
  font-family: "Instrument Sans", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--oak);
  background: var(--cream);
  font-synthesis: none;
}

* {
  box-sizing: border-box;
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  background:
    linear-gradient(rgba(156, 78, 32, 0.025) 1px, transparent 1px),
    var(--cream);
  background-size: 100% 40px;
  animation: room-page-in 300ms cubic-bezier(.2,.72,.2,1) both;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

button {
  font: inherit;
}

.game-shell {
  width: min(100%, 560px);
  min-height: 100vh;
  margin: 0 auto;
  padding: max(22px, env(safe-area-inset-top)) 22px max(24px, env(safe-area-inset-bottom));
}

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--rule);
}

.stillbound-wordmark {
  color: var(--oak);
  font: 400 29px/1 "Newsreader", Georgia, serif;
  text-decoration: none;
  letter-spacing: -1.1px;
}

.stillbound-wordmark span {
  color: var(--copper);
  font-style: italic;
}

.stillbound-monogram {
  display: block;
  width: 35px;
  height: 35px;
  color: inherit;
  text-decoration: none;
  transition: transform 180ms ease;
}

.stillbound-monogram:hover {
  transform: rotate(-3deg) scale(1.04);
}

.stillbound-monogram svg {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
}

.stillbound-monogram text {
  fill: var(--copper);
  font-family: "Newsreader", "Iowan Old Style", Georgia, serif;
  font-size: 84px;
  font-weight: 400;
  letter-spacing: -3px;
}

.stillbound-monogram tspan {
  fill: #d39a3d;
  font-style: italic;
  font-weight: 300;
}

.game-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  padding: 30px 0 20px;
}

.eyebrow,
.score-block span,
.shift-note span,
footer {
  margin: 0;
  color: var(--copper);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 2.25px;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  font-family: "Newsreader", Georgia, serif;
  font-weight: 400;
}

h1 {
  margin-top: 4px;
  font-size: clamp(48px, 13vw, 68px);
  line-height: 0.94;
  letter-spacing: -2.7px;
}

h1 em {
  color: var(--copper);
  font-weight: 400;
}

.new-game,
.restart {
  flex: 0 0 auto;
  min-height: 44px;
  padding: 0 17px;
  border: 1px solid var(--copper);
  border-radius: 7px;
  color: var(--copper);
  background: transparent;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition:
    color 150ms ease,
    background-color 150ms ease,
    box-shadow 150ms ease,
    transform 150ms ease;
}

.new-game:hover,
.restart:hover,
.new-game:active,
.restart:active {
  color: var(--cream-light);
  background: var(--copper);
  box-shadow: 0 5px 14px rgba(156, 78, 32, 0.18);
}

.new-game:active,
.restart:active {
  transform: translateY(1px);
  box-shadow: none;
}

.new-game:focus-visible,
.restart:focus-visible,
.stillbound-wordmark:focus-visible,
.stillbound-monogram:focus-visible {
  outline: 2px solid #d39a3d;
  outline-offset: 3px;
}

.score-strip {
  display: grid;
  grid-template-columns: 74px 74px 1fr;
  gap: 8px;
  margin-bottom: 12px;
}

.score-block,
.shift-note {
  position: relative;
  min-height: 59px;
  padding: 10px 12px;
  border: 1px solid var(--rule);
  border-radius: 7px;
  background: rgba(250, 243, 223, 0.65);
}

.score-block strong {
  display: block;
  margin-top: 3px;
  color: var(--oak);
  font-size: 20px;
  line-height: 1;
}

.score-gain {
  position: absolute;
  right: 9px;
  bottom: 9px;
  color: var(--copper);
  font: 600 11px/1 "Instrument Sans", sans-serif;
  pointer-events: none;
}

.shift-note span {
  display: block;
}

.shift-note strong {
  display: block;
  margin-top: 4px;
  overflow: hidden;
  color: var(--ink);
  font: italic 15px/1.1 "Newsreader", Georgia, serif;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.warehouse {
  position: relative;
  padding: 7px;
  border-radius: 18px;
  background: linear-gradient(145deg, #6a452b, #34251c 58%, #745034);
  box-shadow: 0 20px 42px rgba(42, 31, 23, 0.2);
}

.board {
  --board-gap: 9px;
  --board-pad: 10px;
  position: relative;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--board-gap);
  width: 100%;
  aspect-ratio: 1;
  padding: var(--board-pad);
  border: 2px solid #2d231d;
  border-radius: 11px;
  background:
    linear-gradient(rgba(223, 165, 88, 0.14), transparent 20%),
    repeating-linear-gradient(90deg, #6f472b 0 9%, #5e3924 9.5% 18%, #744a2c 18.5% 27%);
  box-shadow:
    inset 0 0 0 3px rgba(211, 154, 61, 0.18),
    inset 0 0 24px rgba(24, 17, 13, 0.48),
    0 8px 18px rgba(42, 31, 23, 0.2);
  touch-action: none;
  user-select: none;
}

.cell {
  position: relative;
  display: grid;
  aspect-ratio: 1;
  place-items: center;
  overflow: hidden;
  border: 1px solid rgba(211, 154, 61, 0.24);
  border-radius: 4px;
  background:
    radial-gradient(circle at 50% 42%, rgba(129, 92, 52, 0.24), transparent 57%),
    linear-gradient(145deg, rgba(18, 15, 13, 0.9), rgba(51, 38, 29, 0.94));
  box-shadow:
    inset 0 0 16px rgba(0, 0, 0, 0.38),
    0 0 0 2px rgba(41, 26, 17, 0.45);
}

.cask-tile {
  position: absolute;
  display: grid;
  width: calc((100% - var(--board-gap) - var(--board-gap) - var(--board-gap)) / 4);
  aspect-ratio: 1;
  place-items: center;
  top: 0;
  left: 0;
  transform: translate3d(var(--tile-x, 0), var(--tile-y, 0), 0);
  transition: transform 190ms cubic-bezier(0.2, 0.72, 0.22, 1);
  backface-visibility: hidden;
  contain: layout paint;
  will-change: transform;
}

.tile-layer {
  position: absolute;
  z-index: 2;
  inset: var(--board-pad);
  pointer-events: none;
}

.cask-col-0 { --tile-x: 0; }
.cask-col-1 { --tile-x: calc(100% + var(--board-gap)); }
.cask-col-2 { --tile-x: calc(200% + var(--board-gap) + var(--board-gap)); }
.cask-col-3 { --tile-x: calc(300% + var(--board-gap) + var(--board-gap) + var(--board-gap)); }
.cask-row-0 { --tile-y: 0; }
.cask-row-1 { --tile-y: calc(100% + var(--board-gap)); }
.cask-row-2 { --tile-y: calc(200% + var(--board-gap) + var(--board-gap)); }
.cask-row-3 { --tile-y: calc(300% + var(--board-gap) + var(--board-gap) + var(--board-gap)); }

.cell::after {
  position: absolute;
  right: 7px;
  bottom: 5px;
  color: rgba(239, 218, 180, 0.28);
  content: attr(data-bay);
  font-size: 7px;
  font-weight: 600;
  letter-spacing: 1px;
}

.cask-head {
  --head: #c9934f;
  --head-dark: #74401e;
  --hoop: #60482f;
  position: relative;
  display: grid;
  width: 90%;
  aspect-ratio: 1;
  place-items: center;
  border: 5px solid var(--hoop);
  border-radius: 50%;
  background:
    radial-gradient(circle at 38% 28%, rgba(255, 224, 165, 0.42), transparent 24%),
    radial-gradient(circle, transparent 51%, rgba(42, 31, 23, 0.2) 52%, transparent 57%),
    repeating-linear-gradient(90deg, transparent 0 13%, rgba(67, 37, 20, 0.22) 14% 15%),
    radial-gradient(circle at 44% 39%, #e4b36a, var(--head) 47%, var(--head-dark) 100%);
  box-shadow:
    inset 0 0 0 2px rgba(241, 230, 208, 0.2),
    inset 0 -6px 11px rgba(42, 31, 23, 0.24),
    0 8px 10px rgba(10, 8, 6, 0.5),
    0 1px 0 rgba(255, 225, 174, 0.25);
  transform: rotate(var(--tilt, 0deg));
}

.cask-head::before,
.cask-head::after {
  position: absolute;
  border: 1px solid rgba(42, 31, 23, 0.42);
  border-radius: 50%;
  content: "";
  inset: 8%;
}

.cask-head::after {
  border-style: dashed;
  opacity: 0.72;
  inset: 16%;
}

.cask-number {
  position: relative;
  z-index: 1;
  color: #382319;
  font-family: "Courier New", ui-monospace, monospace;
  font-size: clamp(21px, 7vw, 39px);
  font-weight: 700;
  letter-spacing: -2px;
  line-height: 1;
  text-shadow: 0 1px rgba(250, 243, 223, 0.34), 0 2px 2px rgba(42, 31, 23, 0.14);
  transform: rotate(calc(var(--tilt, 0deg) * -1));
}

.cask-tier {
  position: absolute;
  z-index: 1;
  bottom: 16%;
  color: rgba(42, 31, 23, 0.72);
  font-size: 6px;
  font-weight: 700;
  letter-spacing: 0.9px;
  line-height: 1;
  text-transform: lowercase;
  transform: rotate(calc(var(--tilt, 0deg) * -1));
}

.tile-4 .cask-head {
  --head: #bd8141;
  --head-dark: #663516;
}

.tile-4 .cask-head::after,
.tile-16 .cask-head::after {
  inset: 27%;
  border: 3px solid rgba(56, 35, 25, 0.24);
  border-radius: 2px;
  transform: rotate(45deg);
}

.tile-8 .cask-head {
  --head: #c77737;
  --head-dark: #6c2f12;
  --hoop: #4b3a29;
  width: 94%;
}

.tile-8 .cask-head::after {
  inset: 23%;
  border: 4px double rgba(56, 35, 25, 0.24);
}

.tile-16 .cask-head {
  --head: #a95a29;
  --head-dark: #4d2514;
  --hoop: #3d3327;
  width: 95%;
}

.tile-32 .cask-head,
.tile-64 .cask-head {
  --head: #8e4826;
  --head-dark: #3c2118;
  --hoop: #2f2a24;
  width: 96%;
}

.tile-32 .cask-number,
.tile-64 .cask-number,
.tile-128 .cask-number,
.tile-256 .cask-number,
.tile-512 .cask-number,
.tile-1024 .cask-number,
.tile-2048 .cask-number {
  color: var(--cream-light);
  text-shadow: none;
}

.tile-128 .cask-head,
.tile-256 .cask-head,
.tile-512 .cask-head,
.tile-1024 .cask-head,
.tile-2048 .cask-head {
  --head: #6f3b27;
  --head-dark: #251c18;
  --hoop: #c8852e;
  width: 97%;
}

.tile-128 .cask-tier,
.tile-256 .cask-tier,
.tile-512 .cask-tier,
.tile-1024 .cask-tier,
.tile-2048 .cask-tier {
  color: rgba(250, 243, 223, 0.72);
}

.tile-new .cask-head {
  animation: settle 180ms ease-out both;
}

.tile-merged .cask-head {
  animation: merge 235ms cubic-bezier(0.2, 0.8, 0.25, 1.15) both;
}

@keyframes settle {
  from { opacity: 0; transform: rotate(var(--tilt)) scale(0.65); }
  to { opacity: 1; transform: rotate(var(--tilt)) scale(1); }
}

@keyframes merge {
  0% { filter: brightness(1); transform: rotate(var(--tilt)) scale(0.9); }
  55% { filter: brightness(1.09); transform: rotate(var(--tilt)) scale(1.13); }
  100% { transform: rotate(var(--tilt)) scale(1); }
}

.game-message {
  position: absolute;
  z-index: 10;
  display: grid;
  place-content: center;
  inset: 0;
  padding: 26px;
  border-radius: 14px;
  background: rgba(247, 238, 218, 0.94);
  text-align: center;
  animation: message-in 280ms cubic-bezier(0.2, 0.75, 0.3, 1) both;
}

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

.game-message h2 {
  max-width: 280px;
  margin: 7px auto 8px;
  font-size: 36px;
  line-height: 1;
}

.game-message > p:not(.eyebrow) {
  max-width: 300px;
  margin: 0 auto 20px;
  color: var(--stone);
  font-size: 13px;
  line-height: 1.35;
}

@keyframes message-in {
  from { opacity: 0; backdrop-filter: blur(0); }
  to { opacity: 1; backdrop-filter: blur(2px); }
}

.how-to-play {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 20px 3px;
  border-bottom: 1px solid var(--rule);
}

.how-to-play p {
  max-width: 330px;
  margin: 0;
  color: var(--ink);
  font-size: 14px;
  line-height: 1.45;
}

.direction-marks {
  display: grid;
  grid-template-columns: repeat(2, 25px);
  gap: 3px;
}

.direction-marks span {
  display: grid;
  width: 25px;
  height: 25px;
  place-items: center;
  border: 1px solid var(--rule);
  border-radius: 4px;
  color: var(--copper);
  font-size: 12px;
}

footer {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  padding-top: 17px;
  color: #7f7262;
  font-size: 8px;
  letter-spacing: 1.55px;
}

footer a {
  color: var(--copper);
  text-decoration: none;
}

footer a:hover {
  text-decoration: underline;
  text-underline-offset: 3px;
}

@media (max-width: 410px) {
  .game-shell {
    padding-right: 14px;
    padding-left: 14px;
  }

  .score-strip {
    grid-template-columns: 68px 68px 1fr;
  }

  .board {
    --board-gap: 7px;
    --board-pad: 8px;
  }

  .cell {
    border-radius: 7px;
  }

  .cask-tier {
    display: none;
  }
}

@media (min-width: 700px) {
  body {
    padding: 32px;
  }

  .game-shell {
    min-height: calc(100vh - 64px);
    border: 1px solid var(--rule);
    background: rgba(247, 238, 218, 0.93);
    box-shadow: 0 24px 70px rgba(42, 31, 23, 0.12);
  }
}

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

@keyframes room-page-in {
  from { opacity: 0; transform: translateY(8px) scale(.995); }
}

.room-back { color: inherit; text-decoration: none; }
.room-back:hover { text-decoration: underline; }

/* ---- Fit on screen (12 Sep 2026): the board is never below the fold ---- */
.game-heading { padding: 14px 0 12px; }
h1 { font-size: clamp(40px, 9vw, 52px); }
.score-block, .shift-note { min-height: 50px; padding: 7px 11px; }
.score-strip { margin-bottom: 10px; }
.warehouse {
  /* width-bound on phones, height-bound on laptops: 100dvh minus the chrome above the board */
  --chrome: 300px;
  width: min(100%, calc(100dvh - var(--chrome)));
  margin: 0 auto;
}
@media (min-width: 700px) { .warehouse { --chrome: 340px; } }
@media (max-width: 410px) { .game-heading { padding: 10px 0 8px; } h1 { font-size: 38px; } .warehouse { --chrome: 270px; } }
