/* Patience (Royal Gaps) — Styles */

:root {
  --bg: #1a1f2e;
  --board-bg: #2a3042;
  --card-bg: #f5f0e8;
  --card-border: #d4cfc5;
  --card-shadow: rgba(0, 0, 0, 0.25);
  --gap-bg: rgba(255, 255, 255, 0.06);
  --gap-border: rgba(255, 255, 255, 0.15);
  --dead-gap-bg: rgba(255, 60, 60, 0.08);
  --dead-gap-border: rgba(255, 60, 60, 0.3);
  --valid-gap-bg: rgba(100, 255, 100, 0.12);
  --valid-gap-border: rgba(100, 255, 100, 0.5);
  --movable-glow: rgba(0, 210, 255, 1.0);
  --movable-border: rgba(0, 210, 255, 0.75);
  --selected-glow: rgba(255, 220, 50, 0.8);
  --locked-bg: #e8e4d8;
  --locked-border: #b8b4a8;
  --red: #d63031;
  --black: #2d3436;
  --accent: #6c5ce7;
  --text: #dfe6e9;
  --text-muted: #b2bec3;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0.75rem 1rem;
  padding-top: max(0.75rem, env(safe-area-inset-top));
}

/* Confetti canvas */
#confetti-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 500;
}

/* Top bar */
.top-bar {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  width: 100%;
  max-width: 1100px;
  margin-bottom: 0.5rem;
  flex-shrink: 0;
}

.top-bar-left {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-shrink: 0;
}

.top-bar h1 {
  font-family: 'Coustard', serif;
  font-size: 1.5rem;
  font-weight: 400;
  letter-spacing: 0.05em;
  color: var(--text);
  white-space: nowrap;
}

/* Title gap-fill animation */
h1.title-anim {
  position: relative;
  display: inline-flex;
  align-items: baseline;
}

.title-letter {
  display: inline-block;
}
.title-letter + .title-letter {
  margin-left: 0.03em;
}

h1.title-anim .title-letter,
h1.title-anim .title-gap,
h1.title-anim .title-dragged {
  opacity: 0;
  transform: scale(0.5);
  transition: opacity 0.25s ease, transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}
h1.title-anim .title-letter.pop-in,
h1.title-anim .title-gap.pop-in,
h1.title-anim .title-dragged.pop-in {
  opacity: 1;
  transform: scale(1);
}

.title-gap {
  display: inline-block;
  width: 0.6em;
  margin: 0 0.06em 0 0.03em;
}

.title-gap.filled {
  width: 0;
  opacity: 0;
  margin: 0;
  border-color: transparent;
}

.title-dragged {
  display: inline-block;
  pointer-events: none;
  color: var(--text);
}

.title-icon {
  display: inline-block;
  width: 0.6em;
  height: 0.85em;
  vertical-align: -0.15em;
  -webkit-mask-image: url('../assets/site-icon-v2.svg');
  mask-image: url('../assets/site-icon-v2.svg');
  -webkit-mask-size: contain;
  mask-size: contain;
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
  -webkit-mask-position: center bottom;
  mask-position: center bottom;
  background-color: currentColor;
}

h1.title-anim .title-dragged.lifting {
  position: absolute;
  top: 0;
  opacity: 1;
  transform: none;
  transition: left 0.6s cubic-bezier(0.25, 0.1, 0.25, 1);
}

.title-cursor {
  position: absolute;
  top: -0.1em;
  right: -0.85em;
  width: 0.85em;
  height: 0.85em;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='white' stroke='black' stroke-width='1.5'%3E%3Cpath d='M5 3l14 8-6.5 1.5L11 19z'/%3E%3C/svg%3E");
  background-size: contain;
  background-repeat: no-repeat;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
  transform: scale(0);
}

.title-cursor.pop {
  animation: cursor-pop 0.3s ease-out forwards;
}

@keyframes cursor-pop {
  0% { transform: scale(0); }
  60% { transform: scale(1.3); }
  100% { transform: scale(1); }
}

.title-cursor.burst-out {
  animation: cursor-burst-out 0.25s ease-in forwards;
}

@keyframes cursor-burst-out {
  0% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.4); opacity: 0.6; }
  100% { transform: scale(0); opacity: 0; }
}

body.light-mode .title-cursor {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='black' stroke='white' stroke-width='1.5'%3E%3Cpath d='M5 3l14 8-6.5 1.5L11 19z'/%3E%3C/svg%3E");
}

.top-bar-right {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

/* Status bar — centred in top-bar */
.status-bar {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  align-items: center;
  gap: 1.25rem;
  font-size: 0.85rem;
  pointer-events: none;
}

.status-item {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  white-space: nowrap;
}

.status-label {
  color: var(--text-muted);
}

.status-value {
  color: var(--text);
  font-weight: 600;
}


button {
  font-family: inherit;
  padding: 0.5rem 1.25rem;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  font-size: 0.85rem;
  line-height: 1;
  cursor: pointer;
  transition: all 0.2s;
}

button:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.15);
  border-color: rgba(255, 255, 255, 0.35);
}

button:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

button.primary {
  background: var(--accent);
  border-color: var(--accent);
}

button.primary:hover:not(:disabled) {
  background: #7c6cf7;
}

/* Share button */
.share-btn {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.5rem 0.9rem;
}

.share-btn svg {
  flex-shrink: 0;
}

/* Game area — centers board vertically */
.game-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  max-width: 1100px;
  min-height: 0;
}

/* Board */
#board {
  display: grid;
  grid-template-columns: repeat(10, 1fr);
  grid-template-rows: repeat(4, 1fr);
  gap: 6px;
  padding: 1rem;
  background: var(--board-bg);
  border-radius: 12px;
  width: 100%;
  touch-action: none;
}

/* Classic board style */
body.classic-board #board {
  background: #2d6a4f;
  box-shadow: inset 0 0 60px rgba(0, 0, 0, 0.35);
  border-radius: 14px;
  outline: 3px solid #1b4332;
  outline-offset: -3px;
  position: relative;
}

body.classic-board #board::after {
  content: '';
  position: absolute;
  inset: 7px;
  border-radius: 8px;
  border: 2px dashed rgba(255, 255, 255, 0.22);
  pointer-events: none;
  z-index: 0;
}

body.light-mode.classic-board #board {
  background: #2d6a4f;
  outline-color: #1b4332;
  box-shadow: inset 0 0 60px rgba(0, 0, 0, 0.3), 0 4px 18px rgba(0, 0, 0, 0.18);
}

/* Classic board overrides */
body.classic-board .cell.gap.dead-gap {
  background: rgba(220, 30, 30, 0.28);
  border-color: rgba(255, 60, 60, 0.75);
}

body.classic-board .dead-icon {
  color: rgba(255, 80, 80, 0.85);
}

body.classic-board {
  --valid-gap-bg: rgba(200, 255, 200, 0.15);
  --valid-gap-border: rgba(200, 255, 200, 0.8);
  --movable-glow: rgba(0, 60, 200, 1.0);
  --movable-border: rgba(0, 60, 200, 0.9);
}

body.classic-board .cell.gap.target-gap {
  background: rgba(200, 255, 200, 0.28);
  border-color: rgba(200, 255, 200, 0.95);
}

/* Wood board style */
body.wood-board #board {
  background:
    repeating-linear-gradient(
      0deg,
      transparent,
      transparent 4px,
      rgba(0, 0, 0, 0.04) 4px,
      rgba(0, 0, 0, 0.04) 5px
    ),
    repeating-linear-gradient(
      0deg,
      transparent,
      transparent 23px,
      rgba(0, 0, 0, 0.07) 23px,
      rgba(0, 0, 0, 0.07) 25px
    ),
    linear-gradient(90deg, #6b4226 0%, #7a4e2d 30%, #6b4226 60%, #7a4e2d 100%);
  box-shadow: inset 0 0 60px rgba(0, 0, 0, 0.3);
}


body.light-mode.wood-board #board {
  background:
    repeating-linear-gradient(
      0deg,
      transparent,
      transparent 4px,
      rgba(0, 0, 0, 0.03) 4px,
      rgba(0, 0, 0, 0.03) 5px
    ),
    repeating-linear-gradient(
      0deg,
      transparent,
      transparent 23px,
      rgba(0, 0, 0, 0.05) 23px,
      rgba(0, 0, 0, 0.05) 25px
    ),
    linear-gradient(90deg, #8b6340 0%, #9a7350 30%, #8b6340 60%, #9a7350 100%);
}

body.wood-board .cell.gap.dead-gap {
  background: rgba(220, 30, 30, 0.28);
  border-color: rgba(255, 60, 60, 0.75);
}

body.wood-board .dead-icon {
  color: rgba(255, 80, 80, 0.85);
}

body.wood-board {
  --valid-gap-bg: rgba(200, 255, 200, 0.15);
  --valid-gap-border: rgba(200, 255, 200, 0.8);
  --movable-glow: rgba(0, 60, 200, 1.0);
  --movable-border: rgba(0, 60, 200, 0.9);
}

body.wood-board .cell.gap.target-gap {
  background: rgba(200, 255, 200, 0.28);
  border-color: rgba(200, 255, 200, 0.95);
}

/* Cell (common) */
.cell {
  aspect-ratio: 5 / 7;
  border-radius: 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: clamp(0.7rem, 2vw, 1rem);
  transition: transform 0.15s, box-shadow 0.15s, opacity 0.15s;
  position: relative;
  user-select: none;
}

/* Card */
.cell.card {
  background: var(--card-bg);
  border: 1.5px solid var(--card-border);
  box-shadow: 0 2px 4px var(--card-shadow);
  cursor: pointer;
}

.cell.card.movable {
  cursor: grab;
  box-shadow: 0 0 14px var(--movable-glow), 0 2px 4px var(--card-shadow);
  border-color: var(--movable-border);
}

.cell.card.movable:hover {
  transform: translateY(-4px);
  box-shadow: 0 0 24px var(--movable-glow), 0 6px 12px var(--card-shadow);
}

.cell.card.selected {
  box-shadow: 0 0 16px var(--selected-glow), 0 6px 12px var(--card-shadow);
  border-color: rgba(255, 220, 50, 0.85);
  transform: translateY(-6px) scale(1.04);
  z-index: 10;
  cursor: grab;
}

