:root {
  color-scheme: light;
  --ink: #302118;
  --ink-soft: #76584a;
  --paper: #f4e8cf;
  --paper-light: #fbf4e4;
  --wood: #70442c;
  --wood-dark: #39231a;
  --gold: #bd8c3e;
  --gold-light: #e4bd68;
  --red: #a84030;
  --green: #526f58;
  --blue: #416d78;
  --shadow: rgba(43, 25, 17, 0.26);
  font-family: "Noto Serif SC", "Source Han Serif SC", "Songti SC", SimSun, serif;
}

* { box-sizing: border-box; }

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

body {
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  overflow-x: clip;
  color: var(--ink);
  background:
    radial-gradient(circle at 12% 8%, rgba(228, 189, 104, 0.16), transparent 28rem),
    radial-gradient(circle at 88% 86%, rgba(168, 64, 48, 0.13), transparent 30rem),
    repeating-linear-gradient(92deg, rgba(255, 255, 255, 0.015) 0 1px, transparent 1px 8px),
    linear-gradient(145deg, #291a14, #4a2d20 48%, #211510);
}

button,
select { font: inherit; }

button:focus-visible,
select:focus-visible,
a:focus-visible,
canvas:focus-visible,
.mine-cell:focus-visible {
  outline: 3px solid var(--gold-light);
  outline-offset: 3px;
}

a { color: inherit; }

.hall-shell,
.arcade-shell {
  position: relative;
  width: min(1160px, calc(100% - 30px));
  margin: 0 auto;
  padding: max(32px, env(safe-area-inset-top)) env(safe-area-inset-right) max(24px, env(safe-area-inset-bottom)) env(safe-area-inset-left);
}

.site-bridge {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
  color: rgba(248, 232, 198, 0.7);
  font-size: 0.76rem;
  letter-spacing: 0.11em;
}

.site-bridge a,
.site-nav a {
  display: inline-flex;
  min-height: 44px;
  align-items: center;
}

.site-bridge a {
  padding: 8px 10px;
  color: inherit;
  text-decoration: none;
}

.site-bridge a:hover,
.site-bridge a:focus-visible {
  color: var(--gold-light);
}

.hall-hero {
  position: relative;
  max-width: 760px;
  margin: 0 auto 34px;
  color: #f8e8c6;
  text-align: center;
}

.hall-seal {
  display: grid;
  width: 46px;
  height: 46px;
  margin: 0 auto 13px;
  place-items: center;
  border: 2px solid #d26b52;
  color: #f1aa92;
  font-size: 1.35rem;
  transform: rotate(-5deg);
}

.hall-kicker,
.arcade-kicker {
  margin: 0 0 8px;
  color: var(--gold-light);
  font-size: 0.73rem;
  letter-spacing: 0.34em;
}

.hall-hero h1 {
  margin: 0;
  font-size: clamp(2.4rem, 6vw, 4.2rem);
  font-weight: 500;
  letter-spacing: 0.22em;
  text-indent: 0.22em;
  text-shadow: 0 5px 20px rgba(0, 0, 0, 0.3);
}

.hall-intro {
  max-width: 620px;
  margin: 14px auto 0;
  color: rgba(248, 232, 198, 0.67);
  font-size: 0.9rem;
  letter-spacing: 0.13em;
  line-height: 1.9;
}

.game-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 18px;
}

.game-tile {
  position: relative;
  overflow: hidden;
  min-height: 500px;
  padding: 30px 28px 26px;
  border: 1px solid rgba(228, 189, 104, 0.58);
  border-radius: 5px;
  color: var(--ink);
  background:
    repeating-linear-gradient(3deg, rgba(112, 68, 44, 0.028) 0 1px, transparent 1px 9px),
    var(--paper);
  box-shadow: 0 22px 50px rgba(0, 0, 0, 0.25), inset 0 0 42px rgba(112, 68, 44, 0.07);
  text-decoration: none;
  transition: transform 200ms ease, box-shadow 200ms ease, border-color 200ms ease;
}

.game-tile::before,
.game-tile::after {
  position: absolute;
  width: 42px;
  height: 42px;
  border-color: rgba(168, 64, 48, 0.32);
  content: "";
}

.game-tile::before {
  top: 10px;
  left: 10px;
  border-top: 1px solid;
  border-left: 1px solid;
}

.game-tile::after {
  right: 10px;
  bottom: 10px;
  border-right: 1px solid;
  border-bottom: 1px solid;
}

