
/* ===== App shell: sidebar + content ===== */
.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--sidebar-width);
  background: var(--sidebar);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  z-index: 50;
  padding: var(--s-16) var(--s-12);
  border-right: 1px solid #1a1917;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: var(--s-12);
  padding: var(--s-8) var(--s-12) var(--s-20);
  font-weight: var(--fw-extrabold);
  font-size: var(--fs-18);
  letter-spacing: 0;
  color: #ffffff;
}

.sidebar-brand .logo-mark {
  width: 34px;
  height: 34px;
  border-radius: var(--radius-card);
  background: var(--accent);
  display: grid;
  place-items: center;
  color: #ffffff;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.sidebar-brand .logo-mark [data-lucide] {
  width: 20px;
  height: 20px;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
  overflow-y: auto;
}

.nav-section-label {
  margin: var(--s-16) var(--s-12) var(--s-6);
  font-size: var(--fs-11);
  font-weight: var(--fw-bold);
  color: var(--sidebar-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: var(--s-12);
  padding: 10px var(--s-12);
  border-radius: var(--radius-card);
  color: var(--sidebar-text);
  font-size: var(--fs-14);
  font-weight: var(--fw-medium);
  transition: background 0.12s ease, color 0.12s ease;
}

.nav-link:hover {
  background: var(--sidebar-hover);
  color: #ffffff;
}

.nav-link.is-active {
  background: var(--sidebar-active);
  color: var(--accent);
  font-weight: var(--fw-bold);
}

.nav-link [data-lucide] {
  width: 18px;
  height: 18px;
}

.nav-sub {
  display: flex;
  flex-direction: column;
  gap: 1px;
  margin: 0 0 var(--s-8) var(--s-16);
  padding-left: var(--s-12);
  border-left: 2px solid #3d3b38;
}

.nav-sub .nav-link {
  padding: 7px var(--s-10);
  font-size: var(--fs-13);
  color: var(--sidebar-muted);
}

.nav-sub .nav-link:hover {
  color: #ffffff;
}

.nav-sub .nav-link.is-active {
  color: var(--accent);
  background: transparent;
}

.sidebar-foot {
  margin-top: auto;
  padding-top: var(--s-16);
  border-top: 1px solid #363430;
  display: flex;
  flex-direction: column;
  gap: var(--s-12);
}

.account-block {
  display: flex;
  align-items: center;
  gap: var(--s-12);
  padding: var(--s-8) var(--s-10);
  background: rgba(255, 255, 255, 0.04);
  border-radius: var(--radius-card);
}

.account-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--accent);
  color: #ffffff;
  display: grid;
  place-items: center;
  font-weight: var(--fw-bold);
  font-size: var(--fs-14);
  flex-shrink: 0;
}

.account-meta {
  min-width: 0;
  flex: 1;
}

.account-meta strong {
  display: block;
  font-size: var(--fs-13);
  font-weight: var(--fw-semibold);
  color: #ffffff;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.account-meta span,
.account-meta a {
  font-size: var(--fs-12);
  color: var(--sidebar-muted);
}

.account-meta a:hover {
  color: var(--accent);
  text-decoration: underline;
}

.lang-switch {
  display: inline-flex;
  background: #1e1d1b;
  border: 1px solid #383633;
  border-radius: var(--radius-pill);
  padding: 2px;
  align-self: stretch;
}

.lang-switch [data-lang] {
  flex: 1;
  border: 0;
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--sidebar-muted);
  padding: 5px 0;
  cursor: pointer;
  font-size: var(--fs-12);
  font-weight: var(--fw-bold);
  transition: background 0.12s ease, color 0.12s ease;
}

.lang-switch [data-lang]:hover {
  color: #ffffff;
}

.lang-switch [data-lang].is-active {
  background: var(--accent);
  color: #ffffff;
}

.mobile-top {
  display: none;
  position: sticky;
  top: 0;
  z-index: 40;
  height: var(--header-mobile);
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--s-16);
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.mobile-top .brand-mini {
  font-weight: var(--fw-bold);
  font-size: var(--fs-16);
}

.icon-btn {
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: var(--radius-card);
  background: transparent;
  color: var(--ink);
  display: grid;
  place-items: center;
  cursor: pointer;
  touch-action: manipulation;
}

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

.bottom-nav {
  display: none;
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: var(--bottom-nav);
  background: var(--sidebar);
  border-top: 1px solid #363430;
  z-index: 45;
  justify-content: space-around;
  align-items: center;
  padding: 0 var(--s-8) env(safe-area-inset-bottom, 0px);
  box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.4);
}

.bottom-nav a {
  color: var(--sidebar-muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: 10px;
  font-weight: var(--fw-medium);
  padding: var(--s-4) var(--s-6);
  min-height: 44px;
  min-width: 48px;
  height: 100%;
}

.bottom-nav a.is-active {
  color: var(--accent);
}

.content {
  flex: 1;
  margin-left: var(--sidebar-width);
  min-width: 0;
  padding: var(--s-24) var(--s-32) var(--s-48);
}

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 45;
}

body.sidebar-open {
  overflow: hidden;
}

body.sidebar-open .sidebar-backdrop {
  display: block;
}

/* ===== Lobby: Chess.com style Dashboard ===== */
.lobby-layout {
  display: grid;
  grid-template-columns: minmax(360px, 480px) minmax(320px, 420px);
  gap: var(--s-32);
  align-items: start;
  max-width: 1080px;
  margin: 0 auto;
}

.lobby-hero-board {
  display: flex;
  flex-direction: column;
  gap: var(--s-16);
}

.lobby-board-frame {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  border-radius: 6px;
  overflow: hidden;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
  border: 4px solid #4a3e2c;
  background: var(--board-dark);
}

.lobby-board-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--s-12) var(--s-16);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
}

.lobby-board-banner strong {
  font-size: var(--fs-14);
  color: var(--ink);
}

.lobby-board-banner span {
  font-size: var(--fs-12);
  color: var(--muted);
}

/* Play Console (Modes) */
.play-console {
  display: flex;
  flex-direction: column;
  gap: var(--s-16);
}

.console-header {
  padding-bottom: var(--s-4);
}

.console-header h1 {
  font-size: var(--fs-24);
  font-weight: var(--fw-extrabold);
}

.console-header p {
  margin: var(--s-4) 0 0;
  font-size: var(--fs-14);
  color: var(--muted);
}

/* Mode Card Item */
.mode-card-compact {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  padding: var(--s-16);
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: var(--s-12);
  transition: border-color 0.15s ease;
}

.mode-card-compact:hover {
  border-color: #cbd5e1;
}

.mode-head {
  display: flex;
  align-items: center;
  gap: var(--s-12);
}

.mode-icon-circle {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-card);
  background: var(--ok-bg);
  color: var(--accent-hover);
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.mode-icon-circle [data-lucide] {
  width: 20px;
  height: 20px;
}

.mode-head-text {
  flex: 1;
  min-width: 0;
}

.mode-head-text h2 {
  font-size: var(--fs-16);
  font-weight: var(--fw-bold);
  margin: 0;
}

.mode-head-text p {
  margin: 2px 0 0;
  font-size: var(--fs-13);
  color: var(--muted);
}

.difficulty-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--s-4);
  background: var(--bg);
  padding: 3px;
  border-radius: var(--radius-card);
  border: 1px solid var(--line);
}

.diff-tab {
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: var(--fs-13);
  font-weight: var(--fw-semibold);
  padding: 6px 0;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease;
}

.diff-tab:hover {
  color: var(--ink);
}

.diff-tab.is-active {
  background: var(--surface);
  color: var(--ink);
  font-weight: var(--fw-bold);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.friend-tabs {
  display: flex;
  gap: var(--s-8);
  margin-bottom: var(--s-4);
}

.friend-tab-btn {
  flex: 1;
  border: 1px solid var(--line);
  background: var(--bg);
  border-radius: var(--radius-sm);
  font-size: var(--fs-12);
  font-weight: var(--fw-semibold);
  padding: 6px 0;
  cursor: pointer;
}

.friend-tab-btn.is-active {
  background: var(--surface);
  border-color: var(--accent);
  color: var(--accent-hover);
  font-weight: var(--fw-bold);
}

.invite-box {
  display: none;
  padding: var(--s-12);
  background: var(--ok-bg);
  border: 1px solid var(--ok-border);
  border-radius: var(--radius-card);
}

.invite-box.is-visible {
  display: block;
}

.invite-box code {
  display: block;
  word-break: break-all;
  padding: var(--s-6) var(--s-8);
  background: var(--surface);
  border: 1px solid #d4e8c1;
  border-radius: var(--radius-sm);
  margin: var(--s-6) 0 var(--s-8);
  font-size: var(--fs-12);
  font-family: monospace;
}

/* Matchmaking active search state */
.mm-search-box {
  display: flex;
  align-items: center;
  gap: var(--s-12);
  padding: var(--s-10) var(--s-12);
  background: var(--warn-bg);
  border: 1px solid var(--warn-border);
  border-radius: var(--radius-card);
  color: var(--warn-text);
  font-size: var(--fs-13);
  font-weight: var(--fw-semibold);
}

.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid #e0c58b;
  border-top-color: #8a6414;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* Guest prompt banner */
.guest-banner {
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius-card);
  padding: var(--s-12) var(--s-16);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-12);
}

.guest-banner p {
  margin: 0;
  font-size: var(--fs-13);
  color: var(--ink);
}

.guest-banner span {
  display: block;
  font-size: var(--fs-12);
  color: var(--muted);
}

/* Active games panel */
.active-games-panel {
  display: flex;
  flex-direction: column;
  gap: var(--s-8);
}

.active-game-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--s-10) var(--s-12);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
}

.active-game-item .active-game-end {
  color: #ffb6b2;
  border-color: rgba(255, 107, 102, 0.34);
}

.active-game-info strong {
  font-size: var(--fs-14);
}

.active-game-info span {
  font-size: var(--fs-12);
  color: var(--muted);
  display: block;
}

/* Stats Widget in Console */
.stats-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  padding: var(--s-16);
}

.stats-card h3 {
  margin-bottom: var(--s-12);
  font-size: var(--fs-14);
  font-weight: var(--fw-bold);
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--s-8);
}

.stat-box {
  background: var(--bg);
  border-radius: var(--radius-sm);
  padding: var(--s-10) var(--s-8);
  text-align: center;
}

.stat-box strong {
  display: block;
  font-size: var(--fs-20);
  font-weight: var(--fw-extrabold);
  color: var(--ink);
}

.stat-box span {
  font-size: var(--fs-11);
  font-weight: var(--fw-semibold);
  color: var(--muted);
  text-transform: uppercase;
}

/* ===== Game Page: Chess.com style Play View ===== */
.play-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: var(--s-28);
  align-items: start;
  max-width: 1040px;
  margin: 0 auto;
}