.cell.card.dragging {
  opacity: 0.35;
  transform: scale(0.95);
  cursor: grabbing;
}

.cell.card.dimmed {
  opacity: 0.45;
}

.cell.card.locked {
  cursor: default;
  background: var(--locked-bg);
  border-color: var(--locked-border);
  opacity: 0.75;
}

/* Card colors */
.cell.card.red .card-rank,
.cell.card.red .card-suit {
  color: var(--red);
}

.cell.card.black .card-rank,
.cell.card.black .card-suit {
  color: var(--black);
}

.card-rank {
  font-size: 1.3em;
  font-weight: 700;
  line-height: 1;
}

.card-suit {
  font-size: 1.75em;
  line-height: 1;
  margin-top: 2px;
}

/* Classic card style (PNG images) */
.cell.card.classic {
  padding: 0;
  background: #fff;
  overflow: hidden;
}

.cell.card.classic .card-rank,
.cell.card.classic .card-suit {
  display: none;
}

.classic-card-img {
  position: absolute;
  top: 4%;
  left: 4%;
  width: 92%;
  height: 92%;
  pointer-events: none;
  background-size: 103% 102%;
  background-repeat: no-repeat;
  background-position: center;
  border-radius: 3px;
}

.cell.card.classic.locked {
  filter: grayscale(40%) brightness(0.85) sepia(15%);
}

/* Vintage card style (SVG sprite) */
.cell.card.vintage {
  padding: 0;
  background: #fff;
  overflow: hidden;
}

.cell.card.vintage .card-rank,
.cell.card.vintage .card-suit {
  display: none;
}

.vintage-card-svg {
  width: 100%;
  height: 100%;
  display: block;
  pointer-events: none;
}

.cell.card.vintage.locked {
  background: var(--locked-bg);
  filter: grayscale(40%) brightness(0.85) sepia(15%);
}

/* Gap */
.cell.gap {
  background: var(--gap-bg);
  border: 1.5px dashed var(--gap-border);
  cursor: default;
}

.cell.gap.valid-gap {
  background: var(--valid-gap-bg);
  border-color: var(--valid-gap-border);
  animation: pulse-gap 2s ease-in-out infinite;
}

/* Target gap: selected card can go here — brighter highlight */
.cell.gap.target-gap {
  background: rgba(100, 255, 100, 0.2);
  border-color: rgba(100, 255, 100, 0.9);
  border-style: solid;
  cursor: pointer;
  position: relative;
}

.cell.gap.target-gap::after {
  content: '';
  position: absolute;
  inset: -2px;
  border-radius: inherit;
  box-shadow: 0 0 20px rgba(100, 255, 100, 0.9);
  animation: pulse-target-opacity 0.9s ease-in-out infinite;
  pointer-events: none;
}

.cell.gap.incompatible-gap {
  opacity: 0.4;
}

.cell.gap.drag-over {
  background: rgba(100, 255, 100, 0.35);
  border-color: rgba(100, 255, 100, 1);
  border-style: solid;
  transform: scale(1.05);
}

.cell.gap.dead-gap {
  background: var(--dead-gap-bg);
  border-color: var(--dead-gap-border);
  cursor: not-allowed;
}

#board.game-over .cell {
  cursor: default !important;
}

.dead-icon {
  color: rgba(255, 60, 60, 0.4);
  font-size: 1.2em;
}

@keyframes pulse-gap {
  0%, 100% { border-color: var(--valid-gap-border); background: var(--valid-gap-bg); }
  50% { border-color: rgba(100, 255, 100, 0.15); background: transparent; }
}

@keyframes pulse-gap-light {
  0%, 100% { border-color: var(--valid-gap-border); background: var(--valid-gap-bg); }
  50% { border-color: rgba(20, 130, 20, 0.3); background: transparent; }
}

body.light-mode .cell.gap.valid-gap {
  animation-name: pulse-gap-light;
}

@keyframes pulse-target-opacity {
  0%, 100% { opacity: 0.6; }
  50% { opacity: 1; }
}

.cell.gap.invalid-target {
  animation: shake-invalid 0.38s ease forwards !important;
}

@keyframes shake-invalid {
  0%   { transform: translateX(0);    background: rgba(255, 70, 70, 0.18); border-color: rgba(255, 70, 70, 0.8); }
  22%  { transform: translateX(-4px); background: rgba(255, 70, 70, 0.22); }
  44%  { transform: translateX(4px);  border-color: rgba(255, 70, 70, 1.0); }
  66%  { transform: translateX(-3px); }
  88%  { transform: translateX(2px);  background: rgba(255, 70, 70, 0.1); }
  100% { transform: translateX(0);    background: var(--gap-bg); border-color: var(--gap-border); }
}

/* Floating card (used during animations) */
.floating-card {
  border-radius: 6px;
  background: var(--card-bg);
  border: 1.5px solid var(--card-border);
  box-shadow: 0 8px 20px rgba(0,0,0,0.4);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: clamp(0.7rem, 2vw, 1rem);
}

/* Deal-in animation */
@keyframes deal-in {
  from {
    opacity: 0;
    transform: translateY(-28px) scale(0.88);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.cell.card.deal-in {
  animation: deal-in 0.32s ease-out both;
}

/* Message bar (redeal prompt) — modal overlay */
.message-bar {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.7);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
  z-index: 200;
}

.message-bar.visible {
  opacity: 1;
  pointer-events: all;
}

.message-bar-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.85rem;
  padding: 2.5rem;
  background: var(--board-bg);
  border-radius: 16px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: var(--text);
  text-align: center;
  width: min(90vw, 400px);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}

body.light-mode .message-bar-box {
  background: var(--board-bg);
  border-color: rgba(0, 0, 0, 0.1);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.18);
}

.message-bar-title {
  font-family: 'Coustard', serif;
  font-size: 1.8rem;
  font-weight: 400;
  letter-spacing: 0.05em;
  color: var(--text);
  margin: 0;
}

.message-bar-text {
  font-size: 0.9rem;
  color: var(--text-muted);
  line-height: 1.5;
  margin: 0;
}

.redeal-tip {
  font-size: 0.8rem;
  color: var(--text-muted);
  opacity: 0.75;
  line-height: 1.5;
  margin: 0.5rem -2.5rem -2.5rem;
  background: rgba(255, 255, 255, 0.05);
  padding: 1rem 2.5rem 1.25rem;
  border-radius: 0 0 16px 16px;
}

body.light-mode .redeal-tip {
  background: rgba(0, 0, 0, 0.04);
}

.redeal-progress {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.1rem;
}

.redeal-score-value {
  font-size: 1.4rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  color: var(--text);
}

.redeal-score-label {
  font-size: 0.62rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
}

#redeal-btn {
  margin-top: 0.65rem;
  width: 100%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
}

/* Toast message (share feedback etc.) */
#message {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  padding: 0.6rem 1.2rem;
  border-radius: 8px;
  background: rgba(255, 200, 50, 0.12);
  border: 1px solid rgba(255, 200, 50, 0.3);
  color: #ffd866;
  font-size: 0.85rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
  z-index: 50;
}

#message.visible {
  opacity: 1;
}

/* Overlay */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
}

.overlay.visible {
  opacity: 1;
  pointer-events: all;
}

.overlay-content {
  background: var(--board-bg);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 16px;
  padding: 0.75rem 2.5rem 2.5rem;
  text-align: center;
  max-width: 400px;
  max-height: calc(100dvh - 2rem);
  overflow-y: auto;
  position: relative;
  transform: translateZ(0);
  -webkit-transform: translateZ(0);
}

.overlay.visible .overlay-content {
  animation: overlay-enter 0.45s cubic-bezier(0.34, 1.4, 0.64, 1) forwards;
}

