:root {
  color-scheme: light;
  --paper: #faf4ec;
  --ink: #26152a;
  --violet: #482d6a;
  --outline: #643e8d;
  --panel: #e4d9fa;
  --lit: #ffcf77;
  --quiet: #665174;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--paper);
  color: var(--ink);
}
* { box-sizing: border-box; }
body { margin: 0; }
button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { cursor: default; }
button:focus-visible { outline: 3px solid #8c42c0; outline-offset: 3px; }
[hidden] { display: none !important; }
.site { width: min(calc(100% - 7.3vw), 1424px); margin: auto; }
.masthead {
  min-height: 81px; border-bottom: 2px solid var(--ink); padding: 0 20px;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
}
.brand { display: flex; align-items: center; gap: 22px; font-weight: 850; font-size: clamp(24px, 2.3vw, 36px); white-space: nowrap; }
.brand svg { color: var(--outline); flex: none; }
.cadence { font-size: clamp(12px, 1.6vw, 23px); font-weight: 650; }
.header-actions { display: flex; align-items: center; gap: 18px; }
#history { display: inline-flex; align-items: center; gap: 7px; flex: none; min-height: 44px; padding: 6px 12px; border: 1px solid var(--outline); border-radius: 10px; background: var(--paper); font-weight: 700; font-size: 16px; }
#history:hover { background: var(--panel); }
#archive { width: min(480px, calc(100% - 28px)); box-shadow: 0 20px 70px #26152a33; }
#archive-list { display: grid; gap: 10px; max-height: 45dvh; overflow-y: auto; overscroll-behavior: contain; padding: 4px; margin: -4px -4px 16px; }
#archive-list button { display: flex; align-items: center; gap: 10px; text-align: left; font-size: 16px; padding: 14px 16px; border-width: 1px; border-color: #643e8d55; border-radius: 12px; }
#archive-list button[aria-current="true"] { background: var(--panel); border-color: var(--outline); }
.archive-copy { display: grid; gap: 5px; flex: 1; min-width: 0; }
.archive-copy time { font-size: 12px; font-weight: 500; letter-spacing: .04em; color: var(--quiet); }
.archive-copy strong { font-size: 20px; line-height: 1.3; }
.archive-badge { flex: none; font-size: 12px; font-weight: 600; color: var(--violet); background: #faf4ecbb; padding: 4px 7px; border-radius: 6px; }
.archive-arrow { font-size: 24px; color: var(--quiet); }
#archive .archive-note { font-size: 14px; color: var(--quiet); }
#archive .archive-footnote { font-size: 12px; color: var(--quiet); margin-bottom: 14px; }
#archive .hint-actions { justify-content: flex-end; }
#archive-status:empty { display: none; }
@media (max-width: 830px) { .header-actions .cadence { display: none; } }
.layout {
  display: grid; grid-template-columns: minmax(0, 0.94fr) minmax(0, 1fr);
  grid-template-areas: "intro play" "extras play"; grid-template-rows: auto 1fr;
  align-items: start; column-gap: clamp(26px, 2.5vw, 38px);
  padding: clamp(34px, 4.15vw, 64px) clamp(12px, 2.2vw, 34px) clamp(35px, 3.2vw, 49px);
}
.intro { grid-area: intro; }
time { display: block; font-size: clamp(18px, 1.7vw, 26px); font-weight: 650; }
h1 {
  margin: 15px 0 21px; color: #1c101d; font-weight: 950; letter-spacing: -.047em;
  font-size: clamp(52px, 8.15vw, 123px); line-height: 1.08;
}
h1[data-long] { font-size: clamp(43px, 6.3vw, 95px); }
.intro p { max-width: 30em; margin: 0 0 28px; font-size: clamp(17px, 2vw, 29px); font-weight: 570; line-height: 1.55; }
.extras { grid-area: extras; }
.art {
  display: block; width: 100%; height: auto; aspect-ratio: 1.79; object-fit: cover; object-position: 73% 60%; border-radius: 16px;
}
.actions { display: flex; flex-wrap: wrap; gap: clamp(8px, 1.6vw, 24px); margin-top: 26px; }
.actions button#hint { padding-inline: .85em; }
.hint-text { margin: 12px 0 0; border-left: 3px solid var(--outline); padding: 7px 12px; color: var(--ink); background: var(--panel); font-size: clamp(15px, 1.4vw, 20px); line-height: 1.55; }
.actions button, dialog button, .directions button {
  border: 2px solid var(--ink); border-radius: 10px; background: var(--paper); padding: .55em 1.5em;
  font-size: clamp(17px, 1.75vw, 26px); font-weight: 700; min-height: 44px;
}
.actions button:hover, dialog button:hover, .directions button:hover { background: #f1e7ff; }
.play {
  grid-area: play; width: 100%; border-radius: 24px; border: 1.5px solid var(--outline); background: var(--panel);
  padding: clamp(22px, 3vw, 42px) clamp(20px, 3.8vw, 58px) clamp(20px, 2.3vw, 34px);
}
.stats { display: grid; grid-template-columns: 1fr 1fr; margin-bottom: clamp(19px, 2.65vw, 41px); }
.stats div {
  display: flex; justify-content: center; align-items: baseline; gap: clamp(7px, 1.3vw, 20px);
  font-size: clamp(15px, 2vw, 29px); font-weight: 750; white-space: nowrap;
}
.stats div + div { border-left: 1px solid #967db0; }
.stats strong { font: 750 clamp(24px, 3.5vw, 51px)/1 Georgia, serif; font-variant-numeric: tabular-nums; }
.board {
  display: grid; grid-template-columns: repeat(var(--columns, 5), minmax(0, 1fr));
  gap: clamp(4px, .57vw, 9px); margin-inline: auto; width: 100%;
}
.tile {
  display: grid; place-items: center; aspect-ratio: 1; border: 0; padding: 0; min-width: 0;
  border-radius: clamp(5px, 1vw, 15px); background: var(--violet); color: #f2eaff;
  font-size: clamp(14px, var(--tile-font, 3vw), 44px); font-weight: 780; touch-action: manipulation;
  transition: background-color 140ms, color 140ms, transform 140ms;
}
.tile:not(:disabled):active { transform: scale(.95); }
.tile:not(:disabled):hover { box-shadow: inset 0 0 0 2px #fff8; }
.tile.is-lit { background: var(--lit); color: #341b2c; }
.tile.is-soft { background: #faf1fc; color: #4b2e68; }
.tile.is-empty { background: #c9b6e5; color: #4d3564; }
.tile.is-marked { background: #94525f; color: #fff5e5; }
.tile.is-wall { background: #30213d; color: #f2eaff; }
.tile.is-selected { box-shadow: inset 0 0 0 3px #fda; }
.tile.is-clue { background: transparent; color: var(--ink); font-size: clamp(12px, 1.5vw, 21px); line-height: 1.05; white-space: pre-line; }
.tile.is-region { border-bottom: 3px solid #a37ec8; }
.tile .dot { display: block; width: 14%; aspect-ratio: 1; border-radius: 50%; background: currentColor; }
.directions { display: flex; gap: 7px; justify-content: center; flex-wrap: wrap; margin-top: 14px; }
.directions button { padding: .25em .65em; min-width: 44px; font-size: 16px; }
.directions button[aria-pressed="true"] { background: var(--lit); }
.status { min-height: 1.5em; text-align: center; margin: clamp(15px, 2vw, 29px) 0 0; font-size: clamp(16px, 1.7vw, 25px); font-weight: 650; line-height: 1.45; }
.status.win { color: #3e285f; font-weight: 850; }
footer { border-top: 2px solid var(--ink); text-align: center; padding: 11px 0 15px; font-size: clamp(15px, 1.5vw, 22px); font-weight: 650; }
dialog { width: min(460px, calc(100% - 34px)); padding: 25px; border: 2px solid var(--outline); border-radius: 17px; background: var(--paper); color: var(--ink); }
dialog::backdrop { background: #23132e78; }
dialog h2 { margin: 0 0 10px; }
dialog p { font-size: 17px; line-height: 1.7; margin: 0 0 18px; }
@media (max-width: 830px) {
  .site { width: min(calc(100% - 30px), 600px); }
  .masthead { min-height: 60px; padding: 0 2px; }
  .brand { font-size: 21px; gap: 8px; }
  .brand svg { width: 25px; height: 25px; }
  .cadence { font-size: 12px; text-align: right; }
  .layout { grid-template-columns: 1fr; grid-template-areas: "intro" "play" "extras"; grid-template-rows: auto; gap: 19px; padding: 24px 0 29px; }
  h1, h1[data-long] { margin: 8px 0 10px; font-size: clamp(42px, 12vw, 66px); }
  .intro p { margin: 0; }
  .play { padding: 18px 16px 15px; border-radius: 17px; }
  .stats { margin-bottom: 15px; }
  .stats div { gap: 8px; }
  .tile { font-size: clamp(15px, var(--mobile-tile-font, 6vw), 36px); }
  .tile.is-clue { font-size: clamp(11px, 3vw, 16px); }
  .extras { display: flex; flex-direction: column; gap: 15px; }
  .actions { order: -1; margin: 0; }
  .actions button { padding-inline: .85em; }
  .hint-text { order: -1; margin: 0; }
  .art { aspect-ratio: 2.3; border-radius: 11px; }
}
@media (prefers-reduced-motion: reduce) { .tile { transition: none; } }
.board[data-game="merge"] { touch-action: none; }
.board[data-game="merge"] .tile { touch-action: none; }
.board[data-game="code"] .tile { aspect-ratio: 1.8; }
.board[data-game="sudoku"] .tile:nth-child(6n + 3) { border-right: 3px solid #a37ec8; }
.board[data-game="echo"] { max-width: 460px; }
.board[data-game="merge"] .tile { pointer-events: none; }
@media (min-width: 831px) {
  .intro h1:not([data-long]) { font-size: clamp(52px, 8.6vw, 132px); margin-bottom: 12px; }
  .intro p { white-space: pre-line; }
  .play:has([data-game="lights"]) { padding-bottom: clamp(20px, 1.85vw, 28px); }
  .play:has([data-game="lights"]) .stats { margin-bottom: clamp(19px, 2.45vw, 38px); }
  .board[data-game="lights"] .tile { aspect-ratio: 1.035; }
  .actions button { min-width: clamp(105px, 11.8vw, 182px); padding-block: .44em; }
}
.board[data-game="reversi"] .tile.is-wall { background: #b8a3d5; color: #28183a; }
.board[data-game="reversi"] .tile.is-lit { color: #fff6e8; }

/* Keep the game and its controls inside the visible browser viewport. */
html, body { height: 100%; overflow: hidden; overscroll-behavior: none; }
.site { height: 100vh; height: 100dvh; display: flex; flex-direction: column; }
.masthead { flex: none; min-height: clamp(48px, 9dvh, 81px); }
.layout { flex: 1; min-height: 0; grid-template-rows: auto minmax(0, 1fr); padding-block: clamp(12px, 3dvh, 32px); }
.intro h1, .intro h1:not([data-long]) { font-size: clamp(36px, min(7vw, 10dvh), 110px); margin: 10px 0; }
.intro p { font-size: clamp(16px, min(2vw, 3dvh), 25px); margin-bottom: 16px; }
.extras { min-height: 0; height: 100%; display: flex; flex-direction: column; }
.art { min-height: 0; flex: 1; object-fit: cover; }
.actions { flex: none; gap: 10px; margin-top: 16px; }
.actions button { min-width: 0; font-size: clamp(16px, 1.5vw, 22px); }
.play { height: 100%; min-height: 0; display: flex; flex-direction: column; padding: clamp(12px, 2dvh, 26px) clamp(12px, 2vw, 30px); }
.stats, .play:has([data-game="lights"]) .stats { flex: none; margin-bottom: 12px; }
.stats div { font-size: clamp(14px, 1.6vw, 22px); }
.stats strong { font-size: clamp(23px, 4dvh, 38px); }
.board-space { flex: 1; min-height: 0; container-type: size; display: grid; place-items: center; }
#action-game { display: block; width: min(100cqw, calc(100cqh * .75)); height: auto; aspect-ratio: 3 / 4; max-height: 100%; border: 1px solid #967db0; border-radius: 12px; background: #201730; touch-action: none; user-select: none; }
#action-game:focus-visible { outline: 2px solid var(--lit); outline-offset: -3px; }
.is-action .directions button:first-child { background: var(--violet); color: var(--paper); min-width: 96px; }
.is-action .status { font-size: 14px; }
.board {
  --cell-aspect: 1;
  width: min(100cqw, calc(100cqh * var(--columns, 5) * var(--cell-aspect) / var(--rows, 5)));
  aspect-ratio: calc(var(--columns, 5) * var(--cell-aspect)) / var(--rows, 5);
  grid-template-rows: repeat(var(--rows, 5), minmax(0, 1fr));
  container-type: inline-size;
  gap: clamp(2px, .5vw, 7px);
  touch-action: pinch-zoom;
  user-select: none;
}
.board[data-game="code"] { --cell-aspect: 1.8; }
.board .tile { aspect-ratio: auto; min-height: 0; font-size: clamp(10px, calc(60cqw / var(--columns, 5)), 36px); touch-action: pinch-zoom; }
.board .tile.is-clue { font-size: clamp(9px, calc(35cqw / var(--columns, 5)), 18px); }
.directions { flex: none; margin-top: 10px; }
.status { flex: none; margin-top: 10px; font-size: clamp(14px, 1.4vw, 20px); }
footer { flex: none; padding-block: 8px; font-size: 15px; }
dialog { max-height: calc(100dvh - 32px); overflow-y: auto; overscroll-behavior: contain; }
.hint-text { margin: 0 0 18px; }
.hint-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.hint-actions button { font-size: 17px; padding-inline: 1em; }
@media (max-width: 830px) {
  .site { padding-top: env(safe-area-inset-top); padding-bottom: env(safe-area-inset-bottom); }
  .layout { grid-template-rows: auto minmax(0, 1fr) auto; gap: 12px; padding-block: 12px; }
  .intro time { font-size: 14px; }
  .intro h1, .intro h1:not([data-long]) { font-size: clamp(28px, 5dvh, 42px); margin: 5px 0; }
  .intro p { font-size: 15px; line-height: 1.4; margin: 0; }
  .extras { height: auto; }
  .art, footer { display: none; }
  .actions { margin: 0; display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
  .actions button, .actions button#hint { padding-inline: 4px; font-size: 16px; }
  .stats { margin-bottom: 10px; }
  .status { font-size: 14px; }
}
@media (max-height: 650px) and (max-width: 599px) {
  .masthead { min-height: 44px; }
  .brand { font-size: 19px; }
  .cadence { font-size: 10px; }
  .layout { gap: 8px; padding-block: 8px; }
  .intro time { font-size: 12px; }
  .intro h1, .intro h1:not([data-long]) { font-size: 26px; margin: 3px 0; }
  .intro p { font-size: 14px; }
  .play { padding: 10px; }
  .stats, .play:has([data-game="lights"]) .stats { margin-bottom: 6px; }
  .directions { gap: 4px; margin-top: 6px; }
  .directions button { min-width: 36px; min-height: 36px; }
  .status { margin-top: 6px; }
}
@media (max-height: 500px) and (min-width: 600px) {
  .site { width: calc(100% - 30px); }
  .masthead { min-height: 40px; }
  .brand { font-size: 21px; }
  .brand svg { width: 25px; height: 25px; }
  .cadence { font-size: 12px; }
  .layout { grid-template-columns: minmax(0, .85fr) minmax(0, 1fr); grid-template-areas: "intro play" "extras play"; grid-template-rows: auto minmax(0, 1fr); gap: 10px 20px; padding: 10px 0; }
  .intro time { font-size: 14px; }
  .intro h1, .intro h1:not([data-long]) { font-size: 28px; margin: 5px 0; }
  .intro p { font-size: 14px; margin: 0; }
  .art, footer { display: none; }
  .actions { margin: 0; gap: 6px; }
  .actions button, .actions button#hint { font-size: 14px; padding-inline: 6px; }
  .play { padding: 10px; }
  .stats, .play:has([data-game="lights"]) .stats { margin-bottom: 6px; }
  .stats strong { font-size: 23px; }
  .directions { margin-top: 6px; gap: 4px; }
  .status { margin-top: 6px; font-size: 13px; }
  .play.is-action { display: grid; grid-template-columns: minmax(0, 1fr) 90px; grid-template-rows: auto 1fr auto; gap: 8px; }
  .is-action .board-space { grid-column: 1; grid-row: 1 / 4; height: 100%; }
  .is-action .stats { grid-column: 2; display: flex; flex-direction: column; gap: 10px; margin: 0; }
  .is-action .stats div { flex-direction: column; align-items: center; gap: 2px; border: 0; }
  .is-action .directions { grid-column: 2; align-self: center; margin: 0; }
  .is-action .directions button, .is-action .directions button:first-child { width: 100%; min-width: 0; font-size: 14px; }
  .is-action .status { grid-column: 2; font-size: 12px; margin: 0; }
}