.board-column {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.board-frame {
  width: min(100%, calc(100vh - 140px), 620px);
  display: grid;
  grid-template-columns: 22px 1fr;
  grid-template-rows: 1fr 22px;
  gap: 2px;
}

.board-wrap {
  grid-column: 2;
  grid-row: 1;
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  border-radius: 4px;
  overflow: hidden;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.14);
  border: 3px solid #3c3224;
  touch-action: manipulation;
  background: var(--board-dark);
}

.rank-labels,
.file-labels {
  display: grid;
  color: #8b8884;
  font-size: 11px;
  font-weight: var(--fw-bold);
  user-select: none;
}

.rank-labels {
  grid-column: 1;
  grid-row: 1;
  grid-template-rows: repeat(8, 1fr);
  align-items: center;
  justify-items: center;
}

.file-labels {
  grid-column: 2;
  grid-row: 2;
  grid-template-columns: repeat(8, 1fr);
  align-items: center;
  justify-items: center;
}

.board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  width: 100%;
  height: 100%;
  position: relative;
  touch-action: none;
}

.board.is-dragging,
.board.is-dragging .sq {
  cursor: grabbing;
}

body.board-piece-dragging {
  cursor: grabbing !important;
  user-select: none;
}

body.board-piece-dragging .piece {
  transition: none;
}

.board-annotations {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 8;
}

.board-arrow,
.board-circle {
  stroke: rgba(245, 196, 55, 0.88);
  stroke-width: 0.58;
  fill: none;
}

.board-arrow-tip { fill: rgba(245, 196, 55, 0.88); }

.sq {
  position: relative;
  user-select: none;
  cursor: default;
}

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

.sq.dark {
  background: var(--board-dark);
  cursor: pointer;
}

.sq.can-move {
  cursor: grab;
}

.sq.selected {
  background-color: #bbc759 !important;
}

.sq.last-from,
.sq.last-to {
  background-color: var(--sq-last-move) !important;
}

.sq.premove-from,
.sq.premove-to {
  background-color: rgba(235, 97, 80, 0.78) !important;
}

.sq.premove-path:not(.premove-from):not(.premove-to) {
  background-color: rgba(235, 97, 80, 0.38) !important;
}

.sq.premove-hl::after {
  content: "";
  position: absolute;
  inset: 34%;
  border-radius: 50%;
  background: rgba(220, 60, 50, 0.45);
  pointer-events: none;
  z-index: 5;
}

.sq.premove-cap::after {
  content: "";
  position: absolute;
  inset: 12%;
  border-radius: 50%;
  border: 4px solid rgba(220, 60, 50, 0.85);
  background: transparent;
  pointer-events: none;
  z-index: 5;
}

.sq.drag-over.drop-target {
  background-color: #cdd86a !important;
}

.sq.drag-over.drop-target.premove-hl,
.sq.drag-over.drop-target.premove-cap {
  background-color: rgba(235, 97, 80, 0.55) !important;
}

.sq.hl,
.sq.cap {
  transition: background-color 0.12s ease;
}

/* Valid move hint dot */
.sq.hl::after {
  content: "";
  position: absolute;
  inset: 34%;
  border-radius: 50%;
  background: rgba(30, 29, 27, 0.28);
  pointer-events: none;
  z-index: 5;
}

/* Capture target hint ring */
.sq.cap::after {
  content: "";
  position: absolute;
  inset: 12%;
  border-radius: 50%;
  border: 4px solid var(--danger);
  background: transparent;
  pointer-events: none;
  z-index: 5;
}

/* Checkers pieces styling */
.piece {
  position: absolute;
  inset: 10%;
  border-radius: 50%;
  z-index: 2;
  pointer-events: none;
  transition:
    transform 0.22s cubic-bezier(0.22, 1, 0.36, 1),
    opacity 0.16s ease,
    box-shadow 0.16s ease;
  box-shadow: 0 3px 5px rgba(0, 0, 0, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  will-change: transform;
}

.piece.is-drag-source {
  opacity: 0.22;
  transform: scale(0.92);
  box-shadow: none;
  transition: opacity 0.1s ease, transform 0.1s ease;
}

.piece.is-moving {
  z-index: 30;
  transition: transform 0.24s cubic-bezier(0.22, 1, 0.36, 1);
  box-shadow: 0 10px 18px rgba(0, 0, 0, 0.38);
  pointer-events: none;
}

.piece.is-landing {
  animation: piece-land 0.22s cubic-bezier(0.22, 1, 0.36, 1);
}

@keyframes piece-land {
  0% { transform: scale(1); }
  55% { transform: scale(1.1); }
  100% { transform: scale(1); }
}

.piece.piece-ghost,
body.game-page .piece.piece-ghost {
  position: fixed !important;
  top: 0 !important;
  left: 0 !important;
  right: auto !important;
  bottom: auto !important;
  z-index: 2000;
  margin: 0;
  pointer-events: none;
  transition: none !important;
  animation: none !important;
  box-shadow: 0 14px 28px rgba(0, 0, 0, 0.42);
  will-change: transform;
  transform-origin: top left;
}

/* White piece */
.piece.white {
  background: radial-gradient(circle at 35% 30%, #ffffff 0%, var(--piece-white-shade) 55%, var(--piece-white-rim) 100%);
  border: 2px solid #ded6c8;
}

.piece.white::before {
  content: "";
  position: absolute;
  inset: 18%;
  border-radius: 50%;
  border: 2px solid rgba(160, 150, 135, 0.35);
}

/* Black piece */
.piece.black {
  background: radial-gradient(circle at 35% 30%, #4a4642 0%, var(--piece-black-shade) 55%, var(--piece-black-rim) 100%);
  border: 2px solid #201e1d;
}

.piece.black::before {
  content: "";
  position: absolute;
  inset: 18%;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.15);
}

/* King / Damka Crown */
.piece.king .crown-icon {
  width: 24px;
  height: 24px;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.4));
  z-index: 4;
}

.piece.white.king .crown-icon {
  color: #b8860b;
}

.piece.black.king .crown-icon {
  color: #f1c40f;
}

/* Mandatory capture highlight on piece */
.piece.must-capture {
  box-shadow: 0 0 0 3px #e74c3c, 0 0 10px rgba(231, 76, 60, 0.6);
  animation: pulse-capture 1.3s infinite ease-in-out;
}