@keyframes overlay-enter {
  from {
    opacity: 0;
    transform: scale(0.88) translateY(18px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.overlay-close-btn {
  position: sticky;
  top: 0.5rem;
  float: right;
  z-index: 10;
  margin: 0 -1rem 0 0;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.1rem;
  cursor: pointer;
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  line-height: 1;
  transition: color 0.15s, background 0.15s;
}

.overlay-close-btn:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.1);
}

body.light-mode .overlay-close-btn:hover {
  background: rgba(0, 0, 0, 0.08);
}

.overlay-content h2 {
  font-family: 'Coustard', serif;
  font-size: 1.8rem;
  font-weight: 400;
  letter-spacing: 0.05em;
  margin-top: 1.75rem;
  margin-bottom: 0.75rem;
}

.overlay-content p {
  color: var(--text-muted);
  margin-bottom: 1.25rem;
  line-height: 1.5;
}

.privacy-content {
  max-width: 480px;
  max-height: 80vh;
  overflow-y: auto;
  text-align: left;
  padding: 2rem 2.25rem;
}

.privacy-content h2 {
  text-align: center;
}

.privacy-content h3 {
  font-size: 0.95rem;
  font-weight: 600;
  margin-top: 1.25rem;
  margin-bottom: 0.4rem;
  color: var(--text);
}

.privacy-content p {
  font-size: 0.85rem;
  line-height: 1.6;
  margin-bottom: 0.6rem;
}

.privacy-content ul {
  font-size: 0.85rem;
  line-height: 1.6;
  padding-left: 1.25rem;
  margin-bottom: 0.6rem;
}

.privacy-content a {
  color: var(--accent, #4a9eff);
}

.overlay-difficulty {
  margin-top: 1.75rem;
  margin-left: -2.5rem;
  margin-right: -2.5rem;
  margin-bottom: -2.5rem;
  padding: 1.1rem 2.5rem 1.5rem;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 0 0 16px 16px;
}

body.light-mode .overlay-difficulty {
  background: rgba(0, 0, 0, 0.04);
}

/* Percentile badge duplicated above the tabs for at-a-glance visibility */
.overlay-percentile {
  margin: 0.25rem 0 0.75rem;
  display: flex;
  justify-content: center;
}

/* Top-10 live leaderboard view (replaces overlay content in place) */
.overlay-top10 {
  padding-top: 0.25rem;
}

.overlay-top10-date {
  margin: -0.5rem 0 1.5rem;
  text-align: center;
  font-size: 0.95rem;
  color: var(--text-muted);
}

.overlay-top10-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
}

.overlay-top10-row {
  position: relative;
  display: grid;
  grid-template-columns: 2.4em 1fr;
  grid-template-rows: auto auto;
  column-gap: 1rem;
  row-gap: 0.15rem;
  padding: 0.8rem 0.5rem 0.8rem 1rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.overlay-top10-row:last-child {
  border-bottom: none;
}

body.light-mode .overlay-top10-row {
  border-bottom-color: rgba(0, 0, 0, 0.1);
}

.overlay-top10-row.gold::before,
.overlay-top10-row.silver::before,
.overlay-top10-row.bronze::before {
  content: '';
  position: absolute;
  left: 0;
  top: 12%;
  bottom: 12%;
  width: 3px;
  border-radius: 2px;
}

.overlay-top10-row.gold::before   { background: #d4af37; }
.overlay-top10-row.silver::before { background: #b9b9b9; }
.overlay-top10-row.bronze::before { background: #cd7f32; }

.overlay-top10-row.is-you {
  background: rgba(255, 255, 255, 0.06);
  border-radius: 6px;
}

body.light-mode .overlay-top10-row.is-you {
  background: rgba(0, 0, 0, 0.05);
}

.overlay-top10-rank {
  grid-column: 1;
  grid-row: 1 / span 2;
  align-self: center;
  font-family: 'Coustard', serif;
  font-size: 1.3rem;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.overlay-top10-score {
  grid-column: 2;
  grid-row: 1;
  text-align: left;
  font-family: 'Coustard', serif;
  font-size: 1.05rem;
  letter-spacing: -0.01em;
  font-variant-numeric: tabular-nums;
}

.overlay-top10-meta {
  grid-column: 2;
  grid-row: 2;
  text-align: left;
  font-size: 0.95rem;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  line-height: 1.25;
}

.overlay-top10-status {
  margin: 1.5rem 0 0;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.85rem;
}

.deal-info-heading {
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Coustard', serif;
  font-size: 1.1rem;
  font-weight: 400;
  color: var(--text);
  margin-bottom: 0.2rem;
}

.deal-ai-icon {
  width: 18px;
  height: 18px;
  opacity: 0.7;
  flex-shrink: 0;
  margin-right: 0.35em;
}

.deal-info-subheading {
  display: block;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 0.72rem;
  color: var(--text-muted);
  line-height: 1.4;
  margin-bottom: 8px;
}

.deal-info-stats {
  display: flex;
  justify-content: center;
  gap: 1.5rem;
}

.deal-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.1rem;
}

.deal-stat-value {
  display: inline-flex;
  align-items: center;
  gap: 0.35em;
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
}

.deal-stat-label {
  font-size: 0.6rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  white-space: nowrap;
}

@keyframes skeleton-shimmer {
  0% { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}
.skeleton-line {
  display: block;
  height: 0.75rem;
  border-radius: 4px;
  background: linear-gradient(90deg, rgba(255,255,255,0.06) 25%, rgba(255,255,255,0.12) 50%, rgba(255,255,255,0.06) 75%);
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.5s ease infinite;
  margin: 6px auto;
}
body.light-mode .skeleton-line {
  background: linear-gradient(90deg, rgba(0,0,0,0.06) 25%, rgba(0,0,0,0.1) 50%, rgba(0,0,0,0.06) 75%);
  background-size: 200% 100%;
}
.skeleton-badge {
  display: block;
  height: 2rem;
  width: 70%;
  border-radius: 999px;
  margin: 10px auto;
  background: linear-gradient(90deg, rgba(255,255,255,0.06) 25%, rgba(255,255,255,0.12) 50%, rgba(255,255,255,0.06) 75%);
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.5s ease infinite;
}
body.light-mode .skeleton-badge {
  background: linear-gradient(90deg, rgba(0,0,0,0.06) 25%, rgba(0,0,0,0.1) 50%, rgba(0,0,0,0.06) 75%);
  background-size: 200% 100%;
}

.difficulty-badge {
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 14px;
}

.difficulty-badge-value {
  display: inline-flex;
  align-items: center;
  gap: 0.35em;
  font-size: 0.85rem;
  font-weight: 400;
  color: var(--text);
  background: rgba(255, 255, 255, 0.08);
  padding: 0.3em 0.9em;
  border-radius: 999px;
}

body.light-mode .difficulty-badge-value {
  background: rgba(0, 0, 0, 0.07);
}

.compare-details-btn {
  display: block;
  margin: 0 auto;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.72rem;
  cursor: pointer;
  text-decoration: underline;
  padding: 0;
}

.compare-details-btn:hover {
  color: var(--text);
  background: none;
  border: none;
}

body.light-mode .compare-details-btn,
body.light-mode .compare-details-btn:hover {
  background: none;
  border: none;
}

.compare-back-btn {
  position: sticky;
  top: 0.5rem;
  float: left;
  z-index: 10;
  margin: 0 0 0 -1rem;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.85rem;
  cursor: pointer;
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  line-height: 1;
  transition: color 0.15s, background 0.15s;
}

.compare-back-btn:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.1);
}

body.light-mode .compare-back-btn:hover {
  background: rgba(0, 0, 0, 0.08);
}

.compare-progress-bar {
  margin: 0.3rem 0 0;
}

.compare-progress-track {
  position: relative;
  height: 8px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.13);
  overflow: visible;
}

body.light-mode .compare-progress-track {
  background: rgba(0, 0, 0, 0.1);
}

.compare-progress-fill {
  height: 100%;
  border-radius: 4px;
  background: linear-gradient(to right, #a29bfe, #6c5ce7);
}

body.light-mode .compare-progress-fill {
  background: linear-gradient(to right, #8f85e0, #5a4fcf);
}

.compare-progress-avg {
  position: absolute;
  top: -3px;
  width: 2px;
  height: 14px;
  background: rgba(255, 255, 255, 0.6);
  border-radius: 1px;
  transform: translateX(-50%);
  z-index: 1;
}

body.light-mode .compare-progress-avg {
  background: rgba(0, 0, 0, 0.3);
}

.compare-progress-avg-label {
  position: absolute;
  top: 100%;
  margin-top: 2px;
  transform: translateX(-50%);
  font-size: 0.5rem;
  color: var(--text-muted);
  white-space: nowrap;
  line-height: 1;
}

.compare-winrate-bar {
  display: flex;
  height: 8px;
  border-radius: 4px;
  overflow: hidden;
  margin-top: 0.3rem;
}

.compare-winrate-won {
  background: linear-gradient(to right, #00b894, #2ecc71);
}

.compare-winrate-lost {
  background: linear-gradient(to right, #d63031, #e74c3c);
}

.compare-winrate-legend {
  display: flex;
  gap: 0.8rem;
  margin-top: 6px;
  font-size: 0.55rem;
  color: var(--text-muted);
}

.compare-winrate-legend-item {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.compare-winrate-legend-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* Detail view — replaces entire overlay content */
.compare-detail-view {
  text-align: left;
}

.compare-detail-title,
.overlay-content .compare-detail-title {
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Coustard', serif;
  font-size: 1.3rem;
  font-weight: 400;
  margin: 0;
  padding-top: 2.5rem;
  clear: both;
  white-space: nowrap;
  text-align: center;
  letter-spacing: normal;
  margin-bottom: 0;
}

.compare-detail-subtitle {
  font-size: 0.68rem;
  color: var(--text-muted);
  margin: 0 0 1rem;
  line-height: 1.4;
  text-align: center;
}

.compare-divider {
  height: 1px;
  background: rgba(255, 255, 255, 0.12);
  margin: 0.6rem 0;
}

body.light-mode .compare-divider {
  background: rgba(0, 0, 0, 0.1);
}

.compare-section {
  margin-bottom: 0;
  text-align: left;
}

.compare-section-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 0.25rem;
}

.compare-section-label {
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text);
}

.compare-section-value {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text);
}

.compare-section-sub {
  display: flex;
  align-items: flex-start;
  gap: 0.25rem;
  font-size: 0.6rem;
  color: var(--text-muted);
  margin-top: 4px;
  line-height: 1.3;
}

.compare-section-sub--spaced {
  margin-top: 1rem;
}

.compare-section-sub--after-slider {
  margin-top: 1.2rem;
}

.compare-info-icon {
  width: 10px;
  height: 10px;
  flex-shrink: 0;
  margin-top: 0.05em;
  opacity: 0.6;
}

/* Goes breakdown */
.compare-goes-breakdown {
  display: flex;
  flex-direction: column;
  gap: 0rem;
  margin-top: 0.6rem;
}

.compare-goes-bar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding-bottom: 1.1rem;
  opacity: 0.5;
}

.compare-goes-bar.compare-goes-active {
  opacity: 1;
}

.compare-goes-label {
  font-size: 0.65rem;
  font-weight: 600;
  color: var(--text);
  width: 2.5rem;
  flex-shrink: 0;
}

.compare-goes-fill-track {
  flex: 1;
  height: 6px;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.1);
  overflow: visible;
  position: relative;
}

body.light-mode .compare-goes-fill-track {
  background: rgba(0, 0, 0, 0.08);
}

.compare-goes-fill {
  height: 100%;
  border-radius: 3px;
  background: linear-gradient(to right, #a29bfe, #6c5ce7);
  min-width: 2px;
}

body.light-mode .compare-goes-fill {
  background: linear-gradient(to right, #8f85e0, #5a4fcf);
}

.compare-goes-avg {
  position: absolute;
  top: -2px;
  width: 2px;
  height: 10px;
  background: rgba(255, 255, 255, 0.6);
  border-radius: 1px;
  transform: translateX(-50%);
  z-index: 1;
}

body.light-mode .compare-goes-avg {
  background: rgba(0, 0, 0, 0.3);
}

.compare-goes-avg-label {
  position: absolute;
  top: 100%;
  margin-top: 3px;
  transform: translateX(-50%);
  font-size: 0.55rem;
  color: var(--text-muted);
  white-space: nowrap;
  line-height: 1;
}

.compare-goes-pct {
  font-size: 0.65rem;
  color: var(--text-muted);
  width: 2.2rem;
  text-align: right;
  flex-shrink: 0;
}


.compare-difficulty-badge {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 600;
  color: #fff;
  padding: 0.15em 0.7em;
  border-radius: 999px;
}

.compare-expand-btn {
  display: flex;
  align-items: center;
  gap: 0.35em;
  background: none;
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 4px;
  color: var(--text-muted);
  font-size: 0.6rem;
  letter-spacing: 0.02em;
  cursor: pointer;
  padding: 0.25rem 0.55rem;
  margin-top: 0.5rem;
  margin-left: auto;
  transition: color 0.2s, border-color 0.2s;
}
.compare-expand-btn:hover {
  color: var(--text);
  border-color: rgba(255,255,255,0.25);
}
body.light-mode .compare-expand-btn { border-color: rgba(0,0,0,0.12); }
body.light-mode .compare-expand-btn:hover { border-color: rgba(0,0,0,0.3); }
.compare-expand-chevron {
  font-size: 0.45rem;
  transition: transform 0.3s ease;
}
.compare-expand-btn.expanded .compare-expand-chevron {
  transform: rotate(180deg);
}
.compare-expandable {
  max-height: 0;
  overflow: hidden;
  opacity: 0;
  transition: max-height 0.35s ease, opacity 0.25s ease, padding 0.35s ease;
  padding-top: 0;
}
.compare-expandable.open {
  max-height: 300px;
  opacity: 1;
  padding-top: 0.5rem;
}

.compare-difficulty-bar {
  position: relative;
  display: flex;
  height: 8px;
  border-radius: 4px;
  overflow: visible;
  margin-top: 0.4em;
}

.compare-difficulty-zone {
  height: 100%;
}

.compare-difficulty-zone--hard {
  width: 24%;
  background: #d63031;
  border-radius: 4px 0 0 4px;
}

.compare-difficulty-zone--medium {
  width: 26%;
  background: #ff9800;
}

.compare-difficulty-zone--easy {
  width: 50%;
  background: #4caf50;
  border-radius: 0 4px 4px 0;
}

.compare-difficulty-marker {
  position: absolute;
  top: -3px;
  transform: translateX(-50%);
  width: 2px;
  height: 14px;
  background: rgba(255, 255, 255, 0.6);
  border-radius: 1px;
  z-index: 1;
}

body.light-mode .compare-difficulty-marker {
  background: rgba(0, 0, 0, 0.3);
}

.compare-difficulty-marker-label {
  position: absolute;
  top: 100%;
  margin-top: 2px;
  transform: translateX(-50%);
  font-size: 0.5rem;
  color: var(--text-muted);
  white-space: nowrap;
  line-height: 1;
}

.compare-difficulty-labels {
  display: flex;
  font-size: 0.7rem;
  font-weight: 600;
  margin-top: 0.25em;
}

.compare-difficulty-labels-item {
  text-align: center;
  opacity: 0.85;
}

.compare-difficulty-labels-item:nth-child(1) {
  width: 24%;
}

.compare-difficulty-labels-item:nth-child(2) {
  width: 26%;
}

.compare-difficulty-labels-item:nth-child(3) {
  width: 50%;
}

.compare-difficulty-inline {
  display: flex;
  align-items: center;
  gap: 0.5em;
  margin-top: 0.5em;
  font-size: 0.82rem;
  color: var(--text-muted);
}

.compare-difficulty-text strong {
  color: var(--text);
}

.diff-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.overlay-score {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
  margin-bottom: 1.25rem;
}

.score-value {
  font-size: 2.25rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  color: var(--text);
  line-height: 1;
}

.score-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
}

.overlay-details {
  display: flex;
  gap: 1.25rem;
  justify-content: center;
  margin-bottom: 1.25rem;
}

.detail-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.1rem;
}

.detail-label {
  font-size: 0.62rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  white-space: nowrap;
}

.detail-value {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
}

.overlay-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.5rem;
  margin-bottom: 1.25rem;
  padding: 0.75rem 0;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

body.light-mode .overlay-stats {
  border-color: rgba(0, 0, 0, 0.1);
}

.stat-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.15rem;
}

.stat-value {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text);
}

.stat-label {
  font-size: 0.62rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}

.overlay-actions {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

/* Floating buttons (Today's Result + Watch Replay) */
.floating-btns {
  position: fixed;
  bottom: 3.5rem;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 0.5rem;
  z-index: 50;
}

.view-result-btn {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: #fff;
  padding: 0.6rem 1.2rem;
  border-radius: 6px;
  font-size: 0.85rem;
  cursor: pointer;
  transition: background 0.2s;
  white-space: nowrap;
}

.view-result-btn:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.15);
}

