:root {
  color-scheme: light;
  --page: #f6f4f0;
  --paper: #fffdf9;
  --ink: #242122;
  --muted: #615b5a;
  --line: #ded8d2;
  --gold: #e8bc63;
  --board-size: clamp(17rem, calc(100svh - 15rem), 30rem);
  font: 16px/1.45 system-ui, sans-serif;
  color: var(--ink);
  background: var(--page);
}
*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; min-height: 100svh; }
[hidden] { display: none !important; }
button, a, input, select, textarea { -webkit-tap-highlight-color: transparent; }
button, a { touch-action: manipulation; }
button, select, input, textarea { color: inherit; font: inherit; }
button {
  min-height: 43px; padding: 7px 13px; border: 1px solid var(--line); border-radius: 13px;
  background: var(--paper); cursor: pointer; font-size: .9rem; line-height: 1.12; font-weight: 730;
}
button:disabled { color: #827c79; background: transparent; cursor: default; }
:focus-visible { outline: 3px solid #9b641d; outline-offset: 3px; }
@media (hover: hover) {
  button:hover:not(:disabled) { background: #ede8df; border-color: #c8bbb0; }
}
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.site-header { background: var(--paper); border-bottom: 1px solid var(--line); padding-inline: max(12px, env(safe-area-inset-left), env(safe-area-inset-right)); }
.site-row { width: min(100%, 62rem); min-height: 64px; margin-inline: auto; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px; }
.brand { display: inline-flex; width: fit-content; align-items: center; gap: 8px; color: var(--ink); text-decoration: none; font-size: 1.35rem; font-weight: 880; letter-spacing: -.065em; }
.brand img { flex: 0 0 auto; width: 28px; height: 28px; }
.main-nav, .utilities { display: flex; align-items: center; gap: 3px; }
.utilities { justify-content: end; }
.main-nav button, .icon-button, .join-button { border-color: transparent; background: transparent; color: var(--muted); }
.main-nav button[aria-current="page"] { background: #eae3da; color: var(--ink); }
.main-nav #create { margin-inline-start: 3px; color: #fff9f0; background: #302829; border-color: #302829; }
.main-nav #create[aria-current="page"] { background: #603e36; border-color: #603e36; }
.join-button { color: var(--ink); }
.icon-button { width: 39px; min-height: 39px; padding: 0; display: grid; place-items: center; }
.icon-button svg { width: 19px; height: 19px; }

main { padding: 19px max(12px, env(safe-area-inset-left), env(safe-area-inset-right)) max(19px, env(safe-area-inset-bottom)); }
.game-layout, .builder-layout { margin-inline: auto; width: min(100%, var(--board-size)); }
.game-layout { display: grid; grid-template-areas: "intro" "sizes" "hud" "board" "footer" "extras"; }
.game-intro { grid-area: intro; text-align: center; margin-bottom: 12px; }
.eyebrow { margin: 0 0 3px; color: var(--muted); font-size: .86rem; font-weight: 720; }
.eyebrow:empty { display: none; }
h1 { margin: 0; font-size: clamp(2.2rem, 5vw, 3.25rem); line-height: 1; font-weight: 880; letter-spacing: -.065em; text-wrap: balance; }
.rival { margin: 7px 0 0; color: #704e31; font-size: .88rem; font-weight: 700; }
.size-tabs { grid-area: sizes; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 3px; padding: 4px; border: 1px solid #ded5c9; background: #eee7dd; border-radius: 15px; margin-bottom: 9px; }
.size-tabs button { position: relative; min-height: 39px; padding: 5px; background: transparent; border: 1px solid transparent; border-radius: 11px; color: #5f5750; font-weight: 800; font-variant-numeric: tabular-nums; }
.size-tabs button[aria-pressed="true"] { background: #302829; color: #fff8ef; border-color: #302829; }
.size-tabs .has-result::after { content: ""; position: absolute; width: 5px; height: 5px; border-radius: 50%; top: 6px; right: 7px; background: #56834c; }
.size-tabs button[aria-pressed="true"].has-result::after { background: #a6d58f; }
.hud { grid-area: hud; display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; padding: 2px 0 8px; }
.hud span { display: grid; justify-items: center; align-content: center; gap: 4px; padding: 4px; border-left: 1px solid var(--line); color: var(--muted); font-size: .82rem; font-weight: 650; line-height: 1.06; }
.hud span:first-child { border-left: 0; }
.hud strong { color: var(--ink); font-weight: 880; font-size: 1.19rem; font-variant-numeric: tabular-nums; }
.hud .all-lit strong { color: #7a4d0c; }
.hud .low strong { color: #a13c30; }

.board-frame {
  grid-area: board; width: 100%; position: relative; isolation: isolate; overflow: hidden; align-self: start;
  padding: 9px; border: 1px solid #54484a; border-radius: 22px; background: #211b1e;
  box-shadow: 0 11px 22px #3f2b2820, inset 0 1px #ffffff14;
}
.board-frame.won { border-color: #9f814e; box-shadow: 0 0 0 3px #e8bc6355, 0 11px 22px #3f2b2820; }
.board { display: grid; grid-template-columns: repeat(var(--size, 5), minmax(0, 1fr)); gap: 4px; container-type: inline-size; }
.tile {
  --tile: #342c30;
  position: relative; min-width: 0; min-height: 0; aspect-ratio: 1; padding: 0; border: 0;
  display: grid; place-items: center; place-content: center;
  color: #bfb3b5; background: var(--tile); border-radius: clamp(6px, 2.4cqw, 11px);
}
.tile[aria-disabled="true"] { cursor: default; }
.tile-icon { display: grid; place-items: center; z-index: 2; }
.tile-icon svg { display: block; width: calc(64cqw / var(--size, 5)); height: auto; }
.tile.start { --tile: #40363a; color: #bfaeb0; }
.tile.wall { --tile: repeating-linear-gradient(135deg, #494244 0 5px, #413a3d 5px 9px); color: #c1b7b7; }
.tile.light { --tile: #29262b; color: #b1a8b3; box-shadow: inset 0 0 0 1px #514b54; }
.tile.light:not(.on) .tile-icon svg { width: calc(52cqw / var(--size, 5)); }
.tile.light.on {
  --tile: #9c682e; color: #fff7ca;
  box-shadow: inset 0 0 0 2px #f1cc79, 0 0 10px #db964c5c;
}
.tile.light.on .tile-icon svg { width: calc(75cqw / var(--size, 5)); filter: drop-shadow(0 0 5px #fff3a658); }
.tile.exit { --tile: #334037; color: #b7d5b1; }
.tile.exit.ready { --tile: #496446; color: #d7f0c6; box-shadow: inset 0 0 0 2px #a2c791; }
.tile.spring { --tile: #532e3a; color: #f0b5c7; }
.tile.portal { --tile: #47334f; color: #e3bbf1; }
.tile.valid:not(.special) { --tile: #473c41; }
.tile.valid::after { content: ""; position: absolute; width: 14%; min-width: 5px; max-width: 9px; aspect-ratio: 1; z-index: 2; border-radius: 50%; background: #eee4dc; }
.tile.valid.special::after { width: 12%; max-width: 7px; top: 9%; right: 10%; }
.board .tile.current:not(.in-flight) { --tile: #e7ba6a; color: #322214; box-shadow: inset 0 0 0 2px #f5d89d; }
.tile.current[data-under]::after { content: attr(data-under); color: inherit; background: none; position: absolute; top: 7%; right: 10%; width: auto; height: auto; font-size: clamp(.6rem, 2.2cqw, .9rem); font-weight: 850; line-height: 1; }
.tile.in-flight .tile-icon, .tile.in-flight::after { visibility: hidden; }
.tile.suggested { outline: 2px dashed #f7cd78; outline-offset: -4px; }
.tile.will-light { outline: 2px dashed #f8de91; outline-offset: -4px; }
.tile.will-dim { outline: 2px dashed #dfb5d7; outline-offset: -4px; }
.tile:focus-visible { outline: 2px solid #f8d58d; outline-offset: -2px; z-index: 4; }
.tile.blocked { opacity: .43; }
.tile.selected-tile { outline: 2px solid #e4bef1; outline-offset: -3px; }
@media (hover: hover) {
  .board .tile:hover:not(:disabled) { background: var(--tile); }
  .board .tile.valid:hover, .board .tile.paintable:not(.blocked):hover { box-shadow: inset 0 0 0 2px #bf9c7f; }
  .main-nav #create:hover:not(:disabled) { background: #553830; border-color: #553830; }
  .size-tabs button[aria-pressed="true"]:hover:not(:disabled) { background: #302829; border-color: #302829; }
}
.trail, .effects { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.trail { z-index: 1; }
.trail line { stroke: #e9cbacd0; stroke-width: .6; stroke-dasharray: 1.1 1.2; stroke-linecap: round; }
.trail .warp-preview { stroke: #dab5ec; stroke-dasharray: .45 1.4; }
.effects { z-index: 5; }
.effects .piece, .effects .ring, .effects .spark { position: absolute; translate: -50% -50%; }
.effects .piece { display: grid; place-items: center; aspect-ratio: 1; color: #322214; background: #e7ba6a; border: 2px solid #f5d89d; border-radius: 30%; }
.effects .piece svg { width: 82%; height: 82%; }
.effects .ring { aspect-ratio: 1; border: 3px solid #dcacee; border-radius: 50%; }
.effects .spark { width: 5px; aspect-ratio: 1; border-radius: 2px; background: var(--spark, #ffe78b); }

.game-footer { grid-area: footer; min-width: 0; }
.status { margin: 8px 0 4px; color: var(--muted); font-size: .9rem; }
.status:empty, .dialog-status:empty { display: none; }
.status.success { color: #4c583c; font-weight: 760; }
.actions, .extras { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.game-footer .actions { margin-top: 8px; }
.actions button { display: inline-flex; align-items: center; justify-content: center; gap: 5px; }
.controls .primary { order: -1; }
.actions svg { width: 16px; height: 16px; }
.primary { color: #302313; background: #ebc471; border-color: #d8aa51; font-weight: 840; }
@media (hover: hover) { button.primary:hover:not(:disabled) { background: #f2d088; border-color: #c79842; } }
.extras { grid-area: extras; margin-top: 4px; gap: 8px 15px; }
.text-button { min-height: 38px; padding-inline: 0; border-color: transparent; color: #664a38; background: transparent; }
@media (hover: hover) { .text-button:hover:not(:disabled) { border-color: transparent; background: transparent; text-decoration: underline; } }

.builder-layout { --board-size: 30rem; }
.builder-tools { margin-bottom: 9px; }
.palette { display: flex; flex-wrap: wrap; gap: 5px; }
.palette button { min-height: 38px; display: inline-flex; align-items: center; gap: 4px; padding-inline: 9px; }
.palette button[aria-pressed="true"] { color: #533815; border-color: #bd9252; background: #f3e0bb; }
.palette svg { width: 16px; height: 16px; }
.editor-frame { grid-area: auto; }
.builder-actions .status { margin-bottom: 8px; }

select, input, textarea { min-height: 43px; border: 1px solid #c9bcb2; border-radius: 11px; background: var(--paper); padding: 7px 10px; }
dialog {
  max-width: min(27rem, calc(100% - 22px)); width: 100%; max-height: calc(100svh - 24px); margin: auto; overflow: auto;
  padding: 15px 17px 17px; border: 1px solid #d1c2b5; border-radius: 20px;
  color: var(--ink); background: var(--paper); box-shadow: 0 16px 60px #2c211b51;
}
dialog::backdrop { background: #241d20a8; }
.dialog-top { display: flex; justify-content: space-between; align-items: center; gap: 9px; margin-bottom: 3px; }
.dialog-top form { margin: 0 -4px 0 0; }
.dialog-top h2 { margin: 0; font-size: 1.3rem; letter-spacing: -.04em; line-height: 1.17; }
.dialog-content { display: grid; gap: 10px; }
.dialog-content p { color: var(--muted); margin: 0; }
.dialog-content textarea, .dialog-status input { width: 100%; resize: vertical; font-size: .88rem; }
.menu-list { display: grid; gap: 6px; }
.menu-list button { display: flex; align-items: center; justify-content: space-between; gap: 8px; width: 100%; text-align: start; }
.menu-list small { flex: 0 0 auto; color: var(--muted); font-size: .8rem; font-weight: 560; }
.menu-list .selected { background: #eee3d5; border-color: #c4a98b; }
.dialog-content canvas { width: 100%; height: auto; border-radius: 13px; }
.solution-frame { grid-area: auto; width: min(100%, 22rem); margin-inline: auto; }
.dialog-content .solution-status { text-align: center; }
.guide { display: grid; gap: 8px; margin: 0; padding: 0; list-style: none; }
.guide li { display: grid; grid-template-columns: 31px 1fr; align-items: center; gap: 8px; color: var(--muted); }
.guide .key { display: grid; place-items: center; width: 31px; height: 31px; border-radius: 8px; color: #fbebdc; background: #493c42; }
.guide .key svg { width: 20px; height: 20px; }
.guide .key.player { background: #e7ba6a; color: #322214; }
.guide .key.exit { background: #496446; color: #d7f0c6; }
.guide .key.light { background: #9c682e; color: #fff7ca; }
.join-form { display: flex; gap: 7px; flex-wrap: wrap; }
.code-input { flex: 1; min-width: 9rem; font: 780 1.05rem/1.2 ui-monospace, monospace; }
.code-share { text-align: center; padding: 15px 7px; background: #eee7dd; border: 1px solid #ded0bd; border-radius: 14px; }
.code-value { color: #392815; user-select: all; font: 850 clamp(1.7rem, 8vw, 2.6rem)/1.2 ui-monospace, monospace; letter-spacing: .14em; }

@media (max-width: 600px) {
  main { padding-top: 13px; }
  .site-row { grid-template-columns: minmax(0, 1fr) auto; gap: 0; min-height: 0; }
  .brand { min-height: 45px; gap: 5px; font-size: 1.22rem; }
  .brand img { width: 25px; height: 25px; }
  .utilities { grid-row: 1; grid-column: 2; gap: 0; }
  .utilities .icon-button { width: 34px; min-height: 36px; }
  .join-button { padding-inline: 8px; min-height: 36px; }
  .main-nav { grid-row: 2; grid-column: 1/-1; justify-content: space-between; padding-bottom: 6px; }
  .main-nav button { padding-inline: 10px; min-height: 36px; }
  .main-nav #create { margin: 0; }
  .game-intro { margin-bottom: 10px; }
  .board-frame { padding: 7px; border-radius: 18px; }
  .board { gap: 3px; }
  .palette button { padding-inline: 6px; font-size: .82rem; }
}
@media (max-height: 680px) and (min-width: 690px) {
  .game-layout {
    --board-size: min(49vw, 28rem, max(13rem, calc(100svh - 90px)));
    width: min(100%, calc(17rem + 23px + var(--board-size)));
    grid-template-columns: minmax(0, 1fr) var(--board-size);
    grid-template-rows: auto auto auto auto 1fr;
    grid-template-areas: "intro board" "sizes board" "hud board" "footer board" "extras board";
    column-gap: 23px;
  }
  .game-intro { text-align: start; }
}
@media (forced-colors: active) {
  .tile.valid { outline: 1px solid LinkText; outline-offset: -2px; }
  .tile.valid::after { background: ButtonText; forced-color-adjust: none; }
  .tile.current, .tile.light.on { outline: 3px solid Highlight; outline-offset: -3px; }
}

.archive-layout { width: min(100%, 31rem); margin-inline: auto; }
.archive-toolbar { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin: 17px 0 12px; }
.archive-toolbar label, .archive-calendar-field { display: grid; gap: 4px; font-size: .87rem; font-weight: 730; color: var(--muted); }
.archive-toolbar select, .archive-toolbar button { width: 100%; min-width: 0; }
.archive-calendar-field button { color: var(--ink); text-align: start; }
.archive-puzzles { padding: 0; margin: 0; list-style: none; display: grid; gap: 4px; }
.archive-puzzles button {
  width: 100%; min-height: 48px; display: grid; grid-template-columns: auto 1fr auto; align-items: center;
  gap: 10px; text-align: start; padding-inline: 13px;
}
.archive-puzzles small { color: var(--muted); font-size: .84rem; white-space: nowrap; }
.archive-puzzles .archive-solved small { color: #485e37; }

.archive-number { color: #795c3e; font-size: .82rem; font-variant-numeric: tabular-nums; }
.calendar-nav { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 5px; text-align: center; }
.calendar-nav strong { font-size: .95rem; }
.calendar-nav button { min-height: 39px; padding: 6px 9px; }
.calendar-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 3px; text-align: center; }
.calendar-grid span { color: var(--muted); font-size: .79rem; padding-block: 3px; }
.calendar-grid button { min-height: 39px; padding: 3px; border-radius: 9px; }
.calendar-grid button.selected { color: #362718; background: #efcf8e; border-color: #d6ad66; }
.calendar-grid button:disabled { border-color: transparent; opacity: .65; }
