* {
  box-sizing: border-box;
}

:root {
  --ink: #1f1b17;
  --ink-soft: #4b4036;
  --parchment: #f6f1e5;
  --parchment-dark: #e4d6c0;
  --accent: #111111;
  --color-green: #2ecc71;
  --color-red: #e74c3c;
  --bg-1: #fff9ef;
  --bg-2: #f1e6d3;
  --bg-3: #dfd1bb;
  --page-bg:
    radial-gradient(circle at 12% 18%, rgba(255, 255, 255, 0.7), rgba(255, 255, 255, 0) 58%),
    radial-gradient(circle at 88% 12%, rgba(255, 255, 255, 0.35), rgba(255, 255, 255, 0) 55%),
    linear-gradient(140deg, var(--bg-1), var(--bg-2) 52%, var(--bg-3) 100%);
  --cell-size: clamp(40px, 12vw, 92px);
  --grid-gap: 8px;
  --radius: 18px;
}

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background-color: var(--bg-1);
  background-image: var(--page-bg);
}

body {
  font-family: "Alegreya", "Garamond", "Georgia", serif;
  color: var(--ink);
  min-height: 100vh;
  min-height: 100svh;
  min-height: 100dvh;
  background-attachment: fixed;
}

.page {
  width: min(1080px, 100%);
  margin: 0 auto;
  padding: 42px 20px 64px;
  display: flex;
  flex-direction: column;
  gap: 40px;
}

.top-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.top-nav .nav-left,
.top-nav .nav-right {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
}

.top-nav .nav-center {
  display: flex;
  justify-content: center;
  flex: 1;
}

.top-nav .top-link {
  width: 100%;
  justify-content: center;
}

.top-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  font: inherit;
  font-size: clamp(0.8rem, 2.4vw, 1rem);
  padding: 10px 18px;
  border-radius: 999px;
  border: 2px solid var(--ink);
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease, background 0.2s ease;
  white-space: nowrap;
}

.top-link:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 18px rgba(0, 0, 0, 0.15);
}

.top-link:active {
  transform: translateY(0);
  box-shadow: none;
}

.top-link.ghost {
  background: transparent;
}

.top-link.icon-link {
  gap: 8px;
  padding: 10px 14px;
}

.top-link.icon-link .nav-label {
  padding-right: 4px;
}

.top-link:not(.icon-link) .icon-gear {
  display: none;
}

.top-link.is-active {
  background: var(--ink);
  color: #ffffff;
  border-color: var(--ink);
}

.icon-gear {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
}

.view[hidden] {
  display: none !important;
}

.hero {
  display: flex;
  flex-direction: column;
  gap: 18px;
  animation: riseIn 0.8s ease both;
}

.hero-title h1 {
  margin: 0;
  font-family: "Bodoni MT", "Didot", "Palatino", serif;
  font-size: clamp(36px, 8vw, 72px);
  letter-spacing: 2px;
}

.eyebrow {
  text-transform: uppercase;
  letter-spacing: 3px;
  font-size: 0.85rem;
  font-weight: 700;
}

.subtitle {
  margin: 0;
  font-size: 1.1rem;
  color: var(--ink-soft);
  max-width: 640px;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.mode-toggle {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 6px;
}

.mode-btn {
  font: inherit;
  padding: 8px 16px;
  border-radius: 999px;
  border: 2px solid var(--ink);
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease, background 0.2s ease;
}

.mode-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 18px rgba(0, 0, 0, 0.15);
}

.mode-btn:active {
  transform: translateY(0);
  box-shadow: none;
}

.mode-btn.is-active {
  background: #111111;
  color: #ffffff;
  border-color: #111111;
}

.mode-btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.hero-meta {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
}

.meta-card {
  background: var(--parchment);
  border: 2px solid var(--ink);
  border-radius: 16px;
  padding: 12px 16px;
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.16);
}

.meta-label {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 2px;
  color: var(--ink-soft);
}

.meta-value {
  font-size: 1.35rem;
  font-weight: 700;
  margin-top: 6px;
}

.meta-value.status-solved {
  color: #1a7f3a;
}

.status-solved {
  color: #1a7f3a;
}

.game {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding-top: 64px;
  animation: riseIn 0.9s ease both;
  animation-delay: 0.08s;
}

.board-shell {
  position: relative;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
}