.view-result-btn svg {
  flex-shrink: 0;
}

body.light-mode .view-result-btn {
  background: #e6e2da;
  color: var(--text);
}

body.light-mode .view-result-btn:hover:not(:disabled) {
  background: #ddd9d0;
}

/* Countdown timer */
.overlay-countdown {
  text-align: center;
  margin-top: 1rem;
}

.countdown-title {
  display: block;
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-bottom: 0.4rem;
  letter-spacing: 0.02em;
}

.countdown-boxes {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  gap: 0;
}

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

.countdown-unit {
  font-size: 0.5rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-top: 0.15rem;
}

.countdown-sep {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-muted);
  line-height: 1.5rem;
  margin: 0 0.15rem;
}

/* Rolling digit (odometer) */
.roll-group {
  display: flex;
  gap: 1px;
}

.roll-digit {
  width: 1.1rem;
  height: 1.5rem;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.07);
  border-radius: 4px;
  contain: strict;
}

body.light-mode .roll-digit {
  background: rgba(0, 0, 0, 0.05);
}

.roll-strip {
  display: flex;
  flex-direction: column;
  transition: transform 0.4s cubic-bezier(0.23, 1, 0.32, 1);
  will-change: transform;
  transform: translateZ(0);
  backface-visibility: hidden;
}

.roll-strip span {
  height: 1.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Coustard', serif;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text);
  flex-shrink: 0;
}

.overlay-share-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  width: 100%;
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.2);
}

.overlay-share-btn:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.15);
}

.overlay-share-btn.copied {
  background: rgba(255, 255, 255, 0.15);
}

/* Tabs at the top of the difficulty/practice section — flush with the card edges */
.overlay-tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  margin: -1.1rem -2.5rem 1rem;
}

body.light-mode .overlay-tabs {
  border-bottom-color: rgba(0, 0, 0, 0.1);
}

.overlay-tab,
body.light-mode .overlay-tab {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.85rem 0.3rem;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  margin-bottom: -1px;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease;
}

.overlay-tab-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  opacity: 0.9;
  stroke-width: 2.5;
  transform: translateZ(0);
  backface-visibility: hidden;
}

.overlay-tab:hover:not(:disabled),
body.light-mode .overlay-tab:hover:not(:disabled) {
  background: transparent;
  border-color: transparent;
  border-bottom-color: rgba(255, 255, 255, 0.25);
  color: var(--text);
}

body.light-mode .overlay-tab:hover:not(:disabled) {
  border-bottom-color: rgba(0, 0, 0, 0.2);
}

.overlay-tab.active,
.overlay-tab.active:hover:not(:disabled),
body.light-mode .overlay-tab.active,
body.light-mode .overlay-tab.active:hover:not(:disabled) {
  color: var(--text);
  border-bottom-color: var(--accent);
}

.overlay-tabs--skeleton .overlay-tab {
  cursor: default;
}

.tab-badge-new {
  display: inline-flex;
  align-items: center;
  padding: 0.15rem 0.4rem;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 0.6rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  line-height: 1;
}

.overlay-tab-panel[data-panel='practice'] {
  margin-left: -1.25rem;
  margin-right: -1.25rem;
}

.overlay-tab-panel[hidden] {
  display: none;
}

/* Practice deal buttons */
.practice-panel-intro {
  margin: 0 0 0.6rem;
  font-size: 0.72rem;
  color: var(--text-muted);
  text-align: center;
  line-height: 1.4;
}

.practice-deals {
  display: flex;
  flex-direction: row;
  gap: 0.5rem;
}

.practice-deals .practice-deal-btn {
  flex: 1;
  min-width: 0;
}

.practice-deal-btn {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  width: 100%;
  padding: 0.7rem 1.7rem 0.7rem 0.55rem;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  color: var(--text);
  cursor: pointer;
  text-align: left;
  transition: background 0.15s ease;
}

.practice-deal-btn:hover {
  background: rgba(255, 255, 255, 0.15);
}

body.light-mode .practice-deal-btn {
  background: rgba(0, 0, 0, 0.04);
  border-color: rgba(0, 0, 0, 0.12);
}

body.light-mode .practice-deal-btn:hover {
  background: rgba(0, 0, 0, 0.08);
}

.practice-deal-btn .deal-title {
  font-family: 'Coustard', serif;
  font-size: 0.8rem;
  font-weight: 400;
  white-space: nowrap;
}

.practice-deal-btn .deal-sub {
  font-size: 0.65rem;
  color: var(--text-muted);
  margin-top: 0.15rem;
  line-height: 1.35;
}

.deal-played-mark {
  position: absolute;
  right: 0.6rem;
  bottom: 0.55rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #7de29b;
  pointer-events: none;
}

body.light-mode .deal-played-mark {
  color: #2f7a47;
}

.deal-played-mark svg {
  width: 18px;
  height: 18px;
  display: block;
  transform: translateZ(0);
  backface-visibility: hidden;
}


/* Hide the Gaps logo entirely in practice mode so the exit button replaces it */
body.practice-mode .top-bar-left h1 {
  display: none;
}

/* Exit Practice button — matches icon-btn height, red tint, sits where the logo was */
.practice-exit-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  height: 2.2rem;
  padding: 0 0.75rem;
  font-size: 0.78rem;
  color: #ff6b6b;
  border: 1px solid rgba(255, 107, 107, 0.45);
  background: rgba(255, 107, 107, 0.12);
  border-radius: 6px;
  cursor: pointer;
  white-space: nowrap;
}

.practice-exit-btn:hover:not(:disabled) {
  background: rgba(255, 107, 107, 0.22);
  border-color: rgba(255, 107, 107, 0.7);
}

