:root {
  --r-wood-dark: #2c1a10;
  --r-wood: #6b4327;
  --r-wood-mid: #7d4f2e;
  --r-wood-light: #a5713f;
  --r-tray: #1f130b;
  --r-bg: #ece1cf;
  --r-bg2: #e2d3ba;
  --r-panel: #fffbf4;
  --r-ink: #2a1d14;
  --r-muted: #6B5B4A;   /* 10/27: was #8a7a68 (3.9:1 on paper); now 5.9:1 on the paper ground, WCAG AA */
  --r-muted2: #6B5B4A;
  --r-border: #e2d3bd;
  --r-accent: #b5442e;
  --r-accent2: #d15b3f;
  --r-red: #c23b2c;
  --r-red-light: #e8624a;
  --r-blue: #2b5f8a;
  --r-blue-light: #4f8ab8;
  --r-white-piece: #f6f1e6;
  --r-gold: #c99a3e;
  --r-gold-light: #e6bd6a;
  --r-bronze: #a3623a;
  --r-silver: #9aa3ab;
  --r-shadow: rgba(20, 10, 4, 0.35);
}



* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  color: var(--r-ink);
  -webkit-tap-highlight-color: transparent;
}

.layout { max-width: 1080px; margin: 0 auto; padding: 26px max(16px, env(safe-area-inset-left)) 60px; }

.screen { display: none; }
.screen.active { display: block; animation: fadeIn 0.25s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) {
  .screen.active { animation: none; }
}

.panel-header { margin-bottom: 20px; display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap; }
.panel-header h2 { margin: 0; font-size: 22px; font-family: Georgia, "Iowan Old Style", serif; }
.panel-header .sub { margin: 4px 0 0; color: var(--r-muted); font-size: 13.5px; width: 100%; line-height: 1.5; }

.back-btn {
  background: none; border: 1px solid var(--r-border); color: var(--r-ink);
  padding: 8px 14px; border-radius: 8px; cursor: pointer; font-size: 13px;
  min-height: 40px;
}
.back-btn:active { background: var(--r-bg2); }

/* Levels screen layout */
.levels-layout { display: grid; grid-template-columns: 1fr 300px; gap: 22px; align-items: start; }

.level-list { display: flex; flex-direction: column; gap: 9px; }
.level-row {
  display: grid; grid-template-columns: 40px 1fr auto; align-items: center; gap: 14px;
  background: var(--r-panel); border: 1px solid var(--r-border); border-radius: 12px;
  padding: 14px 18px; cursor: pointer; text-align: left; font-size: 15px; color: var(--r-ink);
  box-shadow: 0 1px 2px var(--r-shadow);
  transition: border-color 0.15s ease, transform 0.12s ease, box-shadow 0.15s ease;
  min-height: 44px;
}
.level-row:hover { border-color: var(--r-gold); transform: translateX(3px); box-shadow: 0 4px 14px var(--r-shadow); }
.level-row:active { transform: translateX(1px) scale(0.995); }
.level-num {
  width: 36px; height: 36px; border-radius: 50%;
  color: #fff; display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 14px; font-variant-numeric: tabular-nums;
  box-shadow: inset 0 -3px 4px rgba(0,0,0,0.25), inset 0 2px 2px rgba(255,255,255,0.2);
}
.level-name { font-weight: 700; }
.level-tag { display: block; font-size: 11.5px; color: var(--r-muted); font-weight: 400; margin-top: 1px; }
.level-arrow { color: var(--r-gold); font-size: 18px; opacity: 0.7; }