.board-wrap {
  background: var(--parchment);
  border: 2px solid var(--ink);
  border-radius: var(--radius);
  padding: 18px min(20px, calc(var(--cell-size) / 2 - 2px)) 22px;
  box-shadow: 0 18px 34px rgba(0, 0, 0, 0.18);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  position: relative;
  z-index: 2;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.board-tabs {
  position: absolute;
  top: -48px;
  left: 16px;
  display: inline-flex;
  gap: 8px;
  z-index: 1;
}

.board-tabs .mode-btn {
  position: relative;
  padding: 8px 18px 12px;
  border-radius: 14px 14px 0 0;
  border: 2px solid var(--ink);
  border-bottom: none;
  background: var(--parchment);
  color: var(--ink);
  margin: 0;
  box-shadow: 0 6px 10px rgba(0, 0, 0, 0.12);
  transform: translateY(0);
}

.board-tabs .mode-btn::after {
  content: "";
  position: absolute;
  left: -2px;
  right: -2px;
  bottom: -16px;
  height: 16px;
  background: inherit;
  border-left: 2px solid var(--ink);
  border-right: 2px solid var(--ink);
  pointer-events: none;
}

.board-tabs .mode-btn.is-active {
  background: var(--parchment);
  color: var(--ink);
  z-index: 1;
}

.board-tabs .mode-btn:not(.is-active) {
  background: var(--parchment-dark);
  color: var(--ink-soft);
  box-shadow: inset 0 -6px 10px rgba(0, 0, 0, 0.18);
  transform: translateY(4px);
}

.board-tabs .mode-btn:not(.is-active):hover {
  transform: translateY(2px);
}

.board-header {
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 12px;
  font-weight: 700;
  letter-spacing: 0.5px;
  flex-wrap: nowrap;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  position: relative;
}

.board-header .banner {
  padding: 6px 12px;
  font-size: 0.85rem;
  line-height: 1;
}

.shift-counter,
.move-counter {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
}

.shift-counter {
  left: 0;
}

.move-counter {
  right: 0;
  text-align: right;
}

.count-value {
  display: inline-block;
  min-width: 2ch;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.shift-counter {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.grid {
  display: inline-grid;
  gap: var(--grid-gap);
  padding: 10px;
  background: var(--parchment);
  border: 3px solid var(--ink);
  border-radius: 16px;
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.08);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.grid-empty {
  display: block;
  padding: 24px;
  text-align: center;
  color: var(--ink-soft);
  font-weight: 700;
}

.grid-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.grid-loading::after {
  content: "";
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 3px solid var(--ink-soft);
  border-top-color: var(--ink);
  animation: spin 0.9s linear infinite;
}

.actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: center;
  width: min(520px, 100%);
}

.actions button {
  flex: 1 1 0;
}

button {
  font: inherit;
  font-size: clamp(0.8rem, 2.4vw, 1rem);
  padding: 10px 18px;
  border-radius: 999px;
  border: 2px solid var(--ink);
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease, background 0.2s ease;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  white-space: nowrap;
}

button:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 18px rgba(0, 0, 0, 0.15);
}

button:active {
  transform: translateY(0);
  box-shadow: none;
}

button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.hidden {
  display: none;
}

button.primary {
  background: #111111;
  color: #ffffff;
}

button.ghost {
  background: transparent;
}

.banner {
  padding: 10px 16px;
  background: #111111;
  color: #ffffff;
  font-weight: 700;
  font: inherit;
  border-radius: 999px;
  border: 2px solid #111111;
  opacity: 0;
  transform: translateY(6px);
  transition: opacity 0.2s ease, transform 0.2s ease;
  cursor: pointer;
  appearance: none;
}

.banner.show {
  opacity: 1;
  transform: translateY(0);
}

.banner.invalid {
  background: #b5332a;
  border-color: #b5332a;
  cursor: default;
  pointer-events: none;
}

.banner.invalid.flash {
  animation: invalidFlash 0.35s ease;
}

@keyframes invalidFlash {
  0% {
    filter: brightness(1);
  }
  50% {
    filter: brightness(1.3);
  }
  100% {
    filter: brightness(1);
  }
}

.how {
  display: flex;
  flex-direction: column;
  gap: 12px;
  animation: riseIn 0.9s ease both;
  animation-delay: 0.16s;
}

.how h2 {
  margin: 0;
  font-family: "Bodoni MT", "Didot", "Palatino", serif;
  font-size: clamp(26px, 5vw, 40px);
  letter-spacing: 1px;
}

.how p {
  margin: 0;
  color: var(--ink-soft);
  line-height: 1.6;
}

.settings {
  display: flex;
  flex-direction: column;
  gap: 18px;
  animation: riseIn 0.9s ease both;
}

.settings h2 {
  margin: 0;
  font-family: "Bodoni MT", "Didot", "Palatino", serif;
  font-size: clamp(26px, 5vw, 40px);
  letter-spacing: 1px;
}

.view-more .settings h2:first-of-type {
  text-align: center;
}

.view-more .settings-footer h2 {
  margin-top: 24px;
}

.settings p {
  margin: 0;
  color: var(--ink-soft);
  line-height: 1.6;
}

.view-more .settings p {
  font-size: 1.15rem;
}

.view-more .settings-footer {
  font-size: 1.1rem;
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px;
}

.settings-card {
  background: var(--parchment);
  border: 2px solid var(--ink);
  border-radius: 16px;
  padding: 16px;
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.16);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.settings-card h3 {
  margin: 0;
  font-size: 1rem;
  letter-spacing: 1px;
  text-transform: uppercase;
}

.color-options {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
}

.color-option {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 2px solid var(--accent);
  background: var(--accent);
  color: #ffffff;
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease, background 0.2s ease;
}

.color-option:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.16);
}