.game-tile:hover {
  border-color: var(--gold-light);
  box-shadow: 0 28px 62px rgba(0, 0, 0, 0.34), inset 0 0 45px rgba(112, 68, 44, 0.09);
  transform: translateY(-6px);
}

.tile-number {
  position: absolute;
  top: 18px;
  right: 20px;
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border: 1px solid rgba(168, 64, 48, 0.44);
  color: var(--red);
  font-size: 0.8rem;
  transform: rotate(4deg);
}

.tile-art {
  position: relative;
  height: 210px;
  margin: 18px 0 24px;
}

.tile-art--hanoi::before,
.tile-art--hanoi::after {
  position: absolute;
  bottom: 10px;
  left: 50%;
  background: linear-gradient(90deg, #a46b41, #5a3422);
  content: "";
  transform: translateX(-50%);
}

.tile-art--hanoi::before { width: 82%; height: 18px; border-radius: 3px 3px 8px 8px; }
.tile-art--hanoi::after { width: 10px; height: 174px; border-radius: 8px 8px 0 0; }
.tile-art--hanoi i {
  position: absolute;
  z-index: 2;
  bottom: calc(29px + var(--level, 0) * 27px);
  left: 50%;
  width: calc(38% + var(--level, 0) * 9%);
  height: 25px;
  border: 1px solid rgba(57, 35, 26, 0.58);
  border-radius: 6px;
  background: #c65640;
  box-shadow: 0 3px 5px rgba(48, 28, 20, 0.18), inset 0 2px rgba(255,255,255,.22);
  transform: translateX(-50%);
}
.tile-art--hanoi i:nth-child(1) { --level: 0; width: 78%; background: #8a5260; }
.tile-art--hanoi i:nth-child(2) { --level: 1; width: 68%; background: #557789; }
.tile-art--hanoi i:nth-child(3) { --level: 2; width: 58%; background: #70865b; }
.tile-art--hanoi i:nth-child(4) { --level: 3; width: 48%; background: #d18b3c; }
.tile-art--hanoi i:nth-child(5) { --level: 4; width: 38%; background: #c65640; }

.tile-art--mine {
  display: grid;
  grid-template-columns: repeat(3, 52px);
  grid-template-rows: repeat(3, 52px);
  justify-content: center;
  align-content: center;
  gap: 4px;
}

.tile-art--mine i {
  position: relative;
  display: grid;
  place-items: center;
  border: 1px solid rgba(112, 68, 44, 0.38);
  background: #d9c49e;
  box-shadow: inset 2px 2px rgba(255,255,255,.32), inset -2px -2px rgba(72,43,29,.12);
}
.tile-art--mine i:nth-child(2)::after,
.tile-art--mine i:nth-child(6)::after { color: #477183; content: "2"; font: 600 1.5rem Georgia; }
.tile-art--mine i:nth-child(4)::after { color: var(--red); content: "⚑"; font-size: 1.3rem; }
.tile-art--mine i:nth-child(5) { background: #efe3c9; }
.tile-art--mine i:nth-child(5)::after { color: #8a352a; content: "✦"; font-size: 1.35rem; }

.tile-art--snake i {
  position: absolute;
  width: 34px;
  height: 34px;
  border: 1px solid #38513e;
  border-radius: 9px;
  background: linear-gradient(135deg, #78986c, #4f7257);
  box-shadow: inset 0 2px rgba(255,255,255,.18), 0 4px 7px rgba(50,34,24,.16);
}
.tile-art--snake i:nth-child(1) { top: 78px; left: 12%; }
.tile-art--snake i:nth-child(2) { top: 78px; left: 25%; }
.tile-art--snake i:nth-child(3) { top: 78px; left: 38%; }
.tile-art--snake i:nth-child(4) { top: 78px; left: 51%; }
.tile-art--snake i:nth-child(5) { top: 112px; left: 51%; }
.tile-art--snake i:nth-child(6) { top: 146px; left: 51%; }
.tile-art--snake i:nth-child(7) { top: 146px; left: 64%; }
.tile-art--snake i:nth-child(8) {
  top: 146px;
  left: 81%;
  width: 26px;
  height: 26px;
  border-color: #a63d2f;
  border-radius: 50%;
  background: #c95a42;
  box-shadow: 0 0 0 5px rgba(201,90,66,.12);
}

.tile-type { margin: 0; color: var(--gold); font-size: 0.72rem; letter-spacing: 0.25em; }
.game-tile h2 { margin: 7px 0 10px; font-size: 2rem; font-weight: 500; letter-spacing: 0.16em; }
.game-tile > p:not(.tile-type) { min-height: 58px; margin: 0; color: var(--ink-soft); font-size: 0.84rem; line-height: 1.75; }
.tile-action { display: inline-flex; align-items: center; gap: 12px; margin-top: 20px; color: var(--red); font-size: 0.82rem; letter-spacing: 0.14em; }
.tile-action b { font-size: 1.1rem; transition: transform 160ms ease; }
.game-tile:hover .tile-action b { transform: translateX(5px); }

.hall-note {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 18px;
  margin-top: 20px;
  padding: 14px;
  color: rgba(248, 232, 198, 0.64);
  font-size: 0.78rem;
  letter-spacing: 0.09em;
  text-align: center;
}
.hall-note p { margin: 0; }
.hall-note span { color: var(--gold); }
.hall-footer { padding-top: 8px; color: rgba(248,232,198,.38); font-size: .7rem; letter-spacing: .42em; text-align: center; }

/* Shared game pages */
.site-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  color: rgba(248, 232, 198, 0.72);
  font-size: 0.76rem;
  letter-spacing: 0.11em;
}
.site-nav a { padding: 8px 10px; text-decoration: none; }
.site-nav__back { display: flex; gap: 4px; }
.site-nav a:hover,
.site-nav a[aria-current="page"] { color: var(--gold-light); }
.site-nav__games { display: flex; gap: 4px; }

.arcade-heading { margin-bottom: 22px; color: #f8e8c6; text-align: center; }
.arcade-heading h1 { margin: 0; font-size: clamp(2.2rem, 5vw, 3.6rem); font-weight: 500; letter-spacing: .2em; text-indent: .2em; }
.arcade-heading p:last-child { margin: 8px 0 0; color: rgba(248,232,198,.62); font-size: .82rem; letter-spacing: .16em; }

.arcade-card {
  overflow: hidden;
  border: 1px solid rgba(228, 189, 104, 0.58);
  border-radius: 5px;
  background:
    repeating-linear-gradient(3deg, rgba(112,68,44,.025) 0 1px, transparent 1px 9px),
    var(--paper);
  box-shadow: 0 22px 55px rgba(0,0,0,.28), inset 0 0 40px rgba(112,68,44,.06);
}

.game-toolbar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 18px;
  padding: 18px 24px;
  border-bottom: 1px solid rgba(112,68,44,.2);
  background: rgba(112,68,44,.05);
}
.toolbar-field { display: flex; align-items: center; gap: 10px; color: var(--ink-soft); font-size: .78rem; }
.toolbar-options { display: flex; align-items: center; gap: 14px; }
.toolbar-field select { padding: 8px 30px 8px 11px; border: 1px solid rgba(112,68,44,.3); border-radius: 2px; color: var(--ink); background: rgba(255,252,242,.7); }
.toolbar-field select { min-height: 44px; }
.game-stats { display: flex; }
.game-stat { min-width: 95px; padding: 0 20px; text-align: center; }
.game-stat + .game-stat { border-left: 1px solid rgba(112,68,44,.22); }
.game-stat span,
.game-stat strong { display: block; }
.game-stat span { color: var(--ink-soft); font-size: .66rem; letter-spacing: .16em; }
.game-stat strong { margin-top: 3px; color: var(--red); font: 600 1.35rem Georgia, serif; font-variant-numeric: tabular-nums; }
.toolbar-actions { display: flex; justify-content: flex-end; gap: 9px; }
.arcade-button {
  min-height: 44px;
  padding: 9px 16px;
  border: 1px solid rgba(112,68,44,.3);
  border-radius: 2px;
  color: var(--ink);
  background: rgba(255,252,242,.64);
  cursor: pointer;
}
.arcade-button--primary { color: #fff2d5; border-color: #7e3125; background: linear-gradient(135deg, #b24a37, #8c3024); box-shadow: 0 5px 12px rgba(126,49,37,.18); }
.arcade-button:hover { transform: translateY(-1px); }
.icon-button { width: 44px; padding: 0; border-radius: 50%; color: var(--red); }
.game-status { min-height: 44px; padding: 14px 14px 4px; color: var(--ink-soft); font-size: .8rem; letter-spacing: .07em; text-align: center; }
.game-status::before,
.game-status::after { margin: 0 9px; color: var(--gold); content: "—"; }

.game-help {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-top: 18px;
  padding: 18px 24px;
  border: 1px solid rgba(228,189,104,.42);
  border-radius: 4px;
  color: rgba(248,232,198,.68);
  background: rgba(244,232,207,.07);
  font-size: .76rem;
}
.game-help div { display: flex; align-items: center; justify-content: center; gap: 9px; }
.game-help b { display: grid; width: 25px; height: 25px; place-items: center; border: 1px solid rgba(228,189,104,.42); color: var(--gold-light); font-weight: 400; }

/* Minesweeper */
.mine-stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow: auto;
  padding: 20px 18px 30px;
  overscroll-behavior-inline: contain;
  -webkit-overflow-scrolling: touch;
}
.mine-board {
  --cell-size: 31px;
  display: grid;
  grid-template-columns: repeat(var(--columns), var(--cell-size));
  gap: 2px;
  width: max-content;
  padding: 8px;
  border: 1px solid #563624;
  border-radius: 3px;
  background: #8b5b39;
  box-shadow: 0 10px 24px rgba(63,36,22,.2), inset 0 2px rgba(255,255,255,.13);
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}
.mine-cell {
  position: relative;
  display: grid;
  width: var(--cell-size);
  height: var(--cell-size);
  padding: 0;
  place-items: center;
  border: 1px solid rgba(74,43,27,.38);
  border-radius: 2px;
  color: var(--ink);
  background: linear-gradient(145deg, #e7d4ad, #c5aa7e);
  box-shadow: inset 2px 2px rgba(255,255,255,.35), inset -2px -2px rgba(74,43,27,.16);
  font: 700 .9rem Georgia, serif;
  cursor: pointer;
}
.mine-cell:hover:not(.is-open) { filter: brightness(1.06); }
.mine-cell.is-open { border-color: rgba(112,68,44,.16); background: #f2e7d0; box-shadow: inset 0 0 4px rgba(112,68,44,.08); cursor: default; }
.mine-cell.is-flagged::after { color: var(--red); content: "⚑"; font-size: 1rem; }
.mine-cell.is-mine::after { color: #592f25; content: "✦"; font-size: 1rem; }
.mine-cell.is-exploded { background: #c96b55; }
.mine-cell[data-near="1"] { color: #3b6d8c; }
.mine-cell[data-near="2"] { color: #4e7758; }
.mine-cell[data-near="3"] { color: #a33d31; }
.mine-cell[data-near="4"] { color: #66558c; }
.mine-cell[data-near="5"],
.mine-cell[data-near="6"],
.mine-cell[data-near="7"],
.mine-cell[data-near="8"] { color: #6b3e2f; }
.mine-scroll-hint { display: none; margin: 12px 0 0; color: var(--ink-soft); font-size: .72rem; line-height: 1.6; text-align: center; }

/* Snake */
.snake-stage { display: grid; grid-template-columns: minmax(280px, 620px) 210px; justify-content: center; gap: 24px; padding: 18px 24px 28px; }
.snake-canvas-wrap { position: relative; width: 100%; aspect-ratio: 1; }
#snake-canvas {
  display: block;
  width: 100%;
  height: 100%;
  border: 8px solid #70442c;
  border-radius: 4px;
  background: #eadcbd;
  box-shadow: 0 12px 28px rgba(63,36,22,.22), inset 0 0 18px rgba(112,68,44,.08);
  touch-action: none;
}
.snake-overlay {
  position: absolute;
  inset: 8px;
  display: grid;
  place-items: center;
  color: #fff0d0;
  background: rgba(49,31,23,.66);
  text-align: center;
  backdrop-filter: blur(2px);
  pointer-events: none;
}
.snake-overlay[hidden] { display: none; }
.snake-overlay strong { display: block; margin-bottom: 7px; font-size: 1.5rem; letter-spacing: .18em; }
.snake-overlay span { font-size: .78rem; letter-spacing: .1em; }
.snake-side { display: flex; flex-direction: column; justify-content: space-between; gap: 18px; }
.snake-legend { padding: 18px; border: 1px solid rgba(112,68,44,.24); background: rgba(255,252,242,.4); }
.snake-legend h2 { margin: 0 0 14px; color: var(--ink-soft); font-size: .85rem; letter-spacing: .16em; }
.snake-legend p { display: flex; align-items: center; gap: 9px; margin: 9px 0; color: var(--ink-soft); font-size: .74rem; }
.legend-dot { width: 13px; height: 13px; border-radius: 4px; background: var(--green); }
.legend-dot--food { border-radius: 50%; background: #c84e3d; box-shadow: 0 0 0 3px rgba(200,78,61,.12); }
.legend-dot--wall { border-radius: 2px; background: #795038; }
.legend-dot--portal { border: 3px solid #4e7891; border-radius: 50%; background: transparent; }
.legend-dot--orb { border-radius: 50%; background: #b6893d; box-shadow: 0 0 0 3px rgba(182,137,61,.14); }
.d-pad { display: grid; grid-template-columns: repeat(3, 54px); grid-template-rows: repeat(3, 48px); justify-content: center; gap: 5px; }
.d-pad button { border: 1px solid rgba(112,68,44,.3); border-radius: 4px; color: var(--ink); background: rgba(255,252,242,.68); font-size: 1.1rem; cursor: pointer; touch-action: manipulation; }
.d-pad button:active { color: #fff0d0; background: var(--wood); }
.d-pad .up { grid-column: 2; }
.d-pad .left { grid-column: 1; grid-row: 2; }
.d-pad .pause { grid-column: 2; grid-row: 2; color: var(--red); }
.d-pad .right { grid-column: 3; grid-row: 2; }
.d-pad .down { grid-column: 2; grid-row: 3; }

.arcade-toast {
  position: fixed;
  z-index: 100;
  bottom: 24px;
  left: 50%;
  max-width: calc(100% - 30px);
  padding: 10px 17px;
  border: 1px solid rgba(228,189,104,.48);
  border-radius: 2px;
  color: #f8e8c6;
  background: rgba(49,31,23,.95);
  box-shadow: 0 9px 24px rgba(0,0,0,.3);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 12px);
  transition: opacity 160ms ease, transform 160ms ease;
}
.arcade-toast.is-visible { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 880px) {
  .game-grid { grid-template-columns: 1fr; }
  .game-tile { display: grid; grid-template-columns: 240px 1fr; column-gap: 25px; min-height: 280px; align-content: center; }
  .tile-art { grid-row: 1 / span 5; height: 220px; margin: 0; }
  .tile-type { align-self: end; }
  .game-tile > p:not(.tile-type) { min-height: 0; }
  .game-toolbar { grid-template-columns: 1fr auto; }
  .game-stats { grid-column: 1 / -1; grid-row: 2; justify-content: center; }
  .snake-stage { grid-template-columns: minmax(280px, 580px); }
  .snake-side { flex-direction: row; align-items: center; }
  .snake-legend { flex: 1; }
}

@media (max-width: 600px) {
  .hall-shell,
  .arcade-shell { width: min(100% - 18px, 1160px); padding-top: max(18px, env(safe-area-inset-top)); }
  .site-bridge { align-items: flex-start; flex-direction: column; gap: 2px; margin-bottom: 14px; }
  .site-bridge span { padding: 0 10px; }
  .hall-hero { margin-bottom: 22px; }
  .hall-hero h1 { font-size: 2.35rem; }
  .hall-intro { font-size: .8rem; }
  .game-tile { display: block; min-height: 0; padding: 24px 22px; }
  .tile-art { height: 190px; margin: 10px 0 18px; }
  .tile-art--mine { grid-template-columns: repeat(3, 45px); grid-template-rows: repeat(3, 45px); }
  .game-tile h2 { font-size: 1.7rem; }
  .hall-note { align-items: flex-start; line-height: 1.7; }
  .site-nav { display: grid; grid-template-columns: 1fr; align-items: flex-start; gap: 2px; margin-bottom: 18px; }
  .site-nav__back,
  .site-nav__games { flex-wrap: wrap; justify-content: flex-start; }
  .site-nav a { padding: 8px 9px; }
  .arcade-heading { margin-bottom: 16px; }
  .game-toolbar { gap: 14px; padding: 16px 13px; }
  .toolbar-field { align-items: flex-start; flex-direction: column; gap: 5px; }
  .toolbar-options { align-items: flex-start; flex-direction: column; gap: 9px; }
  .toolbar-actions { align-items: flex-end; flex-direction: column-reverse; }
  .toolbar-actions .arcade-button--primary { width: 100%; }
  .game-stat { min-width: 0; flex: 1; padding: 0 10px; }
  .game-status { line-height: 1.6; }
  .mine-stage { align-items: flex-start; padding: 16px 8px 24px; }
  .mine-board { --cell-size: 32px; margin: 0 auto; }
  .mine-scroll-hint { display: block; align-self: center; }
  .game-help { grid-template-columns: 1fr; gap: 10px; }
  .game-help div { justify-content: flex-start; }
  .snake-stage { gap: 18px; padding: 14px 10px 22px; }
  .snake-side { flex-direction: column; }
  .snake-legend { width: 100%; }
}

@media (max-width: 380px) {
  .mine-board { --cell-size: 30px; }
}

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