.practice-exit-btn svg {
  flex-shrink: 0;
}

body.light-mode .practice-exit-btn {
  color: #c42f2f;
  border-color: rgba(196, 47, 47, 0.45);
  background: rgba(196, 47, 47, 0.1);
}

body.light-mode .practice-exit-btn:hover:not(:disabled) {
  background: rgba(196, 47, 47, 0.18);
  border-color: rgba(196, 47, 47, 0.7);
}

/* Mobile: match the shrunken icon-btn size */
@media (max-width: 600px) {
  .practice-exit-btn {
    height: 1.9rem;
    padding: 0 0.55rem;
    font-size: 0.72rem;
  }
}

#overlay-btn {
  width: 100%;
}

/* Replay transport bar */
.replay-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1.5rem;
  padding: 0.8rem 1rem;
  padding-bottom: calc(0.8rem + env(safe-area-inset-bottom, 0px));
  background: rgba(20, 20, 30, 0.95);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 9999;
}

.replay-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  color: rgba(255, 255, 255, 0.8);
  cursor: pointer;
  padding: 0.5rem;
  border-radius: 50%;
  transition: background 0.15s, color 0.15s;
  width: 40px;
  height: 40px;
}

.replay-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
}

.replay-btn.replay-play {
  width: 48px;
  height: 48px;
  background: rgba(255, 255, 255, 0.1);
}

.replay-btn.replay-play:hover {
  background: rgba(255, 255, 255, 0.2);
}

.replay-btn svg {
  width: 20px;
  height: 20px;
}

.replay-btn.replay-play svg {
  width: 24px;
  height: 24px;
}

.replay-exit-btn {
  background: none;
  border: 1px solid rgba(255, 255, 255, 0.25);
  color: rgba(255, 255, 255, 0.8);
  cursor: pointer;
  padding: 0.4rem 1rem;
  border-radius: 6px;
  font-size: 0.8rem;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
}

.replay-exit-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
}

.replay-speed-btn {
  background: none;
  border: 1px solid rgba(255, 255, 255, 0.25);
  color: rgba(255, 255, 255, 0.8);
  cursor: pointer;
  padding: 0.4rem 0.7rem;
  border-radius: 6px;
  font-size: 0.8rem;
  font-weight: 600;
  min-width: 2.4rem;
  text-align: center;
  transition: background 0.15s, color 0.15s;
}

.replay-speed-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
}

.replay-go-label {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Coustard', serif;
  font-size: 2rem;
  font-weight: 400;
  color: #fff;
  background: rgba(0, 0, 0, 0.7);
  border-radius: 12px;
  z-index: 100;
  pointer-events: none;
  animation: replay-go-fade 1s ease-out forwards;
}

@keyframes replay-go-fade {
  0%   { opacity: 1; }
  70%  { opacity: 1; }
  100% { opacity: 0; }
}

/* =====================
   Light Mode
   ===================== */
body.light-mode {
  --bg: #f4f0e8;
  --board-bg: #e4dfd4;
  --card-bg: #ffffff;
  --card-border: #c8c2b8;
  --card-shadow: rgba(0, 0, 0, 0.12);
  --gap-bg: rgba(0, 0, 0, 0.04);
  --gap-border: rgba(0, 0, 0, 0.18);
  --dead-gap-bg: rgba(220, 50, 50, 0.07);
  --dead-gap-border: rgba(220, 50, 50, 0.35);
  --valid-gap-bg: rgba(20, 130, 20, 0.18);
  --valid-gap-border: rgba(20, 130, 20, 0.75);
  --movable-glow: rgba(0, 140, 255, 0.85);
  --movable-border: rgba(0, 140, 255, 0.65);
  --selected-glow: rgba(230, 160, 0, 0.8);
  --locked-bg: #ede9de;
  --locked-border: #b8b4a8;
  --red: #c0392b;
  --black: #1a1a2e;
  --accent: #5a4fcf;
  --text: #1a1a2e;
  --text-muted: #5a6470;
}

body.light-mode button {
  border-color: rgba(0, 0, 0, 0.2);
  background: rgba(0, 0, 0, 0.06);
  color: var(--text);
}

body.light-mode button:hover:not(:disabled) {
  background: rgba(0, 0, 0, 0.12);
  border-color: rgba(0, 0, 0, 0.3);
}

body.light-mode button.primary {
  background: var(--text);
  border-color: var(--text);
  color: #fff;
}

/* =====================
   Settings button
   ===================== */
.icon-btn {
  width: 2.2rem;
  height: 2.2rem;
  padding: 0;
  font-size: 1.05rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

#fullscreen-btn {
  display: none;
}

/* =====================
   Settings sidebar
   ===================== */
.settings-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s;
}

.settings-backdrop.open {
  opacity: 1;
  pointer-events: all;
}

.settings-sidebar {
  position: fixed;
  top: 0;
  right: 0;
  height: 100%;
  width: 320px;
  max-width: 90vw;
  background: var(--board-bg);
  border-left: 1px solid rgba(255, 255, 255, 0.12);
  z-index: 201;
  transform: translateX(100%);
  transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  flex-direction: column;
}

body.light-mode .settings-sidebar {
  border-left-color: rgba(0, 0, 0, 0.12);
}

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

.settings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.25rem 1.25rem 1rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

body.light-mode .settings-header {
  border-bottom-color: rgba(0, 0, 0, 0.1);
}

.settings-header h3 {
  font-family: 'Coustard', serif;
  font-size: 1rem;
  font-weight: 400;
  letter-spacing: 0.08em;
  color: var(--text);
}

.settings-close-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.1rem;
  cursor: pointer;
  padding: 0.25rem 0.4rem;
  border-radius: 4px;
  line-height: 1;
  transition: color 0.15s, background 0.15s;
}

.settings-close-btn:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.1);
}

body.light-mode .settings-close-btn:hover {
  background: rgba(0, 0, 0, 0.08);
}

.settings-body {
  flex: 1;
  overflow-y: auto;
  padding: 0.75rem 0;
}

.settings-group-title {
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 0.75rem 1.25rem 0.35rem;
}

.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.7rem 1.25rem;
}

.settings-row-info {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  flex: 1;
  min-width: 0;
}

.settings-label {
  font-size: 0.9rem;
  color: var(--text);
  font-weight: 500;
}

.settings-hint {
  font-size: 0.73rem;
  color: var(--text-muted);
  line-height: 1.4;
}

/* Toggle switch */
.toggle-switch {
  flex-shrink: 0;
  cursor: pointer;
  display: inline-block;
}

.toggle-switch input {
  display: none;
}

.toggle-track {
  display: block;
  width: 42px;
  height: 24px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.15);
  border: 1px solid rgba(255, 255, 255, 0.2);
  position: relative;
  transition: background 0.2s, border-color 0.2s;
}

body.light-mode .toggle-track {
  background: rgba(0, 0, 0, 0.12);
  border-color: rgba(0, 0, 0, 0.2);
}

.toggle-track::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--text-muted);
  transition: transform 0.2s, background 0.2s;
}

.toggle-switch input:checked + .toggle-track {
  background: var(--accent);
  border-color: var(--accent);
}

.toggle-switch input:checked + .toggle-track::after {
  transform: translateX(18px);
  background: #fff;
}

/* Volume slider */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.15);
  outline: none;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
}
input[type="range"]::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  cursor: pointer;
}
body.light-mode input[type="range"] {
  background: rgba(0, 0, 0, 0.12);
}

/* Sound mixer accordion */
.sound-mixer {
  overflow: hidden;
  max-height: 0;
  transition: max-height 0.3s ease, opacity 0.25s ease;
  opacity: 0;
  background: rgba(255, 255, 255, 0.04);
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}
.sound-mixer.open {
  max-height: 400px;
  opacity: 1;
}
body.light-mode .sound-mixer {
  background: rgba(0, 0, 0, 0.03);
  border-color: rgba(0, 0, 0, 0.07);
}
.sound-mixer-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 1.25rem;
}
.sound-mixer-label {
  font-size: 0.82rem;
  color: var(--text-muted);
  width: 6.5rem;
  flex-shrink: 0;
}
.sound-mixer-slider {
  flex: 1;
}

/* Stacked settings row (label above, control below) */
.settings-row.settings-row-stacked {
  flex-direction: column;
  align-items: stretch;
  gap: 0.5rem;
}

/* Settings radio group (segmented control) */
.settings-radio-group {
  display: flex;
  gap: 0;
  flex-shrink: 0;
}

.settings-radio-option {
  cursor: pointer;
  flex: 1;
}

.settings-radio-option input {
  display: none;
}

.radio-label {
  display: block;
  padding: 0.45rem 0.5rem;
  font-size: 0.78rem;
  text-align: center;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-left: none;
  color: var(--text-muted);
  transition: background 0.2s, border-color 0.2s, color 0.2s;
}

.settings-radio-option:first-child .radio-label {
  border-left: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 6px 0 0 6px;
}

.settings-radio-option:last-child .radio-label {
  border-radius: 0 6px 6px 0;
}

.settings-radio-option:only-child .radio-label {
  border-radius: 6px;
}

body.light-mode .radio-label {
  background: rgba(0, 0, 0, 0.05);
  border-color: rgba(0, 0, 0, 0.15);
  border-left: none;
}

body.light-mode .settings-radio-option:first-child .radio-label {
  border-left: 1px solid rgba(0, 0, 0, 0.15);
}

.settings-radio-option input:checked + .radio-label {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  position: relative;
  z-index: 1;
}

.radio-label.radio-loading {
  color: transparent;
  pointer-events: none;
}

.radio-label.radio-loading::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 14px;
  height: 14px;
  margin: -7px 0 0 -7px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: radio-spin 0.6s linear infinite;
}

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

/* Settings preview group (card & board style pickers) */
.settings-preview-group {
  display: flex;
  gap: 12px;
  flex-shrink: 0;
}

.settings-preview-option {
  cursor: pointer;
  flex: 1;
  text-align: center;
}

.settings-preview-option input {
  display: none;
}

.preview-card-wrapper,
.preview-board-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 8px;
  border-radius: 8px;
  border: 2px solid transparent;
  transition: border-color 0.2s, background 0.2s;
  background: rgba(255, 255, 255, 0.04);
}