.color-option.is-selected {
  background: var(--parchment);
  border-color: var(--ink);
  color: var(--ink);
  box-shadow: 0 10px 18px rgba(0, 0, 0, 0.18);
}

.color-option.is-disabled {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
  box-shadow: none;
}

.color-option:disabled {
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
  opacity: 1;
}

.color-swatch {
  width: 22px;
  height: 22px;
  border-radius: 6px;
  background: var(--swatch);
  border: 2px solid #000000;
}

.settings-footer {
  display: flex;
  flex-direction: column;
  gap: 6px;
  text-align: center;
}

.view-more .settings-footer .top-link {
  background: var(--ink);
  color: #ffffff;
  border-color: var(--ink);
  box-shadow: 0 14px 24px rgba(0, 0, 0, 0.25);
  margin-bottom: 12px;
}

.settings-promo {
  font-weight: 600;
}

.settings-credit {
  text-transform: uppercase;
  letter-spacing: 2px;
  font-weight: 700;
  color: var(--ink-soft);
}

.how-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.how-shortcuts {
  margin-top: 18px;
  padding: 14px 16px;
  border: 2px solid var(--ink);
  border-radius: 14px;
  background: var(--parchment);
  box-shadow: 0 10px 20px rgba(0, 0, 0, 0.14);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.how-shortcuts-title {
  text-transform: uppercase;
  letter-spacing: 2px;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--ink-soft);
}

.how-shortcuts-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 8px 12px;
}

.how-shortcut {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-weight: 600;
}

.how-shortcut-key {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 52px;
  padding: 4px 10px;
  border-radius: 10px;
  border: 2px solid var(--ink);
  background: #ffffff;
}

.how-item {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 12px;
  align-items: center;
}

.how-tiles {
  display: flex;
  gap: 10px;
  align-items: center;
}

.view-more .how-tiles {
  justify-content: center;
}

.how-item .cell {
  width: 52px;
  height: 52px;
}

.footer {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  text-align: center;
  font-weight: 700;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--ink-soft);
  margin-top: 32px;
}

.cell {
  width: var(--cell-size);
  height: var(--cell-size);
  background: #fffdf6;
  border: 2px solid #c8bda9;
  position: relative;
  border-radius: 8px;
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.06);
}

.cell.wall {
  background: #0f0f0f;
  border-color: #0f0f0f;
  box-shadow: inset 0 0 0 2px #0f0f0f;
}

.cell.goal-green {
  border: 5px solid var(--color-green);
}

.cell.goal-red {
  border: 5px solid var(--color-red);
}

.cell.shadow-gate {
  border: 5px solid #000000;
}

.cell.dawn-barrier {
  background: #fffdf6;
  border: 2px solid #c8bda9;
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.06);
}

.cell.dawn-barrier::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 68%;
  height: 68%;
  transform: translate(-50%, -50%);
  background: #0f0f0f;
  border-radius: 6px;
  box-shadow: 0 6px 12px rgba(0, 0, 0, 0.18);
}

.cell.color-wall-green,
.cell.color-wall-red {
  background: #0f0f0f;
  border-color: #0f0f0f;
  position: relative;
}

.cell.color-wall-green::after,
.cell.color-wall-red::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 80%;
  height: 80%;
  transform: translate(-50%, -50%);
  border-radius: 12px;
  z-index: 1;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.18);
  background: transparent;
  border: 5px solid currentColor;
}

.cell.color-wall-green::after {
  color: var(--color-green);
}

.cell.color-wall-red::after {
  color: var(--color-red);
}

.cell.dizzy {
  background: #0f0f0f;
  border-color: #0f0f0f;
  position: relative;
}

.cell.dizzy::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 80%;
  height: 80%;
  transform: translate(-50%, -50%);
  border-radius: 12px;
  z-index: 1;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.18);
  background: transparent;
  border: 5px solid #fffdf6;
}