@keyframes pulse-capture {
  0%, 100% { box-shadow: 0 0 0 3px #e74c3c, 0 0 8px rgba(231, 76, 60, 0.5); }
  50% { box-shadow: 0 0 0 4px #c0392b, 0 0 14px rgba(231, 76, 60, 0.9); }
}

.piece.capturing {
  animation: piece-capture 0.22s cubic-bezier(0.4, 0, 0.2, 1) forwards;
  z-index: 25;
}

@keyframes piece-capture {
  0% {
    transform: scale(1);
    opacity: 1;
  }
  100% {
    transform: scale(0.12);
    opacity: 0;
  }
}

/* Game side panel */
.side-panel {
  display: flex;
  flex-direction: column;
  gap: var(--s-12);
}

/* Player cards in Play view */
.player-card {
  display: flex;
  align-items: center;
  gap: var(--s-12);
  padding: var(--s-12) var(--s-16);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  transition: border-color 0.15s ease;
}

.player-card.is-active-turn {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}

.player-card .avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: var(--fw-bold);
  font-size: var(--fs-14);
  color: #ffffff;
  background: #504d49;
  flex-shrink: 0;
}

.player-card .avatar.you {
  background: var(--accent);
}

.player-meta {
  min-width: 0;
  flex: 1;
}

.player-meta strong {
  display: block;
  font-size: var(--fs-14);
  font-weight: var(--fw-bold);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.player-meta span {
  font-size: var(--fs-12);
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 4px;
}

.piece-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 1px solid #777;
}

.piece-dot.white { background: #fff; }
.piece-dot.black { background: #333; }

/* Status Banner */
.status-banner {
  padding: var(--s-10) var(--s-16);
  border-radius: var(--radius-card);
  background: var(--ok-bg);
  border: 1px solid var(--ok-border);
  color: var(--ok-text);
  font-weight: var(--fw-bold);
  font-size: var(--fs-14);
  text-align: center;
}

.status-banner.warn {
  background: var(--warn-bg);
  border-color: var(--warn-border);
  color: var(--warn-text);
}

.status-banner.danger {
  background: #fdeeee;
  border-color: #f5c2c2;
  color: #b52a2a;
}

/* Actions Row */
.actions-row {
  display: flex;
  gap: var(--s-8);
}

.actions-row .btn {
  flex: 1;
  font-size: var(--fs-13);
  height: 38px;
}

/* Move Notation Log */
.move-log-panel {
  padding: var(--s-14) var(--s-16);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  max-height: 220px;
  display: flex;
  flex-direction: column;
}

.move-log-panel h3 {
  font-size: var(--fs-12);
  margin-bottom: var(--s-8);
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.move-log {
  overflow-y: auto;
  font-variant-numeric: tabular-nums;
  font-size: var(--fs-13);
  font-family: monospace;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.move-log-row {
  display: grid;
  grid-template-columns: 28px 1fr 1fr;
  padding: 3px 4px;
  border-radius: 3px;
}

.move-log-row:nth-child(even) {
  background: var(--bg);
}

.move-log-row .num {
  color: var(--muted);
  font-weight: var(--fw-bold);
}

.move-log-row .white-move,
.move-log-row .black-move {
  font-weight: var(--fw-medium);
}

/* Modal Overlay (Game Over, Resign Confirm) */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: var(--s-16);
  animation: modal-fade-in 0.15s ease;
}

@keyframes modal-fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal-dialog {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: var(--s-28);
  width: min(380px, 100%);
  box-shadow: var(--shadow-modal);
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: var(--s-16);
  animation: modal-pop 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes modal-pop {
  from { transform: scale(0.92); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.modal-dialog h2 {
  font-size: var(--fs-24);
  font-weight: var(--fw-extrabold);
  margin: 0;
}

.modal-dialog p {
  margin: 0;
  color: var(--muted);
  font-size: var(--fs-14);
}

/* ===== Auth Pages ===== */
.auth-page {
  position: relative;
  min-height: 100vh;
  min-height: 100dvh;
  min-height: -webkit-fill-available;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--s-24);
  background: var(--bg);
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  box-sizing: border-box;
}

.auth-card {
  width: min(400px, 100%);
  padding: var(--s-32);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
}

.auth-card h1 {
  margin-bottom: var(--s-6);
  font-size: var(--fs-24);
}

.auth-card .lead {
  margin: 0 0 var(--s-20);
  color: var(--muted);
  font-size: var(--fs-14);
}

.auth-card form {
  display: flex;
  flex-direction: column;
  gap: var(--s-14);
}

.auth-links {
  margin-top: var(--s-20);
  text-align: center;
  font-size: var(--fs-14);
  color: var(--muted);
}

.auth-links a {
  color: var(--accent-hover);
  font-weight: var(--fw-bold);
}

.auth-top-lang {
  position: absolute;
  top: var(--s-16);
  right: var(--s-16);
}

/* Focused sign-in scene; the board is decorative and kept outside the form flow. */
.auth-page {
  isolation: isolate;
  padding: 28px;
  background: #111a22;
}

.auth-board-backdrop {
  position: absolute;
  z-index: -1;
  width: min(74vw, 940px);
  aspect-ratio: 1;
  right: max(-12vw, -150px);
  top: 50%;
  transform: translateY(-50%) rotate(10deg);
  opacity: 0.96;
}

.auth-board-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  width: 100%;
  height: 100%;
  border: 12px solid #252c2e;
  box-shadow: 0 24px 72px rgba(0, 0, 0, 0.46);
}

.auth-board-grid span { background: #e0d7be; }
.auth-board-grid span:nth-child(16n + 1),
.auth-board-grid span:nth-child(16n + 3),
.auth-board-grid span:nth-child(16n + 5),
.auth-board-grid span:nth-child(16n + 7),
.auth-board-grid span:nth-child(16n + 10),
.auth-board-grid span:nth-child(16n + 12),
.auth-board-grid span:nth-child(16n + 14),
.auth-board-grid span:nth-child(16n + 16) { background: #607f58; }

.auth-piece {
  position: absolute;
  width: 12.5%;
  aspect-ratio: 1;
  border-radius: 50%;
  box-shadow: inset 0 8px 0 rgba(255, 255, 255, 0.18), inset 0 -8px 0 rgba(0, 0, 0, 0.2), 0 10px 16px rgba(0, 0, 0, 0.28);
}

.auth-piece-black { background: #252a2a; }
.auth-piece-white { background: #f2eee0; }
.auth-piece.piece-one { left: 23%; top: 19%; }
.auth-piece.piece-two { left: 48%; top: 31.5%; }
.auth-piece.piece-three { left: 61%; top: 57%; }
.auth-piece.piece-four { left: 35.5%; top: 69.5%; }

.auth-card {
  position: relative;
  width: min(420px, 100%);
  padding: 34px;
  background: rgba(250, 251, 249, 0.97);
  border: 1px solid rgba(255, 255, 255, 0.72);
  border-radius: 8px;
  box-shadow: 0 18px 56px rgba(0, 0, 0, 0.3);
}

.auth-brand {
  display: inline-block;
  margin-bottom: 22px;
  color: #466e42;
  font-size: 15px;
  font-weight: var(--fw-extrabold);
  letter-spacing: 0;
  text-decoration: none;
}

.auth-card h1 { font-size: 28px; }
.auth-card .lead { margin-bottom: 24px; }
.auth-card .field input { background: #ffffff; }
.auth-card .btn { min-height: 44px; }
.auth-home-link { display: inline-block; margin-top: 12px; color: var(--muted); font-weight: var(--fw-normal); }

.auth-top-lang {
  z-index: 2;
  top: 22px;
  right: 24px;
}

.auth-top-lang .lang-switch {
  display: flex;
  align-items: center;
  width: auto;
  height: 36px;
  padding: 3px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 6px;
  background: rgba(17, 26, 34, 0.82);
}

.auth-top-lang .lang-switch [data-lang] {
  flex: 0 0 auto;
  min-width: 39px;
  height: 28px;
  padding: 0 8px;
  border-radius: 4px;
  color: #cbd5dc;
  font-size: 11px;
}

.auth-top-lang .lang-switch [data-lang].is-active { background: #5e9858; color: #ffffff; }

@media (max-width: 700px) {
  .auth-page { place-items: center; padding: 76px 18px 24px; }
  .auth-board-backdrop { width: 110vw; right: -45vw; top: 78%; opacity: 0.34; }
  .auth-card { padding: 28px 22px; }
  .auth-top-lang { top: 16px; right: 16px; }
}

/* Full-bleed login scene, based on the supplied checkers reference. */
.auth-page {
  background: #06131b;
}

.auth-board-backdrop {
  position: fixed;
  z-index: 0;
  inset: 0;
  width: auto;
  aspect-ratio: auto;
  transform: none;
  opacity: 1;
  background: #06131b url('/images/login-board-scene-d5a66dbbc74bf4df75da7f7336e793f6.png') center / cover no-repeat;
}

.auth-board-backdrop::after {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(1, 10, 15, 0.24);
}

.auth-board-grid,
.auth-piece { display: none; }

.auth-card {
  z-index: 1;
  width: min(606px, calc(100vw - 36px));
  padding: 34px 54px 32px;
  color: #eef5f7;
  text-align: center;
  background: #06151e;
  border: 1px solid rgba(26, 220, 130, 0.72);
  border-radius: 18px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.5), inset 0 1px rgba(255, 255, 255, 0.04);
}

.auth-page .auth-card { border-color: rgba(26, 220, 130, 0.72); }

.auth-mark {
  position: relative;
  width: 52px;
  height: 42px;
  margin: 0 auto 12px;
}

.auth-mark i {
  position: absolute;
  width: 33px;
  height: 15px;
  border: 3px solid #d6d5cb;
  border-radius: 50%;
  background: repeating-radial-gradient(ellipse at center, #3e4449 0 2px, #131a1f 3px 5px);
  transform: rotate(-17deg);
  box-shadow: 0 3px 0 #080d10, 0 7px 8px rgba(0, 0, 0, 0.4);
}

.auth-mark i:first-child { left: 3px; top: 7px; }
.auth-mark i:last-child { right: 1px; top: 14px; border-color: #f4d8a4; background: repeating-radial-gradient(ellipse at center, #f4e6c9 0 2px, #b8874e 3px 5px); transform: rotate(14deg); }

.auth-card h1 {
  margin: 0 0 2px;
  color: #f8fbfc;
  font-size: 40px;
  line-height: 1.15;
}

.auth-card .lead { margin: 0 0 25px; color: #90a8bb; font-size: 16px; }
.auth-card form { gap: 18px; text-align: left; }
.auth-card .field { gap: 7px; }
.auth-card .field label { color: #d6e1e9; font-size: 11px; font-weight: var(--fw-bold); letter-spacing: 1.7px; text-transform: uppercase; }

.auth-input-control {
  display: flex;
  align-items: center;
  min-height: 58px;
  padding: 0 17px;
  border: 1px solid #3d596b;
  border-radius: 14px;
  background: rgba(11, 31, 43, 0.9);
}

.auth-input-control:focus-within { border-color: #61df76; box-shadow: 0 0 0 3px rgba(97, 223, 118, 0.15); }
.auth-input-control > svg { width: 21px; margin-right: 15px; color: #8ea7ba; flex: 0 0 auto; }
.auth-input-control input,
.auth-card .field input {
  min-width: 0;
  height: 56px;
  padding: 0;
  border: 0;
  background: transparent;
  color: #eff5f7;
  box-shadow: none;
}
.auth-input-control input:focus { box-shadow: none; }
.auth-input-control input::placeholder { color: #829cb0; }

.auth-card .btn {
  min-height: 58px;
  border-radius: 14px;
  font-size: 17px;
  font-weight: var(--fw-bold);
}
.auth-card .btn-primary { margin-top: 4px; box-shadow: 0 8px 22px rgba(59, 218, 91, 0.27); }
.auth-card .btn-ghost { background: transparent; border-color: #466176; color: #f2f6f8; }
.auth-card .muted { margin: 2px 0 0; color: #8da6b8; text-align: center; }
.auth-links { margin-top: 22px; color: #95aabd; }
.auth-links a { color: #65e477; }
.auth-home-link { display: block; color: #91a9bc; }
.auth-top-lang { top: 22px; right: 28px; }
.auth-top-lang .lang-switch { background: rgba(4, 19, 27, 0.85); border-color: rgba(126, 169, 188, 0.35); }

/* Final geometry for the supplied authentication reference. */
.auth-page .auth-top-lang {
  display: block;
  position: fixed;
  z-index: 2;
  top: 24px;
  right: 28px;
}
.auth-page .auth-top-lang .lang-switch {
  display: inline-flex;
  width: auto;
  height: 42px;
  padding: 4px;
  gap: 2px;
  border: 1px solid rgba(108, 184, 204, 0.42);
  border-radius: 9px;
  background: rgba(3, 18, 27, 0.78);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.24), inset 0 1px rgba(255, 255, 255, 0.04);
  backdrop-filter: blur(10px);
}
.auth-page .auth-top-lang .lang-switch [data-lang] {
  flex: 0 0 auto;
  min-width: 38px;
  height: 32px;
  padding: 0 8px;
  border-radius: 6px;
  color: #b7c9d5;
  font-size: 11px;
  line-height: 1;
  letter-spacing: 0.4px;
}
.auth-page .auth-top-lang .lang-switch [data-lang]:hover { color: #ffffff; background: rgba(105, 219, 114, 0.14); }
.auth-page .auth-top-lang .lang-switch [data-lang].is-active {
  background: #6b9f63;
  color: #ffffff;
  box-shadow: inset 0 -1px rgba(0, 0, 0, 0.18);
}
.auth-page .auth-card {
  padding-bottom: 26px;
  border-color: #10b878;
}
.auth-page .auth-mark { margin-bottom: 32px; }
.auth-page .field-error:empty { display: none; }
.auth-page .btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 13px;
}
.auth-page .btn-primary svg { width: 21px; height: 21px; }

/* ===== Game table: dark competitive layout ===== */
.game-page {
  background: #07121c;
  color: #dce8f4;
}

.game-page .game-content {
  min-height: 100vh;
  min-width: 0;
  margin-left: 272px;
  padding: 32px 36px;
  overflow-x: hidden;
  background:
    radial-gradient(circle at 50% -20%, rgba(30, 76, 96, 0.22), transparent 46%),
    #07121c;
}

.game-page .sidebar {
  width: 272px;
}

.game-page .play-layout {
  grid-template-columns: minmax(0, 1fr) minmax(280px, 420px);
  gap: 32px;
  max-width: 1330px;
  width: 100%;
  margin: 0 auto;
  align-items: stretch;
}

.game-page .board-column {
  justify-content: center;
  min-width: 0;
  max-width: 100%;
}

.game-page .board-frame {
  width: min(100%, calc(100vh - 118px), 760px);
  max-width: 100%;
  padding: 18px 14px 10px;
  grid-template-columns: 26px minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr) 24px;
  gap: 3px;
  border: 1px solid rgba(99, 160, 181, 0.16);
  border-radius: 24px;
  background: linear-gradient(145deg, rgba(26, 48, 61, 0.98), rgba(8, 22, 32, 0.98));
  box-shadow: 0 22px 52px rgba(0, 0, 0, 0.28), inset 0 1px rgba(255, 255, 255, 0.04);
}

.game-page .board-wrap {
  border: 0;
  border-radius: 6px;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.32);
}
.game-page .rank-labels,
.game-page .file-labels { color: #9bb0c5; font-size: 16px; }
.game-page .sq.light { background: #edf0d2; }
.game-page .sq.dark { background: #5f8a48; }
.game-page .piece { inset: 12%; box-shadow: 0 7px 10px rgba(0, 0, 0, 0.42); }
.game-page .piece.black { background: radial-gradient(circle at 35% 27%, #656565, #111 52%, #010101 100%); border-color: #030303; }
.game-page .piece.white { background: radial-gradient(circle at 35% 27%, #fff, #eeeae1 58%, #c9c2b4 100%); }

.game-page .side-panel {
  height: min(calc(100vh - 64px), 724px);
  min-width: 0;
  min-height: 0;
  padding: 18px;
  gap: 14px;
  border: 1px solid rgba(94, 158, 181, 0.35);
  border-radius: 22px;
  background: linear-gradient(145deg, rgba(25, 45, 57, 0.96), rgba(10, 24, 35, 0.98));
  box-shadow: 0 22px 52px rgba(0, 0, 0, 0.24), inset 0 1px rgba(255, 255, 255, 0.04);
}

.game-page .player-card {
  min-height: 76px;
  padding: 12px;
  border-color: rgba(102, 167, 191, 0.26);
  border-radius: 14px;
  background: linear-gradient(125deg, rgba(7, 22, 32, 0.98), rgba(17, 38, 51, 0.94));
}
.game-page .player-card .avatar { width: 60px; height: 60px; font-size: 22px; background: #676a69; }
.game-page .player-card .avatar.you { background: linear-gradient(145deg, #5af187, #1ac964); }
.game-page .player-meta strong { font-size: 18px; color: #ecf4ff; }
.game-page .player-meta span { font-size: 15px; color: #a8bad1; }
.game-page .piece-dot.white { background: #ffffff; border: 1px solid #c9c2b4; }
.game-page .piece-dot.black { background: #111111; border: 1px solid #444444; }

.game-page .status-banner {
  min-height: 56px;
  border-color: rgba(103, 238, 133, 0.65);
  border-radius: 14px;
  background: linear-gradient(105deg, #eefbe8, #c9f4cf);
  color: #154f25;
  font-size: 18px;
  box-shadow: 0 8px 22px rgba(79, 222, 111, 0.22);
}
.game-page .status-banner.warn { background: #fff1c7; color: #725317; border-color: #e7bf62; }
.game-page .status-banner.danger { background: #3a1820; color: #ffb4b4; border-color: #bd4252; }

.game-page .actions-row { gap: 12px; }
.game-page .actions-row .btn {
  min-width: 0;
  height: 58px;
  padding: 0 12px;
  border-radius: 13px;
  border-color: rgba(96, 151, 185, 0.38);
  background: linear-gradient(145deg, #1a3145, #0e1e2e);
  color: #ecf3ff;
  box-shadow: inset 0 2px rgba(140, 186, 217, 0.12), 0 4px 0 rgba(2, 10, 16, 0.7);
}
.game-page .actions-row .btn-danger { border-color: #f04e5a; background: linear-gradient(145deg, #ff4c54, #cd1f32); color: #fff; }
.game-page .actions-row .btn > svg { flex: 0 0 auto; }

.game-page .move-log-panel {
  flex: 1;
  min-height: 0;
  max-height: none;
  padding: 16px 18px;
  border-color: rgba(95, 158, 182, 0.3);
  border-radius: 16px;
  background: rgba(5, 20, 30, 0.72);
}
.game-page .move-log-panel h3 {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-bottom: 15px;
  border-bottom: 1px solid rgba(97, 148, 173, 0.18);
  color: #b6c7dd;
  font-size: 18px;
  letter-spacing: 0;
  text-transform: none;
}
.game-page .move-log-panel h3 svg { width: 24px; height: 24px; padding: 4px; border-radius: 7px; background: #243b51; }
.game-page .move-log {
  min-height: 0;
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-color: rgba(105, 219, 114, 0.58) transparent;
}
.game-page .move-log::-webkit-scrollbar { width: 7px; }
.game-page .move-log::-webkit-scrollbar-thumb { border-radius: 999px; background: rgba(105, 219, 114, 0.5); }
.game-page .move-log:empty::after {
  content: "Moves will appear here as the game progresses";
  display: block;
  margin: 48px auto;
  text-align: center;
  color: #7b8e9f;
  font-size: 13px;
  font-family: var(--font);
  max-width: 200px;
  line-height: 1.4;
}

@media (max-width: 1450px) {
  .game-page .game-content { padding: 28px 24px; }
  .game-page .play-layout {
    grid-template-columns: minmax(0, 1fr) minmax(260px, 360px);
    gap: 24px;
  }
}

/*
 * Play page: collapse the left sidebar before the board is crushed under it.
 * Board stays fully playable; menu opens via the mobile top bar.
 */
@media (max-width: 1200px) {
  .game-page .sidebar {
    width: min(292px, calc(100vw - 42px));
    transform: translateX(-105%);
    transition: transform 0.2s ease;
  }

  body.game-page.sidebar-open .sidebar {
    transform: translateX(0);
  }

  .game-page .mobile-top {
    display: flex;
  }

  .game-page .game-content {
    margin-left: 0;
    padding: 18px 16px 28px;
  }

  .game-page .play-layout {
    grid-template-columns: minmax(0, 1fr) minmax(240px, 320px);
    gap: 18px;
  }

  .game-page .board-frame {
    width: min(100%, calc(100vh - 140px), 640px);
  }
}

@media (max-width: 980px) {
  .game-page .game-content {
    margin-left: 0;
    padding: 16px 14px calc(var(--bottom-nav) + 20px);
  }

  .game-page .bottom-nav {
    display: flex;
  }

  .game-page .play-layout {
    grid-template-columns: 1fr;
    max-width: 640px;
  }

  .game-page .side-panel {
    height: auto;
    min-height: 0;
  }

  .game-page .move-log-panel {
    min-height: 220px;
  }

  .game-page .board-frame {
    width: min(100%, calc(100vw - 28px), calc(100vh - 160px));
  }
}

@media (max-width: 700px) {
  .auth-page { padding: 72px 18px 26px; }
  .auth-board-backdrop { background-position: 42% center; }
  .auth-card { width: min(100%, 480px); padding: 28px 24px; border-radius: 14px; }
  .auth-card h1 { font-size: 32px; }
  .auth-card .lead { font-size: 14px; }
  .auth-top-lang { top: 14px; right: 14px; }
  .auth-page .auth-top-lang { top: 14px; right: 14px; }
}

/* ===== FAQ / History ===== */
.page-panel {
  max-width: 820px;
  margin: 0 auto;
  padding: var(--s-28);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
}

/* ===== FAQ Component ===== */
.faq-page-panel {
  display: flex;
  flex-direction: column;
  gap: var(--s-16);
}

.faq-head-bar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--s-12);
  flex-wrap: wrap;
}

.faq-search-wrapper {
  position: relative;
  display: flex;
  align-items: center;
  width: 100%;
}

.faq-search-icon {
  position: absolute;
  left: 14px;
  color: var(--muted);
  pointer-events: none;
  width: 18px;
  height: 18px;
}

.faq-search-input {
  width: 100%;
  height: 46px;
  padding: 0 16px 0 42px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-card);
  background: var(--surface-alt);
  color: var(--ink);
  font-size: 16px; /* Prevents iOS auto-zoom */
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.faq-search-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(105, 219, 114, 0.2);
}

.faq-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.faq-accordion {
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  background: var(--surface-alt);
  overflow: hidden;
  transition: border-color 0.15s ease;
}

.faq-accordion[open] {
  border-color: rgba(105, 219, 114, 0.35);
}

.faq-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  min-height: 48px; /* Touch target */
  cursor: pointer;
  user-select: none;
  list-style: none;
}

/* Hide native browser disclosure triangle across all engines */
.faq-summary::-webkit-details-marker {
  display: none !important;
}
.faq-summary::marker {
  display: none !important;
  content: "" !important;
}

.faq-question-text {
  font-size: var(--fs-15);
  font-weight: var(--fw-semibold);
  color: var(--ink);
  line-height: 1.35;
}

.faq-icon-wrapper {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  transition: transform 0.2s ease, color 0.15s ease;
  flex-shrink: 0;
}

.faq-accordion[open] .faq-icon-wrapper {
  transform: rotate(180deg);
  color: var(--accent);
}

.faq-answer-content {
  padding: 0 16px 16px;
  border-top: 1px solid rgba(148, 163, 184, 0.08);
  padding-top: 12px;
}

.faq-answer-content p {
  margin: 0;
  color: var(--ink-secondary);
  font-size: var(--fs-14);
  line-height: 1.55;
}

.faq-empty {
  text-align: center;
  padding: 32px 16px;
  color: var(--muted);
}

.faq-cta-bar {
  display: flex;
  justify-content: flex-start;
  margin-top: var(--s-8);
}

/* ===== History Table Container ===== */
.history-table-container {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin-top: var(--s-16);
  border-radius: var(--radius-card);
}

.history-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--fs-14);
  margin-top: var(--s-16);
}

.history-table th,
.history-table td {
  text-align: left;
  padding: var(--s-12) var(--s-10);
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}

.history-table th {
  color: var(--muted);
  font-size: var(--fs-12);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: var(--fw-bold);
}

.mode-badge {
  display: inline-block;
  padding: 3px 8px;
  border-radius: var(--radius-pill);
  font-size: var(--fs-11);
  font-weight: var(--fw-bold);
  background: var(--bg);
  border: 1px solid var(--line);
}

/* ===== Toast notifications ===== */
#toast-root {
  position: fixed;
  right: var(--s-20);
  bottom: var(--s-20);
  z-index: 1100;
  display: flex;
  flex-direction: column;
  gap: var(--s-8);
  width: min(340px, calc(100% - 2rem));
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  background: #242220;
  color: #ffffff;
  padding: var(--s-12) var(--s-16);
  border-radius: var(--radius-card);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.2);
  font-size: var(--fs-14);
  font-weight: var(--fw-medium);
  animation: toast-in 0.18s ease;
}

.toast.error {
  background: var(--danger);
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}

/* ===== AI Assistant Widget (bottom-right) ===== */
.assistant {
  position: fixed;
  left: auto;
  right: 16px;
  bottom: 16px;
  width: 340px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  z-index: 1000;
}

.assistant-toggle {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 0;
  background: var(--accent);
  color: #ffffff;
  display: grid;
  place-items: center;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  transition: background 0.15s ease, transform 0.1s ease;
}

.assistant-toggle:hover {
  background: var(--accent-hover);
  transform: scale(1.04);
}

.assistant-toggle [data-lucide] {
  width: 22px;
  height: 22px;
}

.assistant-panel {
  display: none;
  width: 340px;
  height: 430px;
  margin-bottom: var(--s-10);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-modal);
  overflow: hidden;
  flex-direction: column;
}

.assistant.is-open .assistant-panel {
  display: flex;
}

.assistant-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--s-12) var(--s-16);
  background: var(--sidebar);
  color: #ffffff;
  font-weight: var(--fw-bold);
  font-size: var(--fs-14);
}

.assistant-head .icon-btn {
  color: #ffffff;
  width: 32px;
  height: 32px;
}

.assistant-head .icon-btn:hover {
  background: var(--sidebar-hover);
}

.assistant-body {
  padding: var(--s-12);
  display: flex;
  flex-direction: column;
  min-height: 0;
  flex: 1;
}

.assistant-chips {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-6);
  margin-bottom: var(--s-10);
}

.chip {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  font-size: var(--fs-11);
  padding: 4px 10px;
  cursor: pointer;
  color: var(--ink);
  transition: background 0.12s ease, border-color 0.12s ease;
}

.chip:hover {
  background: var(--ok-bg);
  border-color: var(--accent);
  color: var(--accent-hover);
}

.assistant-log {
  flex: 1;
  overflow-y: auto;
  margin-bottom: var(--s-10);
  display: flex;
  flex-direction: column;
  gap: var(--s-8);
  padding-right: 4px;
}

.assistant-msg {
  padding: var(--s-8) var(--s-12);
  border-radius: var(--radius-card);
  font-size: var(--fs-13);
  max-width: 88%;
  line-height: 1.4;
}

.assistant-msg.bot {
  background: var(--surface-alt);
  color: var(--ink);
  align-self: flex-start;
  border-bottom-left-radius: 2px;
}

.assistant-msg.user {
  background: var(--accent);
  color: #ffffff;
  align-self: flex-end;
  border-bottom-right-radius: 2px;
}

.assistant-msg strong {
  display: block;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 2px;
  opacity: 0.75;
}

.assistant-msg p {
  margin: 0;
  white-space: pre-wrap;
}

.assistant.is-open .assistant-toggle {
  display: none;
}

.assistant-form {
  display: flex;
  gap: var(--s-6);
}

.assistant-form input {
  flex: 1;
  height: 40px;
  padding: 0 var(--s-12);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--surface-alt);
  color: var(--ink);
  outline: none;
  font-size: var(--fs-13);
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}

.assistant-form input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(105, 219, 114, 0.25);
}

.assistant-form .btn {
  height: 38px;
  padding: 0 var(--s-12);
}

/* ===== Responsive adjustments ===== */
@media (max-width: 1024px) {
  .lobby-layout {
    grid-template-columns: 1fr;
    max-width: 520px;
  }

  .play-layout {
    grid-template-columns: 1fr;
    max-width: 560px;
  }
}

@media (max-width: 768px) {
  .app-shell {
    display: block;
  }

  .sidebar {
    transform: translateX(-105%);
    transition: transform 0.2s ease;
  }

  body.sidebar-open .sidebar {
    transform: translateX(0);
  }

  .mobile-top {
    display: flex;
  }

  .bottom-nav {
    display: flex;
  }

  .content {
    margin-left: 0;
    padding: var(--s-16);
    padding-bottom: calc(var(--bottom-nav) + var(--s-24));
  }

  .assistant {
    left: auto;
    right: var(--s-16);
    width: min(320px, calc(100vw - 32px));
    bottom: calc(var(--bottom-nav) + var(--s-12));
  }

  .assistant-panel {
    width: min(320px, calc(100vw - 32px));
    height: 380px;
  }

  .board-frame {
    width: min(100%, calc(100vw - 32px));
  }
}

@media (prefers-reduced-motion: reduce) {
  .piece,
  .piece-ghost,
  .btn,
  .toast,
  .sidebar {
    transition: none !important;
    animation: none !important;
  }

  .piece.is-moving,
  .piece.is-drag-source {
    transform: none !important;
  }
}

/* ===== Chess.com-inspired polish layer ===== */
.content {
  min-height: 100vh;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.42), rgba(255, 255, 255, 0) 180px),
    var(--bg);
}

.btn {
  min-width: 0;
  white-space: nowrap;
}

.btn span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.lobby-layout {
  grid-template-columns: minmax(360px, 560px) minmax(320px, 390px);
  gap: var(--s-40);
  max-width: 1120px;
}

.lobby-hero-board {
  position: sticky;
  top: var(--s-24);
}

.lobby-hero-board .board-frame,
.board-frame {
  color: #7f7d79;
}

.lobby-hero-board .board-wrap {
  border-color: #40362a;
  box-shadow: 0 16px 38px rgba(37, 35, 32, 0.18), 0 2px 0 rgba(0, 0, 0, 0.18);
}

.lobby-board-banner {
  border-color: #d6d3cd;
  box-shadow: var(--shadow-sm);
}

.play-console {
  background: #ecebe8;
  border: 1px solid #d8d5cf;
  border-radius: var(--radius-card);
  padding: var(--s-16);
  box-shadow: var(--shadow-card);
}

.console-header {
  padding: var(--s-4) var(--s-4) var(--s-8);
}

.console-header h1 {
  font-size: var(--fs-28);
}

.mode-card-compact {
  border-color: #d6d3cd;
  box-shadow: none;
}

.mode-card-compact:hover {
  border-color: #b9b5ae;
}

.mode-icon-circle {
  background: #e7f1de;
}

.guest-banner,
.stats-card,
.active-game-item {
  border-color: #d6d3cd;
}

.play-layout {
  grid-template-columns: minmax(420px, 640px) minmax(300px, 340px);
  gap: var(--s-32);
  max-width: 1060px;
}

.board-column {
  min-width: 0;
}

.board-frame {
  width: min(100%, calc(100vh - 118px), 636px);
  grid-template-columns: 20px minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr) 20px;
}

.board-wrap {
  border-color: #3e3427;
  box-shadow: 0 18px 40px rgba(31, 29, 26, 0.2), 0 2px 0 rgba(0, 0, 0, 0.2);
}

.sq.must-capture-sq {
  background-image: linear-gradient(var(--sq-must-capture), var(--sq-must-capture));
}

.side-panel {
  background: #e7e5e1;
  border: 1px solid #d4d1cb;
  border-radius: var(--radius-card);
  padding: var(--s-12);
  box-shadow: var(--shadow-card);
}

.player-card,
.move-log-panel {
  border-color: #d4d1cb;
  box-shadow: none;
}

.player-card.is-active-turn {
  border-color: var(--accent);
  box-shadow: inset 4px 0 0 var(--accent);
}

.status-banner {
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.move-log-panel {
  min-height: 190px;
  max-height: min(280px, calc(100vh - 470px));
}

.move-log-row {
  min-height: 24px;
  align-items: center;
}

.actions-row {
  min-width: 0;
}

.actions-row .btn {
  padding-inline: var(--s-10);
}

.modal-dialog {
  border-radius: var(--radius-card);
}

.page-panel,
.auth-card {
  border-color: rgba(148, 163, 184, 0.16);
}

.history-table {
  min-width: 620px;
}

[data-history-table-wrap] {
  overflow-x: auto;
}

@media (max-width: 1180px) {
  .content {
    padding-inline: var(--s-24);
  }

  .lobby-layout,
  .play-layout {
    gap: var(--s-24);
  }
}

@media (max-width: 1024px) {
  .lobby-layout,
  .play-layout {
    grid-template-columns: 1fr;
    max-width: 560px;
  }

  .lobby-hero-board {
    position: static;
  }

  .play-console,
  .side-panel {
    width: 100%;
  }

  .side-panel {
    display: grid;
    grid-template-columns: 1fr 1fr;
    align-items: stretch;
  }

  .status-banner,
  .actions-row,
  .move-log-panel,
  [data-draw-offer] {
    grid-column: 1 / -1;
  }

  .move-log-panel {
    max-height: 240px;
  }
}

@media (max-width: 640px) {
  .content {
    padding: var(--s-12);
    padding-bottom: calc(var(--bottom-nav) + var(--s-20));
  }

  .lobby-layout,
  .play-layout {
    max-width: none;
  }

  .play-console,
  .side-panel,
  .mode-card-compact,
  .stats-card,
  .guest-banner {
    padding: var(--s-12);
  }

  .console-header h1 {
    font-size: var(--fs-24);
  }

  .guest-banner {
    align-items: stretch;
    flex-direction: column;
  }

  .mode-head {
    align-items: flex-start;
  }

  .board-frame {
    width: min(100%, calc(100vw - 48px));
    grid-template-columns: 16px minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr) 16px;
  }

  .lobby-board-banner {
    min-width: 0;
    overflow: hidden;
  }

  .rank-labels,
  .file-labels {
    font-size: 10px;
  }

  .side-panel {
    grid-template-columns: 1fr;
  }

  .player-card,
  .status-banner,
  .actions-row,
  .move-log-panel,
  [data-draw-offer] {
    grid-column: auto;
  }

  .actions-row {
    display: flex;
    gap: var(--s-8);
  }

  .actions-row .btn {
    flex: 1;
    min-width: 0;
  }

  .move-log-panel {
    min-height: 160px;
    max-height: 220px;
  }

  #toast-root {
    right: var(--s-12);
    bottom: calc(var(--bottom-nav) + var(--s-12));
  }
}

/* ===== Dark dashboard reference layer ===== */
body {
  background:
    radial-gradient(circle at 72% 2%, rgba(80, 126, 89, 0.16), transparent 30vw),
    linear-gradient(135deg, #071018 0%, #0a121c 48%, #081018 100%);
}

.app-shell {
  background: transparent;
}

.content,
.dashboard-content {
  margin-left: 272px;
  min-height: 100vh;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.025) 1px, transparent 1px),
    linear-gradient(180deg, rgba(255, 255, 255, 0.025) 1px, transparent 1px),
    transparent;
  background-size: 80px 80px;
}

.sidebar {
  width: 272px;
  padding: 18px 16px;
  border-right: 1px solid rgba(148, 163, 184, 0.14);
  background:
    linear-gradient(180deg, rgba(12, 22, 32, 0.96), rgba(6, 12, 19, 0.98)),
    var(--sidebar);
  box-shadow: 18px 0 40px rgba(0, 0, 0, 0.22);
}

.sidebar-brand {
  gap: 14px;
  padding: 0 8px 24px;
  font-size: 22px;
}

.sidebar-brand .logo-mark {
  width: 42px;
  height: 42px;
  border-radius: 10px;
  color: #102017;
  background:
    radial-gradient(circle at 65% 35%, #182129 0 13%, transparent 14%),
    radial-gradient(circle at 36% 67%, #182129 0 16%, transparent 17%),
    linear-gradient(135deg, #8cf095, #56c965);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.42), 0 12px 24px rgba(58, 197, 86, 0.18);
}

.sidebar-brand .logo-mark [data-lucide] {
  opacity: 0;
}

.sidebar-nav {
  gap: 10px;
}

.nav-section-label,
.nav-sub {
  display: none;
}

.nav-link {
  min-height: 54px;
  padding: 0 16px;
  gap: 18px;
  border: 1px solid transparent;
  border-radius: 8px;
  color: #dce7f2;
  font-size: 17px;
  font-weight: 650;
}

.nav-link [data-lucide] {
  width: 26px;
  height: 26px;
  color: #b8c7d6;
}

.nav-link:hover {
  background: rgba(255, 255, 255, 0.06);
  border-color: rgba(255, 255, 255, 0.08);
}

.nav-link.is-active {
  background: var(--sidebar-active);
  border-color: rgba(105, 219, 114, 0.16);
  color: var(--accent-hover);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08), 0 16px 34px rgba(50, 175, 75, 0.12);
}

.nav-link.is-active [data-lucide] {
  color: var(--accent-hover);
  fill: rgba(105, 219, 114, 0.18);
}

.sidebar-foot {
  border-top: 0;
  gap: 16px;
}

.account-block {
  padding: 14px;
  border: 1px solid rgba(148, 163, 184, 0.14);
  background: linear-gradient(145deg, rgba(24, 36, 49, 0.9), rgba(15, 24, 34, 0.9));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

.account-avatar {
  width: 44px;
  height: 44px;
  background: linear-gradient(180deg, #9aa8b6, #5f6d79);
  color: #f7fbff;
}

.account-meta strong {
  font-size: 16px;
}

.account-meta span,
.account-meta a {
  font-size: 13px;
  color: #9fb0c1;
}

.lang-switch {
  height: 46px;
  border-radius: 8px;
  border-color: rgba(148, 163, 184, 0.16);
  background: rgba(12, 20, 29, 0.92);
}

.lang-switch [data-lang] {
  border-radius: 6px;
  color: #b4c3d2;
}

.lang-switch [data-lang].is-active {
  background: linear-gradient(135deg, #5ed66d, #43ad58);
  color: #ffffff;
}

.dashboard-content {
  margin-left: 272px;
  padding: 22px 24px 36px 34px;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(640px, 1fr) 320px;
  gap: 24px;
  max-width: 1360px;
  margin: 0 auto;
}

.dashboard-main {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.dashboard-hero,
.recent-panel,
.side-widget,
.mode-strip {
  border: 1px solid rgba(148, 163, 184, 0.14);
  background: linear-gradient(145deg, rgba(19, 31, 43, 0.92), rgba(12, 21, 31, 0.94));
  box-shadow: var(--shadow-card);
  backdrop-filter: blur(16px);
}

.dashboard-hero {
  min-height: 274px;
  position: relative;
  overflow: hidden;
  display: grid;
  grid-template-columns: minmax(260px, 0.92fr) minmax(320px, 1fr);
  align-items: center;
  gap: 18px;
  border-radius: 14px 14px 0 0;
  padding: 40px 36px;
}

.dashboard-hero::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(120deg, rgba(8, 16, 24, 0.98) 0%, rgba(8, 16, 24, 0.84) 42%, rgba(8, 16, 24, 0.2) 100%),
    linear-gradient(135deg, transparent 0 38%, rgba(105, 219, 114, 0.08) 39% 48%, transparent 49% 100%);
  pointer-events: none;
}

.hero-copy {
  position: relative;
  z-index: 1;
}

.hero-copy h1 {
  max-width: 500px;
  color: #ffffff;
  font-size: clamp(34px, 4vw, 52px);
  line-height: 1.1;
  letter-spacing: 0;
}

.hero-copy h1 span,
.hero-copy h1 strong {
  display: block;
}

.hero-copy h1 strong {
  color: var(--accent-hover);
}

.hero-copy p {
  max-width: 440px;
  margin: 18px 0 0;
  color: #c7d2df;
  font-size: 18px;
}

.hero-copy .muted:empty {
  display: none;
}

.hero-board-scene {
  position: relative;
  z-index: 1;
  min-height: 236px;
  perspective: 800px;
}

.hero-board {
  position: absolute;
  right: 0;
  top: 50%;
  width: min(470px, 100%);
  aspect-ratio: 1;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  border: 14px solid #7b4b26;
  border-radius: 10px;
  overflow: hidden;
  transform: translateY(-47%) rotateX(58deg) rotateZ(-25deg);
  box-shadow: 0 38px 58px rgba(0, 0, 0, 0.5), inset 0 0 0 2px rgba(255, 255, 255, 0.16);
}

.hero-board span:nth-child(16n + 1),
.hero-board span:nth-child(16n + 3),
.hero-board span:nth-child(16n + 5),
.hero-board span:nth-child(16n + 7),
.hero-board span:nth-child(16n + 10),
.hero-board span:nth-child(16n + 12),
.hero-board span:nth-child(16n + 14),
.hero-board span:nth-child(16n + 16),
.mini-board span:nth-child(16n + 1),
.mini-board span:nth-child(16n + 3),
.mini-board span:nth-child(16n + 5),
.mini-board span:nth-child(16n + 7),
.mini-board span:nth-child(16n + 10),
.mini-board span:nth-child(16n + 12),
.mini-board span:nth-child(16n + 14),
.mini-board span:nth-child(16n + 16) {
  background: #6d3d20;
}

.hero-board span,
.mini-board span {
  background: #f0c893;
}

.hero-piece {
  position: absolute;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  transform: rotateX(58deg) rotateZ(-25deg);
  box-shadow: 0 10px 16px rgba(0, 0, 0, 0.36), inset 0 3px 6px rgba(255, 255, 255, 0.18);
}

.hero-piece-black {
  right: 162px;
  top: 70px;
  background: radial-gradient(circle at 36% 30%, #424242, #111 72%);
}

.hero-piece-white {
  right: 250px;
  top: 154px;
  background: radial-gradient(circle at 36% 30%, #ffffff, #cfbfaa 72%);
}

.mode-strip {
  display: grid;
  grid-template-columns: 1.18fr repeat(3, 1fr);
  gap: 12px;
  padding: 18px;
  margin-top: -22px;
  border-radius: 0 0 14px 14px;
}

.mode-tile {
  min-height: 132px;
  position: relative;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 14px;
  overflow: hidden;
  padding: 20px;
  border: 1px solid rgba(148, 163, 184, 0.16);
  border-radius: 8px;
  background: linear-gradient(145deg, rgba(28, 43, 57, 0.96), rgba(15, 26, 38, 0.96));
  color: #edf4fb;
}

.mode-tile-primary {
  background: linear-gradient(145deg, rgba(105, 219, 114, 0.86), rgba(35, 121, 61, 0.92));
  color: #ffffff;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.24);
}

.mode-tile h2 {
  color: inherit;
  font-size: 19px;
}

.mode-tile p {
  margin: 5px 0 0;
  color: rgba(237, 244, 251, 0.76);
  font-size: 14px;
}

.mode-tile-icon {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: rgba(148, 163, 184, 0.15);
  color: #b9c8d8;
}

.mode-tile-primary .mode-tile-icon {
  background: rgba(255, 255, 255, 0.82);
  color: #42a94f;
}

.mode-tile-action {
  width: 34px;
  height: 44px;
  display: grid;
  place-items: center;
  border: 0;
  background: transparent;
  color: inherit;
  cursor: pointer;
}

.mode-tile-action [data-lucide] {
  width: 22px;
  height: 22px;
}

.mode-tile .difficulty-tabs {
  grid-column: 1 / -1;
  background: rgba(5, 12, 18, 0.5);
  border-color: rgba(148, 163, 184, 0.15);
}

.mode-tile .diff-tab.is-active {
  background: rgba(255, 255, 255, 0.16);
  color: #ffffff;
  box-shadow: none;
}

.mode-tile .mm-search-box {
  grid-column: 1 / -1;
}

.mm-search-box {
  min-width: 0;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 8px 10px;
  padding: 10px;
  border-radius: 8px;
  background: rgba(5, 12, 18, 0.3);
}

.mm-search-box.hidden {
  display: none;
}

.mm-search-box [data-mm-status] {
  min-width: 0;
  overflow-wrap: anywhere;
  line-height: 1.25;
}

.mm-search-box .btn {
  grid-column: 1 / -1;
  width: 100%;
  min-width: 0;
  white-space: normal;
}

.dashboard-invite,
.join-code-row {
  max-width: 100%;
}

.join-code-row {
  display: flex;
  gap: 10px;
}

.join-code-row input {
  flex: 1;
  min-width: 0;
  height: 44px;
  padding: 0 14px;
  color: var(--ink);
  font-size: 16px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: rgba(14, 24, 34, 0.9);
  outline: none;
}

.recent-panel {
  padding: 18px;
  border-radius: 14px;
}

.panel-title-row,
.widget-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.panel-title-row h2,
.widget-title h2 {
  color: #f5f8fb;
  font-size: 21px;
}

.panel-title-row a,
.rating-widget a {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: #bdc9d7;
  font-size: 14px;
}

.recent-list {
  margin-top: 14px;
  overflow: hidden;
  border: 1px solid rgba(148, 163, 184, 0.12);
  border-radius: 12px;
  background: rgba(9, 17, 25, 0.32);
}

.recent-row {
  min-height: 62px;
  display: grid;
  grid-template-columns: 44px minmax(110px, 1fr) minmax(96px, 0.7fr) minmax(110px, 0.75fr) minmax(95px, 0.6fr);
  align-items: center;
  gap: 14px;
  padding: 10px 14px;
  color: #ccd6e1;
  border-bottom: 1px solid rgba(148, 163, 184, 0.12);
}

.recent-row:last-child {
  border-bottom: 0;
}

.recent-empty {
  margin: 0;
  padding: 22px 14px;
  color: #aab7c5;
  text-align: center;
}

.recent-row strong {
  color: #ffffff;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.recent-row small {
  color: #aab7c5;
}

.recent-avatar,
.profile-avatar {
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: #edf4fb;
  background: linear-gradient(180deg, #9aa8b6, #5f6d79);
}

.recent-avatar {
  width: 38px;
  height: 38px;
}

.recent-win {
  color: var(--accent-hover);
  font-weight: 700;
}

.recent-loss {
  color: #ff6b66;
  font-weight: 700;
}

.dashboard-aside {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.side-widget {
  padding: 18px;
  border-radius: 14px;
}

.profile-widget {
  display: grid;
  grid-template-columns: 66px 1fr;
  gap: 16px;
  align-items: center;
}

.profile-widget .btn {
  grid-column: 1 / -1;
}

.profile-avatar {
  width: 62px;
  height: 62px;
}

.profile-widget strong {
  display: block;
  color: #ffffff;
  font-size: 18px;
}

.profile-widget p {
  margin: 5px 0 0;
  color: #aebdca;
}

.rating-widget > strong {
  display: block;
  margin: 12px 0 2px;
  color: #ffffff;
  font-size: 34px;
  line-height: 1;
}

.rating-hint {
  margin: 0 0 12px;
  color: #aebdca;
  font-size: 13px;
  line-height: 1.35;
}

.stats-grid {
  gap: 8px;
}

.stat-box {
  background: rgba(7, 14, 21, 0.55);
  border: 1px solid rgba(148, 163, 184, 0.12);
}

.stat-box strong {
  color: #ffffff;
}

.task-widget {
  text-align: center;
}

.task-widget .panel-title-row {
  margin-bottom: 14px;
  text-align: left;
}

.mini-board {
  width: min(236px, 100%);
  aspect-ratio: 1;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  overflow: hidden;
  margin: 0 auto 10px;
  border: 8px solid #74451f;
  border-radius: 4px;
}

.task-widget p {
  margin: 8px 0 12px;
  color: #edf4fb;
  font-weight: 700;
}

[data-mode-card] {
  cursor: pointer;
  transition: border-color 0.14s ease, transform 0.14s ease, background 0.14s ease;
}

[data-mode-card]:hover,
[data-mode-card]:focus-visible {
  border-color: rgba(105, 219, 114, 0.42);
  transform: translateY(-1px);
}

[data-mode-card]:focus-visible {
  outline: 3px solid rgba(105, 219, 114, 0.22);
  outline-offset: 2px;
}

.tip-widget {
  display: grid;
  grid-template-columns: 52px 1fr;
  align-items: center;
  gap: 14px;
}

.tip-widget p {
  margin: 0;
  color: #c7d2df;
}

.tip-star {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: rgba(105, 219, 114, 0.16);
  color: var(--accent-hover);
}

.btn-primary {
  background: linear-gradient(180deg, #75df7c, #42b456);
  border-color: rgba(117, 223, 124, 0.8);
  color: #ffffff;
  box-shadow: 0 2px 0 rgba(36, 126, 55, 0.9), 0 14px 28px rgba(72, 201, 101, 0.18);
}

.btn-ghost {
  background: rgba(14, 24, 34, 0.85);
  color: #edf4fb;
  border-color: rgba(148, 163, 184, 0.24);
}

.invite-box {
  background: rgba(34, 113, 57, 0.18);
  border-color: rgba(105, 219, 114, 0.28);
  color: #edf4fb;
}

.invite-box code {
  color: #edf4fb;
  background: rgba(4, 10, 16, 0.45);
  border-color: rgba(148, 163, 184, 0.18);
}

.mm-search-box {
  background: rgba(18, 34, 28, 0.95);
  border-color: rgba(105, 219, 114, 0.32);
  color: #dfffe3;
}

.spinner {
  border-color: rgba(105, 219, 114, 0.28);
  border-top-color: var(--accent-hover);
}

.mobile-top {
  background: rgba(8, 16, 24, 0.94);
  border-bottom-color: rgba(148, 163, 184, 0.14);
  color: #edf4fb;
}

.bottom-nav {
  background: rgba(8, 16, 24, 0.98);
  border-top-color: rgba(148, 163, 184, 0.14);
}

@media (max-width: 1280px) {
  .dashboard-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .dashboard-aside {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 1024px) {
  .dashboard-content {
    padding-inline: 22px;
  }

  .dashboard-hero {
    grid-template-columns: 1fr;
  }

  .hero-board-scene {
    min-height: 210px;
  }

  .mode-strip {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 768px) {
  .sidebar {
    width: min(292px, calc(100vw - 42px));
  }

  .dashboard-content,
  .content {
    margin-left: 0;
    padding: 14px;
    padding-bottom: calc(var(--bottom-nav) + 22px);
  }

  .dashboard-grid,
  .dashboard-aside {
    display: flex;
    flex-direction: column;
  }

  .dashboard-hero {
    min-height: 0;
    padding: 28px 22px;
  }

  .hero-copy h1 {
    font-size: 34px;
  }

  .hero-copy p {
    font-size: 16px;
  }

  .mode-strip {
    grid-template-columns: 1fr;
    margin-top: -14px;
  }

  .mode-tile {
    min-height: 104px;
  }

  .recent-row {
    grid-template-columns: 38px minmax(0, 1fr) auto;
  }

  .recent-row > span:nth-of-type(3),
  .recent-row small {
    display: none;
  }

  .join-code-row {
    flex-direction: column;
  }
}

@media (max-width: 520px) {
  .hero-board-scene {
    min-height: 170px;
  }

  .hero-board {
    width: 330px;
    right: -84px;
  }

  .hero-piece {
    display: none;
  }

  .panel-title-row {
    align-items: flex-start;
    flex-direction: column;
  }
}

/* Mode cards need to survive long Russian and Armenian labels. */
.mode-tile {
  grid-template-columns: 1fr auto;
  grid-template-rows: auto 1fr auto;
  align-content: start;
  align-items: start;
  min-width: 0;
  padding: 18px;
}

.mode-tile-icon {
  grid-column: 1;
  grid-row: 1;
  width: 44px;
  height: 44px;
  margin-bottom: 14px;
}

.mode-tile .mode-tile-copy {
  grid-column: 1 / -1;
  grid-row: 2;
  min-width: 0;
  width: 100%;
}

.mode-tile h2 {
  overflow-wrap: anywhere;
  font-size: 18px;
  line-height: 1.2;
}

.mode-tile p {
  overflow-wrap: anywhere;
  line-height: 1.38;
}

.mode-tile-action {
  grid-column: 2;
  grid-row: 1;
  justify-self: end;
}

.mode-tile .difficulty-tabs {
  grid-row: 3;
  margin-top: 12px;
  min-width: 0;
}

.mode-tile .diff-tab {
  min-width: 0;
  padding-inline: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
}

.difficulty-select {
  grid-column: 1 / -1;
  grid-row: 3;
  width: 100%;
  height: 34px;
  margin-top: 12px;
  padding: 0 10px;
  border: 1px solid rgba(148, 163, 184, 0.18);
  border-radius: 7px;
  background: rgba(5, 12, 18, 0.5);
  color: #edf4fb;
  font-size: 13px;
  font-weight: 700;
  outline: none;
}

@media (max-width: 768px) {
  .mode-tile {
    min-height: 0;
  }

  .assistant {
    left: auto;
    right: 16px;
    bottom: calc(var(--bottom-nav) + 20px);
  }

  .assistant-panel {
    width: min(320px, calc(100vw - 32px));
  }
}

/* ===== Dedicated menu/tasks/rating pages ===== */
.mode-page,
.task-page,
.rating-page {
  max-width: 980px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.mode-page-head {
  border: 1px solid rgba(148, 163, 184, 0.14);
  border-radius: 14px;
  padding: 28px;
  background: linear-gradient(145deg, rgba(19, 31, 43, 0.92), rgba(12, 21, 31, 0.94));
  box-shadow: var(--shadow-card);
}

.mode-page-head h1 {
  color: #ffffff;
  font-size: clamp(30px, 4vw, 46px);
}

.mode-page-head p {
  max-width: 680px;
  margin: 10px 0 0;
  color: #bdc9d7;
  font-size: 17px;
}

.mode-strip-page {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin-top: 0;
  border-radius: 14px;
}

.task-board-layout,
.rating-grid {
  display: grid;
  grid-template-columns: minmax(300px, 430px) minmax(280px, 1fr);
  gap: 18px;
}

.task-board-card,
.task-answer-card,
.rating-summary-card,
.rating-stats-card,
.rating-levels-card {
  border: 1px solid rgba(148, 163, 184, 0.14);
  border-radius: 14px;
  padding: 18px;
  background: linear-gradient(145deg, rgba(19, 31, 43, 0.92), rgba(12, 21, 31, 0.94));
  box-shadow: var(--shadow-card);
}

.task-board-interactive {
  width: min(100%, 390px);
  aspect-ratio: 1;
  margin: 0 auto;
  border: 10px solid #74451f;
  border-radius: 6px;
  overflow: hidden;
}

.task-board-interactive .sq {
  border: 0;
  cursor: pointer;
}

.task-board-interactive .sq:disabled {
  cursor: default;
}

.task-board-interactive .sq.cap::after {
  width: 42%;
  height: 42%;
}

.task-board-interactive.is-solved {
  opacity: 0.78;
}

.task-instructions {
  margin: 0;
  color: #bdc9d7;
  line-height: 1.45;
}

.task-board {
  position: relative;
  width: min(100%, 390px);
  aspect-ratio: 1;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  overflow: hidden;
  margin: 0 auto;
  border: 10px solid #74451f;
  border-radius: 6px;
}

.task-board span {
  background: #f0c893;
}

.task-board span:nth-child(16n + 1),
.task-board span:nth-child(16n + 3),
.task-board span:nth-child(16n + 5),
.task-board span:nth-child(16n + 7),
.task-board span:nth-child(16n + 10),
.task-board span:nth-child(16n + 12),
.task-board span:nth-child(16n + 14),
.task-board span:nth-child(16n + 16) {
  background: #6d3d20;
}

.task-piece {
  position: absolute;
  width: 9.5%;
  height: 9.5%;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  box-shadow: 0 6px 12px rgba(0, 0, 0, 0.36), inset 0 2px 5px rgba(255, 255, 255, 0.18);
}

.task-piece.dark {
  background: radial-gradient(circle at 36% 30%, #424242, #111 72%);
}

.task-piece.light {
  background: radial-gradient(circle at 36% 30%, #ffffff, #cfbfaa 72%);
}

.p-b6 { left: 18.75%; top: 31.25%; }
.p-d6 { left: 43.75%; top: 31.25%; }
.p-f6 { left: 68.75%; top: 31.25%; }
.p-c3 { left: 31.25%; top: 68.75%; }
.p-e3 { left: 56.25%; top: 68.75%; }
.p-g3 { left: 81.25%; top: 68.75%; }
.p-b2 { left: 18.75%; top: 81.25%; }

.task-answer-card {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.task-answer-card h2,
.rating-stats-card h2,
.rating-levels-card h2 {
  color: #ffffff;
  font-size: 24px;
}

.task-options {
  display: grid;
  gap: 10px;
}

.task-feedback {
  border-radius: 8px;
  padding: 12px;
  color: #ffffff;
  font-weight: 700;
}

.task-feedback.ok {
  background: rgba(105, 219, 114, 0.18);
  border: 1px solid rgba(105, 219, 114, 0.3);
}

.task-feedback.bad {
  background: rgba(255, 107, 102, 0.16);
  border: 1px solid rgba(255, 107, 102, 0.28);
}

.rating-grid {
  grid-template-columns: minmax(260px, 0.85fr) minmax(280px, 1fr);
}

.rating-summary-card {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.rating-kicker {
  color: #aebdca;
  font-size: 13px;
  font-weight: 800;
  text-transform: uppercase;
}

.rating-summary-card > strong {
  color: #ffffff;
  font-size: 64px;
  line-height: 1;
}

.rating-summary-card > strong.is-empty {
  color: #c7d2df;
  font-size: 42px;
}

.rating-summary-card p {
  margin: 0;
  color: #bdc9d7;
}

.rating-levels-card {
  grid-column: 1 / -1;
}

.rating-level-row {
  display: grid;
  grid-template-columns: 90px 1fr;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid rgba(148, 163, 184, 0.14);
  color: #dce7f2;
}

.rating-level-row:last-child {
  border-bottom: 0;
}

.rating-level-row span {
  color: var(--accent-hover);
  font-weight: 800;
}

@media (max-width: 900px) {
  .mode-strip-page,
  .task-board-layout,
  .rating-grid {
    grid-template-columns: 1fr;
  }
}

/* ===== Comprehensive Mobile Experience Enhancements ===== */

/* Task actions row */
.task-actions-row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: center;
}

/* Modals mobile friendliness */
.modal-dialog {
  width: min(420px, calc(100vw - 32px));
  max-height: calc(100vh - 48px);
  overflow-y: auto;
}

@media (max-width: 480px) {
  .modal-dialog {
    padding: 22px 18px;
  }
  .modal-dialog .actions-row {
    flex-direction: column;
    gap: 8px;
  }
  .modal-dialog .actions-row .btn {
    width: 100%;
    height: 44px;
  }
}

/* 1. Dedicated Mobile Game Page (<= 768px) */
@media (max-width: 768px) {
  .game-page .game-content {
    margin-left: 0;
    padding: 8px 10px calc(var(--bottom-nav) + 24px);
  }

  .game-page .play-layout {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-width: 460px;
    margin: 0 auto;
    width: 100%;
  }

  /* Unfold side panel into play-layout for natural vertical game flow */
  .game-page .side-panel {
    display: contents;
  }

  .game-page .side-panel-header {
    order: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 4px;
    margin-bottom: 2px;
  }

  .game-page [data-opp-card] {
    order: 1;
    min-height: 48px;
    padding: 6px 12px;
    border-radius: 12px;
  }

  .game-page .board-column {
    order: 2;
    width: 100%;
    display: flex;
    justify-content: center;
  }

  .game-page .board-frame {
    width: min(calc(100vw - 20px), calc(100vh - 360px), 420px);
    max-width: 100%;
    padding: 6px 4px 2px;
    border-radius: 14px;
    grid-template-columns: 18px minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr) 18px;
    gap: 2px;
  }

  .game-page .rank-labels,
  .game-page .file-labels {
    font-size: 11px;
    color: #8da4bc;
  }

  .game-page [data-you-card] {
    order: 3;
    min-height: 48px;
    padding: 6px 12px;
    border-radius: 12px;
  }

  .game-page .player-card .avatar {
    width: 38px;
    height: 38px;
    font-size: 15px;
  }

  .game-page .player-meta strong {
    font-size: 15px;
  }

  .game-page .player-meta span {
    font-size: 12px;
  }

  .game-page [data-game-status] {
    order: 4;
    min-height: 40px;
    font-size: 14px;
    padding: 6px 12px;
    border-radius: 10px;
  }

  .game-page .game-actions-row {
    order: 5;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  .game-page .game-actions-row .btn {
    height: 44px;
    font-size: 14px;
    border-radius: 10px;
  }

  .game-page [data-draw-offer] {
    order: 6;
    border-radius: 12px;
  }

  .game-page .move-log-panel {
    order: 7;
    min-height: 120px;
    max-height: 180px;
    padding: 12px 14px;
    border-radius: 12px;
  }

  .game-page .move-log-panel h3 {
    font-size: 15px;
    padding-bottom: 8px;
  }

  /* Do not let assistant bubble occlude player controls on mobile game screen */
  .game-page .assistant {
    display: none !important;
  }
}

/* 2. Compact Viewports (<= 360px) */
@media (max-width: 360px) {
  .game-page .game-content {
    padding: 4px 6px calc(var(--bottom-nav) + 20px);
  }

  .game-page .board-frame {
    width: calc(100vw - 12px);
    padding: 4px 2px 2px;
    grid-template-columns: 14px minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr) 14px;
  }

  .game-page .rank-labels,
  .game-page .file-labels {
    font-size: 9px;
  }

  .game-page .player-card {
    padding: 5px 8px;
    min-height: 40px;
  }

  .game-page .player-card .avatar {
    width: 30px;
    height: 30px;
    font-size: 12px;
  }

  .game-page .player-meta strong {
    font-size: 13px;
  }

  .game-page .player-meta span {
    font-size: 11px;
  }

  .game-page [data-game-status] {
    min-height: 36px;
    font-size: 13px;
    padding: 4px 8px;
  }

  .game-page .game-actions-row .btn {
    height: 40px;
    font-size: 13px;
    padding: 0 8px;
  }
}

/* 3. Lobby Hero & Modes Optimization on Small Screens (<= 600px) */
@media (max-width: 600px) {
  .dashboard-hero {
    padding: 18px 16px;
    border-radius: 14px;
    min-height: 0;
  }

  /* Hide huge 3D decorative board scene so playable game modes stay above fold */
  .hero-board-scene {
    display: none;
  }

  .hero-copy h1 {
    font-size: 22px;
    line-height: 1.25;
  }

  .hero-copy h1 strong {
    display: block;
  }

  .hero-copy p {
    font-size: 14px;
    margin-top: 6px;
  }

  .mode-strip {
    margin-top: 12px;
    gap: 10px;
  }

  .mode-tile {
    padding: 14px;
  }

  .mode-tile-icon {
    width: 40px;
    height: 40px;
    margin-bottom: 8px;
  }

  .mode-tile h2 {
    font-size: 16px;
  }

  .mode-tile p {
    font-size: 13px;
  }
}

/* 4. Daily Tasks Mobile Refinements */
@media (max-width: 768px) {
  .task-page .mode-page-head {
    padding: 16px 14px;
    border-radius: 12px;
  }

  .task-page .mode-page-head h1 {
    font-size: 24px;
  }

  .task-page .mode-page-head p {
    font-size: 14px;
    margin-top: 4px;
  }

  .task-board-card {
    padding: 12px;
  }

  .task-board-interactive {
    width: min(100%, 320px);
    touch-action: manipulation;
  }

  .task-answer-card {
    padding: 14px 16px;
  }

  .task-answer-card h2 {
    font-size: 18px;
  }

  .task-instructions {
    font-size: 13px;
  }

  .task-actions-row {
    flex-direction: column;
    width: 100%;
  }

  .task-actions-row .btn {
    width: 100%;
    height: 44px;
  }
}

/* 5. Rating Page Mobile Refinements */
@media (max-width: 768px) {
  .rating-page .mode-page-head {
    padding: 16px 14px;
    border-radius: 12px;
  }

  .rating-page .mode-page-head h1 {
    font-size: 24px;
  }

  .rating-page .mode-page-head p {
    font-size: 14px;
    margin-top: 4px;
  }

  .rating-summary-card,
  .rating-stats-card,
  .rating-levels-card {
    padding: 14px 16px;
    border-radius: 12px;
  }

  .rating-summary-card > strong {
    font-size: 48px;
  }
}

/* 6. Mode Page & FAQ mobile padding */
@media (max-width: 768px) {
  .mode-page-head {
    padding: 18px 16px;
    border-radius: 12px;
  }

  .mode-page-head h1 {
    font-size: 24px;
  }

  .mode-page-head p {
    font-size: 14px;
  }

  .page-panel {
    padding: 18px 14px;
  }
}

/* 7. Auth Pages Mobile Fit & Bottom Toolbar (Firefox/Safari/Chrome) Clearance */
@media (max-width: 768px) {
  .auth-page {
    min-height: 100vh;
    min-height: 100dvh;
    min-height: -webkit-fill-available;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding-top: calc(54px + env(safe-area-inset-top, 0px));
    padding-bottom: calc(100px + env(safe-area-inset-bottom, 0px));
    padding-left: 14px;
    padding-right: 14px;
    box-sizing: border-box;
    width: 100%;
  }

  .auth-card {
    width: 100%;
    max-width: 440px;
    padding: 22px 18px 20px;
    box-sizing: border-box;
    margin: auto auto;
    border-radius: 16px;
  }

  .auth-page .auth-mark {
    width: 44px;
    height: 32px;
    margin-bottom: 12px;
  }

  .auth-page .auth-card h1 {
    font-size: 26px;
    margin-bottom: 2px;
    line-height: 1.2;
  }

  .auth-page .auth-card .lead {
    font-size: 13px;
    margin-bottom: 14px;
  }

  .auth-page .auth-card form {
    gap: 10px;
  }

  .auth-page .auth-card .field {
    gap: 4px;
  }

  .auth-page .auth-input-control {
    min-height: 48px;
    padding: 0 14px;
    border-radius: 12px;
  }

  .auth-page .auth-input-control svg {
    width: 18px;
    height: 18px;
    margin-right: 10px;
  }

  .auth-page .auth-input-control input,
  .auth-page .auth-card .field input {
    height: 46px;
    font-size: 16px;
  }

  .auth-page .auth-card .btn {
    min-height: 46px;
    height: 46px;
    font-size: 15px;
    border-radius: 12px;
  }

  .auth-page .auth-card .muted {
    font-size: 12px;
    margin-top: 2px;
  }

  .auth-page .auth-links {
    margin-top: 14px;
    font-size: 13px;
  }

  .auth-top-lang {
    top: calc(10px + env(safe-area-inset-top, 0px));
    right: 12px;
  }

  .auth-page .auth-top-lang {
    top: calc(10px + env(safe-area-inset-top, 0px));
    right: 12px;
  }
}

@media (max-width: 360px) {
  .auth-page {
    padding-top: calc(48px + env(safe-area-inset-top, 0px));
    padding-bottom: calc(90px + env(safe-area-inset-bottom, 0px));
    padding-left: 8px;
    padding-right: 8px;
  }

  .auth-card {
    padding: 18px 12px 16px;
  }

  .auth-page .auth-card h1 {
    font-size: 23px;
  }

  .auth-page .auth-card .lead {
    font-size: 12px;
    margin-bottom: 12px;
  }

  .auth-page .auth-input-control {
    min-height: 44px;
    padding: 0 10px;
  }

  .auth-page .auth-input-control input {
    height: 42px;
  }

  .auth-page .auth-card .btn {
    min-height: 44px;
    height: 44px;
    font-size: 14px;
  }
}