body.light-mode .preview-card-wrapper,
body.light-mode .preview-board-wrapper {
  background: rgba(0, 0, 0, 0.03);
}

.settings-preview-option input:checked ~ .preview-card-wrapper,
.settings-preview-option input:checked ~ .preview-board-wrapper {
  border-color: var(--accent);
  background: rgba(59, 130, 246, 0.1);
}

.preview-label {
  font-size: 0.72rem;
  color: var(--text-muted);
  font-weight: 500;
}

.settings-preview-option input:checked ~ .preview-card-wrapper .preview-label,
.settings-preview-option input:checked ~ .preview-board-wrapper .preview-label {
  color: var(--accent);
}

/* Preview card */
.preview-card {
  width: 48px;
  aspect-ratio: 5 / 7;
  border-radius: 5px;
  background: var(--card-bg);
  border: 1.5px solid var(--card-border);
  box-shadow: 0 2px 4px var(--card-shadow);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  position: relative;
  overflow: hidden;
}

.preview-card .card-rank {
  font-size: 1.1em;
  font-weight: 700;
  line-height: 1;
}

.preview-card .card-suit {
  font-size: 1.4em;
  line-height: 1;
  margin-top: 1px;
}

.preview-card.red .card-rank,
.preview-card.red .card-suit {
  color: var(--red);
}

.preview-card.classic-preview {
  background: #fff;
  padding: 0;
}

.preview-card.classic-preview .classic-card-img {
  position: absolute;
  top: 4%;
  left: 4%;
  width: 92%;
  height: 92%;
  background-size: 103% 102%;
  background-repeat: no-repeat;
  background-position: center;
  border-radius: 2px;
}

.preview-card.vintage-preview {
  background: #fff;
  padding: 0;
}

.preview-card.vintage-preview.vintage-placeholder {
  padding: 0;
  overflow: hidden;
}

.vintage-placeholder-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.preview-card.vintage-preview .vintage-card-svg {
  width: 100%;
  height: 100%;
  display: block;
}

/* Preview board */
.preview-board {
  width: 100%;
  aspect-ratio: 2.5 / 1;
  border-radius: 6px;
  position: relative;
}

.preview-board-default {
  background: var(--board-bg);
}

.preview-board-classic {
  background: #2d6a4f;
  box-shadow: inset 0 0 20px rgba(0, 0, 0, 0.35);
  outline: 2px solid #1b4332;
  outline-offset: -2px;
}

body.light-mode .preview-board-classic {
  background: #2d6a4f;
}

.preview-board-wood {
  background: linear-gradient(90deg, #6b4226 0%, #7a4e2d 30%, #6b4226 60%, #7a4e2d 100%);
  box-shadow: inset 0 0 20px rgba(0, 0, 0, 0.3);
}

body.light-mode .preview-board-wood {
  background: linear-gradient(90deg, #8b6340 0%, #9a7350 30%, #8b6340 60%, #9a7350 100%);
}

/* Settings action row (tutorial button) */
.settings-row-action {
  flex-direction: row;
  align-items: center;
}

.settings-action-btn {
  flex-shrink: 0;
  padding: 0.4rem 0.85rem;
  font-size: 0.8rem;
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  border-radius: 6px;
  cursor: pointer;
  font-family: inherit;
  border: 1px solid var(--accent);
  transition: background 0.2s;
}

.settings-action-btn:hover {
  background: #7c6cf7;
}

/* Card style attribution tooltip icon (inline in label) */
.card-style-attribution {
  font-size: 0.7em;
  color: var(--text-muted);
  opacity: 0.45;
  text-decoration: none;
  cursor: help;
  margin-left: 0.25em;
  vertical-align: middle;
  transition: opacity 0.15s, color 0.15s;
}

.card-style-attribution:hover {
  opacity: 0.85;
  color: var(--text);
}

.settings-footer-attribution {
  font-size: 0.68rem;
  color: var(--text-muted);
  opacity: 0.35;
}

.settings-footer-attribution a {
  font-size: inherit;
  opacity: 1;
}

.settings-footer {
  padding: 0.75rem 1.25rem;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  text-align: center;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.settings-footer-top {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 0.5rem;
}

.settings-footer-copyright {
  font-size: 0.75rem;
  color: var(--text-muted);
  opacity: 0.45;
}

.settings-footer-links {
  font-size: 0.75rem;
  color: var(--text-muted);
  opacity: 0.45;
}

.settings-footer .settings-footer-links a {
  opacity: 1;
  color: inherit;
}

.settings-footer a {
  font-size: 0.75rem;
  color: var(--text-muted);
  opacity: 0.45;
  text-decoration: none;
  transition: opacity 0.2s, color 0.2s;
}

.settings-footer a:hover {
  opacity: 0.8;
  color: var(--text);
}

body.light-mode .settings-footer {
  border-top-color: rgba(0, 0, 0, 0.06);
}

/* =====================
   Tutorial overlay
   ===================== */
.tutorial-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 300;
  pointer-events: none;
  opacity: 0;
  transform: translateY(20px);
  transition: opacity 0.25s, transform 0.25s;
}

.tutorial-overlay.visible {
  opacity: 1;
  transform: translateY(0);
  pointer-events: all;
}

.tutorial-card {
  background: var(--board-bg);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 14px;
  padding: 1.25rem 1.5rem 1rem;
  max-width: 560px;
  width: 100%;
  box-shadow: 0 4px 32px rgba(0, 0, 0, 0.45);
  min-height: 260px;
  display: flex;
  flex-direction: column;
}

body.light-mode .tutorial-card {
  border-color: rgba(0, 0, 0, 0.12);
  box-shadow: 0 -4px 32px rgba(0, 0, 0, 0.18);
}

.tutorial-title {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-family: 'Coustard', serif;
  font-size: 1.2rem;
  font-weight: 400;
  color: var(--text);
  margin-bottom: 0.5rem;
}

.tutorial-help-icon {
  flex-shrink: 0;
  color: var(--text-muted);
}

.tutorial-text {
  font-size: 0.85rem;
  color: var(--text-muted);
  line-height: 1.65;
  margin-bottom: 0.75rem;
}

.tutorial-text ul {
  margin: 0;
  padding-left: 1.2rem;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.tutorial-help-toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  padding-top: 0.75rem;
  margin-top: 0.25rem;
  margin-bottom: 0.75rem;
}

body.light-mode .tutorial-help-toggle-row {
  border-top-color: rgba(0, 0, 0, 0.08);
}

.tutorial-help-text {
  font-size: 0.8rem;
  color: var(--text-muted);
  line-height: 1.55;
  background: rgba(108, 92, 231, 0.1);
  border-left: 3px solid var(--accent);
  border-radius: 0 6px 6px 0;
  padding: 0.55rem 0.75rem;
  margin-bottom: 1rem;
}

body.light-mode .tutorial-help-text {
  background: rgba(108, 92, 231, 0.07);
}

.tutorial-nav {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
  margin-top: auto;
}

.tutorial-nav-btn {
  padding: 0.4rem 0.9rem;
  font-size: 0.8rem;
  border-radius: 6px;
  cursor: pointer;
  font-family: inherit;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.07);
  color: var(--text);
  transition: background 0.15s;
}

body.light-mode .tutorial-nav-btn {
  border-color: rgba(0, 0, 0, 0.18);
  background: rgba(0, 0, 0, 0.05);
}

.tutorial-nav-btn:hover {
  background: rgba(255, 255, 255, 0.13);
}

body.light-mode .tutorial-nav-btn:hover {
  background: rgba(0, 0, 0, 0.1);
}

.tutorial-nav-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.tutorial-nav-primary:hover {
  background: #7c6cf7 !important;
}

/* =====================
   Interactive tutorial
   ===================== */

/* Golden pulse glow on highlighted tutorial cells / elements */
@keyframes tutorial-pulse-opacity {
  0%, 100% { opacity: 0.5; }
  50% { opacity: 1; }
}

.tutorial-target {
  z-index: 2;
  position: relative;
  border-radius: 8px;
}

.tutorial-target::after {
  content: '';
  position: absolute;
  inset: -2px;
  border-radius: inherit;
  box-shadow: 0 0 14px 5px rgba(255, 200, 50, 0.85);
  animation: tutorial-pulse-opacity 1.2s ease-in-out infinite;
  pointer-events: none;
}

#settings-btn.tutorial-target,
#how-to-play-btn.tutorial-target {
  box-shadow: 0 0 14px 5px rgba(255, 200, 50, 0.85);
  animation: tutorial-pulse-opacity 1.2s ease-in-out infinite;
}

#settings-btn.tutorial-target::after,
#how-to-play-btn.tutorial-target::after {
  display: none;
}

/* Dim non-target cells during tutorial */
body.tutorial-mode #board .cell:not(.tutorial-target) {
  opacity: 0.45;
  transition: opacity 0.2s;
}

body.tutorial-mode #board .cell.tutorial-target {
  opacity: 1;
}

body.tutorial-free-move #board .cell {
  opacity: 1 !important;
}

.tutorial-text-with-hint {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}
.tutorial-hint-btn {
  display: inline-block;
  flex-shrink: 0;
  padding: 0.3em 0.9em;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--accent, #5b9cf5);
  background: rgba(91, 156, 245, 0.1);
  border: 1px solid var(--accent, #5b9cf5);
  border-radius: 6px;
  cursor: pointer;
}
.tutorial-hint-btn:hover {
  background: rgba(91, 156, 245, 0.2);
}

/* Hide irrelevant UI during tutorial */
#auto-complete-wrap {
  position: relative;
}

#auto-complete-btn {
  background: #e74c3c;
  color: #fff;
  font-size: 0.65rem;
  padding: 0.25em 0.6em;
  border-radius: 4px;
  border: none;
  cursor: pointer;
  opacity: 0.8;
}

#auto-complete-btn:hover {
  opacity: 1;
}

.auto-complete-dropdown {
  display: none;
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 4px;
  background: var(--board-bg);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 6px;
  padding: 8px 10px;
  z-index: 100;
  min-width: 170px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

body.light-mode .auto-complete-dropdown {
  background: #fff;
  border-color: rgba(0, 0, 0, 0.12);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
}

.auto-complete-dropdown.open {
  display: block;
}

.ac-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
  font-size: 0.65rem;
  color: var(--text);
}