.cell.switch-tile {
  position: relative;
  border: 5px solid transparent;
  border-radius: 8px;
  background:
    linear-gradient(#fffdf6, #fffdf6) padding-box,
    linear-gradient(90deg, var(--color-green) 0%, var(--color-green) 50%, var(--color-red) 50%, var(--color-red) 100%) border-box;
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.06);
  overflow: hidden;
}

.cell.button-tile {
  position: relative;
  background: #fffdf6;
  border: 2px solid #c8bda9;
  border-radius: 8px;
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.06);
}

.cell.button-tile .btn-bar {
  position: absolute;
  background: #0f0f0f;
  border-radius: 6px;
  opacity: 0.9;
}

.cell.button-tile .btn-bar.top {
  top: 7%;
  left: 50%;
  width: 36%;
  height: 6px;
  transform: translateX(-50%);
}

.cell.button-tile .btn-bar.bottom {
  bottom: 7%;
  left: 50%;
  width: 36%;
  height: 6px;
  transform: translateX(-50%);
}

.cell.button-tile .btn-bar.left {
  left: 7%;
  top: 50%;
  width: 6px;
  height: 36%;
  transform: translateY(-50%);
}

.cell.button-tile .btn-bar.right {
  right: 7%;
  top: 50%;
  width: 6px;
  height: 36%;
  transform: translateY(-50%);
}

.cell.removable-wall {
  background: #0f0f0f;
  border: 2px solid #0f0f0f;
  border-radius: 8px;
  position: relative;
  box-shadow: inset 0 0 0 2px #0f0f0f;
}

.cell.removable-wall::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 115%;
  height: 10%;
  transform: translate(-50%, -50%) rotate(-45deg);
  background: #fffdf6;
  border-radius: 6px;
  z-index: 0;
}

.cell.removable-wall.removed-wall {
  background: #fffdf6;
  border: 2px solid #c8bda9;
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.06);
}

.cell.removable-wall.removed-wall::after {
  background: #0f0f0f;
}

.cell.teleport-tile {
  position: relative;
  background: #fffdf6;
  border: 2px solid #0f0f0f;
  border-radius: 8px;
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.08);
  overflow: hidden;
}

.cell.teleport-tile .tp-tick {
  position: absolute;
  background: #0f0f0f;
  border-radius: 4px;
  opacity: 0.9;
}

.cell.teleport-tile .tp-tick.top {
  top: 3%;
  left: 50%;
  width: 20%;
  height: 6px;
  transform: translateX(-50%) rotate(-90deg);
}

.cell.teleport-tile .tp-tick.bottom {
  bottom: 3%;
  left: 50%;
  width: 20%;
  height: 6px;
  transform: translateX(-50%) rotate(-90deg);
}

.cell.teleport-tile .tp-tick.left {
  left: 3%;
  top: 50%;
  width: 6px;
  height: 20%;
  transform: translateY(-50%);
}

.cell.teleport-tile .tp-tick.right {
  right: 3%;
  top: 50%;
  width: 6px;
  height: 20%;
  transform: translateY(-50%);
}

.cell.teleport-tile .tp-tick.tl {
  top: 2%;
  left: 5%;
  width: 6px;
  height: 20%;
  transform: rotate(-45deg);
}

.cell.teleport-tile .tp-tick.tr {
  top: 2%;
  right: 5%;
  width: 6px;
  height: 20%;
  transform: rotate(45deg);
}

.cell.teleport-tile .tp-tick.bl {
  bottom: 2%;
  left: 5%;
  width: 6px;
  height: 20%;
  transform: rotate(45deg);
}

.cell.teleport-tile .tp-tick.br {
  bottom: 2%;
  right: 5%;
  width: 6px;
  height: 20%;
  transform: rotate(-45deg);
}

.character {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 68%;
  height: 68%;
  transform: translate(-50%, -50%);
  border-radius: 6px;
  box-shadow: 0 6px 12px rgba(0, 0, 0, 0.18);
  z-index: 1;
}

.character.green {
  background: var(--color-green);
}

.character.red {
  background: var(--color-red);
}

.active-cell {
  outline: 3px dashed #000000;
  outline-offset: 3px;
}

@keyframes riseIn {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@media (max-width: 760px) {
  .page {
    padding: 32px 14px 52px;
    gap: 32px;
  }

  .board-header {
    font-size: 0.95rem;
  }

  .how-item {
    grid-template-columns: auto;
  }
}

@media (max-width: 520px) {
  :root {
    --cell-size: clamp(36px, 14vw, 76px);
  }

  .hero-meta {
    grid-template-columns: 1fr;
  }
}