/* Tier accent colors, escalating grandeur across the 10 levels */
.tier-1, .tier-2 { background: linear-gradient(160deg, #8a6a4a, var(--r-bronze)); }
.tier-3, .tier-4 { background: linear-gradient(160deg, #7d8a94, var(--r-silver)); }
.tier-5, .tier-6 { background: linear-gradient(160deg, #6b8fae, var(--r-blue)); }
.tier-7, .tier-8 { background: linear-gradient(160deg, #e6bd6a, var(--r-gold)); }
.tier-9, .tier-10 { background: linear-gradient(160deg, #f0d68a, #c99a3e); box-shadow: 0 0 12px rgba(201,154,62,0.55), inset 0 -3px 4px rgba(0,0,0,0.25); }

/* Side panel (Level Leaders + per-level leaderboard) */
.side-panel {
  background: var(--r-panel); border: 1px solid var(--r-border); border-radius: 14px;
  padding: 16px; box-shadow: 0 2px 10px var(--r-shadow);
}
.side-panel-title {
  font-weight: 800; font-size: 13.5px; margin-bottom: 10px; color: var(--r-ink);
  display: flex; align-items: center; gap: 6px; letter-spacing: 0.2px;
}
.trophy { font-size: 15px; filter: drop-shadow(0 1px 2px rgba(0,0,0,0.3)); }

.leaders-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.leader-row {
  display: grid; grid-template-columns: 28px 1fr auto; align-items: center; gap: 10px;
  padding: 7px 8px; border-radius: 8px; font-size: 12.5px;
  background: rgba(201,154,62,0.05);
  cursor: pointer; transition: background 0.15s ease;
}
.leader-row:hover { background: rgba(201,154,62,0.16); }
.leader-row:active { background: rgba(201,154,62,0.24); }
.leader-row.current { outline: 1.5px solid var(--r-gold); background: rgba(201,154,62,0.14); }
.leader-medal {
  width: 26px; height: 26px; border-radius: 50%; color: #fff;
  display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 11px;
  box-shadow: inset 0 -2px 3px rgba(0,0,0,0.25);
}
.leader-info { min-width: 0; }
.leader-level { font-size: 10.5px; color: var(--r-muted); text-transform: uppercase; letter-spacing: 0.3px; }
.leader-name-line { display: flex; align-items: baseline; gap: 5px; flex-wrap: wrap; }
.leader-name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 110px; }
.leader-compliment { font-size: 11px; font-style: italic; color: var(--r-accent2); }
.leader-empty { color: var(--r-muted); font-size: 11px; font-style: italic; }
.leader-score { font-variant-numeric: tabular-nums; font-size: 12px; color: var(--r-muted); white-space: nowrap; }

.lb-divider { height: 1px; background: var(--r-border); margin: 14px 0; }

.lb-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.lb-list li { display: flex; justify-content: space-between; font-size: 13px; padding: 4px 0; border-bottom: 1px dashed var(--r-border); }
.lb-list li:first-child .lb-name::before { content: "🏆 "; }
.lb-name { font-weight: 600; }
.lb-score { color: var(--r-muted); font-variant-numeric: tabular-nums; }
.lb-empty, .lb-loading { color: var(--r-muted); font-size: 12.5px; font-style: italic; }

/* Game layout */
.game-layout { display: grid; grid-template-columns: 1fr 300px; gap: 22px; align-items: start; }
.game-main { min-width: 0; }

.game-topbar {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-bottom: 8px;
}
.level-label { font-weight: 700; font-size: 14px; flex: 1; min-width: 140px; }
.stats { display: flex; gap: 16px; font-size: 13px; color: var(--r-muted); }
.stats b { color: var(--r-ink); font-variant-numeric: tabular-nums; }
.reset-btn {
  background: linear-gradient(160deg, var(--r-accent2), var(--r-accent)); color: #fff; border: none; padding: 9px 16px;
  border-radius: 8px; cursor: pointer; font-size: 13px; font-weight: 700; min-height: 40px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.25);
}
.reset-btn:active { transform: translateY(1px); }
.skip-btn {
  background: transparent; color: var(--r-ink); border: 1px solid var(--r-border); padding: 9px 14px;
  border-radius: 8px; cursor: pointer; font-size: 13px; font-weight: 600; min-height: 40px;
}
.skip-btn:hover { border-color: var(--r-blue-light); color: var(--r-blue); }
.skip-btn:active { transform: translateY(1px); }

.streak-bar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  font-size: 12.5px; color: var(--r-muted); margin: 6px 0 12px;
}
.streak-dots { display: flex; gap: 4px; }
.streak-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--r-border); transition: background 0.2s ease; }
.streak-dot.filled { background: var(--r-gold); box-shadow: 0 0 4px rgba(201,154,62,0.6); }

.goal-hint { color: var(--r-muted); font-size: 13px; margin: 6px 0 16px; }
.white-dot-label { font-weight: 700; color: var(--r-ink); }

.board-wrap { display: flex; justify-content: center; padding: 10px 0 20px; touch-action: pan-y; }
.board {
  position: relative;
  background:
    repeating-linear-gradient(90deg, rgba(255,255,255,0.02) 0 2px, transparent 2px 10px),
    linear-gradient(160deg, #241509, var(--r-tray) 60%);
  border-radius: 12px;
  box-shadow: inset 0 0 0 7px var(--r-wood), inset 0 0 0 9px rgba(0,0,0,0.3), 0 10px 28px var(--r-shadow);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
.cell {
  position: absolute;
  border-radius: 5px;
  background: rgba(0,0,0,0.12);
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.3), inset 0 2px 4px rgba(0,0,0,0.25);
}
.goal-cell {
  box-shadow: inset 0 0 0 2px var(--r-gold-light), inset 0 0 12px rgba(230,189,106,0.35);
  background: rgba(230,189,106,0.09);
  animation: goalPulse 2.2s ease-in-out infinite;
}
@keyframes goalPulse {
  0%, 100% { box-shadow: inset 0 0 0 2px var(--r-gold-light), inset 0 0 10px rgba(230,189,106,0.3); }
  50% { box-shadow: inset 0 0 0 2px var(--r-gold-light), inset 0 0 20px rgba(230,189,106,0.6); }
}
@media (prefers-reduced-motion: reduce) {
  .goal-cell { animation: none; }
}
/* Persistent target outline — always shows the true 2x2 goal, even when a piece
   sits on part of it (so the exit never looks smaller than it really is). */
.goal-frame {
  position: absolute;
  pointer-events: none;
  z-index: 50;
  border: 3px dashed var(--r-gold-light);
  border-radius: 12px;
  box-shadow: 0 0 16px rgba(230,189,106,0.55), inset 0 0 16px rgba(230,189,106,0.28);
  box-sizing: border-box;
  animation: goalFramePulse 2.2s ease-in-out infinite;
}
.goal-frame-tag {
  position: absolute;
  top: -10px; left: 50%; transform: translateX(-50%);
  background: var(--r-gold); color: #201400;
  font-size: 10px; font-weight: 800; letter-spacing: 1.5px;
  padding: 1px 8px; border-radius: 99px; white-space: nowrap;
}
@keyframes goalFramePulse {
  0%, 100% { opacity: 0.7; }
  50% { opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
  .goal-frame { animation: none; opacity: 0.9; }
}

.piece {
  position: absolute;
  border-radius: 10px;
  cursor: grab;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 8px rgba(0,0,0,0.4), inset 0 1px 0 rgba(255,255,255,0.18), inset 0 -4px 6px rgba(0,0,0,0.2);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  will-change: left, top;
}
.piece-red { background: linear-gradient(160deg, #9c6640, #6b4327 65%); }
.piece-blue { background: linear-gradient(160deg, #8c6a48, #5f4128 65%); }
.piece-white { background: linear-gradient(160deg, #a5754a, #6b4327 65%); }
.piece.selected { outline: 3px solid var(--r-gold-light); outline-offset: -3px; }
.piece.dragging {
  transition: none !important; cursor: grabbing; z-index: 20;
  box-shadow: 0 10px 22px rgba(0,0,0,0.5), inset 0 1px 0 rgba(255,255,255,0.25);
  filter: brightness(1.06);
}
.piece:not(.dragging) { transition: left 0.16s cubic-bezier(.2,.7,.3,1), top 0.16s cubic-bezier(.2,.7,.3,1); }
.piece.locked-shake { animation: shake 0.28s ease; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}
@media (prefers-reduced-motion: reduce) {
  .piece.locked-shake { animation: none; }
}

.dot {
  width: 44%; height: 44%; min-width: 26px; min-height: 26px;
  border-radius: 50%;
  box-shadow: inset -3px -4px 7px rgba(0,0,0,0.35), inset 3px 3px 5px rgba(255,255,255,0.3), 0 2px 4px rgba(0,0,0,0.35);
}
.dot-red { background: radial-gradient(circle at 32% 28%, #ef7a63, var(--r-red) 72%); }
.dot-blue { background: radial-gradient(circle at 32% 28%, #6ea3c9, var(--r-blue) 72%); }
.dot-white { background: radial-gradient(circle at 32% 28%, #ffffff, var(--r-white-piece) 72%); }

/* Modals: none of Risto's own. The sign-in / invite / coach dialogs are the shared G140.modal (g140.css); Risto used to
   restyle .modal/.modal-card here, which turned the sign-in box into a dark blurred brown sheet (Brian 11/3). Removed. */
.primary-btn {
  width: 100%; padding: 12px; border-radius: 8px; border: none;
  background: linear-gradient(160deg, var(--r-accent2), var(--r-accent)); color: #fff;
  font-weight: 700; font-size: 14px; cursor: pointer; min-height: 44px;
  box-shadow: 0 3px 8px rgba(0,0,0,0.3);
}
.primary-btn:active { transform: translateY(1px); }
.secondary-btn {
  width: 100%; padding: 12px; border-radius: 8px; margin-top: 8px; min-height: 44px;
  border: 1px solid var(--r-border); background: transparent; color: var(--r-ink);
  font-weight: 700; font-size: 14px; cursor: pointer;
}
.secondary-btn:hover { border-color: var(--r-gold); }
.win-badge {
  display: inline-block; background: linear-gradient(160deg, var(--r-gold-light), var(--r-gold));
  color: #2a1a10; font-weight: 800;
  padding: 7px 18px; border-radius: 20px; margin-bottom: 12px; font-size: 14px;
  box-shadow: 0 3px 8px rgba(0,0,0,0.25);
}
.win-stats { font-size: 13.5px; color: var(--r-muted); }

@media (max-width: 760px) {
  .levels-layout { grid-template-columns: 1fr; }
  .game-layout { grid-template-columns: 1fr; }
  .risto-brand h1 { font-size: 19px; }
  .panel-header h2 { font-size: 19px; }
}

/* Undo / Hint transient message */
.risto-flash {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%) translateY(10px);
  background: var(--r-gold); color: #201400; font-weight: 800; font-size: 14px;
  padding: 10px 18px; border-radius: 99px; box-shadow: 0 6px 20px rgba(0,0,0,0.4);
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 200;
}
.risto-flash.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.skip-btn:disabled, .reset-btn:disabled { opacity: .45; cursor: default; }

/* ── 10/27: Risto inside Games140 (standard header, board-page shell, account names) ── */
.risto-title { font: 900 26px "Nunito", sans-serif; margin: 0 0 4px; color: var(--bp-ink); letter-spacing: -.01em; }
.risto-daily { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; text-align: left;
  background: var(--bp-leaf); box-shadow: inset 0 0 0 1px var(--bp-rule); border-radius: 16px; padding: 12px 14px; margin: 10px 0 16px; }
.risto-daily .k { font: 800 11.5px "Nunito", sans-serif; letter-spacing: .06em; text-transform: uppercase; color: var(--bp-ink-2); }
.risto-daily p { margin: 2px 0 0; color: var(--bp-ink); }
.risto-daily .btn { min-height: 44px; }
.legacy { font-size: 11px; font-weight: 800; color: var(--bp-ink-2); background: var(--bp-paper); border-radius: 99px; padding: 1px 6px; margin-left: 4px; }
.lb-note { color: var(--bp-ink-2); margin: 10px 4px 0; line-height: 1.4; }
.leader-row { list-style: none; }
.leader-btn { display: flex; align-items: center; gap: 10px; width: 100%; min-height: 44px; background: none; border: 0; padding: 4px 2px; cursor: pointer; text-align: left; font: inherit; color: inherit; }
.leader-btn:focus-visible { outline: 3px solid var(--bp-iris); outline-offset: 2px; border-radius: 8px; }
.sheet-levels { padding: 0; margin: 8px 0 0; }
.risto-hint { margin: 0 0 6px; color: var(--bp-iris); font-weight: 800; min-height: 0; }
.risto-hint:empty { display: none; }
#screen-game .bp-board .board { margin: 0 auto; }
.level-row { min-height: 52px; }