.ac-radio {
  display: flex;
  align-items: center;
  gap: 3px;
  cursor: pointer;
  font-size: 0.65rem;
}

.ac-radio input {
  margin: 0;
}

.ac-label {
  font-size: 0.6rem;
  color: var(--text-muted);
  white-space: nowrap;
}

#ac-moves-slider {
  flex: 1;
  cursor: pointer;
  accent-color: #e74c3c;
  height: 18px;
}

#ac-go-btn {
  width: 100%;
  background: #e74c3c;
  color: #fff;
  border: none;
  border-radius: 4px;
  padding: 4px 0;
  font-size: 0.65rem;
  cursor: pointer;
  opacity: 0.9;
}

#ac-go-btn:hover {
  opacity: 1;
}

body.light-mode .replay-bar {
  background: rgba(255, 255, 255, 0.95);
}
body.light-mode .replay-btn {
  color: rgba(0, 0, 0, 0.7);
}
body.light-mode .replay-btn:hover {
  background: rgba(0, 0, 0, 0.08);
  color: #000;
}
body.light-mode .replay-btn.replay-play {
  background: rgba(0, 0, 0, 0.06);
}
body.light-mode .replay-btn.replay-play:hover {
  background: rgba(0, 0, 0, 0.12);
}
body.light-mode .replay-exit-btn {
  border-color: rgba(0, 0, 0, 0.2);
  color: rgba(0, 0, 0, 0.6);
}
body.light-mode .replay-exit-btn:hover {
  background: rgba(0, 0, 0, 0.06);
  color: #000;
}
body.light-mode .replay-speed-btn {
  border-color: rgba(0, 0, 0, 0.2);
  color: rgba(0, 0, 0, 0.6);
}
body.light-mode .replay-speed-btn:hover {
  background: rgba(0, 0, 0, 0.06);
  color: #000;
}
body.light-mode .replay-go-label {
  color: #fff;
  background: rgba(0, 0, 0, 0.6);
}

body.tutorial-mode #floating-btns {
  display: none;
}

body.tutorial-mode #how-to-play-btn {
  pointer-events: none;
  opacity: 0.3;
}

body.tutorial-mode .settings-body {
  overflow-y: hidden;
}

/* Speech bubble */
#tutorial-bubble {
  display: none;
}

.tutorial-bubble-visible {
  display: block !important;
  position: fixed;
  z-index: 400;
  background: var(--board-bg);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 12px;
  padding: 1rem 1.2rem 0.75rem;
  max-width: 340px;
  width: calc(100vw - 32px);
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.45);
}

.tutorial-bubble-visible.tutorial-bubble-ready {
  animation: bubble-in 0.25s ease-out;
}

body.light-mode .tutorial-bubble-visible {
  border-color: rgba(0, 0, 0, 0.12);
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.18);
}

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

.tutorial-bubble-center {
  max-width: 380px;
}

.tutorial-bubble-title {
  font-family: 'Coustard', serif;
  font-size: 1rem;
  font-weight: 400;
  color: var(--text);
  margin-bottom: 0.4rem;
}

.tutorial-bubble-text {
  font-size: 0.82rem;
  color: var(--text-muted);
  line-height: 1.6;
  margin-bottom: 0.6rem;
}

.tutorial-bubble-text em {
  color: var(--accent);
  font-style: normal;
}

/* Mini card sequence examples in tutorial */
.tutorial-seq {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin: 0.25rem 0;
}

.tutorial-seq-cards {
  display: flex;
  align-items: center;
  gap: 2px;
}

.tutorial-seq:first-of-type {
  margin-top: 0.6rem;
}

.tutorial-seq:last-of-type {
  margin-bottom: 0.6rem;
}

.tutorial-seq-label {
  font-size: 0.7rem;
  line-height: 1;
  flex-shrink: 0;
  white-space: nowrap;
  min-width: 4.5em;
  text-align: left;
}

.tutorial-seq-label.valid {
  color: #22c55e;
}

.tutorial-seq-label.invalid {
  color: #ef4444;
}

.tutorial-mini-card {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--card-bg);
  border: 1.5px solid var(--card-border);
  border-radius: 3px;
  width: 1.55rem;
  height: 2.1rem;
  flex-shrink: 0;
  line-height: 1;
  box-shadow: 0 1px 2px var(--card-shadow);
}

.tutorial-mini-card .mini-rank {
  font-size: 0.5rem;
  font-weight: 700;
}

.tutorial-mini-card .mini-suit {
  font-size: 0.65rem;
}

.tutorial-mini-card.red .mini-rank,
.tutorial-mini-card.red .mini-suit {
  color: var(--red);
}

.tutorial-mini-card.black .mini-rank,
.tutorial-mini-card.black .mini-suit {
  color: var(--black);
}

.tutorial-mini-card.invalid-card {
  border-color: #ef4444;
  box-shadow: 0 0 6px rgba(239, 68, 68, 0.4);
}

.tutorial-bubble-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  padding-top: 0.5rem;
}

body.light-mode .tutorial-bubble-footer {
  border-top-color: rgba(0, 0, 0, 0.08);
}

.tutorial-bubble-counter {
  font-size: 0.7rem;
  color: var(--text-muted);
  opacity: 0.7;
}

.tutorial-bubble-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.tutorial-bubble-skip {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-decoration: none;
  opacity: 0.7;
  transition: opacity 0.15s;
}

.tutorial-bubble-skip:hover {
  opacity: 1;
}

.tutorial-bubble-next {
  padding: 0.3rem 0.8rem;
  font-size: 0.78rem;
  font-family: inherit;
  border-radius: 6px;
  border: none;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  transition: background 0.15s;
}

.tutorial-bubble-next:hover {
  background: #7c6cf7;
}

body.light-mode .tutorial-bubble-next {
  background: var(--accent);
  color: #fff;
  border: none;
}

/* Arrow pointers for positioned bubbles */
.tutorial-bubble-above::after,
.tutorial-bubble-below::before,
.tutorial-bubble-left::after,
.tutorial-bubble-right::before {
  content: '';
  position: absolute;
  width: 0;
  height: 0;
}

.tutorial-bubble-below::before {
  top: -7px;
  left: 50%;
  transform: translateX(-50%);
  border-left: 7px solid transparent;
  border-right: 7px solid transparent;
  border-bottom: 7px solid var(--board-bg);
}

.tutorial-bubble-above::after {
  bottom: -7px;
  left: 50%;
  transform: translateX(-50%);
  border-left: 7px solid transparent;
  border-right: 7px solid transparent;
  border-top: 7px solid var(--board-bg);
}

.tutorial-bubble-left::after {
  right: -7px;
  top: 50%;
  transform: translateY(-50%);
  border-top: 7px solid transparent;
  border-bottom: 7px solid transparent;
  border-left: 7px solid var(--board-bg);
}

.tutorial-bubble-right::before {
  left: -7px;
  top: 50%;
  transform: translateY(-50%);
  border-top: 7px solid transparent;
  border-bottom: 7px solid transparent;
  border-right: 7px solid var(--board-bg);
}

/* Mobile: compact bubble */
@media (max-width: 480px) {
  .tutorial-bubble-visible {
    max-width: calc(100vw - 24px);
    padding: 0.75rem 1rem 0.6rem;
  }

  .tutorial-bubble-title {
    font-size: 0.9rem;
  }

  .tutorial-bubble-text {
    font-size: 0.78rem;
  }
}

/* =====================
   Responsive
   ===================== */
@media (max-width: 600px) {
  body {
    padding: 0.2rem;
    padding-top: max(0.2rem, env(safe-area-inset-top));
    padding-bottom: max(0.2rem, env(safe-area-inset-bottom));
    height: 100svh;
    overflow: hidden;
  }

  .game-area {
    justify-content: flex-start;
  }

  .top-bar {
    gap: 0.35rem;
    margin-bottom: 0;
    padding: 0 0.25rem;
  }

  .top-bar-left {
    gap: 0.35rem;
  }

  .top-bar h1 {
    font-size: 1.15rem;
  }

  #board {
    gap: 2px;
    padding: 0.3rem;
    border-radius: 8px;
    /* Size columns from available height so 4 rows fit without overflow.
       Use svh so iOS Safari URL bar doesn't cause unused space.
       Overhead ≈ body padding + top-bar + gaps + board padding ≈ 46px */
    grid-template-columns: repeat(10, calc((100svh - env(safe-area-inset-top) - env(safe-area-inset-bottom) - 46px) / 4 * 5 / 7));
    width: auto;
    margin: 0 auto;
  }

  .cell {
    border-radius: 3px;
  }

  .card-rank {
    font-size: 1.1em;
  }

  .card-suit {
    font-size: 1.4em;
  }

  .status-bar {
    gap: 0.5rem;
    font-size: 0.7rem;
  }

  .status-item {
    gap: 0.1rem;
  }

  button {
    padding: 0.35rem 0.65rem;
    font-size: 0.75rem;
  }

  .icon-btn {
    width: 1.9rem;
    min-width: 1.9rem;
    max-width: 1.9rem;
    height: 1.9rem;
    padding: 0;
    font-size: 0.95rem;
    overflow: hidden;
  }

  .site-footer {
    display: none;
  }

  /* Shrink board when replay bar is visible */
  body.replay-active #board {
    grid-template-columns: repeat(10, calc((100svh - env(safe-area-inset-top) - env(safe-area-inset-bottom) - 46px - 105px) / 4 * 5 / 7));
  }

  /* Full-height end-game overlay on mobile */
  .overlay {
    align-items: stretch;
  }

  .overlay-content {
    width: 100vw;
    max-width: 100vw;
    min-height: 100svh;
    max-height: 100svh;
    border-radius: 0;
    border-left: none;
    border-right: none;
    padding: 1rem 1.25rem max(1rem, env(safe-area-inset-bottom)) 1.25rem;
  }

  /* Stretch the tabs background to fill to the modal bottom */
  .overlay-content {
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
  }

  /* Close button relies on float: right — restore right-alignment in flex */
  .overlay-close-btn {
    align-self: flex-end;
  }

  /* Bleed to modal edges without overflowing the viewport, plus
     breathing room either side of the Practice Run buttons. */
  .overlay-difficulty {
    flex-grow: 1;
    margin-left: -1.25rem;
    margin-right: -1.25rem;
    padding-left: 1.5rem;
    padding-right: 1.5rem;
  }

}

