:root {
  --page-bg: #c7cbd5;
  --page-panel: rgba(255, 255, 255, 0.18);
  --page-grid: rgba(255, 255, 255, 0.22);
  --ink: #2d3038;
  --muted: #656977;
  --board-frame: #f5efe3;
  --board-frame-shadow: #393840;
  --board-shadow: #2a2930;
  --board-highlight: #fcf5e8;
  --board-light: #f1cf9e;
  --board-dark: #d4ad71;
  --board-selected: #f0e17a;
  --board-target: #5d73d0;
  --board-target-glow: rgba(93, 115, 208, 0.35);
  --board-check: #cf4c3d;
  --board-check-glow: rgba(207, 76, 61, 0.35);
  --board-active: #4f79d0;
  --board-focus: #d8e2ff;
  --branch: #9f73c6;
  --branch-dark: #76539a;
  --preview: #61948a;
  --board-turn-white: #f3ede0;
  --board-turn-white-shadow: #4c4950;
  --board-turn-black: #4c4f5d;
  --board-turn-black-shadow: #2d303a;
  --timeline-track: rgba(83, 86, 97, 0.28);
  --button-bg: rgba(247, 240, 226, 0.92);
  --button-bg-hover: rgba(252, 246, 235, 0.98);
  --button-border: rgba(129, 110, 82, 0.4);
  --button-primary: #f0dfbf;
  --button-primary-border: rgba(122, 95, 59, 0.45);
  --button-ink: #443a2f;
  --accent-white: rgba(248, 241, 230, 0.88);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html, body {
  height: 100%;
  overflow: hidden;
}

/* Allow scrolling on non-game pages */
body:has(.lobby-page),
body:has(.history-page),
body:has(.devise-page),
body:has(.puzzle-play-page),
body:has(.puzzle-editor-page),
body:has(.analytics-page) {
  overflow: auto;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

body {
  margin: 0;
  color: var(--ink);
  font-family: Georgia, "Times New Roman", serif;
  background:
    radial-gradient(circle at top left, rgba(255, 255, 255, 0.32), transparent 30%),
    radial-gradient(circle at 20% 25%, rgba(255, 255, 255, 0.08), transparent 14%),
    linear-gradient(var(--page-grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--page-grid) 1px, transparent 1px),
    linear-gradient(180deg, #d2d7df 0%, var(--page-bg) 18%, #bfc3ce 100%);
  background-size: auto, 18rem 18rem, 7.5rem 7.5rem, 7.5rem 7.5rem, 100% 100%;
  background-attachment: fixed;
}

button {
  font: inherit;
}

.game-page {
  max-width: none;
  margin: 0;
  padding: 3.65rem 0.9rem 0;
  padding-right: 14rem;
  height: calc(100vh - 3rem);
  overflow: visible;
}

.puzzle-editor__sandbox.game-page {
  position: relative;
  height: 70vh;
  min-height: 28rem;
  padding-top: 0.5rem;
  border-radius: 0.5rem;
  overflow: hidden;
}

.game-page__header {
  position: fixed;
  top: 3.75rem;
  left: 0.9rem;
  z-index: 110;
  display: flex;
  align-items: center;
  gap: 0.65rem;
  margin: 0;
  padding: 0;
}

.game-page__caption {
  margin: 0;
  color: rgba(57, 61, 72, 0.52);
  font-size: 0.72rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.game-page__new-game {
  border: 0.12rem solid var(--button-primary-border);
  border-radius: 999px;
  background: linear-gradient(180deg, #fff6e7 0%, var(--button-primary) 100%);
  color: var(--button-ink);
  width: 2.35rem;
  height: 2.35rem;
  padding: 0;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.95rem;
  box-shadow:
    0 0.18rem 0 rgba(117, 96, 69, 0.35),
    0 0.45rem 1rem rgba(88, 91, 103, 0.16);
}

.game-page__loading {
  margin: 0;
  color: rgba(54, 59, 69, 0.82);
}

.game-page__admin-actions {
  display: flex;
  justify-content: flex-end;
  padding: 0 1rem;
}

.game-page__delete-btn {
  background: #c0392b;
  color: #fff;
  border: none;
  padding: 0.4rem 1rem;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.85rem;
}

.game-page__delete-btn:hover {
  background: #96281b;
}

.five-d-game {
  position: relative;
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.five-d-toolbar {
  position: fixed;
  top: 3.8rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 0.5rem 1.4rem;
  padding: 0.55rem 1.1rem;
  background: var(--accent-white);
  border: 0.08rem solid rgba(128, 109, 82, 0.28);
  border-radius: 1.2rem;
  box-shadow:
    0 0.14rem 0 rgba(132, 111, 79, 0.32),
    0 0.7rem 1.8rem rgba(78, 81, 93, 0.18);
  backdrop-filter: blur(12px);
}

.five-d-toolbar__players {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.85rem;
  color: var(--ink);
  margin-right: 1rem;
}

.five-d-toolbar__player {
  font-weight: 600;
}

.five-d-toolbar__player--white {
  color: var(--button-ink);
}

.five-d-toolbar__player--black {
  color: var(--ink);
}

.five-d-toolbar__presence-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 4px;
  vertical-align: middle;
}

.five-d-toolbar__presence-dot--online {
  background-color: #22c55e;
}

.five-d-toolbar__presence-dot--offline {
  background-color: #9ca3af;
}

.five-d-toolbar__status--warning {
  color: #dc2626;
  font-weight: 600;
  white-space: nowrap;
}

.five-d-toolbar__vs {
  color: var(--muted);
  font-style: italic;
  font-size: 0.8rem;
}

.five-d-toolbar__actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
}

.five-d-toolbar__move-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.five-d-toolbar__button,
.timeline-sidebar__button {
  border: 0.08rem solid var(--button-border);
  border-radius: 999px;
  background: var(--button-bg);
  color: var(--button-ink);
  box-shadow: 0 0.12rem 0 rgba(124, 101, 72, 0.3);
}

.five-d-toolbar__button {
  min-width: 8.6rem;
  padding: 0.5rem 0.95rem;
  font-size: 0.88rem;
}

.five-d-toolbar__button:not(:disabled):hover,
.timeline-sidebar__button:hover {
  background: var(--button-bg-hover);
}

.five-d-toolbar__button:disabled,
.timeline-board__focus-button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.five-d-toolbar__button--primary {
  background: linear-gradient(180deg, #fff8eb 0%, var(--button-primary) 100%);
  border-color: var(--button-primary-border);
  color: var(--button-ink);
}

.five-d-toolbar__button--danger {
  background: linear-gradient(180deg, #fff3ee 0%, #f1b9a9 100%);
  border-color: #c4785f;
  color: #5b2017;
}

.five-d-toolbar__timer {
  display: flex;
  gap: 0.6rem;
  align-items: center;
}

.five-d-toolbar__clock {
  font-family: 'Courier New', monospace;
  font-size: 1rem;
  font-weight: 700;
  padding: 0.25rem 0.5rem;
  border-radius: 0.4rem;
  background: var(--button-bg);
  border: 0.08rem solid var(--button-border);
  color: var(--ink);
  min-width: 4rem;
  text-align: center;
}

.five-d-toolbar__clock--active {
  background: linear-gradient(180deg, #fff8eb 0%, var(--button-primary) 100%);
  border-color: var(--button-primary-border);
}

.five-d-toolbar__clock--low {
  color: #dc2626;
}

.five-d-layout {
  flex: 1;
  display: flex;
  min-height: 0;
}

.move-history-panel {
  position: fixed;
  right: 0;
  top: 3rem;
  bottom: 0;
  width: 13rem;
  z-index: 100;
  display: flex;
  flex-direction: column;
  background: rgba(255, 255, 255, 0.65);
  backdrop-filter: blur(10px);
  border-left: 1px solid rgba(0, 0, 0, 0.08);
  font-size: 0.82rem;
}

.move-history-panel__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 0.75rem;
  border-bottom: 1px solid rgba(0, 0, 0, 0.06);
}

.move-history-panel__title {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--ink);
  margin: 0;
}

.move-history-panel__live-btn {
  font-size: 0.7rem;
  font-weight: 600;
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  border: 1px solid var(--board-active);
  background: var(--board-focus);
  color: var(--board-active);
  cursor: pointer;
}

.move-history-panel__live-btn:hover {
  background: var(--board-active);
  color: #fff;
}

.move-history-panel__controls {
  display: flex;
  gap: 0.35rem;
  padding: 0.4rem 0.75rem;
  border-bottom: 1px solid rgba(0, 0, 0, 0.06);
}

.move-history-panel__control-btn {
  flex: 1;
  font-size: 0.7rem;
  padding: 0.3rem 0.4rem;
  border-radius: 4px;
  border: 1px solid var(--button-border);
  background: var(--button-bg);
  color: var(--button-ink);
  cursor: pointer;
}

.move-history-panel__control-btn:hover {
  background: var(--button-bg-hover);
}

.move-history-panel__control-btn--active {
  background: linear-gradient(180deg, #fff8eb 0%, var(--button-primary) 100%);
  border-color: var(--button-primary-border);
}

.move-history-panel__game-actions {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid rgba(0, 0, 0, 0.06);
}

.move-history-panel__draw-status {
  font-size: 0.75rem;
  color: var(--ink);
  text-align: center;
}

.move-history-panel__action-row {
  display: flex;
  gap: 0.35rem;
}

.move-history-panel__action-btn {
  flex: 1;
  font-size: 0.7rem;
  padding: 0.35rem 0.4rem;
  border-radius: 4px;
  border: 1px solid var(--button-border);
  background: var(--button-bg);
  color: var(--button-ink);
  cursor: pointer;
}

.move-history-panel__action-btn:not(:disabled):hover {
  background: var(--button-bg-hover);
}

.move-history-panel__action-btn:disabled {
  opacity: 0.5;
  cursor: default;
}

.move-history-panel__action-btn--primary {
  background: linear-gradient(180deg, #fff8eb 0%, var(--button-primary) 100%);
  border-color: var(--button-primary-border);
}

.move-history-panel__action-btn--danger {
  background: linear-gradient(180deg, #fff0f0 0%, #f5d0d0 100%);
  border-color: #d4a0a0;
  color: #8b3030;
}

.move-history-panel__body {
  flex: 1;
  overflow-y: auto;
  padding: 0.4rem 0;
}

.move-history-panel__empty {
  color: var(--muted);
  text-align: center;
  padding: 1.5rem 0.75rem;
  font-style: italic;
  font-size: 0.78rem;
}

.move-history-panel__handle {
  display: none;
  justify-content: center;
  padding: 0.5rem 0 0.25rem;
  cursor: grab;
}

.move-history-panel__handle-bar {
  width: 2.5rem;
  height: 0.25rem;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 2px;
}

.move-history-panel__row {
  display: grid;
  grid-template-columns: 1.6rem 1fr 1fr;
  gap: 0.15rem;
  padding: 0.15rem 0.5rem;
}

.move-history-panel__number {
  color: var(--muted);
  font-size: 0.75rem;
  text-align: right;
  padding-right: 0.3rem;
  line-height: 1.6;
}

.move-history-panel__move {
  padding: 0.15rem 0.35rem;
  border-radius: 3px;
  cursor: pointer;
  font-family: monospace;
  font-size: 0.75rem;
  line-height: 1.6;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.move-history-panel__move:hover {
  background: rgba(0, 0, 0, 0.06);
}

.move-history-panel__move--active {
  background: var(--board-focus);
  color: var(--board-active);
  font-weight: 600;
}

.timeline-stage-wrapper {
  min-width: 0;
  min-height: 0;
  position: relative;
  flex: 1;
  overflow: visible;
  cursor: grab;
  margin-right: 13rem;
  touch-action: none;
}

.five-d-endstate {
  position: fixed;
  bottom: 0.75rem;
  left: 0.75rem;
  z-index: 110;
  padding: 1rem 1.5rem;
}

.five-d-endstate__title {
  margin: 0;
  font-size: 2rem;
  color: rgba(50, 46, 43, 0.92);
  text-shadow: 0 0.1rem 0.35rem rgba(255, 255, 255, 0.45);
}

.five-d-endstate__detail {
  margin: 0.25rem 0 0;
  font-size: 1rem;
  color: rgba(72, 68, 64, 0.76);
}

.timeline-stage {
  position: relative;
  overflow: visible;
  width: 100%;
  height: 100%;
}

.timeline-stage__viewport {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 1.65rem;
  min-height: 100%;
  padding: 1.4rem 3rem 2rem 3.5rem;
  transform-origin: 0 0;
  will-change: transform;
}

.timeline-row {
  position: relative;
  display: grid;
  grid-template-columns: repeat(var(--timeline-columns), minmax(14rem, 14rem));
  gap: 0 1.65rem;
  align-items: center;
}

.timeline-stage__arrows {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 10;
  overflow: visible;
}

.timeline-stage__arrow-move {
  fill: none;
  stroke: #6f79dc;
  stroke-width: 3px;
  stroke-linecap: round;
  opacity: 0.8;
}

.timeline-stage__arrow-submitted {
  fill: none;
  stroke: #5f6fd8;
  stroke-width: 3.2px;
  stroke-linecap: round;
  opacity: 0.48;
}

.timeline-stage__arrow-draft {
  fill: none;
  stroke: #7b82e1;
  stroke-width: 3.4px;
  stroke-linecap: round;
  opacity: 0.62;
  stroke-dasharray: 8 4;
}

.timeline-stage__arrow-check {
  fill: none;
  stroke: var(--board-check);
  stroke-width: 3px;
  stroke-linecap: round;
  opacity: 0.8;
}

.timeline-stage__arrow-branch,
.timeline-stage__arrow-continuation {
  fill: none;
  stroke: var(--branch);
  stroke-width: 5px;
  stroke-linecap: round;
  opacity: 0.55;
}


.timeline-stage__label {
  position: absolute;
  left: -2.05rem;
  top: 50%;
  transform: translateY(-50%);
  color: rgba(54, 59, 69, 0.38);
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.timeline-board {
  position: relative;
  z-index: 1;
  width: 12.9rem;
}

.timeline-board__badges {
  display: flex;
  gap: 0.3rem;
  margin-bottom: 0.35rem;
}

.timeline-board--branched::before {
  display: none;
}

.timeline-branch-trunk {
  position: absolute;
  top: 0;
  left: -0.65rem;
  width: 0.18rem;
  height: 100%;
  border-radius: 999px;
  background: var(--branch);
  opacity: 0.55;
  pointer-events: none;
  z-index: 0;
}

.timeline-board__badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 1.45rem;
  padding: 0.14rem 0.58rem;
  border-radius: 999px;
  color: #fff;
  font-size: 0.74rem;
  line-height: 1;
  white-space: nowrap;
  box-shadow: 0 0.16rem 0.45rem rgba(0, 0, 0, 0.28);
}

.timeline-board__badge--check {
  background: linear-gradient(180deg, #f08a65 0%, #e97854 100%);
}

.timeline-board__badge--preview {
  background: linear-gradient(180deg, #7ebcb1 0%, #5d9a8f 100%);
}

.timeline-board__check-indicator {
  position: absolute;
  top: -0.35rem;
  right: -0.35rem;
  z-index: 10;
  width: 1.5rem;
  height: 1.5rem;
  border-radius: 50%;
  border: 2px solid rgba(204, 51, 51, 0.6);
  background: linear-gradient(180deg, #e8735a 0%, #cf4c3d 100%);
  color: #fff;
  font-weight: 800;
  font-size: 0.9rem;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 0.12rem 0.4rem rgba(204, 51, 51, 0.45);
  transition: transform 0.15s, box-shadow 0.15s;
  padding: 0;
}

.timeline-board__check-indicator:hover {
  transform: scale(1.15);
  box-shadow: 0 0.16rem 0.6rem rgba(204, 51, 51, 0.7);
}

.timeline-board__check-indicator--active {
  background: linear-gradient(180deg, #cf4c3d 0%, #b03a2e 100%);
  box-shadow: 0 0 0.5rem rgba(204, 51, 51, 0.6);
}

.timeline-board__surface {
  position: relative;
}

.timeline-board__shadow {
  position: absolute;
  inset: 0.8rem 1.15rem -0.6rem -0.8rem;
  border-radius: 0.9rem;
  background: var(--board-shadow);
  box-shadow:
    0 0.3rem 0.9rem rgba(0, 0, 0, 0.44),
    0 0.8rem 1.65rem rgba(0, 0, 0, 0.2);
}

.timeline-board__grid {
  position: relative;
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  border: 0.34rem solid var(--board-frame);
  border-radius: 0.72rem;
  overflow: hidden;
  background: var(--board-frame);
  box-shadow: 0 0 0 0.34rem var(--board-frame-shadow);
}

.timeline-board--turn-white .timeline-board__grid {
  border-color: var(--board-turn-white);
  box-shadow: 0 0 0 0.3rem var(--board-turn-white-shadow);
}

.timeline-board--turn-black .timeline-board__grid {
  border-color: var(--board-turn-black);
  box-shadow: 0 0 0 0.3rem var(--board-turn-black-shadow);
}

.timeline-board--active .timeline-board__grid,
.timeline-board--active-player .timeline-board__grid {
  box-shadow: 0 0 0 0.34rem var(--board-frame-shadow), 0 0 0.8rem rgba(79, 121, 208, 0.42);
}

.timeline-board--checked {
  background: rgba(204, 51, 51, 0.08);
}

.timeline-board--checked .timeline-board__grid {
  border-color: var(--board-check);
  box-shadow: 0 0 0 0.34rem var(--board-frame-shadow), 0 0 0.95rem var(--board-check-glow);
}

.timeline-board--frontier-preview {
  opacity: 0.7;
}

.timeline-board--frontier-preview .timeline-board__grid {
  border-style: dashed;
  border-color: var(--board-check);
}

.timeline-board--targeted .timeline-board__grid {
  border-color: var(--board-target);
  box-shadow: 0 0 0 0.34rem var(--board-frame-shadow), 0 0 0.8rem var(--board-target-glow);
}

.timeline-square {
  position: relative;
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 0;
  user-select: none;
}

.timeline-square--light {
  background: var(--board-light);
}

.timeline-square--dark {
  background: var(--board-dark);
}

.timeline-square--playable {
  cursor: pointer;
  transition: filter 0.1s;
}

.timeline-square--playable:hover {
  filter: brightness(1.15);
}

.timeline-square--submitted-move {
  background: rgba(95, 111, 216, 0.3);
  box-shadow: inset 0 0 0 0.12rem rgba(95, 111, 216, 0.55);
}

.timeline-square--classical-move {
  background: rgba(239, 225, 109, 0.45);
  box-shadow: inset 0 0 0 0.12rem rgba(200, 185, 60, 0.6);
}

.timeline-square--selected {
  background: var(--board-selected);
}

.timeline-square--legal-target {
  background: rgba(100, 120, 200, 0.45);
  box-shadow: inset 0 0 0 0.12rem rgba(140, 130, 220, 0.7);
}

.timeline-square--checked {
  background: rgba(204, 51, 51, 0.25);
  box-shadow: inset 0 0 0 0.15rem rgba(204, 51, 51, 0.6);
}

.timeline-square--disabled {
  cursor: not-allowed;
  filter: grayscale(0.6) opacity(0.55);
}

.timeline-square__piece {
  width: min(74%, 2.5rem);
  max-height: 74%;
  object-fit: contain;
  pointer-events: none;
  user-select: none;
}

@media (max-width: 1024px) {
  .timeline-sidebar {
    top: auto;
    bottom: 0.5rem;
    right: 0.5rem;
    transform: none;
    flex-direction: row;
  }

  .timeline-sidebar__button {
    writing-mode: horizontal-tb;
  }

  .timeline-sidebar__icon-button {
    width: 2.15rem;
    height: 2.15rem;
  }
}

@media (max-width: 720px) {
  .game-page__header,
  .five-d-toolbar,
  .five-d-toolbar__actions {
    flex-direction: column;
    align-items: stretch;
  }

  .game-page__header {
    left: 0.65rem;
    top: 0.65rem;
  }

  .five-d-toolbar__button {
    min-width: 0;
  }

  .timeline-stage__viewport {
    padding-left: 3rem;
    gap: 1rem;
  }

  .timeline-row {
    grid-template-columns: repeat(var(--timeline-columns), minmax(11.5rem, 11.5rem));
    gap: 0 1rem;
  }

  .timeline-stage__label {
    display: none;
  }

  .timeline-board {
    width: 10.6rem;
  }

}

.site-nav {
  position: relative;
  z-index: 200;
  background: rgba(245, 239, 227, 0.82);
  border-bottom: 1px solid rgba(129, 110, 82, 0.2);
  backdrop-filter: blur(12px);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.55), 0 2px 8px rgba(60, 57, 52, 0.08);
}

.site-nav__inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: 72rem;
  margin: 0 auto;
  padding: 0 1.25rem;
  height: 3rem;
}

.site-nav__brand {
  font-size: 1.05rem;
  font-weight: normal;
  letter-spacing: 0.06em;
  color: var(--button-ink);
  text-decoration: none;
  font-style: italic;
}

.site-nav__brand:hover {
  color: var(--ink);
}

.site-nav__links {
  display: flex;
  align-items: center;
  gap: 0.15rem;
}

.site-nav__link {
  display: inline-block;
  padding: 0.32rem 0.75rem;
  border-radius: 999px;
  font-size: 0.82rem;
  color: var(--muted);
  text-decoration: none;
  background: transparent;
  border: none;
  cursor: pointer;
  font: inherit;
  letter-spacing: 0.02em;
  transition: color 0.12s, background 0.12s;
}

.site-nav__link:hover {
  color: var(--button-ink);
  background: rgba(129, 110, 82, 0.1);
}

.site-nav__link--active {
  color: var(--button-ink);
  background: rgba(129, 110, 82, 0.12);
  font-weight: 600;
}

/* ── Hamburger menu ── */

.site-nav__hamburger {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.4rem;
  z-index: 201;
}

.site-nav__hamburger-line {
  display: block;
  width: 20px;
  height: 2px;
  background: var(--ink);
  border-radius: 1px;
  transition: transform 0.2s, opacity 0.2s;
}

.site-nav--open .site-nav__hamburger-line:nth-child(1) {
  transform: rotate(45deg) translate(4px, 4px);
}

.site-nav--open .site-nav__hamburger-line:nth-child(2) {
  opacity: 0;
}

.site-nav--open .site-nav__hamburger-line:nth-child(3) {
  transform: rotate(-45deg) translate(4px, -4px);
}

.site-nav__links form {
  margin: 0;
  display: inline;
}

.site-nav__link--subtle {
  color: var(--muted);
  font-size: 0.78rem;
}

.flash {
  padding: 0.65rem 1.25rem;
  font-size: 0.85rem;
  text-align: center;
  border-bottom: 1px solid transparent;
}

.flash--notice {
  background: rgba(224, 242, 230, 0.88);
  border-color: rgba(90, 160, 110, 0.3);
  color: #2d5c3a;
}

.flash--alert {
  background: rgba(250, 224, 218, 0.88);
  border-color: rgba(200, 90, 75, 0.3);
  color: #6b2318;
}

.lobby-page {
  max-width: 48rem;
  margin: 0 auto;
  padding: 2.5rem 1.25rem 4rem;
}

.lobby-hero {
  text-align: center;
  padding: 3rem 0 2.5rem;
}

.lobby-hero__title {
  margin: 0 0 0.5rem;
  font-size: 3rem;
  font-weight: normal;
  color: var(--button-ink);
  letter-spacing: 0.04em;
  font-style: italic;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.6);
}

.lobby-hero__tagline {
  margin: 0;
  font-size: 1.05rem;
  color: var(--muted);
  font-style: italic;
  letter-spacing: 0.03em;
}

.lobby-section {
  margin-bottom: 2.5rem;
}

.lobby-section__heading {
  margin: 0 0 1rem;
  font-size: 0.78rem;
  font-weight: normal;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
  border-bottom: 1px solid rgba(129, 110, 82, 0.18);
  padding-bottom: 0.45rem;
}

.lobby-section__description {
  margin: 0 0 0.75rem;
  font-size: 0.9rem;
  color: var(--muted);
  text-align: center;
}

.lobby-section__prompt {
  margin: 0;
  font-size: 0.95rem;
  color: var(--muted);
  text-align: center;
  padding: 1.25rem 0;
}

.lobby-section__prompt a {
  color: var(--button-ink);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.lobby-section__empty {
  margin: 0;
  font-size: 0.92rem;
  color: var(--muted);
  font-style: italic;
  padding: 1.5rem 0;
  text-align: center;
}

.lobby-create {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.lobby-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem 1.2rem;
  border-radius: 999px;
  font-size: 0.85rem;
  font: inherit;
  font-size: 0.85rem;
  cursor: pointer;
  text-decoration: none;
  border: 1px solid var(--button-border);
  background: var(--button-bg);
  color: var(--button-ink);
  box-shadow: 0 1px 0 rgba(124, 101, 72, 0.28), 0 2px 6px rgba(60, 58, 52, 0.08);
  transition: background 0.12s, box-shadow 0.12s;
}

.lobby-btn:hover {
  background: var(--button-bg-hover);
  box-shadow: 0 2px 0 rgba(124, 101, 72, 0.32), 0 4px 10px rgba(60, 58, 52, 0.12);
}

.lobby-btn form,
form.lobby-btn {
  display: inline;
  margin: 0;
}

.lobby-btn--local {
  background: linear-gradient(180deg, #dce8f5 0%, #b8cde8 100%);
  border-color: rgba(60, 100, 160, 0.38);
  color: #2a3f5e;
}

.lobby-btn--local:hover {
  background: linear-gradient(180deg, #e4eef8 0%, #c2d5ec 100%);
}

.lobby-btn--white {
  background: linear-gradient(180deg, #fffdf7 0%, #f5ead2 100%);
  border-color: rgba(140, 118, 80, 0.4);
  color: #3d3222;
}

.lobby-btn--white:hover {
  background: linear-gradient(180deg, #ffffff 0%, #faedd5 100%);
}

.lobby-btn--black {
  background: linear-gradient(180deg, #5a5d6e 0%, #3e404e 100%);
  border-color: rgba(30, 30, 42, 0.55);
  color: #f0eadb;
  box-shadow: 0 1px 0 rgba(20, 18, 25, 0.45), 0 2px 6px rgba(40, 38, 50, 0.18);
}

.lobby-btn--black:hover {
  background: linear-gradient(180deg, #636778 0%, #45475a 100%);
}

.lobby-btn--create {
  align-self: flex-start;
  padding: 0.55rem 1.8rem;
  background: linear-gradient(180deg, #fff8eb 0%, var(--button-primary) 100%);
  border: 0.08rem solid var(--button-primary-border);
  border-radius: 999px;
  color: var(--button-ink);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 0.12rem 0 rgba(124, 101, 72, 0.3);
}
.lobby-btn--create:hover {
  background: linear-gradient(180deg, #fff0d4 0%, #e5c886 100%);
}

.lobby-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  max-width: 28rem;
}
.lobby-form__group {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}
.lobby-form__label {
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--ink);
}
.lobby-form__options {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}
.lobby-form__radio {
  font-size: 0.85rem;
  color: var(--ink);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

.lobby-form__time-settings {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}
.lobby-form__time-settings[hidden] {
  display: none;
}
.lobby-form__input {
  padding: 0.35rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--surface);
  color: var(--ink);
  font-size: 0.85rem;
  width: 5rem;
}

.lobby-btn--join {
  background: linear-gradient(180deg, #e8f3ea 0%, #c5dfc9 100%);
  border-color: rgba(80, 140, 95, 0.38);
  color: #2a5733;
}

.lobby-btn--join:hover {
  background: linear-gradient(180deg, #eef6f0 0%, #cee6d2 100%);
}

.lobby-btn--resume {
  background: linear-gradient(180deg, #fff8eb 0%, var(--button-primary) 100%);
  border-color: var(--button-primary-border);
  color: var(--button-ink);
}

.lobby-btn--resume:hover {
  background: linear-gradient(180deg, #fffaf0 0%, #f5e4c5 100%);
}

.lobby-btn--watch {
  background: transparent;
  border-color: rgba(129, 110, 82, 0.28);
  color: var(--muted);
  box-shadow: none;
}

.lobby-btn--watch:hover {
  background: rgba(129, 110, 82, 0.08);
  color: var(--button-ink);
}

.lobby-games {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.lobby-game-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.8rem 1rem;
  background: rgba(247, 241, 228, 0.6);
  border: 1px solid rgba(129, 110, 82, 0.2);
  border-radius: 0.55rem;
  box-shadow: 0 1px 3px rgba(60, 57, 48, 0.06), 0 1px 0 rgba(255, 255, 255, 0.5) inset;
}

.lobby-game-card__info {
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
  flex-wrap: wrap;
  min-width: 0;
}

.lobby-game-card__id {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--button-ink);
  white-space: nowrap;
}

.lobby-game-card__creator,
.lobby-game-card__players {
  font-size: 0.85rem;
  color: var(--ink);
}

.lobby-game-card__time {
  font-size: 0.75rem;
  color: var(--muted);
  white-space: nowrap;
}

.lobby-game-card__actions {
  flex-shrink: 0;
}

.lobby-game-card__actions form {
  margin: 0;
}

.history-page {
  max-width: 56rem;
  margin: 0 auto;
  padding: 2.5rem 1.25rem 4rem;
}

.history-page__header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.75rem;
  border-bottom: 1px solid rgba(129, 110, 82, 0.18);
  padding-bottom: 0.75rem;
}

.history-page__title {
  margin: 0;
  font-size: 1.6rem;
  font-weight: normal;
  color: var(--button-ink);
  font-style: italic;
}

.history-page__empty {
  color: var(--muted);
  font-style: italic;
  font-size: 0.95rem;
  text-align: center;
  padding: 3rem 1rem;
}

.history-page__empty a {
  color: var(--button-ink);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.history-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.history-table thead tr {
  border-bottom: 1px solid rgba(129, 110, 82, 0.22);
}

.history-table th {
  padding: 0.45rem 0.75rem;
  text-align: left;
  font-size: 0.72rem;
  font-weight: normal;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

.history-table th:last-child {
  text-align: right;
}

.history-table__row {
  border-bottom: 1px solid rgba(129, 110, 82, 0.1);
  transition: background 0.1s;
}

.history-table__row:hover {
  background: rgba(247, 241, 228, 0.55);
}

.history-table td {
  padding: 0.65rem 0.75rem;
  color: var(--ink);
  vertical-align: middle;
}

.history-table td:last-child {
  text-align: right;
}

.history-status {
  display: inline-block;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  font-size: 0.72rem;
  letter-spacing: 0.04em;
  border: 1px solid transparent;
}

.history-status--waiting {
  background: rgba(224, 232, 255, 0.7);
  border-color: rgba(100, 120, 200, 0.25);
  color: #3a4fa8;
}

.history-status--active {
  background: rgba(224, 242, 230, 0.75);
  border-color: rgba(80, 150, 100, 0.25);
  color: #2a5a38;
}

.history-status--completed {
  background: rgba(230, 228, 222, 0.6);
  border-color: rgba(129, 110, 82, 0.2);
  color: var(--muted);
}

.invite-popup {
  position: fixed;
  top: 4.35rem;
  left: 0.9rem;
  z-index: 120;
  width: min(29rem, calc(100vw - 1.8rem));
  pointer-events: none;
}

.invite-popup__content {
  background: rgba(245, 239, 227, 0.96);
  border: 1px solid rgba(129, 110, 82, 0.24);
  border-radius: 0.85rem;
  padding: 0.9rem 1rem;
  box-shadow:
    0 0.12rem 0 rgba(132, 111, 79, 0.28),
    0 0.75rem 1.85rem rgba(60, 57, 52, 0.22);
  text-align: left;
  backdrop-filter: blur(8px);
  pointer-events: auto;
}

.invite-popup__title {
  font-size: 1rem;
  font-weight: bold;
  color: var(--ink);
  margin: 0 0 0.35rem;
}

.invite-popup__text {
  color: var(--muted);
  margin: 0 0 0.7rem;
  font-size: 0.82rem;
}

.invite-popup__link-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.invite-popup__input {
  flex: 1;
  min-width: 0;
  padding: 0.45rem 0.7rem;
  border: 1px solid var(--button-border);
  border-radius: 0.5rem;
  font: inherit;
  font-size: 0.8rem;
  background: white;
  color: var(--ink);
}

.invite-popup__copy {
  padding: 0.45rem 0.85rem;
  background: var(--button-primary);
  border: 1px solid var(--button-primary-border);
  border-radius: 0.5rem;
  font: inherit;
  font-size: 0.8rem;
  color: var(--button-ink);
  white-space: nowrap;
  cursor: pointer;
}

.invite-popup__copy:hover {
  background: var(--button-bg-hover);
}

.invite-popup__cancel {
  margin-top: 0.75rem;
  padding: 0.4rem 1rem;
  border: 0.08rem solid #c4785f;
  border-radius: 999px;
  background: linear-gradient(180deg, #fff3ee 0%, #f1b9a9 100%);
  color: #5b2017;
  font-size: 0.85rem;
  cursor: pointer;
  width: 100%;
}
.invite-popup__cancel:hover {
  background: linear-gradient(180deg, #ffe8e0 0%, #e8a090 100%);
}

@media (max-width: 720px) {
  .invite-popup {
    top: 5.35rem;
    left: 0.65rem;
    width: calc(100vw - 1.3rem);
  }

  .invite-popup__link-row {
    flex-direction: column;
    align-items: stretch;
  }
}

.devise-page {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 3.5rem 1.25rem 5rem;
  min-height: calc(100vh - 3rem);
}

.devise-form-card {
  width: 100%;
  max-width: 22rem;
  background: rgba(247, 241, 228, 0.72);
  border: 1px solid rgba(129, 110, 82, 0.22);
  border-radius: 0.75rem;
  padding: 2rem 2rem 1.75rem;
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.6) inset,
    0 4px 20px rgba(60, 57, 48, 0.1);
}

.devise-form-card__title {
  margin: 0 0 1.5rem;
  font-size: 1.35rem;
  font-weight: normal;
  color: var(--button-ink);
  font-style: italic;
  text-align: center;
}

.devise-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.devise-form__field {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.devise-form__field--inline {
  flex-direction: row;
  align-items: center;
  gap: 0.45rem;
}

.devise-form__label {
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.devise-form__label--inline {
  text-transform: none;
  letter-spacing: 0;
  font-size: 0.85rem;
  color: var(--ink);
}

.devise-form__input {
  font: inherit;
  font-size: 0.9rem;
  padding: 0.5rem 0.7rem;
  background: rgba(255, 252, 244, 0.85);
  border: 1px solid rgba(129, 110, 82, 0.32);
  border-radius: 0.35rem;
  color: var(--ink);
  transition: border-color 0.12s, box-shadow 0.12s;
}

.devise-form__input:focus {
  outline: none;
  border-color: rgba(129, 110, 82, 0.55);
  box-shadow: 0 0 0 3px rgba(200, 175, 125, 0.15);
}

.devise-form__checkbox {
  width: 1rem;
  height: 1rem;
  accent-color: var(--button-ink);
  cursor: pointer;
  flex-shrink: 0;
}

.devise-form__hint {
  font-size: 0.74rem;
  color: var(--muted);
  font-style: italic;
}

.devise-form__actions {
  margin-top: 0.5rem;
}

.devise-form__submit {
  display: block;
  width: 100%;
  padding: 0.6rem 1rem;
  border-radius: 999px;
  background: linear-gradient(180deg, #fff8eb 0%, var(--button-primary) 100%);
  border: 1px solid var(--button-primary-border);
  color: var(--button-ink);
  font: inherit;
  font-size: 0.9rem;
  cursor: pointer;
  box-shadow: 0 1px 0 rgba(124, 101, 72, 0.3), 0 3px 8px rgba(60, 58, 52, 0.1);
  transition: background 0.12s, box-shadow 0.12s;
}

.devise-form__submit:hover {
  background: linear-gradient(180deg, #fffaf0 0%, #f5e4c5 100%);
  box-shadow: 0 2px 0 rgba(124, 101, 72, 0.34), 0 5px 12px rgba(60, 58, 52, 0.13);
}

.devise-form__links {
  margin-top: 1.25rem;
  padding-top: 1rem;
  border-top: 1px solid rgba(129, 110, 82, 0.15);
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  text-align: center;
}

.devise-form__links p {
  margin: 0;
}

.devise-form__links a {
  font-size: 0.82rem;
  color: var(--muted);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.devise-form__links a:hover {
  color: var(--button-ink);
}

.devise-form__errors {
  background: rgba(250, 224, 218, 0.8);
  border: 1px solid rgba(200, 90, 75, 0.3);
  border-radius: 0.4rem;
  padding: 0.65rem 0.85rem;
  margin-bottom: 0.25rem;
}

.devise-form__errors-title {
  margin: 0 0 0.4rem;
  font-size: 0.82rem;
  font-weight: 600;
  color: #6b2318;
}

.devise-form__errors-list {
  margin: 0;
  padding: 0 0 0 1.1rem;
  font-size: 0.8rem;
  color: #6b2318;
}

.devise-form__errors-list li + li {
  margin-top: 0.2rem;
}

.puzzle-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.8rem;
  margin-bottom: 0.8rem;
  padding: 0.65rem 0.8rem;
  border-radius: 0.7rem;
  background: rgba(255, 255, 255, 0.65);
  border: 1px solid rgba(128, 109, 82, 0.2);
}

.puzzle-toolbar__title {
  margin: 0;
  font-size: 0.9rem;
  font-weight: 600;
}

.puzzle-toolbar__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.puzzle-editor,
.puzzle-play {
  max-width: 96rem;
  margin: 0 auto;
  padding-bottom: 4rem;
}

.puzzle-editor__card {
  margin-bottom: 1rem;
  padding: 0.8rem;
  border-radius: 0.7rem;
  background: rgba(255, 255, 255, 0.66);
  border: 1px solid rgba(128, 109, 82, 0.2);
}

.puzzle-editor__heading {
  margin: 0 0 0.65rem;
  font-size: 0.9rem;
}

.puzzle-editor__size-label {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  margin-bottom: 0.75rem;
  font-size: 0.88rem;
}

.puzzle-editor__size-label input {
  width: 5rem;
  border-radius: 0.35rem;
  border: 1px solid rgba(128, 109, 82, 0.35);
  padding: 0.3rem 0.4rem;
}

.puzzle-editor__textarea,
.puzzle-editor__fen-input {
  width: 100%;
  margin-bottom: 0.55rem;
  border-radius: 0.4rem;
  border: 1px solid rgba(128, 109, 82, 0.35);
  padding: 0.5rem;
  font: inherit;
}

.puzzle-editor__board-rows {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.puzzle-editor__board-row {
  display: grid;
  grid-template-columns: repeat(5, minmax(8rem, 1fr)) auto;
  gap: 0.45rem;
  align-items: end;
}

.puzzle-editor__board-row label {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  font-size: 0.78rem;
}

.puzzle-editor__board-row input {
  border-radius: 0.35rem;
  border: 1px solid rgba(128, 109, 82, 0.35);
  padding: 0.3rem 0.4rem;
}

.puzzle-editor__palette {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-bottom: 0.55rem;
}

.puzzle-editor__board-shell {
  display: grid;
  margin-bottom: 0.7rem;
}

.puzzle-editor__hint {
  margin: 0 0 0.45rem;
  font-size: 0.82rem;
}

.puzzle-editor__palette-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 0.35rem;
  border: 1px solid rgba(128, 109, 82, 0.35);
  background: rgba(255, 255, 255, 0.85);
  min-width: 2.1rem;
  min-height: 2.1rem;
  cursor: pointer;
}

.puzzle-editor__palette-btn--active {
  border-color: var(--board-active);
  box-shadow: inset 0 0 0 1px var(--board-active);
}

.puzzle-editor__palette-piece {
  width: 1.2rem;
  height: 1.2rem;
  object-fit: contain;
  pointer-events: none;
  user-select: none;
}

.puzzle-editor__grid {
  display: grid;
  grid-template-columns: repeat(8, 2rem);
  grid-template-rows: repeat(8, 2rem);
  gap: 0.12rem;
}

.puzzle-editor__square {
  border: 1px solid rgba(128, 109, 82, 0.24);
  background: rgba(255, 255, 255, 0.9);
  cursor: pointer;
}

.puzzle-play__message {
  margin: 0 0 0.65rem;
  font-size: 0.84rem;
}

.puzzle-play__message--error {
  color: #8a2f25;
}

.puzzle-play__message--success {
  color: #1f5f2a;
}

.puzzle-play__attempt {
  margin: 0 0 0.45rem;
  font-size: 0.82rem;
}

@media (max-width: 600px) {
  .site-nav__inner {
    padding: 0 0.75rem;
  }

  .site-nav__hamburger {
    display: flex;
  }

  .site-nav__links {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    flex-direction: column;
    background: rgba(245, 239, 227, 0.95);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid rgba(129, 110, 82, 0.2);
    box-shadow: 0 4px 12px rgba(60, 57, 52, 0.12);
    padding: 0.5rem 0;
  }

  .site-nav--open .site-nav__links {
    display: flex;
  }

  .site-nav__link {
    padding: 0.6rem 1.25rem;
    font-size: 0.88rem;
    border-radius: 0;
  }

  .lobby-page,
  .history-page {
    padding-top: 1.5rem;
    padding-left: 0.9rem;
    padding-right: 0.9rem;
  }

  .lobby-hero__title {
    font-size: 2.2rem;
  }

  .lobby-game-card {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.6rem;
  }

  .history-table th,
  .history-table td {
    padding: 0.45rem 0.4rem;
  }

  .devise-form-card {
    padding: 1.5rem 1.25rem 1.5rem;
  }

  .game-page {
    padding-right: 0.9rem;
  }

  .move-history-panel {
    position: fixed;
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    height: 80vh;
    max-height: none;
    flex-direction: column;
    border-left: none;
    border-top: 1px solid rgba(0, 0, 0, 0.08);
    border-radius: 0.75rem 0.75rem 0 0;
    box-shadow: 0 -2px 12px rgba(60, 57, 52, 0.12);
    transform: translateY(calc(80vh - 3rem));
    transition: transform 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    will-change: transform;
  }

  .move-history-panel--half {
    transform: translateY(calc(80vh - 40vh));
  }

  .move-history-panel--full {
    transform: translateY(0);
  }

  .move-history-panel__handle {
    display: flex;
  }

  .move-history-panel__body {
    flex: 1;
    overflow-y: auto;
    max-height: none;
    -webkit-overflow-scrolling: touch;
  }

  .timeline-stage-wrapper {
    margin-right: 0;
    margin-bottom: 3.5rem;
  }

  .five-d-toolbar {
    position: fixed;
    bottom: 3.5rem;
    left: 50%;
    transform: translateX(-50%);
    top: auto;
    flex-direction: row;
    flex-wrap: wrap;
    padding: 0.4rem 0.7rem;
    gap: 0.4rem;
    z-index: 101;
  }

  .five-d-toolbar__button {
    min-width: 0;
    padding: 0.4rem 0.65rem;
    font-size: 0.78rem;
  }

  .five-d-endstate {
    position: fixed;
    bottom: auto;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 150;
    text-align: center;
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(8px);
    padding: 1.2rem 2rem;
    border-radius: 0.75rem;
    box-shadow: 0 4px 20px rgba(60, 57, 52, 0.2);
  }

  .five-d-endstate__title {
    font-size: 1.4rem;
  }

  .five-d-endstate__detail {
    font-size: 0.8rem;
  }

  .move-history-panel__move {
    min-height: 2.75rem;
    display: flex;
    align-items: center;
    padding: 0.35rem 0.5rem;
  }

  .move-history-panel__control-btn,
  .move-history-panel__action-btn {
    min-height: 2.75rem;
  }

  .puzzle-toolbar {
    flex-direction: column;
    align-items: stretch;
    gap: 0.5rem;
  }

  .puzzle-toolbar__actions {
    justify-content: center;
  }

  .puzzle-toolbar__hint {
    text-align: center;
    font-size: 0.78rem;
  }
}

@media (max-width: 420px) {
  .site-nav__links {
    gap: 0;
  }

  .site-nav__link {
    padding: 0.25rem 0.35rem;
    font-size: 0.7rem;
  }

  .site-nav__link--subtle {
    font-size: 0.65rem;
  }

  .lobby-hero {
    padding: 2rem 0 1.5rem;
  }

  .lobby-hero__title {
    font-size: 1.8rem;
  }

  .lobby-hero__tagline {
    font-size: 0.88rem;
  }

  .history-page__title {
    font-size: 1.3rem;
  }

  .five-d-toolbar__button {
    font-size: 0.72rem;
    padding: 0.35rem 0.5rem;
  }

  .analytics-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .analytics-page__title {
    font-size: 1.3rem;
  }
}

@media (max-width: 844px) and (orientation: landscape) {
  .site-nav {
    height: 2.2rem;
  }

  .site-nav__inner {
    height: 2.2rem;
  }

  .site-nav__hamburger {
    display: flex;
  }

  .site-nav__links {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    flex-direction: column;
    background: rgba(245, 239, 227, 0.95);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid rgba(129, 110, 82, 0.2);
    box-shadow: 0 4px 12px rgba(60, 57, 52, 0.12);
    padding: 0.5rem 0;
  }

  .site-nav--open .site-nav__links {
    display: flex;
  }

  .move-history-panel {
    position: fixed;
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    height: 60vh;
    max-height: none;
    flex-direction: column;
    border-left: none;
    border-top: 1px solid rgba(0, 0, 0, 0.08);
    border-radius: 0.75rem 0.75rem 0 0;
    box-shadow: 0 -2px 12px rgba(60, 57, 52, 0.12);
    transform: translateY(calc(60vh - 2.5rem));
    transition: transform 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    will-change: transform;
  }

  .move-history-panel--half {
    transform: translateY(calc(60vh - 30vh));
  }

  .move-history-panel--full {
    transform: translateY(0);
  }

  .move-history-panel__handle {
    display: flex;
    padding: 0.3rem 0 0.15rem;
  }

  .move-history-panel__body {
    flex: 1;
    overflow-y: auto;
    max-height: none;
  }

  .five-d-toolbar {
    position: fixed;
    top: auto;
    bottom: 3rem;
    left: 50%;
    transform: translateX(-50%);
    flex-direction: row;
    flex-wrap: wrap;
    padding: 0.4rem 0.7rem;
    gap: 0.4rem;
    z-index: 101;
  }

  .five-d-toolbar__button {
    min-width: 0;
    padding: 0.4rem 0.65rem;
    font-size: 0.78rem;
  }

  .game-page {
    padding-right: 0.9rem;
  }

  .timeline-stage-wrapper {
    margin-right: 0;
    margin-bottom: 3rem;
  }

  .five-d-endstate {
    position: fixed;
    bottom: auto;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 150;
    text-align: center;
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(8px);
    padding: 1.2rem 2rem;
    border-radius: 0.75rem;
    box-shadow: 0 4px 20px rgba(60, 57, 52, 0.2);
  }

  .five-d-endstate__title {
    font-size: 1.4rem;
  }

  .five-d-endstate__detail {
    font-size: 0.8rem;
  }
}

/* ── Analytics dashboard ── */

.analytics-page {
  max-width: 56rem;
  margin: 0 auto;
  padding: 2.5rem 1.25rem 4rem;
}

.analytics-page__header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.75rem;
  border-bottom: 1px solid rgba(129, 110, 82, 0.18);
  padding-bottom: 0.75rem;
}

.analytics-page__title {
  margin: 0;
  font-size: 1.6rem;
  font-weight: normal;
  color: var(--button-ink);
  font-style: italic;
}

.analytics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr));
  gap: 1rem;
  margin-bottom: 2rem;
}

.analytics-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.3rem;
  padding: 1.25rem 1rem;
  background: var(--button-bg);
  border: 1px solid var(--button-border);
  border-radius: 0.5rem;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}

.analytics-card__value {
  font-size: 1.8rem;
  font-weight: bold;
  color: var(--button-ink);
}

.analytics-card__label {
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.analytics-section {
  margin-bottom: 2rem;
}

.analytics-section__title {
  font-size: 1rem;
  font-weight: normal;
  color: var(--button-ink);
  font-style: italic;
  margin: 0 0 0.75rem;
  border-bottom: 1px solid rgba(129, 110, 82, 0.12);
  padding-bottom: 0.4rem;
}

.analytics-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.analytics-table thead tr {
  border-bottom: 1px solid rgba(129, 110, 82, 0.22);
}

.analytics-table th {
  padding: 0.45rem 0.75rem;
  text-align: left;
  font-size: 0.72rem;
  font-weight: normal;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

.analytics-table td {
  padding: 0.45rem 0.75rem;
  border-bottom: 1px solid rgba(129, 110, 82, 0.08);
}

.analytics-chart {
  display: flex;
  align-items: flex-end;
  gap: 2px;
  height: 8rem;
  padding: 0.5rem 0;
}

.analytics-chart__bar-group {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  height: 100%;
  justify-content: flex-end;
}

.analytics-chart__bar {
  width: 100%;
  min-height: 2px;
  background: var(--board-active);
  border-radius: 2px 2px 0 0;
  transition: height 0.2s;
}

.analytics-chart__bar:hover {
  background: var(--branch);
}

.analytics-chart__date {
  font-size: 0.55rem;
  color: var(--muted);
  margin-top: 0.25rem;
  writing-mode: vertical-rl;
  text-orientation: mixed;
  max-height: 3rem;
  overflow: hidden;
}

/* ---- Notifications Bell ---- */
.bell-wrapper {
  position: relative;
  display: inline-flex;
  align-items: center;
}

.bell-icon-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1.2rem;
  padding: 0.25rem 0.5rem;
  color: var(--button-ink);
  position: relative;
}

.bell-badge {
  position: absolute;
  top: 0;
  right: 0;
  background: #e03a3a;
  color: #fff;
  font-size: 0.65rem;
  font-weight: bold;
  min-width: 1.1em;
  height: 1.1em;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.bell-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  background: var(--button-bg);
  border: 1px solid var(--button-border);
  border-radius: 6px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.18);
  min-width: 260px;
  max-width: 340px;
  z-index: 200;
  padding: 0.5rem;
}

.bell-dropdown__section-header {
  font-size: 0.7rem;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0.25rem 0.25rem 0.2rem;
}

.bell-dropdown__row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.25rem 0.25rem;
  border-bottom: 1px solid var(--button-border);
}

.bell-dropdown__row:last-child {
  border-bottom: none;
}

.bell-dropdown__label {
  flex: 1;
  font-size: 0.8rem;
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bell-dropdown__empty {
  font-size: 0.8rem;
  color: var(--muted);
  text-align: center;
  padding: 0.5rem;
  margin: 0;
}

.bell-btn {
  font-size: 0.75rem;
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  border: 1px solid var(--button-border);
  background: var(--button-bg);
  color: var(--button-ink);
  cursor: pointer;
  white-space: nowrap;
}

.bell-btn:hover {
  background: var(--button-bg-hover);
}

.bell-btn--accept {
  background: #d4f4d4;
  border-color: #6aaa6a;
}

.bell-btn--decline,
.bell-btn--cancel {
  background: #f4d4d4;
  border-color: #aa6a6a;
}

.bell-toast {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 500;
  animation: fadeInOut 4s forwards;
}

@keyframes fadeInOut {
  0%   { opacity: 0; transform: translateY(10px); }
  10%  { opacity: 1; transform: translateY(0); }
  80%  { opacity: 1; }
  100% { opacity: 0; }
}

/* ---- Duel Button & Modal ---- */
.duel-region {
  margin-top: 0.75rem;
}

.duel-btn {
  font-size: 0.85rem;
  padding: 0.35rem 0.85rem;
  border-radius: 4px;
  border: 1px solid var(--button-border);
  background: var(--button-primary);
  color: var(--button-ink);
  cursor: pointer;
  font-weight: 600;
}

.duel-btn:hover:not(:disabled) {
  background: var(--button-primary-border);
}

.duel-btn--disabled,
.duel-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.duel-modal {
  position: fixed;
  inset: 0;
  z-index: 400;
  display: flex;
  align-items: center;
  justify-content: center;
}

.duel-modal[hidden] {
  display: none;
}

.duel-modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.45);
}

.duel-modal__box {
  position: relative;
  background: var(--button-bg);
  border: 1px solid var(--button-border);
  border-radius: 8px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.25);
  padding: 1.5rem 1.75rem;
  min-width: 280px;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.duel-modal__title {
  margin: 0 0 0.25rem;
  font-size: 1.1rem;
  color: var(--ink);
}

.duel-modal__label {
  font-size: 0.85rem;
  color: var(--muted);
}

.duel-modal__label--inline {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  cursor: pointer;
}

.duel-modal__select {
  font-size: 0.9rem;
  padding: 0.3rem 0.5rem;
  border: 1px solid var(--button-border);
  border-radius: 4px;
  background: var(--button-bg);
  color: var(--ink);
}

.duel-modal__actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.25rem;
}

.duel-modal__error {
  color: #c0392b;
  font-size: 0.8rem;
  margin: 0;
}
