:root {
  color-scheme: light;
  --paper: #f7f5ee;
  --card: #fffdfa;
  --ink: #183229;
  --green: #214638;
  --dark: #142f27;
  --muted: #4a6056;
  --line: #dedfd3;
  --accent: #bd4d35;
  --shadow: 0 12px 30px #21392a0b;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--paper);
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; min-width: 280px; }
a { color: inherit; }
button { font: inherit; }
button:focus-visible, a:focus-visible, canvas:focus-visible {
  outline: 3px solid #aa4925;
  outline-offset: 3px;
}

.masthead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  max-width: 1160px;
  margin: 0 auto;
  padding: 20px 28px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  font-size: .94rem;
  font-weight: 780;
}

.brand-icon {
  position: relative;
  display: inline-grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 9px;
  background: var(--dark);
}
.brand-icon::before {
  content: "";
  width: 17px;
  height: 13px;
  border: 1.5px solid #fff4d9;
  border-radius: 2px;
  background:
    linear-gradient(90deg, transparent 44%, #fff4d9 44% 56%, transparent 56%),
    linear-gradient(transparent 35%, #fff4d9 35% 48%, transparent 48%);
}
.brand-icon::after {
  content: "";
  position: absolute;
  top: 5px;
  width: 9px;
  height: 5px;
  border: 1.5px solid #fff4d9;
  border-radius: 80% 80% 35% 35%;
}
.home-link { font-size: .88rem; font-weight: 700; text-underline-offset: 4px; white-space: nowrap; }

.lobby { max-width: 1160px; margin: 0 auto; padding: 2px 28px 56px; }
.hero {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) min(39%, 388px);
  align-items: center;
  gap: 10px;
  overflow: hidden;
  padding: 34px 46px;
  border-radius: 26px;
  background: radial-gradient(ellipse at 82% 120%, #37614c, transparent 65%), var(--dark);
  color: #fff9ec;
}
.hero h1, .game-title, .victory h2 {
  margin: 0;
  font-family: Georgia, ui-serif, serif;
  font-weight: 700;
  letter-spacing: -.052em;
  line-height: 1;
}
.hero h1 { font-size: clamp(2.85rem, 6.4vw, 5.3rem); max-width: 11ch; }
.hero p {
  max-width: 35ch;
  margin: 19px 0 0;
  color: #e5e9d8;
  font-size: clamp(.99rem, 2.2vw, 1.16rem);
  line-height: 1.48;
}
.hero canvas { display: block; width: 100%; height: auto; }

.game-list {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
  margin: 23px 0 0;
  padding: 0;
  list-style: none;
}
.game-list li { display: flex; }
.game-link {
  display: grid;
  grid-template-rows: auto 1fr;
  width: 100%;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 19px;
  background: var(--card);
  box-shadow: var(--shadow);
  text-decoration: none;
  transition: transform 160ms ease, border-color 160ms ease;
}
.game-link:hover { transform: translateY(-2px); border-color: #9daea1; }
.game-link canvas { display: block; width: 100%; height: auto; aspect-ratio: 320 / 116; }
.game-label {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 9px;
  padding: 14px 16px 16px;
}
.game-label strong { display: block; font-size: clamp(.99rem, 1.65vw, 1.19rem); line-height: 1.25; }
.game-label small { display: block; margin-top: 4px; color: var(--muted); line-height: 1.35; }
.game-arrow { color: var(--green); font-size: 1.28rem; line-height: 1; }

.game-page { max-width: 850px; margin: 0 auto; padding: 5px 28px 46px; }
.game-intro { margin: 0 0 16px; }
.game-title { font-size: clamp(2.65rem, 6.4vw, 4.25rem); }
.game-intro p { margin: 11px 0 0; color: var(--muted); line-height: 1.45; }
.play-card {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 23px;
  background: var(--card);
  box-shadow: var(--shadow);
}
.play-status {
  padding: 10px 16px;
  min-height: 42px;
  display: flex;
  align-items: center;
  gap: 12px;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
  color: var(--green);
  font-size: .86rem;
  font-weight: 725;
  font-variant-numeric: tabular-nums;
}
.play-status > :last-child { text-align: right; }
.stage {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  overflow: hidden;
  background: #e9eee5;
}
.action-board { display: block; width: 100%; height: auto; touch-action: none; user-select: none; }
.action-board:focus-visible { outline-offset: -5px; }
.action-prompt {
  position: absolute;
  align-self: end;
  justify-self: center;
  bottom: clamp(14px, 4vw, 30px);
  padding: 0;
  border: 0;
  box-shadow: 0 4px 16px #132f2966;
}
.stage:has(.key-controls) .action-prompt { bottom: calc(54px + clamp(14px, 4vw, 30px)); }
.key-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px;
  width: 100%;
  padding: 9px 12px;
  background: #f6f7ec;
  border-top: 1px solid #d6dfd0;
}
.key-controls > button { padding: 5px 12px; min-height: 42px; }
.actions {
  display: flex;
  justify-content: space-between;
  gap: 8px 12px;
  flex-wrap: wrap;
  padding: 11px 14px;
  border-top: 1px solid var(--line);
}
.actions-group { display: flex; gap: 8px; flex-wrap: wrap; }
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  padding: 7px 14px;
  border: 1px solid #cbd6c9;
  border-radius: 11px;
  color: var(--green);
  background: #f8faf2;
  font-size: .89rem;
  font-weight: 720;
  cursor: pointer;
  text-decoration: none;
}
.button:hover { background: #e8efe2; }
.button:disabled { opacity: .53; cursor: default; }
.button.primary { color: #fff9ec; background: var(--green); border-color: var(--green); }
.button.primary:hover { background: #2f5947; }
.hint-box {
  margin: 12px 0 0;
  padding: 12px 15px;
  border: 1px solid #c9d7c1;
  border-radius: 12px;
  background: #eff3e8;
  color: #304638;
  line-height: 1.45;
  font-size: .94rem;
}
.hint-box p { margin: 0; }
.hint-box button { margin-top: 8px; }

.victory {
  min-height: clamp(290px, 61vw, 460px);
  display: grid;
  justify-items: center;
  align-content: center;
  gap: 16px;
  padding: 28px 18px;
  text-align: center;
  background:
    radial-gradient(ellipse at 50% 108%, #3c6348, transparent 65%),
    var(--dark);
  color: #fff9ec;
}
.victory h2 { font-size: clamp(2.55rem, 7vw, 4rem); }
.victory p { margin: 0; max-width: 36ch; color: #e6ecdb; line-height: 1.45; }
.victory .button { margin-top: 3px; }
.victory canvas { width: 150px; height: auto; }

.slider-board {
  position: relative;
  width: min(100% - 34px, 438px);
  aspect-ratio: 1;
  margin: 18px 0 21px;
  border: 5px solid #79625a;
  border-radius: 13px;
  background-image:
    linear-gradient(to right, #efded6 1px, transparent 1px),
    linear-gradient(to bottom, #efded6 1px, transparent 1px);
  background-color: #e3c9b9;
  background-size: 20% 20%;
  box-shadow: 0 6px 0 #79625a29;
  --cell: 20%;
}
.slider-board::after {
  content: "›";
  position: absolute;
  top: 40%;
  right: -15px;
  display: grid;
  align-content: center;
  width: 18px;
  height: 20%;
  border: 2px solid #6c4a43;
  border-radius: 3px;
  background: #fff0c8;
  color: #703b32;
  font-size: 1.65rem;
  font-weight: 800;
  text-align: center;
  z-index: 1;
  pointer-events: none;
}
.stage.slider-stage { background: #f1e7de; }
.piece {
  position: absolute;
  display: grid;
  place-items: center;
  min-width: 0;
  padding: 0;
  border: 1px solid #ffffff36;
  border-radius: 9px;
  color: #fffdf5;
  box-shadow: inset 0 -4px 0 #1b2b2332;
  font-size: clamp(1.32rem, 4vw, 2rem);
  font-weight: 650;
  cursor: grab;
  touch-action: none;
  user-select: none;
  transition: left 155ms ease-out, top 155ms ease-out;
}
.piece:active { cursor: grabbing; }
.piece[aria-pressed="true"], .piece.is-hinted { outline: 3px solid #fff7da; outline-offset: -5px; }
.piece:focus-visible { outline: 3px solid #213b31; outline-offset: 1px; z-index: 2; }
.piece.gift-piece { background: #a53d3e; position: absolute; }
.piece.gift-piece::before, .piece.gift-piece::after {
  content: "";
  position: absolute;
  inset: 0 calc(50% - 4px);
  background: #fcd59a;
  pointer-events: none;
}
.piece.gift-piece::after { inset: calc(50% - 4px) 0; }
.piece.gift-piece span {
  position: relative;
  z-index: 1;
  display: grid;
  place-content: center;
  width: 28px;
  height: 28px;
  border-radius: 100%;
  background: #ffe0aa;
  color: #873331;
  font-size: 1.1rem;
}

.pins-stage { background: #e2eee8; }
.pin-board { position: relative; width: min(100%, 630px); aspect-ratio: 640/390; }
.pin-board canvas { display: block; width: 100%; height: auto; }
.pin {
  position: absolute;
  display: grid;
  place-items: center;
  min-width: 44px;
  min-height: 44px;
  width: 10%;
  height: 14%;
  padding: 0;
  border: 2px solid #493523;
  border-radius: 50%;
  color: #3c2b1d;
  background: #ffd879;
  box-shadow: 0 4px #493523;
  font-size: 1.08rem;
  font-weight: 850;
  transform: translate(-50%, -50%);
  cursor: pointer;
  touch-action: manipulation;
}
.pin:hover { background: #ffeaab; }
.pin.is-hinted { outline: 3px solid #a93c43; outline-offset: 4px; }
.pin:disabled { visibility: hidden; }

.rails-stage { background: #e4eee6; padding: 13px 10px; }
.rails-frame {
  position: relative;
  display: grid;
  grid-template-columns: clamp(32px, 10.5vw, 52px) minmax(0, 1fr) clamp(32px, 10.5vw, 52px);
  grid-template-rows: repeat(3, 1fr);
  align-items: center;
  column-gap: 5px;
  width: min(100%, 540px);
}
.rails-board {
  position: relative;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  grid-column: 2;
  grid-row: 1 / 4;
  aspect-ratio: 4/3;
  gap: 3px;
}
.rail {
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  min-width: 0;
  padding: 0;
  border: 1px solid #b2c5ad;
  border-radius: 8px;
  background: #f8f6df;
  cursor: pointer;
  touch-action: manipulation;
}
.rail:hover { background: #fff8cc; }
.rail.is-hinted { outline: 3px solid #a63d42; outline-offset: -4px; }
.rail canvas { display: block; width: 100%; height: auto; }
.rail-empty {
  display: grid;
  place-items: center;
  min-width: 0;
  border: 1px dashed #b6c8b3;
  border-radius: 8px;
  color: #6a9481;
  font-size: clamp(.65rem, 2.7vw, 1.15rem);
}
.rail-station {
  position: relative;
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  width: 100%;
  border-radius: 10px;
  border: 1px solid #aec5b1;
  background: #fbf7e5;
  color: #294b3c;
  font-size: clamp(.68rem, 2.8vw, 1.45rem);
  font-weight: 800;
}
.rail-station:first-child { grid-column: 1; grid-row: 2; }
.rail-station:last-child { grid-column: 3; grid-row: 3; }
.train-token {
  position: absolute;
  z-index: 2;
  width: clamp(16px, 4.5vw, 34px);
  aspect-ratio: 1;
  border: 2px solid #632e35;
  border-radius: 7px;
  background: #c45049;
  box-shadow: inset 0 0 0 3px #ffd795;
  transform: translate(-50%, -50%);
  pointer-events: none;
}

@media (max-width: 740px) {
  .masthead, .lobby, .game-page { padding-left: 18px; padding-right: 18px; }
  .hero { padding: 27px 28px; }
  .game-list { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
}
@media (max-width: 440px) {
  .masthead { padding: 15px 12px; }
  .lobby, .game-page { padding-left: 12px; padding-right: 12px; }
  .hero { padding: 22px 18px; grid-template-columns: minmax(0, 1fr) 30%; border-radius: 19px; }
  .hero h1 { font-size: clamp(2.17rem, 9.1vw, 2.7rem); }
  .hero p { margin-top: 12px; font-size: .9rem; }
  .hero canvas { width: 150%; margin-left: -23%; }
  .game-list { margin-top: 15px; gap: 9px; }
  .game-link { border-radius: 13px; }
  .game-link canvas { aspect-ratio: 320 / 138; object-fit: cover; }
  .game-label { padding: 10px; gap: 4px; }
  .game-label small { font-size: .76rem; }
  .game-arrow { font-size: .96rem; }
  .play-card { border-radius: 17px; }
  .play-status { padding: 8px 10px; min-height: 36px; font-size: .79rem; }
  .actions { padding: 9px 8px; gap: 8px; }
  .actions-group { gap: 5px; }
  .button { padding-left: 10px; padding-right: 10px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0ms !important; }
}