/* Mobile / tablet landscape — fit all cards in viewport without scrolling */
@media (orientation: landscape) and (max-height: 480px) {
  .site-footer { display: none; }

  .floating-btns {
    opacity: 0.85;
    bottom: 0.75rem;
  }

  body {
    height: 100dvh;
    overflow: hidden;
    padding: 0.2rem 0.75rem;
    padding-left: max(0.75rem, env(safe-area-inset-left));
    padding-right: max(0.75rem, env(safe-area-inset-right));
  }

  /* Position title above the metrics on the left */
  .top-bar-left {
    position: fixed;
    left: 1rem;
    top: 0.5rem;
    transform: none;
    z-index: 10;
  }

  .top-bar-left h1 {
    font-size: 1rem;
    font-weight: 800;
  }

  .top-bar {
    margin-bottom: 0.2rem;
  }

  .game-area {
    justify-content: flex-start;
    padding-left: 55px;   /* space for metrics on the left */
    padding-right: 40px;  /* space for icon buttons on the right */
  }

  #board {
    padding: 0.25rem;
    gap: 2px;
    /* Drive column width from available height so 4 rows always fit.
       Top-bar overhead reduced to ~30px since metrics moved to the side.
       min() ensures board also fits horizontally (side elements + gaps). */
    grid-template-columns: repeat(10, calc(
      min(
        (100dvh - 30px) / 4 * 5 / 7,
        (100dvw - 55px - 40px - 20px) / 10
      )
    ));
    width: auto;
    margin: 0 auto;
  }

  .cell {
    font-size: clamp(0.4rem, 1.8dvh, 0.8rem);
    border-radius: 3px;
  }

  .card-rank {
    font-size: 2.2em;
  }

  .card-suit {
    font-size: 2.8em;
  }

  /* Move metrics to the left of the board, stacked vertically */
  .status-bar {
    position: fixed;
    left: 1rem;
    top: 2.2rem;
    transform: none;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.4rem;
    font-size: 0.65rem;
  }

  /* Stack ? and ⚙ buttons vertically on the right of the board */
  #how-to-play-btn,
  #settings-btn {
    position: fixed;
    right: 1rem;
    z-index: 10;
  }

  #how-to-play-btn {
    top: 0.5rem;
  }

  #settings-btn {
    top: calc(0.5rem + 1.9rem + 8px);
  }

  #fullscreen-btn {
    display: inline-flex;
    position: fixed;
    right: 1rem;
    top: calc(0.5rem + 1.9rem + 8px + 1.9rem + 8px);
    z-index: 10;
  }

  button {
    padding: 0.35rem 0.7rem;
    font-size: 0.78rem;
  }

  /* Narrow the settings sidebar so tutorial bubbles fit to its left */
  .settings-sidebar {
    width: 55vw;
  }

  /* Fit modals within landscape viewport */
  .overlay-content {
    max-height: calc(100dvh - 1rem);
    overflow-y: auto;
    padding: 1.25rem 1.5rem;
  }

  .overlay-content h2 {
    font-size: 1.3rem;
    margin-bottom: 0.4rem;
  }

  .overlay-content p {
    margin-bottom: 0.6rem;
    font-size: 0.8rem;
  }

  .overlay-score {
    margin-bottom: 0.6rem;
  }

  .score-value {
    font-size: 1.3rem;
  }

  .overlay-details {
    margin-bottom: 0.6rem;
    gap: 0.75rem;
  }

  .overlay-stats {
    margin-bottom: 0.6rem;
    padding: 0.4rem 0;
  }

  .overlay-actions {
    gap: 0.4rem;
  }

  .message-bar-box {
    max-height: calc(100dvh - 1rem);
    overflow-y: auto;
    padding: 1.25rem 1.5rem;
    gap: 0.5rem;
  }

  .message-bar-title {
    font-size: 1.3rem;
  }

  .message-bar-text {
    font-size: 0.8rem;
  }

  .redeal-tip {
    font-size: 0.7rem;
    margin: 0.3rem -1.5rem -1.25rem;
    padding: 0.6rem 1.5rem 0.75rem;
  }

  /* Shrink board when replay bar is visible */
  body.replay-active #board {
    grid-template-columns: repeat(10, calc(
      min(
        (100dvh - 30px - 60px) / 4 * 5 / 7,
        (100dvw - 55px - 40px - 20px) / 10
      )
    ));
  }
}

/* =====================
   Tablet landscape (iPad etc.)
   pointer: coarse excludes desktops/laptops (mouse = fine pointer)
   ===================== */
@media (orientation: landscape) and (min-height: 481px) and (pointer: coarse) {
  .top-bar,
  .game-area {
    max-width: 95vw;
  }

  .top-bar h1 {
    font-size: 1.75rem;
  }

  .status-bar {
    font-size: 1rem;
    gap: 1.5rem;
  }

  .icon-btn {
    width: 2.6rem;
    height: 2.6rem;
    font-size: 1.25rem;
  }

  button {
    font-size: 1rem;
    padding: 0.55rem 1.35rem;
  }
}

/* Ace card — slightly dimmed while on board before removal animation */
.cell.ace-card {
  opacity: 0.85;
}

/* =====================
   Footer
   ===================== */
.site-footer {
  margin-top: 1rem;
  padding: 0.75rem 0;
  text-align: center;
  font-size: 0.65rem;
  color: var(--text-muted);
  opacity: 0.45;
  flex-shrink: 0;
}

.site-footer a {
  color: inherit;
  text-decoration: none;
  transition: opacity 0.2s, color 0.2s;
}

.site-footer a:hover {
  opacity: 1;
  color: var(--text);
}

/* =====================
   Portrait mobile — standard landscape layout (not transposed)
   ===================== */
@media (orientation: portrait) and (max-width: 600px) {
  .site-footer { display: none; }

  body:not(.portrait-columns) .game-area {
    justify-content: center;
  }

  body:not(.portrait-columns) #board {
    /* Size columns from viewport width so 10 columns fit on screen.
       Overhead ≈ body padding (2 × 0.2rem ≈ 6px) + board padding (2 × 0.3rem ≈ 10px) + gaps (9 × 2px = 18px) ≈ 34px */
    grid-template-columns: repeat(10, 1fr);
    width: calc(100vw - 0.4rem);
    max-width: 100%;
  }

  body:not(.portrait-columns) .cell {
    font-size: clamp(0.35rem, 2.2vw, 0.7rem);
  }

  body:not(.portrait-columns) .card-rank {
    font-size: 1.1em;
  }

  body:not(.portrait-columns) .card-suit {
    font-size: 1.4em;
  }

  /* Shrink board when replay bar is visible (standard portrait: 4 rows) */
  body.replay-active:not(.portrait-columns) #board {
    grid-template-columns: repeat(10, calc((100svh - env(safe-area-inset-top) - env(safe-area-inset-bottom) - 46px - 105px) / 4 * 5 / 7));
    width: auto;
  }
}

/* =====================
   Portrait Columns — transpose rows↔columns on mobile portrait
   ===================== */
@media (orientation: portrait) and (max-width: 600px) {
  body.portrait-columns {
    height: 100svh;
    overflow: hidden;
    padding: 0.2rem;
    padding-top: max(0.2rem, env(safe-area-inset-top));
    padding-bottom: max(0.2rem, env(safe-area-inset-bottom));
  }

  body.portrait-columns .top-bar {
    margin-bottom: 0.15rem;
  }

  body.portrait-columns #board {
    /* Drive column width from viewport height so all 10 rows always fit on screen.
       Use svh so iOS Safari URL bar doesn't cause unused space.
       Available ≈ 100svh minus safe-area-inset-top, body padding, top-bar, board padding/gaps. */
    grid-template-columns: repeat(4, calc((100svh - env(safe-area-inset-top) - env(safe-area-inset-bottom) - 75px) / 10 * 5 / 7));
    grid-template-rows: repeat(10, auto);
    gap: 2px;
    padding: 0.25rem;
    width: auto;
    margin: 0 auto;
  }

  /* Shrink board when replay bar is visible (portrait-columns: 10 rows) */
  body.replay-active.portrait-columns #board {
    grid-template-columns: repeat(4, calc((100svh - env(safe-area-inset-top) - env(safe-area-inset-bottom) - 75px - 105px) / 10 * 5 / 7));
  }


  /* Map data-row → visual column */
  body.portrait-columns .cell[data-row="0"] { grid-column: 1; }
  body.portrait-columns .cell[data-row="1"] { grid-column: 2; }
  body.portrait-columns .cell[data-row="2"] { grid-column: 3; }
  body.portrait-columns .cell[data-row="3"] { grid-column: 4; }

  /* Map data-col → visual row */
  body.portrait-columns .cell[data-col="0"] { grid-row: 1; }
  body.portrait-columns .cell[data-col="1"] { grid-row: 2; }
  body.portrait-columns .cell[data-col="2"] { grid-row: 3; }
  body.portrait-columns .cell[data-col="3"] { grid-row: 4; }
  body.portrait-columns .cell[data-col="4"] { grid-row: 5; }
  body.portrait-columns .cell[data-col="5"] { grid-row: 6; }
  body.portrait-columns .cell[data-col="6"] { grid-row: 7; }
  body.portrait-columns .cell[data-col="7"] { grid-row: 8; }
  body.portrait-columns .cell[data-col="8"] { grid-row: 9; }
  body.portrait-columns .cell[data-col="9"] { grid-row: 10; }

  body.portrait-columns .cell {
    aspect-ratio: 5 / 7;
    /* Scale text with viewport height so it's readable at any phone size */
    font-size: clamp(0.55rem, 1.6dvh, 0.9rem);
  }

  body.portrait-columns .card-rank {
    font-size: 1.5em;
  }

  body.portrait-columns .card-suit {
    font-size: 2em;
  }
}
