* { margin: 0; padding: 0; box-sizing: border-box; }
:root {
  --board-size: min(95vw, 400px);
  --cell-size: 28px;
  --pool-cell: 28px;
  --gap: 12px;
  /* Android system bar insets (injected by native code) */
  --safe-top: 0px;
  --safe-bottom: 0px;
  --ime-bottom: 0px;
}
/* Desktop: 600px cap at 1200px+, 720px at 1600px+, 900px at 4K */
@media (min-width: 769px) and (pointer: fine) {
  :root {
    --board-size: min(80vh, 80vw, 600px);
    --gap: 20px;
  }
}
@media (min-width: 1200px) and (pointer: fine) {
  :root {
    --board-size: min(80vh, 80vw, 720px);
    --gap: 24px;
  }
}
@media (min-width: 2400px) and (pointer: fine) {
  :root {
    --board-size: min(80vh, 80vw, 900px);
    --gap: 28px;
  }
}
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #1a1a2e;
  color: #eee;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  user-select: none;
  -webkit-user-select: none;
  overflow-x: hidden;
  padding-top: env(safe-area-inset-top, 0px);
}

header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  width: 100%;
  max-width: 600px;
  justify-content: space-between;
}

h1 { font-size: 22px; font-weight: 700; letter-spacing: 1px; }

.header-left {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}
.header-right {
  display: flex;
  align-items: center;
  gap: 6px;
}
.header-left h1 {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#timer {
  font-size: 22px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: #f0e68c;
  text-align: right;
  flex-shrink: 0;
}

#pause-btn {
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  padding: 0;
  line-height: 1;
  color: #f0e68c;
  opacity: 0.7;
  transition: opacity 0.15s;
}
#pause-btn:hover { opacity: 1; }

#pause-overlay {
  display: none;
  position: absolute;
  inset: 0;
  z-index: 50;
  background: rgba(10, 10, 30, 0.92);
  border-radius: 8px;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
}
#pause-overlay.show { display: flex; }
#pause-play-btn {
  background: none;
  border: 2px solid rgba(255,255,255,0.3);
  border-radius: 50%;
  width: 80px;
  height: 80px;
  font-size: 36px;
  cursor: pointer;
  color: #f0e68c;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, border-color 0.15s;
}
#pause-play-btn:hover { background: rgba(255,255,255,0.08); border-color: rgba(255,255,255,0.5); }
#pause-label {
  font-size: 16px;
  color: #888;
  letter-spacing: 2px;
  text-transform: uppercase;
}

#action-bar {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0 12px 2px;
  width: 100%;
  max-width: min(600px, 100vw);
  gap: 4px;
  box-sizing: border-box;
}


#main-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  max-width: 900px;
}

@media (min-width: 769px) {
  #main-area {
    flex-direction: row;
    align-items: flex-start;
    justify-content: center;
    gap: 24px;
    padding: 0 16px;
  }
}

#board-container {
  position: relative;
  margin: 4px auto;
  flex-shrink: 0;
  width: var(--board-size);
  height: var(--board-size);
}
body:not(.in-game) #board-container {
  height: auto;
  min-height: var(--board-size);
}
body:not(.in-game) #welcome-panel {
  position: relative;
  inset: auto;
}

#board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  gap: 2px;
  background: #16213e;
  border: 3px solid #0f3460;
  border-radius: 8px;
  padding: 3px;
  width: var(--board-size);
  height: var(--board-size);
}

.cell {
  background: #1a1a40;
  border-radius: 3px;
  transition: background 0.3s ease, border-color 0.3s ease, box-shadow 0.3s ease;
  position: relative;
}

.cell.occupied { cursor: grab; }
.cell.occupied[data-color="grey"] { cursor: default; }

.cell.preview-valid { background: rgba(255, 255, 255, 0.25); }
.cell.preview-invalid { background: rgba(255, 60, 60, 0.4); }

.cell[data-color="grey"] { background: #888; }
.cell[data-color="red"] { background: #e74c3c; }
.cell[data-color="white"] { background: #ecf0f1; }
.cell[data-color="blue"] { background: #3498db; }
.cell[data-color="yellow"] { background: #f1c40f; }

.cell.hint-flash { animation: hintPulse 0.8s ease-out; }
.cell.hint-flash[data-hint-color="red"] { background: rgba(231,76,60,0.55); }
.cell.hint-flash[data-hint-color="white"] { background: rgba(236,240,241,0.55); }
.cell.hint-flash[data-hint-color="blue"] { background: rgba(52,152,219,0.55); }
.cell.hint-flash[data-hint-color="yellow"] { background: rgba(241,196,15,0.55); }
@keyframes hintPulse {
  0% { opacity: 0; }
  20% { opacity: 1; }
  70% { opacity: 1; }
  100% { opacity: 0; }
}

.cell.border-top { border-top: 2px solid rgba(255,255,255,0.5); }
.cell.border-bottom { border-bottom: 2px solid rgba(255,255,255,0.5); }
.cell.border-left { border-left: 2px solid rgba(255,255,255,0.5); }
.cell.border-right { border-right: 2px solid rgba(255,255,255,0.5); }

#pool-section {
  width: 100%;
  max-width: 600px;
  padding: 6px 0 2px;
}

@media (min-width: 769px) {
  #pool-section {
    max-width: 280px;
    padding: 8px 0;
  }
  #pool-scroll::before, #pool-scroll::after { display: none; }
  #pool {
    flex-wrap: wrap;
    overflow-x: visible;
    justify-content: center;
    gap: var(--gap);
    padding: 0;
    min-height: auto;
  }
  .piece-wrapper { scroll-snap-align: none; }
  #pool .piece-cell { width: var(--pool-cell) !important; height: var(--pool-cell) !important; }
  #pool .piece { grid-template-columns: repeat(var(--cols), var(--pool-cell)) !important; grid-template-rows: repeat(var(--rows), var(--pool-cell)) !important; }
}

#pool-section h2 {
  display: none;
}

#pool-nav {
  display: flex;
  align-items: center;
  gap: 2px;
}
.pool-arrow {
  flex-shrink: 0;
  width: 28px;
  height: 48px;
  border: none;
  border-radius: 6px;
  background: rgba(255,255,255,0.06);
  color: #aaa;
  font-size: 12px;
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
}
.pool-arrow:active { background: rgba(255,255,255,0.15); }
.pool-arrow:disabled { opacity: 0.2; pointer-events: none; }
@media (min-width: 769px) { .pool-arrow { display: none; } }
#pool-scroll {
  position: relative;
  overflow-x: hidden;
  overflow-y: visible;
  background: rgba(255,255,255,0.02);
  border-radius: 8px;
  flex: 1;
  min-width: 0;
}
#pool-hint {
  text-align: center;
  font-size: 12px;
  color: #f1c40f;
  padding: 4px 12px;
  pointer-events: none;
  z-index: 3;
  transition: opacity 0.8s;
}
#pool-hint.hidden { opacity: 0; }
@media (min-width: 769px) { #pool-hint { position: static; margin-top: 4px; } }
#pool-scroll::before, #pool-scroll::after {
  content: '';
  position: absolute;
  top: 0; bottom: 0; width: 20px;
  z-index: 2;
  pointer-events: none;
  transition: opacity 0.2s;
}
#pool-scroll::before { left: 0; background: linear-gradient(to right, var(--bg, #1a1a2e), transparent); }
#pool-scroll::after { right: 0; background: linear-gradient(to left, var(--bg, #1a1a2e), transparent); }
#pool-scroll.at-start::before { opacity: 0; }
#pool-scroll.at-end::after { opacity: 0; }
#pool {
  display: flex;
  gap: 10px;
  align-items: center;
  overflow-x: auto;
  overflow-y: visible;
  padding: 12px 16px;
  scroll-snap-type: x proximity;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  min-height: 90px;
}
#pool::-webkit-scrollbar { display: none; }

/* Color-group spacing: more gap before first piece of a new color */
.piece-wrapper.color-red { margin-left: 4px; }
.piece-wrapper.color-white { margin-left: 4px; }
.piece-wrapper.color-blue { margin-left: 4px; }
.piece-wrapper.color-yellow { margin-left: 4px; }
.piece-wrapper.color-red + .piece-wrapper.color-red,
.piece-wrapper.color-white + .piece-wrapper.color-white,
.piece-wrapper.color-blue + .piece-wrapper.color-blue,
.piece-wrapper.color-yellow + .piece-wrapper.color-yellow { margin-left: 0; }

/* Nudge animation for new players */
@keyframes pieceNudge {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.06); box-shadow: 0 0 10px rgba(240,230,140,0.3); }
}
.piece-wrapper.nudge { animation: pieceNudge 0.6s ease-in-out 2; }

/* Responsive: small phones (iPhone SE, 375px) */
@media (max-width: 400px) {
  header { padding: 6px 8px; gap: 4px; }
  h1 { font-size: 17px; }
  .header-right { gap: 3px; }
  #timer { font-size: 18px; }
  #pause-btn { font-size: 14px; }
  #settings-btn { font-size: 15px; }
  #exp-display, #diamond-display { font-size: 11px; padding: 3px 6px; }
  #energy-display { font-size: 11px; padding: 3px 6px; }
  #controls { gap: 6px; }
  #controls button { padding: 5px 10px; font-size: 12px; }
  .piece-cell { width: 22px; height: 22px; }
  #pool { gap: 8px; }
  #pool-section { padding: 4px 0; }
}

.piece-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
  scroll-snap-align: center;
}

.piece {
  display: grid;
  gap: 1px;
  cursor: grab;
  touch-action: none;
  border-radius: 4px;
  padding: 2px;
  background: rgba(255,255,255,0.05);
  transition: transform 0.15s, box-shadow 0.15s;
}

.piece:hover { transform: scale(1.05); box-shadow: 0 0 12px rgba(255,255,255,0.15); }
.piece:active { cursor: grabbing; }

.piece.selected { outline: 2px solid #f1c40f; outline-offset: 2px; transform: scale(1.08); box-shadow: 0 0 16px rgba(241,196,12,0.4); }

.piece-wrapper.placed { display: none; }

.piece-cell {
  width: 28px;
  height: 28px;
  border-radius: 2px;
}

.piece-cell[data-color="red"] { background: #e74c3c; }
.piece-cell[data-color="white"] { background: #ecf0f1; }
.piece-cell[data-color="blue"] { background: #3498db; }
.piece-cell[data-color="yellow"] { background: #f1c40f; }

#drag-ghost {
  position: fixed;
  pointer-events: none;
  z-index: 1000;
  display: none;
  opacity: 0.85;
}

#drag-ghost .piece-cell {
  width: var(--cell-size) !important;
  height: var(--cell-size) !important;
}

/* old win-overlay styles replaced by enhanced version above */

#level-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 2px 0;
}
#level-nav button {
  background: none;
  border: 1px solid #1a5276;
  border-radius: 4px;
  color: #aaa;
  font-size: 11px;
  padding: 2px 8px;
  cursor: pointer;
  line-height: 1;
}
#level-nav button:hover { color: #eee; border-color: #3498db; }
#level-nav button:disabled { opacity: 0.3; cursor: default; }
#level-label {
  font-size: 13px;
  color: #ccc;
  font-weight: 600;
  min-width: 120px;
  text-align: center;
}
#controls {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: center;
}
#controls button {
  padding: 5px 12px;
  font-size: 13px;
  border: none;
  border-radius: 6px;
  background: #0f3460;
  color: #eee;
  cursor: pointer;
  font-weight: 600;
  white-space: nowrap;
}
#controls button:hover { background: #1a5276; }
#puzzle-input { -moz-appearance: textfield; }
#puzzle-input::-webkit-outer-spin-button,
#puzzle-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.ctrl-btn.is-hidden { display: none; }
#ctrl-rotate, #ctrl-undo { font-size: 16px; padding: 5px 10px; min-width: 32px; }
#hint-btn {
  background: linear-gradient(135deg, #7d5a00, #a67c00);
  box-shadow: 0 1px 6px rgba(241,196,15,0.2);
  padding: 6px 16px;
}
#hint-btn:hover { background: linear-gradient(135deg, #a67c00, #c99400); box-shadow: 0 2px 10px rgba(241,196,15,0.3); }

#settings-btn { background: none; border: none; font-size: 17px; cursor: pointer; padding: 0; line-height: 1; color: #eee; }
.win-card .btn-share { background: #2ecc71; color: #fff; }
.win-card .btn-share:hover { background: #27ae60; }
#help-modal,
#story-modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(0,0,0,0.7);
  align-items: center;
  justify-content: center;
  padding: 20px;
}
#help-modal.show, #story-modal.show { display: flex; }
#help-content,
#story-content {
  background: #16213e;
  border: 2px solid #0f3460;
  border-radius: 12px;
  padding: 28px 24px;
  max-width: 480px;
  width: 100%;
  max-height: 80vh;
  overflow-y: auto;
  position: relative;
  line-height: 1.7;
  font-size: 14px;
  color: #ccc;
}
#help-content h2, #story-content h2 { color: #f0e68c; font-size: 20px; margin-bottom: 14px; }
#help-content h3, #story-content h3 {
  color: #e0c868; font-size: 15px; margin: 24px 0 8px;
  padding-top: 16px; border-top: 1px solid rgba(255,255,255,0.06);
}
#help-content h3:first-of-type, #story-content h3:first-of-type { border-top: none; padding-top: 0; margin-top: 16px; }
#help-content p, #story-content p { margin-bottom: 12px; line-height: 1.8; }
#help-content em, #story-content em { color: #aaa; font-style: italic; }
.app-version { text-align: center; font-size: 11px; color: #666; margin-top: 18px !important; }
.about-dev {
  text-align: center;
  margin-top: 16px !important;
  padding: 12px 0;
  border-top: 1px solid rgba(255,255,255,0.08);
}
.about-dev-label { font-size: 12px; color: #888; margin: 0 0 4px !important; }
.about-feedback { font-size: 11px; color: #666; margin: 0 !important; }
.about-feedback a { color: #3498db; text-decoration: none; }
.about-feedback a:hover { text-decoration: underline; }
.about-support {
  text-align: center;
  margin-top: 16px !important;
  padding: 12px 0;
  border-top: 1px solid rgba(255,255,255,0.08);
}
.about-support-title { font-size: 12px; color: #888; margin: 0 0 8px !important; font-weight: 600; }
.about-rate-btn {
  display: inline-block;
  padding: 6px 18px;
  margin-bottom: 10px;
  border-radius: 16px;
  background: linear-gradient(135deg, #f39c12, #e67e22);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  transition: opacity 0.2s;
}
.about-rate-btn:hover { opacity: 0.85; }
.about-links { text-align: center; font-size: 13px; color: #666; margin-top: 12px !important; display: flex; justify-content: center; gap: 16px; }
.about-links a {
  color: #5dade2; text-decoration: none; padding: 8px 4px;
  min-height: 44px; display: inline-flex; align-items: center;
  transition: color 0.15s;
}
.about-links a:hover { color: #85c1e9; text-decoration: underline; }
#help-content ul { margin: 0 0 10px 18px; }
#help-content li { margin-bottom: 6px; }
#help-content kbd {
  background: #0f3460;
  border: 1px solid #1a5276;
  border-radius: 4px;
  padding: 1px 6px;
  font-size: 12px;
  font-family: inherit;
  color: #eee;
}
#help-close, #story-close, #energy-close, #achieve-close, #profile-close, #auth-close,
#tasks-close, #messages-close {
  position: absolute;
  top: 8px;
  right: 12px;
  background: none;
  border: none;
  color: #888;
  font-size: 24px;
  cursor: pointer;
  line-height: 1;
}
#story-close:hover, #energy-close:hover, #achieve-close:hover, #scoreboard-close:hover,
#profile-close:hover, #auth-close:hover, #tasks-close:hover, #messages-close:hover { color: #eee; }

/* Scoreboard modal */
#scoreboard-modal {
  display: none; position: fixed; inset: 0; z-index: 200;
  background: rgba(0,0,0,0.7); align-items: center; justify-content: center; padding: 20px;
}
#scoreboard-modal.show { display: flex; }
#scoreboard-content {
  background: #16213e; border: 2px solid #0f3460; border-radius: 12px;
  padding: 28px 20px 20px; max-width: 540px; width: 100%; max-height: 82vh;
  overflow-y: auto; position: relative; color: #ccc; font-size: 14px; line-height: 1.6;
}
#scoreboard-content h2 { color: #f0e68c; font-size: 20px; margin-bottom: 4px; text-align: center; }
#scoreboard-close {
  position: absolute; top: 8px; right: 12px; font-size: 28px; font-weight: 700;
  line-height: 1; background: none; border: none; color: #888; cursor: pointer; padding: 4px 8px;
}
.sb-tabs {
  display: flex; gap: 0; margin: 12px 0 16px; border-bottom: 2px solid #0f3460;
}
.sb-tabs button {
  flex: 1; padding: 9px 8px; background: none; border: none; color: #666;
  cursor: pointer; font-size: 13px; font-weight: 600; position: relative;
  transition: color 0.2s; white-space: nowrap;
}
.sb-tabs button:hover { color: #ccc; }
.sb-tabs button.active { color: #f0e68c; }
.sb-tabs button.active::after {
  content: ''; position: absolute; bottom: -2px; left: 0; right: 0;
  height: 2px; background: #f0e68c;
}
.sb-tab-content { display: none; }
.sb-tab-content.active { display: block; }

/* My rank card */
.sb-my-rank {
  background: rgba(241,196,15,0.08); border: 1px solid rgba(241,196,15,0.25);
  border-radius: 10px; padding: 12px 14px; margin-bottom: 14px;
  display: flex; align-items: center; gap: 12px;
}
.sb-my-rank .sb-avatar { width: 40px; height: 40px; border-radius: 8px; flex-shrink: 0; }
.sb-my-rank .sb-my-info { flex: 1; min-width: 0; }
.sb-my-rank .sb-my-name { font-size: 14px; font-weight: 700; color: #f0e68c; }
.sb-my-rank .sb-my-detail { font-size: 11px; color: #888; }
.sb-my-rank .sb-rank-badge {
  text-align: center; flex-shrink: 0;
}
.sb-my-rank .sb-rank-num { font-size: 22px; font-weight: 800; color: #f0e68c; }
.sb-my-rank .sb-rank-pct { font-size: 10px; color: #888; }

/* Leaderboard list */
.sb-list { display: flex; flex-direction: column; gap: 0; }
.sb-row {
  display: flex; align-items: center; gap: 10px; padding: 9px 8px;
  border-bottom: 1px solid rgba(255,255,255,0.06); transition: background 0.15s;
}
.sb-row:hover { background: rgba(255,255,255,0.03); }
.sb-row.sb-me { background: rgba(241,196,15,0.08); border-left: 3px solid #f1c40f; }
.sb-row.sb-crown { background: linear-gradient(135deg, rgba(241,196,15,0.12), transparent); }
.sb-row .sb-pos { width: 28px; text-align: center; font-weight: 700; font-size: 13px; color: #888; flex-shrink: 0; }
.sb-row.sb-crown .sb-pos { color: #f0e68c; }
.sb-row .sb-avatar { width: 32px; height: 32px; border-radius: 6px; flex-shrink: 0; }
.sb-row .sb-name { flex: 1; min-width: 0; font-size: 13px; font-weight: 600; color: #ddd; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sb-row.sb-me .sb-name { color: #f0e68c; }
.sb-row .sb-val { font-size: 12px; color: #888; flex-shrink: 0; text-align: right; min-width: 64px; font-variant-numeric: tabular-nums; }
.sb-row .sb-val strong { color: #ccc; font-weight: 700; display: none;}
.sb-row.sb-crown:nth-child(1) { background: linear-gradient(135deg, rgba(241,196,15,0.15), transparent); }
.sb-row.sb-crown:nth-child(2) { background: linear-gradient(135deg, rgba(192,192,192,0.1), transparent); }
.sb-row.sb-crown:nth-child(3) { background: linear-gradient(135deg, rgba(205,127,50,0.1), transparent); }
.sb-row .sb-row-pct { font-size: 11px; color: #666; min-width: 52px; }

/* Stats grid (My Stats tab) */
.sb-profile { text-align: center; margin-bottom: 16px; }
.sb-profile .sb-avatar-lg { width: 80px; height: 80px; border-radius: 14px; margin: 0 auto 8px; }
.sb-profile .sb-profile-name { font-size: 18px; font-weight: 800; color: #f0e68c; }
.sb-profile .sb-profile-id { font-size: 11px; color: #555; margin-top: 2px; }
.sb-stats-grid {
  display: grid; grid-template-columns: repeat(2,1fr); gap: 10px; margin-bottom: 16px;
}
.sb-stat-card {
  background: rgba(255,255,255,0.04); border: 1px solid rgba(255,255,255,0.08);
  border-radius: 8px; padding: 14px 10px; text-align: center;
}
.sb-stat-card .sb-stat-val { font-size: 24px; font-weight: 800; color: #f0e68c; }
.sb-stat-card .sb-stat-label { font-size: 10px; color: #888; text-transform: uppercase; letter-spacing: 0.5px; margin-top: 2px; }
.sb-stat-card .sb-stat-sub { font-size: 10px; color: #555; margin-top: 2px; }

/* Recent list */
.sb-recent h4 { font-size: 13px; color: #888; margin-bottom: 8px; }
.sb-recent-item {
  display: flex; justify-content: space-between; padding: 6px 0;
  border-bottom: 1px solid rgba(255,255,255,0.05); font-size: 12px; color: #888;
}
.sb-recent-item span:first-child { color: #ccc; font-weight: 600; }

/* Loading / error / empty */
.sb-loading, .sb-error, .sb-empty { text-align: center; padding: 40px 20px; color: #666; }
.sb-loading .sb-spinner {
  width: 28px; height: 28px; border: 3px solid #0f3460; border-top-color: #f0e68c;
  border-radius: 50%; margin: 0 auto 12px; animation: sbSpin 0.8s linear infinite;
}
@keyframes sbSpin { to { transform: rotate(360deg); } }
.sb-error-icon, .sb-empty-icon { font-size: 32px; margin-bottom: 8px; }
.sb-retry { margin-top: 10px; background: #0f3460; color: #eee; border: none; border-radius: 6px; padding: 8px 18px; cursor: pointer; font-size: 13px; }
.sb-retry:hover { background: #1a5276; }

.sb-summary { text-align: center; font-size: 12px; color: #555; margin-bottom: 12px; }

#copy-toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: #2ecc71; color: #fff; padding: 10px 20px; border-radius: 8px; font-weight: 600; font-size: 14px; z-index: 9000; opacity: 0; transition: opacity 0.3s; pointer-events: none; }

/* Welcome panel — Tier 1: World Map */
#welcome-panel {
  position: absolute; inset: 0;
  z-index: 10;
  background: #16213e;
  border: 3px solid #0f3460;
  border-radius: 8px;
  display: flex; flex-direction: column;
  padding: 8px 10px;
  gap: 6px;
  overflow-y: auto;
  overflow-x: hidden;
}
#welcome-panel.hidden { display: none; }

/* Stats header — hidden (header bar already shows EXP, diamonds, streak, energy) */
#wp-stats {
  display: none;
}
.wp-stat { display: flex; align-items: center; gap: 4px; }
.wp-stat-icon { font-size: 15px; }
.wp-stat-value { font-weight: 700; color: #eee; }

/* Quick resume */
#wp-resume {
  width: 100%; padding: 10px 16px;
  border: 2px solid #3498db; border-radius: 10px;
  background: rgba(52,152,219,0.1); color: #eee;
  font-size: 14px; font-weight: 700; cursor: pointer;
  font-family: inherit; text-align: center;
  flex-shrink: 0;
  animation: resumePulse 2s ease-in-out infinite;
}
.wp-resume-ago { display: block; font-size: 11px; color: #888; font-weight: 400; margin-top: 2px; }
#wp-resume:hover { background: rgba(52,152,219,0.2); }
#wp-resume:active { transform: scale(0.98); }
@keyframes resumePulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(52,152,219,0.3); }
  50% { box-shadow: 0 0 12px 2px rgba(52,152,219,0.15); }
}

/* World map — horizontal carousel */
#wp-world-map {
  flex: 1;
  overflow: hidden;
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.carousel-track {
  display: flex;
  flex: 1;
  transition: transform 0.35s ease;
  touch-action: pan-y;
  min-height: 0;
}
.world-slide {
  min-width: 100%;
  display: flex;
  flex-direction: column;
  cursor: pointer;
  padding: 0 6px;
  box-sizing: border-box;
}
.world-slide:active { transform: scale(0.98); }

/* Landscape area */
.world-landscape {
  flex: 1;
  border-radius: 12px 12px 0 0;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  min-height: 100px;
}
.world-slide[data-level="easy"] .world-landscape {
  background: linear-gradient(180deg, #87CEEB 0%, #87CEEB 35%, #27ae60 35%, #2ecc71 55%, #1a8a4a 100%);
}
.world-slide[data-level="medium"] .world-landscape {
  background: linear-gradient(180deg, #1a1a4e 0%, #2980b9 30%, #3498db 50%, #f39c12 70%, #e67e22 100%);
}
.world-slide[data-level="hard"] .world-landscape {
  background: linear-gradient(180deg, #2c3e50 0%, #34495e 25%, #e67e22 60%, #e74c3c 80%, #c0392b 100%);
}
.world-slide[data-level="hell"] .world-landscape {
  background: linear-gradient(180deg, #0a0a1a 0%, #1a0a2e 30%, #8e44ad 60%, #9b59b6 80%, #6c3483 100%);
}
.world-badge {
  position: absolute;
  top: 8px; left: 14px;
  width: 28px; height: 28px;
  background: rgba(0,0,0,0.5);
  border: 2px solid rgba(255,255,255,0.3);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: 800; color: #fff;
}
.world-emoji {
  font-size: 48px;
  filter: drop-shadow(0 2px 8px rgba(0,0,0,0.4));
}
.world-lock {
  position: absolute;
  bottom: 12px;
  font-size: 24px;
  filter: drop-shadow(0 1px 4px rgba(0,0,0,0.6));
}

/* Details panel */
.world-details {
  padding: 10px 12px;
  background: #0f1a2e;
  border-radius: 0 0 12px 12px;
  text-align: center;
}
.world-name { font-size: 15px; font-weight: 700; color: #eee; }
.world-subtitle { font-size: 11px; color: #888; margin-top: 1px; }
.world-counts { font-size: 11px; color: #666; margin-top: 3px; }
.world-status { font-size: 11px; color: #888; margin-top: 4px; }
.world-bar {
  height: 4px; background: #1a3050; border-radius: 2px;
  overflow: hidden; margin-top: 6px;
}
.world-fill { height: 100%; border-radius: 2px; transition: width 0.4s; }
.world-pct { font-size: 18px; font-weight: 800; margin-top: 4px; }

/* Locked overlay */
.world-slide.locked { cursor: not-allowed; }
.world-slide.locked .world-landscape {
  filter: grayscale(0.7) brightness(0.5);
}
.world-slide.locked .world-details { opacity: 0.4; }

/* Active glow */
.world-slide.active .world-landscape {
  box-shadow: inset 0 0 30px rgba(255,255,255,0.08);
  animation: worldGlow 2.5s ease-in-out infinite;
}
@keyframes worldGlow {
  0%, 100% { box-shadow: inset 0 0 30px rgba(255,255,255,0.08); }
  50% { box-shadow: inset 0 0 40px rgba(255,255,255,0.15); }
}

/* Completed checkmark overlay */
.world-slide.completed .world-landscape::after {
  content: '\2713';
  position: absolute;
  top: 8px; right: 14px;
  width: 28px; height: 28px;
  background: rgba(46,204,113,0.7);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; font-weight: 700; color: #fff;
}

/* Carousel navigation */
.carousel-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 6px 0;
  flex-shrink: 0;
}
.carousel-dots { display: flex; gap: 6px; }
.carousel-dots .dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: #1a3050;
  transition: background 0.2s;
  cursor: pointer;
}
.carousel-dots .dot.active { background: #eee; }
.carousel-arrow {
  width: 32px; height: 32px;
  border: none; border-radius: 50%;
  background: rgba(255,255,255,0.08);
  color: #eee; font-size: 14px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-family: inherit;
  transition: background 0.15s;
}
.carousel-arrow:hover { background: rgba(255,255,255,0.15); }
.carousel-arrow:disabled { opacity: 0.2; cursor: not-allowed; }

/* ── Tier 2/3 Full-screen Modals ── */
#chapter-modal, #path-modal {
  display: none; position: fixed; inset: 0; z-index: 200;
  background: rgba(0,0,0,0.6);
}
#chapter-modal.show, #path-modal.show { display: flex; }
#chapter-content, #path-content {
  width: 100%; height: 100%;
  background: #1a1a2e;
  display: flex; flex-direction: column;
  overflow: hidden;
}
@media (min-width: 500px) {
  #chapter-content, #path-content {
    width: 420px; max-height: 90vh;
    margin: auto; border-radius: 16px;
    border: 2px solid #0f3460;
  }
}

/* Modal nav header */
.modal-nav {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px;
  border-bottom: 1px solid #0f3460;
  flex-shrink: 0;
}
.modal-nav button {
  width: 36px; height: 36px; border: none;
  background: rgba(255,255,255,0.08); color: #eee;
  border-radius: 8px; font-size: 20px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.modal-nav button:hover { background: rgba(255,255,255,0.15); }
.modal-nav span:first-of-type { font-size: 16px; font-weight: 700; color: #eee; flex: 1; }
.modal-nav span:last-of-type { font-size: 12px; color: #888; }

/* ── Tier 2: Chapter Grid ── */
#chapter-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 8px;
  padding: 12px 16px;
  overflow: hidden;
  flex: 1;
  align-content: start;
}
.chapter-tile {
  aspect-ratio: 1; border-radius: 10px;
  background: #0a1628; border: 2px solid #1a3050;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  cursor: pointer; font-family: inherit; color: #eee;
  position: relative;
  transition: border-color 0.2s, transform 0.15s;
}
.chapter-tile:hover { border-color: var(--ch-color); }
.chapter-tile:active { transform: scale(0.93); }
.chapter-tile .ch-num { font-size: 13px; font-weight: 700; }
.chapter-tile .ch-check { font-size: 16px; color: var(--ch-color); }
.chapter-tile.done {
  background: color-mix(in srgb, var(--ch-color) 10%, #0a1628);
  border-color: color-mix(in srgb, var(--ch-color) 40%, transparent);
}
.chapter-tile.done .ch-num { font-size: 10px; color: #888; }
.chapter-tile.active {
  border-color: var(--ch-color);
  box-shadow: 0 0 10px color-mix(in srgb, var(--ch-color) 30%, transparent);
  animation: chapterPulse 2s ease-in-out infinite;
}
@keyframes chapterPulse {
  0%, 100% { box-shadow: 0 0 6px color-mix(in srgb, var(--ch-color) 20%, transparent); }
  50% { box-shadow: 0 0 14px color-mix(in srgb, var(--ch-color) 35%, transparent); }
}
.chapter-tile.partial { border-color: color-mix(in srgb, var(--ch-color) 30%, #1a3050); }
.chapter-tile.partial::after {
  content: ''; position: absolute; inset: -2px; border-radius: 10px;
  background: conic-gradient(var(--ch-color) var(--ch-deg), transparent var(--ch-deg));
  mask: radial-gradient(farthest-side, transparent calc(100% - 3px), #000 calc(100% - 3px));
  -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 3px), #000 calc(100% - 3px));
  pointer-events: none;
}
.chapter-tile.locked { opacity: 0.2; cursor: not-allowed; pointer-events: none; }

/* ── Tier 3: Puzzle Path (Snake) ── */
#path-grid {
  display: flex; flex-direction: column;
  align-items: center; gap: 0;
  padding: 12px 16px;
  overflow-y: auto;
  flex: 1;
}
.path-row {
  display: flex; align-items: center; gap: 0;
  justify-content: center;
}
.path-row.reverse { flex-direction: row-reverse; }
.path-node {
  width: 38px; height: 38px; border-radius: 50%;
  background: #0a1628; border: 2px solid #1a3050;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; font-family: inherit; color: #666;
  font-size: 10px; font-weight: 700;
  transition: border-color 0.2s, transform 0.15s;
  flex-shrink: 0;
}
.path-node:hover { border-color: var(--node-color); }
.path-node:active { transform: scale(0.9); }
.path-node .node-num { font-size: 10px; }
.path-node .node-check { font-size: 14px; color: var(--node-color); }
.path-node.solved {
  background: color-mix(in srgb, var(--node-color) 15%, #0a1628);
  border-color: var(--node-color);
}
.path-node.next {
  border-color: var(--node-color); color: #eee;
  box-shadow: 0 0 10px color-mix(in srgb, var(--node-color) 40%, transparent);
  animation: nodePulse 1.5s ease-in-out infinite;
}
@keyframes nodePulse {
  0%, 100% { box-shadow: 0 0 6px color-mix(in srgb, var(--node-color) 25%, transparent); }
  50% { box-shadow: 0 0 14px color-mix(in srgb, var(--node-color) 50%, transparent); }
}
.path-node.locked { opacity: 0.25; cursor: not-allowed; pointer-events: none; }
.path-conn {
  width: 16px; height: 3px; background: #1a3050;
  border-radius: 2px; flex-shrink: 0;
}
.path-conn.done { background: var(--node-color, #2ecc71); }
.path-vconn {
  width: 3px; height: 14px; background: #1a3050; border-radius: 2px;
}
.path-vconn.right { align-self: flex-end; margin-right: 20px; }
.path-vconn.left { align-self: flex-start; margin-left: 20px; }
.path-vconn.done { background: var(--node-color, #2ecc71); }

/* Filler tiles (empty decorative slots in chapter grid) */
.chapter-tile.filler {
  background: transparent; border: 2px dashed #1a3050;
  cursor: default; pointer-events: none; opacity: 0.3;
}

/* Tier 3: Pagination bar */
.path-pagination {
  display: flex; align-items: center; justify-content: center;
  gap: 12px; padding: 8px 0; flex-shrink: 0; width: 100%;
}
.path-page-btn {
  width: 36px; height: 36px; border: none;
  background: rgba(255,255,255,0.08); color: #eee;
  border-radius: 8px; font-size: 16px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-family: inherit; transition: background 0.2s;
}
.path-page-btn:hover:not(:disabled) { background: rgba(255,255,255,0.15); }
.path-page-btn:disabled { opacity: 0.3; cursor: not-allowed; }
.path-page-label { font-size: 14px; font-weight: 700; color: #aaa; min-width: 60px; text-align: center; }

/* Win card grade badge */
.win-grade {
  font-size: 18px; font-weight: 900; display: inline-block;
  border: 2px solid currentColor; border-radius: 4px;
  padding: 0 5px; margin-right: 4px; line-height: 1.3;
}

/* Play Next button (fixed at bottom of path modal) */
#path-play-next {
  margin: 0 16px 12px; padding: 14px;
  border: none; border-radius: 12px;
  background: #f1c40f; color: #1a1a2e;
  font-size: 16px; font-weight: 700;
  cursor: pointer; font-family: inherit;
  flex-shrink: 0;
}
#path-play-next:hover { background: #f39c12; }
#path-play-next:active { transform: scale(0.98); }
.level-complete { text-align: center; padding: 30px 16px; }
.level-complete-icon { font-size: 48px; margin-bottom: 12px; }
.level-complete h2 { color: #f1c40f; font-size: 22px; margin-bottom: 8px; }
.level-complete p { color: #aaa; font-size: 14px; margin-bottom: 20px; }
.level-complete .btn-random { margin-top: 8px; }
.progress-levels { display: flex; flex-direction: column; gap: 12px; width: 100%; grid-column: 1 / -1; }
.progress-level-card { background: #0f1a2e; border: 1px solid #1a3050; border-radius: 10px; padding: 12px 16px; }
.progress-level-card.progress-total { border-color: #3498db; background: rgba(52,152,219,0.06); }
.progress-level-header { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.progress-level-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.progress-level-name { font-size: 15px; font-weight: 700; color: #eee; flex: 1; }
.progress-level-count { font-size: 12px; color: #888; }
.progress-level-bar { height: 6px; background: #1a3050; border-radius: 3px; overflow: hidden; }
.progress-level-fill { height: 100%; border-radius: 3px; transition: width 0.3s; }
.progress-level-pct { font-size: 11px; color: #666; text-align: right; margin-top: 4px; }
.level-complete-banner { background: rgba(241,196,15,0.1); border: 1px solid rgba(241,196,15,0.3); border-radius: 8px; padding: 10px 14px; font-size: 14px; color: #f1c40f; text-align: center; margin: 8px 0; }

/* Game header layout */
.header-left {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
#menu-btn {
  background: none;
  border: none;
  color: #eee;
  font-size: 22px;
  cursor: pointer;
  padding: 4px 6px;
  line-height: 1;
  border-radius: 4px;
}
#menu-btn:hover { background: rgba(255,255,255,0.1); }

/* Enhanced win overlay */
#win-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 2000;
  justify-content: center;
  align-items: center;
}
#win-overlay.show { display: flex; }
/* 3-step win cards */
.win-card {
  background: #16213e;
  border: 2px solid #0f3460;
  border-radius: 16px;
  padding: 32px 28px;
  text-align: center;
  max-width: 340px;
  width: 90%;
  animation: winPop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes winPop {
  from { transform: scale(0.6); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}
.win-card h2 { font-size: 26px; color: #f1c40f; margin-bottom: 12px; }
.win-time-big { font-size: 36px; font-weight: 700; color: #f0e68c; font-variant-numeric: tabular-nums; margin: 8px 0; }
#win-best { font-size: 14px; color: #ccc; margin-bottom: 4px; }
#win-best.win-best-new { color: #2ecc71; font-weight: 700; }
#win-grade { margin: 8px 0; text-align: center; }
.win-grade-letter { display: inline-block; font-size: 72px; font-weight: 700; animation: gradeReveal 1.4s cubic-bezier(0.22, 1, 0.36, 1) both; animation-delay: 0.3s; }
@keyframes gradeReveal {
  0%   { transform: scale(0) rotate(-20deg); opacity: 0; filter: blur(16px); }
  35%  { transform: scale(1.8) rotate(6deg); opacity: 1; filter: blur(0); }
  55%  { transform: scale(0.85) rotate(-3deg); }
  75%  { transform: scale(1.1) rotate(1deg); }
  100% { transform: scale(1) rotate(0); }
}
.win-grade-letter.grade-s {
  text-shadow: 0 0 30px rgba(241,196,15,0.8), 0 0 60px rgba(241,196,15,0.5), 0 0 90px rgba(241,196,15,0.2);
  animation: gradeReveal 0.8s cubic-bezier(0.34, 1.56, 0.64, 1) both, gradeGlow 1.5s ease-in-out 0.8s infinite alternate;
}
@keyframes gradeGlow {
  0%   { text-shadow: 0 0 30px rgba(241,196,15,0.8), 0 0 60px rgba(241,196,15,0.5); }
  100% { text-shadow: 0 0 50px rgba(241,196,15,1), 0 0 100px rgba(241,196,15,0.7), 0 0 140px rgba(241,196,15,0.3); }
}
.win-grade-letter.grade-a {
  text-shadow: 0 0 20px rgba(46,204,113,0.5), 0 0 40px rgba(46,204,113,0.2);
}
.win-grade-desc { display: block; font-size: 13px; font-weight: 400; opacity: 0.7; margin-top: 2px; }
.win-tap-hint { font-size: 12px; color: #666; margin-top: 16px; animation: tapPulse 2s ease-in-out infinite; }
@keyframes tapPulse { 0%,100% { opacity: 0.4; } 50% { opacity: 0.8; } }
#win-puzzle-num { font-size: 14px; color: #aaa; margin-bottom: 4px; }
/* Step 2: rewards with progressive reveal */
#win-rewards { display: flex; flex-direction: column; gap: 12px; margin: 16px 0; font-size: 16px; color: #eee; }
#win-rewards .win-reward-line { opacity: 0; animation: rewardSlideIn 0.3s ease-out forwards; }
.win-reward-reason { display: block; font-size: 11px; opacity: 0.5; font-weight: 400; margin-top: 1px; }
@keyframes rewardSlideIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
/* Step 3: actions */
#win-motivation { font-size: 13px; color: #f0e68c; margin-bottom: 8px; line-height: 1.4; padding: 0 8px; font-weight: 600; }
#win-fact { font-style: italic; font-size: 12px; color: #888; margin-bottom: 16px; line-height: 1.5; padding: 0 8px; }
#win-energy-cost { font-size: 13px; color: #aaa; margin-bottom: 8px; }
/* Encourage toast */
#encourage-toast {
  position: fixed; bottom: 80px; left: 50%; transform: translateX(-50%);
  background: rgba(22,33,62,0.92); border: 1px solid rgba(240,230,140,0.2); border-radius: 20px;
  padding: 8px 20px; font-size: 13px; color: #f0e68c; font-weight: 600;
  z-index: 1500; pointer-events: none; opacity: 0; transition: opacity 0.3s;
  white-space: nowrap;
}
#encourage-toast.show { opacity: 1; }

/* Energy system */
#exp-display {
  display: flex; align-items: center; gap: 3px;
  padding: 3px 8px; border-radius: 12px; background: rgba(241,196,15,0.15);
  color: #f1c40f; font-weight: 700; font-size: 13px;
}
#diamond-display {
  display: flex; align-items: center; gap: 3px;
  padding: 3px 8px; border-radius: 12px; background: rgba(52,152,219,0.15);
  color: #5dade2; font-weight: 700; font-size: 13px;
}
#energy-display {
  display: flex; align-items: center; gap: 3px; cursor: pointer;
  padding: 3px 8px; border-radius: 12px; background: rgba(46,204,113,0.15);
  color: #2ecc71; font-weight: 700; font-size: 13px; transition: background 0.3s, color 0.3s;
}
#energy-display.low { background: rgba(243,156,18,0.15); color: #f39c12; }
#energy-display.empty { background: rgba(231,76,60,0.15); color: #e74c3c; animation: energyShake 0.8s ease-out, energyPulse 1.5s ease-in-out 0.8s infinite; }
@keyframes energyPulse { 0%,100% { opacity: 1; } 50% { opacity: 0.5; } }
@keyframes energyShake {
  0%,100% { transform: translateX(0); }
  10% { transform: translateX(-6px) rotate(-2deg); }
  20% { transform: translateX(6px) rotate(2deg); }
  30% { transform: translateX(-5px) rotate(-1deg); }
  40% { transform: translateX(5px) rotate(1deg); }
  50% { transform: translateX(-3px); }
  60% { transform: translateX(3px); }
  70% { transform: translateX(-2px); }
  80% { transform: translateX(2px); }
}
/* Sound toggle */
#sound-btn {
  background: none; border: none; font-size: 18px; cursor: pointer; padding: 2px;
  color: #aaa; opacity: 0.7; transition: opacity 0.15s; line-height: 1;
}
#sound-btn:hover { opacity: 1; }
#sound-btn.muted { opacity: 0.35; }
/* Hide diamond+energy during gameplay */
body.in-game #diamond-display, body.in-game #energy-display { display: none; }
/* Hide timer when not in gameplay */
body:not(.in-game) #timer { display: none; }
#energy-modal {
  display: none; position: fixed; inset: 0; z-index: 200;
  background: rgba(0,0,0,0.7); align-items: center; justify-content: center; padding: 20px;
}
#energy-modal.show { display: flex; }
#energy-content {
  background: #16213e; border: 2px solid #0f3460; border-radius: 12px;
  padding: 28px 24px; max-width: 380px; width: 100%; position: relative;
  text-align: center; color: #ccc; font-size: 14px; line-height: 1.7;
}
#energy-content h2 { color: #f0e68c; font-size: 20px; margin-bottom: 16px; }
#energy-bar-container {
  width: 100%; height: 12px; background: #0a0a1e; border-radius: 6px;
  overflow: hidden; margin-bottom: 12px;
}
#energy-bar { height: 100%; background: #2ecc71; border-radius: 6px; transition: width 0.4s, background 0.4s; }
#energy-bar.low { background: #f39c12; }
#energy-bar.empty { background: #e74c3c; }
#energy-points-display { font-size: 22px; font-weight: 700; color: #eee; margin-bottom: 8px; }
#energy-recovery-info { font-size: 13px; color: #999; margin-bottom: 12px; }
#energy-daily-stats { font-size: 13px; color: #888; margin-bottom: 12px; }
#energy-tip { font-size: 12px; color: #666; font-style: italic; }
#win-energy-cost { color: #f39c12; font-size: 13px; font-weight: 600; }
#wp-energy-status {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  margin-bottom: 12px; font-size: 13px; color: #999;
}
#wp-energy-status .energy-badge { color: #2ecc71; font-weight: 700; }
#wp-energy-status .energy-badge.low { color: #f39c12; }
#wp-energy-status .energy-badge.empty { color: #e74c3c; }

/* Goals notification dot */
#goals-btn { position: relative; }
.goals-dot {
  position: absolute; top: -2px; right: -2px; width: 8px; height: 8px;
  background: #e74c3c; border-radius: 50%; display: none;
}
.goals-dot.show { display: block; animation: energyPulse 1.5s ease-in-out infinite; }
/* Settings notification dot */
#settings-btn { position: relative; }
.settings-dot {
  position: absolute; top: 0; right: -2px; width: 8px; height: 8px;
  background: #e74c3c; border-radius: 50%; display: none;
}
.settings-dot.show { display: block; animation: energyPulse 1.5s ease-in-out infinite; }
/* --- Auth Modal --- */
#auth-modal {
  display: none; position: fixed; inset: 0; z-index: 210;
  background: rgba(0,0,0,0.7); align-items: center; justify-content: center; padding: 20px;
}
#auth-modal.show { display: flex; }
#auth-content {
  background: #16213e; border: 2px solid #0f3460; border-radius: 12px;
  padding: 28px 20px; max-width: 360px; width: 100%; position: relative; color: #ccc; font-size: 14px;
}
#auth-content h2 { color: #f0e68c; font-size: 20px; margin-bottom: 16px; text-align: center; }
#auth-body input:not([type="checkbox"]) {
  display: block; width: 100%; padding: 10px 12px; margin-bottom: 10px;
  background: #0f1a2e; border: 1px solid #1a3050; border-radius: 8px;
  color: #eee; font-size: 14px; font-family: inherit;
  box-sizing: border-box;
}
#auth-body input::placeholder { color: #555; }
#auth-body input:focus { outline: none; border-color: #2ecc71; }
.auth-btn {
  display: block; width: 100%; padding: 10px; border: none; border-radius: 8px;
  font-size: 14px; font-weight: 600; cursor: pointer; font-family: inherit;
  transition: opacity 0.15s;
}
.auth-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.auth-btn-primary { background: #2ecc71; color: #fff; }
.auth-btn-primary:hover:not(:disabled) { opacity: 0.85; }
.auth-agree {
  display: flex; align-items: flex-start; gap: 8px; margin: 4px 0 14px;
  font-size: 13px; color: #ccc; cursor: pointer; line-height: 1.5;
  text-align: left;
}
.auth-agree input[type="checkbox"] {
  margin-top: 3px; flex-shrink: 0; width: 16px; height: 16px;
  accent-color: #3498db; cursor: pointer;
}
.auth-agree a { color: #5dade2; text-decoration: underline; }
.auth-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.auth-btn-google {
  background: #fff; color: #333; border: 1px solid #ddd;
  display: flex; align-items: center; justify-content: center;
}
.auth-btn-google:hover { background: #f5f5f5; }
.auth-divider {
  text-align: center; margin: 12px 0; position: relative;
  color: #555; font-size: 12px;
}
.auth-divider::before, .auth-divider::after {
  content: ''; position: absolute; top: 50%; width: 40%; height: 1px;
  background: rgba(255,255,255,0.1);
}
.auth-divider::before { left: 0; }
.auth-divider::after { right: 0; }
.auth-links { display: flex; justify-content: space-between; margin-top: 12px; }
.auth-link {
  background: none; border: none; color: #3498db; font-size: 12px;
  cursor: pointer; font-family: inherit; padding: 0;
}
.auth-link:hover { text-decoration: underline; }
.auth-msg { text-align: center; color: #aaa; font-size: 13px; margin-bottom: 12px; }
.auth-error { text-align: center; color: #e74c3c; font-size: 12px; margin-top: 10px; min-height: 16px; }
.profile-auth-row {
  text-align: center; padding: 14px 16px; margin-bottom: 12px;
  background: rgba(46,204,113,0.08); border: 1px solid rgba(46,204,113,0.2);
  border-radius: 12px;
}
.profile-auth-info { font-size: 13px; color: #aaa; margin-bottom: 10px; line-height: 1.5; }
.profile-signin-btn {
  display: inline-block; padding: 10px 32px; border-radius: 20px;
  background: #2ecc71; color: #fff; font-size: 14px; font-weight: 700;
  border: none; cursor: pointer; font-family: inherit;
  box-shadow: 0 2px 12px rgba(46,204,113,0.3);
  transition: transform 0.15s, box-shadow 0.15s;
}
.profile-signin-btn:hover { transform: scale(1.03); box-shadow: 0 4px 16px rgba(46,204,113,0.4); }
.profile-signin-btn:active { transform: scale(0.97); }

/* --- Profile Modal --- */
#profile-modal {
  display: none; position: fixed; inset: 0; z-index: 200;
  background: rgba(0,0,0,0.7); align-items: center; justify-content: center; padding: 20px;
}
#profile-modal.show { display: flex; }
#profile-content {
  background: #16213e; border: 2px solid #0f3460; border-radius: 12px;
  padding: 28px 20px; max-width: 420px; width: 100%; max-height: 85vh;
  overflow-y: auto; position: relative; color: #ccc; font-size: 14px; line-height: 1.6;
}
#profile-content h2 { color: #f0e68c; font-size: 20px; margin-bottom: 12px; text-align: center; }
.profile-header { text-align: center; margin-bottom: 16px; }
.profile-avatar { font-size: 48px; line-height: 1; margin-bottom: 4px; }
.profile-name { font-size: 18px; font-weight: 700; color: #eee; }
.profile-rank { font-size: 13px; margin-top: 2px; }
.profile-rank-title { font-weight: 600; }
.profile-exp-row { font-size: 12px; color: #888; margin-top: 4px; }
.profile-radar { display: flex; justify-content: center; margin: 16px 0; position: relative; }
.profile-radar svg { max-width: 240px; width: 100%; height: auto; }
.profile-radar-labels { font-size: 10px; fill: #aaa; text-anchor: middle; dominant-baseline: central; }
.profile-radar-value { font-size: 9px; fill: #f0e68c; text-anchor: middle; dominant-baseline: central; }
.profile-radar-empty {
  text-align: center; padding: 20px 16px; color: #555; font-size: 13px; line-height: 1.6;
  background: rgba(255,255,255,0.03); border-radius: 10px; margin: 16px 0;
}
.profile-radar-empty-icon { font-size: 32px; margin-bottom: 8px; opacity: 0.4; }
.profile-worlds {
  margin: 16px 0 12px; padding: 14px; background: rgba(255,255,255,0.03);
  border-radius: 12px; border: 1px solid rgba(255,255,255,0.06);
}
.profile-worlds-title {
  font-size: 12px; color: #666; text-transform: uppercase; letter-spacing: 1px;
  margin-bottom: 10px; font-weight: 600;
}
.profile-world-row {
  display: flex; align-items: center; gap: 8px; padding: 8px 0;
  border-bottom: 1px solid rgba(255,255,255,0.04);
}
.profile-world-row:last-child { border-bottom: none; }
.profile-world-icon { font-size: 18px; flex-shrink: 0; width: 28px; text-align: center; }
.profile-world-name { font-size: 13px; color: #ccc; width: 72px; flex-shrink: 0; font-weight: 600; }
.profile-world-bar { flex: 1; height: 10px; background: rgba(255,255,255,0.08); border-radius: 5px; overflow: hidden; }
.profile-world-fill { height: 100%; border-radius: 5px; transition: width 0.3s; }
.profile-world-pct { font-size: 12px; color: #aaa; width: 46px; text-align: right; flex-shrink: 0; font-weight: 600; }
.profile-footer {
  display: flex; justify-content: center; gap: 20px; padding-top: 12px;
  border-top: 1px solid rgba(255,255,255,0.08); font-size: 13px; color: #aaa;
}
.profile-footer-item { text-align: center; }
.profile-footer-val { font-size: 16px; font-weight: 700; color: #eee; }
.profile-footer-label { font-size: 11px; color: #666; }
.profile-world-empty { color: #555; font-size: 11px; font-style: italic; font-weight: 400; }
.profile-new-summary {
  display: flex; justify-content: center; gap: 16px; padding: 14px 0; font-size: 15px; color: #ccc;
}
.profile-new-stat { font-weight: 600; }
.profile-new-cta { text-align: center; padding: 8px 0 14px; }
.profile-cta-btn {
  background: #2ecc71; color: #fff; border: none; border-radius: 8px;
  padding: 10px 28px; font-size: 15px; font-weight: 700; cursor: pointer;
}
.profile-cta-btn:active { opacity: 0.8; }
.profile-advanced {
  margin-top: 12px; border-top: 1px solid rgba(255,255,255,0.08); padding-top: 8px;
}
.profile-advanced summary {
  cursor: pointer; color: #888; font-size: 12px; text-align: center;
  list-style: none; padding: 6px 0;
}
.profile-advanced summary::-webkit-details-marker { display: none; }
.profile-advanced-grid {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; padding: 10px 0;
}
.profile-adv-item { text-align: center; }
.profile-adv-val { font-size: 14px; font-weight: 700; color: #eee; }
.profile-adv-label { font-size: 10px; color: #666; }

#achieve-modal {
  display: none; position: fixed; inset: 0; z-index: 200;
  background: rgba(0,0,0,0.7); align-items: center; justify-content: center; padding: 20px;
}
#achieve-modal.show { display: flex; }
#achieve-content {
  background: #16213e; border: 2px solid #0f3460; border-radius: 12px;
  padding: 28px 20px; max-width: 520px; width: 100%; max-height: 80vh;
  overflow-y: auto; position: relative; color: #ccc; font-size: 14px; line-height: 1.6;
}
#achieve-content h2 { color: #f0e68c; font-size: 20px; margin-bottom: 4px; text-align: center; }
#achieve-summary { text-align: center; font-size: 13px; color: #888; margin-bottom: 16px; }
#achieve-tabs { display: flex; gap: 8px; margin-bottom: 10px; }
.achieve-tab { background: none; border: 1px solid #1a3050; color: #888; border-radius: 16px; padding: 4px 14px; font-size: 12px; cursor: pointer; font-family: inherit; }
.achieve-tab.active { border-color: #f0e68c; color: #f0e68c; background: rgba(241,196,15,0.08); }
.achieve-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
@media (max-width: 480px) { .achieve-grid { grid-template-columns: repeat(4, 1fr); gap: 6px; } }
@media (max-width: 320px) { .achieve-grid { grid-template-columns: repeat(2, 1fr); } }
.achieve-card {
  background: #0f1a2e; border: 1px solid #1a3050; border-radius: 10px;
  padding: 8px 4px; text-align: center; transition: border-color 0.3s, background 0.3s;
}
.achieve-card.unlocked { border-color: #f0e68c; background: rgba(241,196,15,0.06); }
.achieve-card .achieve-icon { font-size: 24px; margin-bottom: 2px; }
.achieve-card.locked .achieve-icon { filter: grayscale(1) opacity(0.3); }
.achieve-card .achieve-name { font-size: 11px; font-weight: 700; color: #eee; margin-bottom: 1px; line-height: 1.3; }
.achieve-card.locked .achieve-name { color: #555; }
.achieve-card .achieve-desc { font-size: 10px; color: #888; line-height: 1.3; }
.achieve-card.locked .achieve-desc { color: #444; }
.achieve-card .achieve-date { font-size: 9px; color: #666; margin-top: 2px; }
.achieve-card .achieve-exp { font-size: 10px; color: #f1c40f; margin-top: 2px; }
.achieve-card.locked .achieve-exp { color: #555; }
.achieve-card .achieve-claim {
  margin-top: 4px;
  padding: 3px 8px;
  border: none;
  border-radius: 6px;
  background: #f1c40f;
  color: #1a1a2e;
  font-size: 10px;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.2s, transform 0.1s;
}
.achieve-card .achieve-claim:hover { background: #f39c12; }
.achieve-card .achieve-claim:active { transform: scale(0.95); }
.achieve-card .achieve-claimed {
  margin-top: 4px;
  font-size: 10px;
  color: #666;
}
#win-exp-earned { color: #f1c40f; font-weight: 700; }
#achieve-toast {
  position: fixed; top: 20px; left: 50%; transform: translateX(-50%) translateY(-200px);
  background: linear-gradient(135deg, #1a1a2e, #16213e); border: 2px solid #f0e68c;
  border-radius: 12px; padding: 14px 24px; z-index: 6000;
  display: flex; align-items: center; gap: 12px; box-shadow: 0 8px 32px rgba(0,0,0,0.5);
  transition: transform 0.5s cubic-bezier(0.34,1.56,0.64,1); pointer-events: none;
}
#achieve-toast.show { transform: translateX(-50%) translateY(0); position: relative; overflow: hidden; }
#achieve-toast.show::after {
  content: ''; position: absolute; inset: 0;
  background: linear-gradient(90deg, transparent 0%, rgba(255,255,255,0.35) 50%, transparent 100%);
  animation: shimmer 0.8s ease-in-out 0.3s;
  pointer-events: none;
}
@keyframes shimmer {
  0%   { left: -100%; }
  100% { left: 100%; }
}
#achieve-toast .toast-icon { font-size: 32px; }
#achieve-toast .toast-text { display: flex; flex-direction: column; }
#achieve-toast .toast-label { font-size: 11px; color: #f0e68c; font-weight: 700; text-transform: uppercase; letter-spacing: 1px; }
#achieve-toast .toast-name { font-size: 15px; color: #eee; font-weight: 700; }
#win-achievement { margin-top: 4px; }
#win-achievement .win-badge-row {
  display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; margin-top: 4px;
}
#win-achievement .win-badge-item {
  display: flex; align-items: center; gap: 4px; background: rgba(241,196,15,0.1);
  border: 1px solid rgba(241,196,15,0.3); border-radius: 6px; padding: 3px 8px;
  font-size: 12px; color: #f0e68c; font-weight: 600;
  animation: winPop 0.4s cubic-bezier(0.34,1.56,0.64,1);
}

.win-card .win-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.win-card .win-actions button {
  padding: 12px 24px;
  font-size: 16px;
  font-weight: 700;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.2s;
}
.win-card .btn-prev { background: #0f3460; color: #eee; }
.win-card .btn-prev:hover { background: #1a5276; }
.win-card .btn-next { background: #f1c40f; color: #1a1a2e; }
.win-card .btn-next:hover { background: #f39c12; }
.win-card .btn-win-random { background: #0f3460; color: #eee; }
.win-card .btn-win-random:hover { background: #1a5276; }
.win-card .btn-view-board { background: #1a3a5c; color: #eee; }
.win-card .btn-view-board:hover { background: #1a5276; }
.win-card .btn-win-menu { background: none; border: 1px solid #333 !important; color: #888; }
.win-card .btn-win-menu:hover { border-color: #555 !important; color: #bbb; }
#win-back-btn {
  display: none;
  position: fixed;
  bottom: 32px;
  left: 0;
  right: 0;
  margin: 0 auto;
  width: fit-content;
  padding: 14px 32px;
  font-size: 16px;
  font-weight: 700;
  border: none;
  border-radius: 28px;
  background: #f1c40f;
  color: #1a1a2e;
  cursor: pointer;
  z-index: 10000;
  box-shadow: 0 4px 20px rgba(0,0,0,0.5);
}
/* Win View Mode: whitelist board (readonly) + back button only */
body.win-view-mode {
  overflow: hidden;
}
body.win-view-mode #main-area,
body.win-view-mode #board-section {
  pointer-events: none;
}
body.win-view-mode #game-board,
body.win-view-mode #win-back-btn {
  pointer-events: auto;
}
body.win-view-mode #win-back-btn {
  display: block;
}
/* Blacklist: hide all controls */
body.win-view-mode header,
body.win-view-mode #pool-section,
body.win-view-mode #controls,
body.win-view-mode #undo-btn,
body.win-view-mode #menu-btn,
body.win-view-mode #restart-btn,
body.win-view-mode #settings-modal {
  display: none !important;
}
#win-back-btn:hover { background: #f39c12; }

/* Update banner */
#update-banner {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 9999;
  background: linear-gradient(135deg, #0f3460, #1a5276);
  border-bottom: 2px solid #f1c40f;
  padding: 12px 16px;
  text-align: center;
  animation: slideDown 0.3s ease-out;
}
@keyframes slideDown { from { transform: translateY(-100%); } to { transform: translateY(0); } }
#update-banner.show { display: block; }
#update-banner p { color: #eee; font-size: 13px; margin-bottom: 8px; }
#update-banner .update-actions { display: flex; justify-content: center; gap: 12px; }
#update-banner .btn-update {
  padding: 8px 20px; font-size: 14px; font-weight: 700;
  border: none; border-radius: 6px; cursor: pointer;
  background: #f1c40f; color: #1a1a2e;
}
#update-banner .btn-update:hover { background: #f39c12; }
#update-banner .btn-dismiss {
  padding: 8px 16px; font-size: 14px;
  border: 1px solid #555; border-radius: 6px; cursor: pointer;
  background: none; color: #888;
}
#update-banner .btn-dismiss:hover { border-color: #888; color: #bbb; }
#update-banner.force {
  top: 0; left: 0; right: 0; bottom: 0; width: 100%; height: 100%;
  display: flex; flex-direction: column; justify-content: center; align-items: center;
  z-index: 99999; border-radius: 0; animation: none;
}
#update-banner.force p { font-size: 16px; max-width: 320px; text-align: center; }

/* Confetti */
.confetti-piece {
  position: fixed;
  width: 8px;
  height: 8px;
  z-index: 2001;
  pointer-events: none;
  animation: confettiFall linear forwards;
}
@keyframes confettiFall {
  0% { transform: translateY(0) rotate(0deg); opacity: 1; }
  80% { opacity: 1; }
  100% { transform: translateY(105vh) rotate(720deg); opacity: 0; }
}

/* FX Canvas */
#fx-canvas { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 5000; }

/* Tutorial hints */
.tutorial-hint {
  position: absolute;
  background: #f1c40f;
  color: #1a1a2e;
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  z-index: 100;
  max-width: 260px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.3);
  animation: hintFloat 2s ease-in-out infinite;
}
.tutorial-hint::after {
  content: '';
  position: absolute;
  top: -8px;
  left: 20px;
  width: 0;
  height: 0;
  border-left: 8px solid transparent;
  border-right: 8px solid transparent;
  border-bottom: 8px solid #f1c40f;
}
.tutorial-hint .hint-close {
  position: absolute;
  top: 2px;
  right: 6px;
  background: none;
  border: none;
  color: #1a1a2e;
  font-size: 16px;
  cursor: pointer;
  line-height: 1;
  opacity: 0.6;
}
.tutorial-hint .hint-close:hover { opacity: 1; }
@keyframes hintFloat {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-4px); }
}

/* Splash screen */
#splash {
  position: fixed;
  inset: 0;
  z-index: 5000;
  background: #1a1a2e;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  transition: opacity 0.6s;
}
#splash.fade-out { opacity: 0; pointer-events: none; }
#splash .logo { font-size: 48px; font-weight: 800; letter-spacing: 4px; color: #eee; }
#splash .tagline {
  max-width: 340px;
  text-align: center;
  font-size: 15px;
  line-height: 1.8;
  color: #999;
  font-style: italic;
  opacity: 0;
  transition: opacity 0.4s;
}
#splash .tagline strong { color: #f0e68c; font-style: normal; }
#splash .tap-hint {
  margin-top: 20px;
  font-size: 14px;
  color: #666;
  letter-spacing: 1px;
  opacity: 0;
  transition: opacity 0.4s;
}
#splash.splash-ready .tagline,
#splash.splash-ready .tap-hint { opacity: 1; }
#splash.splash-ready .tap-hint { animation: tapPulse 1.8s ease-in-out infinite; }
@keyframes tapPulse {
  0%, 100% { opacity: 0.4; }
  50% { opacity: 1; }
}
#splash .splash-mini-board {
  display: grid;
  grid-template-columns: repeat(4, 28px);
  gap: 3px;
  margin-bottom: 8px;
}
#splash .splash-mini-board .mc {
  width: 28px;
  height: 28px;
  border-radius: 4px;
}

/* Focus visible */
button:focus-visible, input:focus-visible {
  outline: 2px solid #f1c40f;
  outline-offset: 2px;
}

/* Transition animations */
#welcome-panel.anim-out {
  animation: welcomeOut 0.3s ease-in forwards;
}
@keyframes welcomeOut {
  to { transform: scale(0.92); opacity: 0; }
}
.game-fade-in {
  animation: gameFadeIn 0.3s ease-out both;
}
@keyframes gameFadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Settings modal — bottom sheet */
#settings-modal {
  display: none; position: fixed; inset: 0; z-index: 250;
  background: rgba(0,0,0,0.7); align-items: flex-end; justify-content: center; padding: 0;
}
#settings-modal.show { display: flex; }
#settings-content {
  background: #16213e;
  border: 2px solid #0f3460;
  border-bottom: none;
  border-radius: 16px 16px 0 0;
  padding: 0 24px 28px;
  max-width: 420px;
  width: 100%;
  position: relative;
  color: #ccc;
  max-height: 85vh;
  overflow-y: auto;
  overscroll-behavior: contain;
  will-change: transform;
}
#settings-content.dragging { transition: none !important; }
.sheet-handle {
  display: flex; align-items: center; justify-content: center;
  padding: 10px 0 4px; cursor: grab; touch-action: none; user-select: none;
  position: sticky; top: 0; background: #16213e; z-index: 1;
}
.sheet-pill {
  width: 36px; height: 4px; background: rgba(255,255,255,0.2); border-radius: 2px;
}
.sheet-handle:active { cursor: grabbing; }
.sheet-handle:active .sheet-pill { background: rgba(255,255,255,0.35); }
#settings-content h2 { color: #f0e68c; font-size: 20px; margin: 0 0 16px; text-align: center; }
#settings-close {
  position: absolute; top: 8px; right: 12px;
  background: none; border: none; color: #888; font-size: 24px; cursor: pointer; line-height: 1;
}
#settings-close:hover { color: #eee; }
.settings-nav-primary {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  margin-bottom: 10px;
}
.settings-nav-secondary {
  display: grid;
  grid-template-columns: 1fr;
  gap: 6px;
  margin-bottom: 16px;
  padding-bottom: 16px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}
.settings-nav-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 8px;
  padding: 8px 6px;
  color: #888;
  font-size: 11px;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s, border-color 0.15s;
  position: relative;
}
.settings-nav-icon { font-size: 16px; width: 20px; text-align: center; flex-shrink: 0; }
.settings-nav-btn:hover { background: rgba(255,255,255,0.08); border-color: rgba(255,255,255,0.15); }
.settings-nav-btn.primary {
  background: rgba(255,255,255,0.06);
  border-color: rgba(255,255,255,0.12);
  color: #ddd;
  font-size: 13px;
  font-weight: 600;
  padding: 12px 10px;
}
.settings-nav-btn.primary:hover { background: rgba(255,255,255,0.12); border-color: rgba(255,255,255,0.2); }
.settings-nav-utility {
  display: flex; justify-content: center; margin-bottom: 16px;
  padding-bottom: 16px; border-bottom: 1px solid rgba(255,255,255,0.08);
}
.settings-nav-utility .settings-nav-btn {
  padding: 6px 20px; font-size: 11px;
}
.settings-nav-icon { /* merged into rule at line 1693 */
  font-size: 16px;
  width: 20px;
  text-align: center;
  flex-shrink: 0;
}
.settings-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 0;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  font-size: 15px;
}
.settings-row:last-child { border-bottom: none; }
.settings-toggle {
  background: #0f3460;
  border: 1px solid #1a5276;
  border-radius: 6px;
  color: #eee;
  font-size: 13px;
  padding: 6px 14px;
  cursor: pointer;
  font-family: inherit;
  min-width: 80px;
  text-align: center;
  transition: background 0.15s;
}
.settings-toggle:hover { background: #1a5276; }
.settings-select {
  background: #0f3460;
  border: 1px solid #1a5276;
  border-radius: 6px;
  color: #eee;
  font-size: 13px;
  padding: 6px 10px;
  cursor: pointer;
  font-family: inherit;
  min-width: 80px;
  text-align: center;
  transition: background 0.15s;
  -webkit-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%23aaa'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  padding-right: 24px;
}
.settings-select:hover { background-color: #1a5276; }
.settings-select option { background: #0a1a2e; color: #eee; }
.settings-divider { height: 1px; background: rgba(255,255,255,0.15); margin: 8px 0; }

/* Diamond Purchase Modal */
#diamond-purchase-modal {
  display: none; position: fixed; inset: 0; z-index: 250;
  background: rgba(0,0,0,0.7); align-items: center; justify-content: center; padding: 20px;
}
#diamond-purchase-modal.show { display: flex; }
#diamond-purchase-content {
  background: #16213e; border: 2px solid #0f3460; border-radius: 12px;
  padding: 28px 24px; max-width: 340px; width: 100%; position: relative;
  text-align: center; color: #ccc; font-size: 14px; line-height: 1.7;
}
#diamond-purchase-content h2 { color: #f0e68c; font-size: 20px; margin-bottom: 12px; }
#dp-item-name { font-size: 18px; font-weight: 600; color: #eee; margin-bottom: 16px; }
#dp-cost, #dp-balance { display: flex; justify-content: space-between; padding: 6px 0; border-bottom: 1px solid rgba(255,255,255,0.08); }
#dp-cost-value, #dp-balance-value { font-weight: 600; }
#dp-insufficient { color: #e74c3c; font-size: 13px; margin-top: 10px; min-height: 18px; }
.dp-actions { display: flex; gap: 12px; margin-top: 18px; }
.dp-btn { flex: 1; padding: 10px 0; border: none; border-radius: 8px; font-size: 15px; font-weight: 600; cursor: pointer; transition: background 0.15s, opacity 0.15s; }
.dp-btn-cancel { background: #2c3e50; color: #ccc; }
.dp-btn-cancel:hover { background: #34495e; }
.dp-btn-confirm { background: #27ae60; color: #fff; }
.dp-btn-confirm:hover { background: #2ecc71; }
.dp-btn-confirm:disabled { background: #555; color: #888; cursor: not-allowed; opacity: 0.6; }

/* Theme Selector (horizontal scroll with arrows) */
#theme-nav { display: flex; align-items: center; gap: 2px; padding: 10px 0; width: 100%; }
.theme-arrow {
  flex-shrink: 0; width: 32px; height: 76px; background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.12); border-radius: 8px;
  color: #ccc; font-size: 16px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.theme-arrow:hover { background: rgba(255,255,255,0.15); color: #fff; border-color: rgba(255,255,255,0.25); }
.theme-arrow:active { background: rgba(255,255,255,0.2); transform: scale(0.95); }
.theme-arrow:disabled { opacity: 0.15; pointer-events: none; }
#theme-scroll {
  flex: 1; overflow-x: hidden; position: relative; min-width: 0;
}
#theme-grid { display: flex; gap: 8px; transition: transform 0.25s ease; }
.theme-tile {
  position: relative; border-radius: 8px; padding: 8px 6px 6px; text-align: center;
  cursor: pointer; border: 2px solid transparent; transition: border-color 0.15s;
  background: #0f1a2e; flex-shrink: 0; width: 76px;
}
.theme-tile:hover { border-color: rgba(255,255,255,0.2); }
.theme-tile.active { border-color: #f0e68c; }
.theme-tile.locked { opacity: 0.7; }
.theme-tile .theme-swatch {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 2px;
  width: 36px; height: 36px; margin: 0 auto 4px; border-radius: 4px; overflow: hidden;
}
.theme-tile .theme-swatch span { display: block; }
.theme-tile .theme-name { font-size: 10px; color: #ccc; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.theme-tile .theme-lock { font-size: 9px; color: #f0e68c; margin-top: 2px; }
.theme-tile .theme-check { position: absolute; top: 3px; right: 3px; font-size: 11px; color: #2ecc71; }

/* Energy Restore Button */
#energy-restore-btn {
  display: none; margin-top: 14px; padding: 10px 20px; border: none; border-radius: 8px;
  background: linear-gradient(135deg, #8e44ad, #9b59b6); color: #fff; font-size: 14px; font-weight: 600;
  cursor: pointer; transition: background 0.15s, transform 0.15s;
}
#energy-restore-btn:hover { transform: translateY(-1px); background: linear-gradient(135deg, #9b59b6, #a66bbe); }
#energy-restore-btn.show { display: inline-block; }

/* ===== Phase 5: Visual Polish ===== */

/* Snap animation on placed cells */
.cell.snap { animation: cellSnap 0.6s ease-out; }
@keyframes cellSnap {
  0%   { transform: scale(1.25) rotate(3deg); box-shadow: 0 0 20px rgba(241,196,15,0.8); }
  30%  { transform: scale(0.9) rotate(-2deg); box-shadow: 0 0 12px rgba(241,196,15,0.5); }
  55%  { transform: scale(1.08) rotate(1deg); box-shadow: 0 0 6px rgba(241,196,15,0.3); }
  80%  { transform: scale(0.97) rotate(-0.3deg); box-shadow: 0 0 2px rgba(241,196,15,0.1); }
  100% { transform: scale(1) rotate(0); box-shadow: none; }
}

/* Board pulse on win */
#board.win-pulse { animation: boardPulse 0.4s ease-out; }
@keyframes boardPulse {
  0% { transform: scale(1); }
  50% { transform: scale(1.02); }
  100% { transform: scale(1); }
}

/* Modal fade + slide transitions */
#help-modal, #story-modal, #settings-modal, #energy-modal,
#achieve-modal, #scoreboard-modal, #profile-modal, #auth-modal,
#diamond-purchase-modal {
  opacity: 0;
  transition: opacity 0.15s ease-out;
  pointer-events: none;
}
#help-modal.show, #story-modal.show, #settings-modal.show, #energy-modal.show,
#achieve-modal.show, #scoreboard-modal.show, #profile-modal.show, #auth-modal.show,
#diamond-purchase-modal.show {
  opacity: 1;
  pointer-events: auto;
}
#help-content, #story-content, #energy-content,
#achieve-content, #scoreboard-content, #profile-content, #auth-content,
#diamond-purchase-content, #tasks-content, #messages-content, #multiplier-confirm-content {
  transform: translateY(12px);
  transition: transform 0.15s ease-out;
}
#settings-content {
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
.show > #help-content, .show > #story-content,
.show > #energy-content, .show > #achieve-content, .show > #scoreboard-content,
.show > #profile-content, .show > #auth-content, .show > #diamond-purchase-content,
.show > #tasks-content, .show > #messages-content, .show > #multiplier-confirm-content {
  transform: translateY(0);
}
.show > #settings-content {
  transform: translateY(0);
}

/* --- Daily Tasks Modal --- */
#tasks-modal {
  display: none; position: fixed; inset: 0; z-index: 200;
  background: rgba(0,0,0,0.7); align-items: center; justify-content: center; padding: 20px;
}
#tasks-modal.show { display: flex; }
#tasks-content {
  background: #16213e; border: 2px solid #0f3460; border-radius: 12px;
  padding: 28px 20px; max-width: 520px; width: 100%; max-height: 80vh;
  overflow-y: auto; position: relative; color: #ccc; font-size: 14px; line-height: 1.6;
}
#tasks-content h2 { color: #f0e68c; font-size: 20px; margin-bottom: 4px; text-align: center; }
#tasks-reset-timer { text-align: center; font-size: 12px; color: #888; margin-bottom: 12px; }
.task-card {
  background: rgba(255,255,255,0.05); border: 1px solid rgba(255,255,255,0.1);
  border-radius: 10px; padding: 14px; margin-bottom: 10px;
}
.task-card.completed { border-color: #2ecc71; }
.task-card.claimed { opacity: 0.7; }
.task-name { font-weight: 600; color: #eee; margin-bottom: 6px; }
.task-progress-bar {
  height: 6px; background: rgba(255,255,255,0.1); border-radius: 3px; overflow: hidden; margin-bottom: 6px;
}
.task-progress-fill { height: 100%; background: #2ecc71; border-radius: 3px; transition: width 0.3s; }
.task-footer { display: flex; justify-content: space-between; align-items: center; font-size: 12px; }
.task-reward { color: #5dade2; }
.task-claim-btn {
  background: #2ecc71; color: #fff; border: none; border-radius: 6px;
  padding: 4px 12px; font-size: 12px; cursor: pointer; font-weight: 600; font-family: inherit;
}
.task-claim-btn:disabled { background: #444; color: #888; cursor: default; }
.task-claimed-tag { color: #2ecc71; font-size: 12px; }
#tasks-bonus {
  text-align: center; padding: 12px; margin-top: 8px;
  background: rgba(241,196,15,0.1); border-radius: 10px; border: 1px solid rgba(241,196,15,0.2);
}

/* --- Message Center Modal --- */
#messages-modal {
  display: none; position: fixed; inset: 0; z-index: 200;
  background: rgba(0,0,0,0.7); align-items: center; justify-content: center; padding: 20px;
}
#messages-modal.show { display: flex; }
#messages-content {
  background: #16213e; border: 2px solid #0f3460; border-radius: 12px;
  padding: 28px 20px; max-width: 520px; width: 100%; max-height: 80vh;
  overflow-y: auto; position: relative; color: #ccc; font-size: 14px; line-height: 1.6;
}
#messages-content h2 { color: #f0e68c; font-size: 20px; margin-bottom: 12px; text-align: center; }
.msg-item {
  display: flex; gap: 12px; padding: 12px; margin-bottom: 8px;
  background: rgba(255,255,255,0.03); border: 1px solid rgba(255,255,255,0.06);
  border-radius: 10px; border-left: 4px solid rgba(255,255,255,0.06);
}
.msg-item.unread { background: rgba(52,152,219,0.08); border-color: rgba(52,152,219,0.2); border-left-color: #3498db; }
.msg-item.msg-type-achievement { border-left-color: #f1c40f; }
.msg-item.msg-type-multiplier, .msg-item.msg-type-multiplier_claim { border-left-color: #2ecc71; }
.msg-item.msg-type-league { border-left-color: #9b59b6; }
.msg-item.msg-type-daily_tasks { border-left-color: #e67e22; }
.msg-icon { font-size: 28px; flex-shrink: 0; width: 36px; text-align: center; }
.msg-body { flex: 1; min-width: 0; }
.msg-type-tag {
  display: inline-block; font-size: 9px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.5px; padding: 1px 6px; border-radius: 3px; margin-bottom: 3px;
  background: rgba(255,255,255,0.06); color: #888;
}
.msg-title { font-weight: 600; color: #eee; font-size: 14px; }
.msg-desc { font-size: 12px; color: #999; margin-top: 2px; }
.msg-time { font-size: 11px; color: #555; margin-top: 4px; }
.msg-actions { display: flex; gap: 8px; margin-top: 8px; align-items: center; }
.msg-action-btn {
  background: rgba(255,255,255,0.06); border: 1px solid rgba(255,255,255,0.1);
  border-radius: 6px; padding: 5px 12px; font-size: 11px; color: #888;
  cursor: pointer; font-family: inherit; transition: background 0.15s, color 0.15s;
}
.msg-action-btn:hover { background: rgba(255,255,255,0.12); color: #ccc; }
.msg-claim-btn, .msg-ach-claim-btn {
  background: rgba(46,204,113,0.15) !important; border-color: rgba(46,204,113,0.3) !important;
  color: #2ecc71 !important; font-weight: 700;
}
.msg-claim-btn:hover, .msg-ach-claim-btn:hover {
  background: rgba(46,204,113,0.25) !important; color: #4ae68a !important;
}
#messages-empty { text-align: center; padding: 32px; color: #666; font-size: 14px; }
.messages-badge {
  background: #e74c3c; color: #fff; font-size: 10px; font-weight: 700;
  min-width: 16px; height: 16px; border-radius: 8px; display: none;
  align-items: center; justify-content: center; padding: 0 4px;
  position: absolute; top: -4px; right: -4px;
}
.messages-badge.show { display: flex; }
#messages-btn { position: relative; }

/* --- Team League --- */
.league-prompt { text-align: center; padding: 40px 20px; }
.league-prompt-icon { font-size: 48px; margin-bottom: 12px; }
.league-prompt-title { font-size: 18px; font-weight: 800; color: #f0e68c; margin-bottom: 8px; }
.league-prompt-desc { font-size: 13px; color: #888; margin-bottom: 20px; line-height: 1.5; }
.league-join-btn, .league-signin-btn {
  background: linear-gradient(135deg, #0f3460, #1a5276);
  color: #f0e68c; border: none; border-radius: 8px;
  padding: 12px 28px; font-size: 15px; font-weight: 700;
  cursor: pointer; font-family: inherit;
}
.league-join-btn:hover, .league-signin-btn:hover { filter: brightness(1.15); }
.league-tier-header {
  display: flex; align-items: center; justify-content: center;
  gap: 10px; padding: 16px 0; margin-bottom: 4px;
  border-bottom: 2px solid var(--tier-color, #cd7f32);
}
.league-tier-badge { font-size: 36px; }
.league-tier-name { font-size: 20px; font-weight: 800; color: var(--tier-color, #cd7f32); }
.league-countdown { text-align: center; font-size: 11px; color: #666; margin-bottom: 10px; }
.league-streak {
  text-align: center; font-size: 12px; padding: 6px 12px;
  border-radius: 6px; margin-bottom: 8px;
}
.league-promo { background: rgba(46,204,113,0.1); color: #2ecc71; }
.league-demote { background: rgba(231,76,60,0.1); color: #e74c3c; }
.league-team-label {
  font-size: 11px; color: #666; text-transform: uppercase;
  letter-spacing: 0.5px; padding: 8px 0 4px;
}
.league-top2 { background: linear-gradient(135deg, rgba(46,204,113,0.08), transparent); }
.sb-row.league-inactive { opacity: 0.4; }
.league-avg-line {
  text-align: center; font-size: 11px; color: #666;
  margin-top: 8px; padding-top: 8px;
  border-top: 1px dashed rgba(255,255,255,0.1);
}
.league-tier-ring {
  border: 2px solid var(--tier-color, transparent); border-radius: 50%;
  padding: 1px;
}

/* --- Diamond Multiplier --- */
#multiplier-display {
  display: none; align-items: center; gap: 3px;
  padding: 3px 8px; border-radius: 12px;
  background: rgba(155,89,182,0.2); color: #bb86fc;
  font-weight: 700; font-size: 13px;
  animation: multiplierPulse 2s ease-in-out infinite;
}
#multiplier-display.active {
  display: flex;
  animation: multiplierPop 0.8s cubic-bezier(0.22,1,0.36,1),
             multiplierPulse 2s ease-in-out 0.8s infinite;
}
@keyframes multiplierPop {
  0%   { transform: scale(0) rotate(-10deg); opacity: 0; }
  40%  { transform: scale(1.5) rotate(4deg); opacity: 1; }
  60%  { transform: scale(0.85) rotate(-2deg); }
  80%  { transform: scale(1.1) rotate(1deg); }
  100% { transform: scale(1) rotate(0); opacity: 1; }
}
#multiplier-display.x3 { background: rgba(241,196,15,0.2); color: #f1c40f; }
@keyframes multiplierPulse { 0%,100% { opacity: 1; } 50% { opacity: 0.7; } }
#multiplier-timer { font-variant-numeric: tabular-nums; margin-left: 2px; }

#multiplier-confirm-modal {
  display: none; position: fixed; inset: 0; z-index: 250;
  background: rgba(0,0,0,0.7); align-items: center; justify-content: center; padding: 20px;
}
#multiplier-confirm-modal.show { display: flex; }
#multiplier-confirm-content {
  background: #16213e; border: 2px solid #9b59b6; border-radius: 16px;
  padding: 32px 24px; max-width: 360px; width: 100%; text-align: center; color: #ccc;
}
#multiplier-confirm-content.x3 { border-color: #f1c40f; }
#multiplier-confirm-icon { font-size: 48px; margin-bottom: 12px; }
#multiplier-confirm-title { color: #bb86fc; font-size: 22px; margin-bottom: 8px; }
#multiplier-confirm-content.x3 #multiplier-confirm-title { color: #f1c40f; }
#multiplier-confirm-desc { font-size: 14px; color: #aaa; margin-bottom: 6px; }
#multiplier-confirm-duration { font-size: 13px; color: #888; margin-bottom: 20px; }
.multiplier-confirm-actions { display: flex; gap: 12px; justify-content: center; }
.multiplier-btn-start {
  background: linear-gradient(135deg, #9b59b6, #8e44ad); color: #fff; border: none;
  border-radius: 10px; padding: 12px 24px; font-size: 16px; font-weight: 700; cursor: pointer; font-family: inherit;
}
#multiplier-confirm-content.x3 .multiplier-btn-start { background: linear-gradient(135deg, #f1c40f, #f39c12); color: #1a1a2e; }
.multiplier-btn-skip {
  background: transparent; color: #888; border: 1px solid #444; border-radius: 10px;
  padding: 12px 24px; font-size: 14px; cursor: pointer; font-family: inherit;
}

#quit-confirm-modal {
  display: none; position: fixed; inset: 0; z-index: 250;
  background: rgba(0,0,0,0.7); align-items: center; justify-content: center; padding: 20px;
}
#quit-confirm-modal.show { display: flex; }
#quit-confirm-modal .modal-content {
  background: #16213e; border: 2px solid #e74c3c; border-radius: 16px;
  padding: 32px 24px; max-width: 360px; width: 100%; text-align: center; color: #ccc;
}
#quit-confirm-title { color: #e74c3c; font-size: 20px; margin-bottom: 16px; font-weight: 600; }
#quit-confirm-body { font-size: 14px; color: #aaa; margin-bottom: 24px; line-height: 1.5; }
#quit-confirm-modal .modal-actions { display: flex; gap: 12px; justify-content: center; }

/* :active press states on all interactive elements */
button:active, .settings-nav-btn:active, .piece:active {
  transform: scale(0.96) !important;
  transition: transform 0.05s !important;
}
.win-card .win-actions button:active { transform: scale(0.96) !important; }
.theme-tile:active { transform: scale(0.95) !important; }

/* Theme crossfade on body */
body { transition: background 0.3s ease; }

/* Diamond float animation (reusable) */
.diamond-float {
  position: fixed; pointer-events: none; z-index: 3000;
  font-size: 16px; font-weight: 700; color: #5dade2;
  animation: floatUp 1s ease-out forwards;
}
@keyframes floatUp {
  0% { opacity: 1; transform: translateY(0); }
  100% { opacity: 0; transform: translateY(-40px); }
}

/* EXP float animation */
.exp-float {
  position: fixed; pointer-events: none; z-index: 3000;
  font-size: 16px; font-weight: 700; color: #f1c40f;
  animation: floatUp 1s ease-out forwards;
}

/* Win share button in new 3-step layout */
.win-card .btn-share { background: #2ecc71; color: #fff; }
.win-card .btn-share:hover { background: #27ae60; }

/* Today Goal card on welcome panel */
#wp-today-goal {
  margin: 0 10px; padding: 4px 8px;
  background: rgba(255,255,255,0.04); border-radius: 6px;
  display: flex; align-items: center; gap: 6px; cursor: pointer;
}
#wp-today-goal:active { background: rgba(255,255,255,0.08); }
.goal-ring { width: 24px; height: 24px; flex-shrink: 0; }
.goal-ring-progress { transition: stroke-dashoffset 0.6s ease; }
.goal-text-wrap { flex: 1; min-width: 0; display: flex; gap: 6px; align-items: baseline; }
.goal-text { font-size: 12px; color: #ccc; white-space: nowrap; }
.goal-hint { font-size: 11px; color: #888; white-space: nowrap; }

/* Daily Challenge Card (Steam-exclusive) */
#wp-daily-challenge {
  margin: 10px 10px 6px; padding: 12px 14px;
  background: linear-gradient(135deg, rgba(243,156,18,0.10) 0%, rgba(241,196,15,0.06) 100%);
  border-radius: 10px;
  border: 1px solid rgba(243,156,18,0.25);
  position: relative;
}
#wp-daily-challenge.dc-disabled { opacity: 0.45; pointer-events: none; }
.dc-header { display: flex; align-items: center; gap: 6px; margin-bottom: 10px; }
.dc-icon { font-size: 18px; }
.dc-title { font-size: 15px; font-weight: 700; color: #f5c842; letter-spacing: 0.5px; }
.dc-offline { font-size: 12px; color: #888; padding: 4px 0; }
.dc-rows { display: flex; flex-direction: column; gap: 2px; }
.daily-row {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 8px; border-radius: 6px;
  background: rgba(255,255,255,0.03);
  transition: background 0.15s;
}
.daily-row-done {
  background: rgba(46,204,113,0.08);
}
.daily-row-locked {
  opacity: 0.55;
}
.daily-dot { font-size: 13px; flex-shrink: 0; width: 18px; text-align: center; }
.daily-row-done .daily-dot { color: #2ecc71; font-weight: 700; font-size: 14px; }
.daily-level { font-size: 13px; font-weight: 600; min-width: 62px; }
.daily-slot { font-size: 11px; color: #666; flex-shrink: 0; }
.daily-result { font-size: 12px; color: #aaa; flex: 1; text-align: right; margin-right: 4px; }
.daily-row-done .daily-result { color: #ccc; font-weight: 600; font-size: 13px; }
.daily-grade { font-weight: 700; margin-left: 2px; }
.daily-grade-S { color: #f1c40f; }
.daily-grade-A { color: #2ecc71; }
.daily-grade-B { color: #3498db; }
.daily-attempted { color: #e67e22; font-size: 11px; }
.daily-action { flex-shrink: 0; }
.daily-play-btn {
  background: linear-gradient(135deg, #f39c12, #f1c40f);
  color: #1a1a2e; border: none; border-radius: 5px;
  padding: 4px 12px; font-size: 12px; font-weight: 700; cursor: pointer;
  transition: transform 0.1s;
}
.daily-play-btn:active { transform: scale(0.95); }
.daily-lb-btn {
  background: rgba(255,255,255,0.06); border: 1px solid rgba(255,255,255,0.1);
  border-radius: 4px; font-size: 15px; cursor: pointer;
  padding: 2px 6px; color: #aaa; transition: color 0.15s, background 0.15s;
}
.daily-lb-btn:hover { color: #fff; background: rgba(255,255,255,0.1); }
.daily-lock-icon { font-size: 13px; color: #555; }
.dc-footer {
  display: flex; align-items: center; gap: 10px; margin-top: 8px;
  font-size: 12px; color: #aaa;
}
.dc-streak { color: #f39c12; font-weight: 600; }
.dc-hint { font-size: 11px; color: #555; margin-top: 3px; }
/* 4/4 complete celebration */
.dc-complete-banner {
  margin-top: 10px; padding: 8px 10px;
  background: linear-gradient(135deg, rgba(46,204,113,0.12), rgba(241,196,15,0.08));
  border-radius: 6px; text-align: center;
}
.dc-complete-text { font-size: 14px; font-weight: 700; color: #2ecc71; }
.dc-complete-sub { font-size: 12px; color: #aaa; margin-top: 2px; }
.dc-complete-streak { font-size: 12px; color: #f39c12; font-weight: 600; margin-top: 4px; }
.dc-complete-cta { font-size: 11px; color: #888; margin-top: 6px; font-style: italic; }
/* 4/4 complete: subtle glow pulse on card border */
#wp-daily-challenge.dc-all-done {
  border-color: rgba(46,204,113,0.5);
  animation: dc-glow 1.5s ease-out 1;
}
@keyframes dc-glow {
  0% { box-shadow: 0 0 0 0 rgba(46,204,113,0.4); border-color: rgba(46,204,113,0.8); }
  50% { box-shadow: 0 0 12px 4px rgba(46,204,113,0.15); }
  100% { box-shadow: none; border-color: rgba(46,204,113,0.5); }
}

/* Daily Challenge Leaderboard Modal */
#dc-leaderboard-modal {
  display: none; position: fixed; inset: 0; z-index: 200;
  background: rgba(0,0,0,0.7); justify-content: center; align-items: center;
}
#dc-leaderboard-modal.show { display: flex; }
#dc-lb-content {
  background: #1e1e3a; border-radius: 12px; padding: 20px;
  width: 90%; max-width: 420px; max-height: 80vh; overflow-y: auto;
  position: relative;
}
#dc-lb-close {
  position: absolute; top: 8px; right: 12px;
  background: none; border: none; color: #888; font-size: 24px; cursor: pointer;
}
#dc-lb-title { font-size: 16px; margin-bottom: 12px; }
.dc-lb-tabs {
  display: flex; gap: 0; margin: 0 0 12px; border-bottom: 2px solid #0f3460;
}
.dc-lb-tabs button {
  flex: 1; padding: 9px 8px; background: none; border: none; color: #666;
  cursor: pointer; font-size: 13px; font-weight: 600; position: relative;
  transition: color 0.2s; white-space: nowrap;
}
.dc-lb-tabs button:hover { color: #ccc; }
.dc-lb-tabs button.active { color: #f0e68c; }
.dc-lb-tabs button.active::after {
  content: ''; position: absolute; bottom: -2px; left: 0; right: 0;
  height: 2px; background: #f0e68c;
}
.dc-rating-desc {
  font-size: 11px; color: #888; margin-bottom: 10px; line-height: 1.4;
}
.dc-rating-desc .dc-rating-help {
  display: inline-block; width: 14px; height: 14px; line-height: 14px;
  text-align: center; font-size: 10px; color: #aaa; border: 1px solid #555;
  border-radius: 50%; cursor: help; margin-left: 4px; vertical-align: middle;
}
.dc-elo-col {
  display: flex; align-items: baseline; gap: 4px; margin-left: auto;
  font-variant-numeric: tabular-nums;
}
.dc-elo-val { font-size: 13px; color: #ccc; }
.dc-elo-delta { font-size: 11px; font-weight: 600; }
.dc-elo-delta.positive { color: #2ecc71; }
.dc-elo-delta.zero { color: #666; }
.dc-elo-delta.negative { color: #e74c3c; }
.dc-grade { font-size: 12px; color: #aaa; margin-left: 6px; min-width: 14px; text-align: center; }

/* Help + About divider */
.help-divider { margin: 24px 0; border-top: 1px solid rgba(255,255,255,0.1); }

/* Near-miss achievement label */
.achieve-card.near-miss { border-color: rgba(241,196,15,0.3); }
.achieve-near-miss-label {
  font-size: 11px; color: #f1c40f; font-weight: 600; margin-top: 4px;
}

/* Share button in scoreboard header */
.sb-header-action {
  position: absolute; top: 16px; right: 48px;
  background: none; border: 1px solid rgba(255,255,255,0.15); border-radius: 6px;
  color: #888; font-size: 16px; padding: 4px 8px; cursor: pointer;
  line-height: 1; font-family: inherit;
}
.sb-header-action:hover { color: #eee; border-color: rgba(255,255,255,0.3); }

/* Tasks rendered inside Goals modal */
.tasks-in-goals { padding: 4px 0; grid-column: 1 / -1; display: block; }
.tasks-in-goals .task-card { margin-bottom: 8px; width: 100%; }
.tasks-in-goals .tasks-reset-line { text-align: center; color: #666; font-size: 12px; margin-bottom: 8px; }
.tasks-in-goals .tasks-bonus-line {
  text-align: center; padding: 12px; margin-top: 8px;
  background: rgba(241,196,15,0.1); border-radius: 10px; border: 1px solid rgba(241,196,15,0.2);
}

/* Help & About sections */
.help-section { margin-top: 20px; }
.help-section h3 { color: #e0c868; font-size: 15px; margin-bottom: 10px; }
.help-legal { text-align: center; margin-top: 24px; padding-top: 16px; border-top: 1px solid rgba(255,255,255,0.08); font-size: 13px; }
.help-legal a { color: #5dade2; }
/* Inline feedback form */
#feedback-inline { margin-bottom: 10px; }
#feedback-text {
  width: 100%; background: #0a1a2e; border: 1px solid #1a3050; border-radius: 8px;
  color: #ccc; font-size: 13px; padding: 10px; font-family: inherit; resize: vertical;
  margin-bottom: 8px;
}
#feedback-text:focus, #feedback-email:focus { border-color: #3498db; outline: none; }
#feedback-email {
  width: 100%; background: #0a1a2e; border: 1px solid #1a3050; border-radius: 8px;
  color: #ccc; font-size: 13px; padding: 8px 10px; font-family: inherit; margin-bottom: 8px;
}
.feedback-send {
  background: #2ecc71; color: #fff; border: none; border-radius: 8px;
  padding: 8px 20px; font-size: 13px; font-weight: 600; cursor: pointer; font-family: inherit;
}
.feedback-send:disabled { background: #444; color: #888; cursor: default; }
#feedback-status { font-size: 12px; color: #888; margin-top: 6px; }
#feedback-status.feedback-ok { color: #2ecc71; }

/* --- Unified Reward Modal --- */
#reward-modal {
  display: none; position: fixed; inset: 0; z-index: 300;
  background: rgba(0,0,0,0.75); align-items: center; justify-content: center; padding: 20px;
}
#reward-modal.show { display: flex; }
#reward-content {
  background: #16213e; border: 2px solid #0f3460; border-radius: 16px;
  padding: 32px 24px 24px; max-width: 360px; width: 100%;
  text-align: center; position: relative;
  animation: rewardPop 0.4s ease-out;
}
@keyframes rewardPop {
  0% { transform: scale(0.5) translateY(40px); opacity: 0; }
  60% { transform: scale(1.05) translateY(-8px); opacity: 1; }
  100% { transform: scale(1) translateY(0); }
}
#reward-title { font-size: 22px; font-weight: 700; color: #f0e68c; margin-bottom: 6px; }
#reward-reason { font-size: 13px; color: #aaa; margin-bottom: 16px; }
#reward-list { margin-bottom: 20px; }
.reward-line {
  font-size: 18px; font-weight: 600; color: #eee; padding: 6px 0;
  display: flex; align-items: center; justify-content: center; gap: 6px;
}
.reward-line .reward-icon { font-size: 20px; }
.reward-line .reward-value { font-variant-numeric: tabular-nums; }
.reward-btn-primary {
  background: linear-gradient(135deg, #2ecc71, #27ae60); color: #fff; border: none;
  border-radius: 10px; padding: 14px 32px; font-size: 16px; font-weight: 700;
  cursor: pointer; font-family: inherit; width: 100%; margin-bottom: 8px;
}
.reward-btn-primary:active { transform: scale(0.96); }
#reward-secondary {
  font-size: 12px; color: #666; cursor: pointer;
}
#reward-secondary:hover { color: #aaa; }

/* Account & Data section in profile */
.profile-account-section {
  margin-top: 18px; padding: 16px; border: 1px solid rgba(255,255,255,0.08);
  border-radius: 12px; background: rgba(255,255,255,0.03); text-align: center;
}
.profile-account-heading { font-size: 13px; font-weight: 600; color: #aaa; margin-bottom: 10px; text-transform: uppercase; letter-spacing: 0.5px; }
.profile-account-label { font-size: 12px; color: #666; }
.profile-account-email { font-size: 14px; color: #ccc; margin-bottom: 12px; word-break: break-all; }
.profile-logout-btn {
  background: none; border: 1px solid #555; color: #888; font-size: 12px;
  padding: 6px 20px; border-radius: 14px; cursor: pointer; font-family: inherit;
}
.profile-logout-btn:hover { border-color: #aaa; color: #aaa; }
.profile-logout-helper { font-size: 11px; color: #555; margin-top: 8px; line-height: 1.5; }
.profile-account-divider { height: 1px; background: rgba(255,255,255,0.06); margin: 14px 0; }
.profile-danger-zone { font-size: 11px; color: #884444; text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 6px; }
.profile-delete-link { font-size: 13px; color: #888; text-decoration: underline; text-underline-offset: 2px; }
.profile-delete-link:hover { color: #e74c3c; }
.profile-delete-helper { font-size: 11px; color: #555; margin-top: 4px; }

/* Logout confirm page */
.logout-confirm-page { padding: 32px 20px; text-align: center; position: relative; }
#profile-content .logout-confirm-page h2 { font-size: 20px; margin-bottom: 16px; }
.logout-confirm-body { font-size: 14px; color: #aaa; line-height: 1.6; margin-bottom: 28px; }

/* Delete account flow pages */
.delete-account-page { padding: 32px 20px; text-align: center; position: relative; }
#profile-content .delete-account-page h2 { font-size: 20px; color: #e74c3c; margin-bottom: 16px; }
.delete-account-bullets { text-align: left; margin: 0 auto 16px; max-width: 280px; font-size: 14px; color: #ccc; line-height: 1.8; list-style: disc; padding-left: 20px; }
.delete-account-bullets li::marker { color: #e74c3c; }
.delete-account-warning { font-weight: 700; color: #e74c3c; font-size: 14px; margin-bottom: 12px; }
.delete-account-hint { font-size: 13px; color: #666; font-style: italic; margin-bottom: 24px; }
.delete-account-hint a { color: #888; }
.delete-account-hint a:hover { color: #ccc; }
.delete-account-confirm-body { font-size: 14px; color: #aaa; line-height: 1.6; margin-bottom: 12px; }
.delete-account-confirm-prompt { font-size: 14px; color: #ccc; margin-bottom: 28px; }
.delete-account-actions { display: flex; gap: 12px; justify-content: center; }
.delete-cancel-btn {
  padding: 10px 24px; border-radius: 20px; font-size: 14px; cursor: pointer;
  background: none; border: 1px solid #555; color: #aaa; font-family: inherit;
}
.delete-cancel-btn:hover { border-color: #888; color: #ccc; }
.delete-danger-btn {
  padding: 10px 24px; border-radius: 20px; font-size: 14px; cursor: pointer;
  background: #e74c3c; border: none; color: #fff; font-weight: 600; font-family: inherit;
}
.delete-danger-btn:hover { background: #c0392b; }
.delete-danger-btn:disabled { opacity: 0.5; cursor: default; }
.delete-error-msg { font-size: 14px; color: #e74c3c; margin-bottom: 24px; line-height: 1.6; }
.delete-offline-msg { font-size: 14px; color: #e67e22; margin-bottom: 24px; line-height: 1.6; }
.modal-close-x { position: absolute; top: 12px; right: 16px; font-size: 22px; color: #666; cursor: pointer; line-height: 1; }
.modal-close-x:hover { color: #aaa; }

/* Android system bar safe area padding for modals/overlays */
#help-modal, #story-modal, #energy-modal, #achieve-modal, #scoreboard-modal,
#profile-modal, #auth-modal, #messages-modal, #tasks-modal, #multiplier-confirm-modal, #quit-confirm-modal,
#diamond-purchase-modal, #settings-modal, #chapter-modal, #path-modal, #reward-modal,
#dc-leaderboard-modal {
  padding-top: var(--safe-top);
  padding-bottom: max(var(--safe-bottom), var(--ime-bottom));
  box-sizing: border-box;
}

/* ── Desktop PC/Steam polish ── */
@media (min-width: 769px) and (pointer: fine) {
  header { max-width: 900px; padding: 12px 24px; }
  #main-area { gap: var(--gap); max-width: 1100px; }
  #board-container { margin: 8px 0; }
  #timer { font-size: 28px; font-family: 'SF Mono', 'Cascadia Code', 'Consolas', monospace; }
  #controls button {
    padding: 8px 20px; font-size: 14px; border-radius: 6px;
    background: rgba(255,255,255,0.06); border: 1px solid rgba(255,255,255,0.12);
  }
  #controls button:hover { background: rgba(255,255,255,0.12); }
  #pool-section {
    max-width: 340px;
    max-height: calc(100vh - 80px);
    overflow-y: auto;
    background: rgba(255,255,255,0.02);
    border: 1px solid rgba(255,255,255,0.06);
    border-radius: 12px;
    padding: 16px 12px;
  }
  /* Pool pieces: quiet by default, emphasize on hover/select */
  .piece-wrapper:not(.placed) .piece { opacity: 0.7; transition: opacity 0.15s, transform 0.15s; }
  .piece-wrapper:not(.placed) .piece:hover,
  .piece-wrapper:not(.placed) .piece.selected { opacity: 1; }

  /* Modals: centered card with backdrop blur */
  #help-modal, #energy-modal, #achieve-modal, #scoreboard-modal,
  #profile-modal, #auth-modal, #messages-modal, #multiplier-confirm-modal, #quit-confirm-modal,
  #diamond-purchase-modal, #reward-modal {
    backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  }
  #help-content, #energy-content, #achieve-content, #scoreboard-content,
  #profile-content, #auth-content, #messages-content, #reward-content {
    max-width: 640px; border-radius: 16px;
    animation: modalFadeIn 0.25s ease-out;
  }
  /* Win card desktop polish */
  .win-card { max-width: 500px; }
}
@media (min-width: 1200px) and (pointer: fine) {
  #main-area { max-width: 1200px; }
  #pool-section { max-width: 380px; }
  header { max-width: 1200px; }
}
@media (min-width: 2400px) and (pointer: fine) {
  #main-area { max-width: 1500px; }
  #pool-section { max-width: 440px; }
  header { max-width: 1500px; }
}

@keyframes modalFadeIn {
  from { opacity: 0; transform: scale(0.96); }
  to { opacity: 1; transform: scale(1); }
}

/* Focus-visible: keyboard navigation indicators */
:focus-visible {
  outline: 2px solid #f1c40f;
  outline-offset: 2px;
}
button:focus-visible, .piece:focus-visible {
  outline: 2px solid #f1c40f;
  outline-offset: 2px;
}
.cell:focus-visible {
  outline: 2px solid #f1c40f;
  outline-offset: -2px;
}

/* ── Zen Mode: hide chrome, just board + pool ── */
/* "The puzzle can breathe." */
body.zen-mode header,
body.zen-mode #action-bar,
body.zen-mode #pool-hint {
  opacity: 0;
  transition: opacity 0.6s ease;
  pointer-events: none;
}
/* Hover the top 60px strip to peek at header; hover action-bar to peek at controls */
body.zen-mode header:hover,
body.zen-mode #action-bar:hover {
  opacity: 0.85;
  pointer-events: auto;
  transition: opacity 0.25s ease;
}
/* Extend hover target: invisible hit area above the collapsed header */
body.zen-mode header {
  position: relative;
}
body.zen-mode header::after {
  content: '';
  position: absolute;
  left: 0; right: 0;
  top: 0; bottom: -12px;
  pointer-events: auto;
}
/* Pool sidebar: keep visible, but soften the chrome parts */
body.zen-mode #pool-hint { opacity: 0; pointer-events: none; }
/* Pool glass border fades in zen to let pieces float */
body.zen-mode #pool-section {
  border-color: transparent;
  background: transparent;
  transition: border-color 0.6s, background 0.6s;
}

/* Keyboard cursor on board */
.cell.kb-cursor {
  outline: 2px solid #f1c40f;
  outline-offset: -2px;
  z-index: 1;
}
/* Piece selected via keyboard */
.piece.kb-selected {
  outline: 3px solid #f1c40f;
  outline-offset: 2px;
}
/* Keyboard shortcuts section — desktop only */
#kb-shortcuts { display: none; }
@media (pointer: fine) {
  #kb-shortcuts { display: block; }
}
.kb-table { border-collapse: collapse; margin: 8px auto; }
.kb-table td { padding: 5px 6px; vertical-align: middle; }
.kb-table td:first-child { white-space: nowrap; padding-right: 14px; text-align: right; }
.kb-table td:last-child { color: rgba(255,255,255,0.8); font-size: 13px; }
.kb-table kbd {
  display: inline-block; min-width: 22px; padding: 2px 6px;
  font-family: inherit; font-size: 12px; text-align: center;
  background: rgba(255,255,255,0.1); border: 1px solid rgba(255,255,255,0.2);
  border-radius: 4px; color: #fff; line-height: 1.4;
}
.kb-hint { font-size: 12px; color: rgba(255,255,255,0.45); margin-top: 10px; text-align: center; }
.kb-hint kbd { display: inline-block; min-width: 18px; padding: 1px 5px; background: rgba(255,255,255,0.08); border: 1px solid rgba(255,255,255,0.15); border-radius: 3px; font-size: 11px; }
.kb-hint-inline { display: none; }
@media (min-width: 769px) {
  .kb-hint-inline {
    display: inline-block; margin-left: 8px;
    font-size: 12px; padding: 2px 6px;
    background: rgba(255,255,255,0.1); border: 1px solid rgba(255,255,255,0.2);
    border-radius: 4px; color: rgba(255,255,255,0.6);
  }
}
/* Crosshair cursor on board when piece is selected (mouse) */
@media (pointer: fine) {
  body.piece-selected #board .cell:not(.occupied) { cursor: crosshair; }
}

/* Mobile fullscreen dialogs — must be last to override all modal styles */
@media (max-width: 540px) {
  #help-modal, #story-modal, #energy-modal, #achieve-modal, #scoreboard-modal,
  #profile-modal, #auth-modal, #messages-modal, #tasks-modal, #multiplier-confirm-modal, #quit-confirm-modal,
  #diamond-purchase-modal, #settings-modal, #chapter-modal, #path-modal, #reward-modal,
  #dc-leaderboard-modal {
    /* Remove padding on mobile - content divs handle safe areas */
    padding: 0;
  }
  #help-content, #story-content, #energy-content, #achieve-content, #scoreboard-content,
  #profile-content, #auth-content, #messages-content, #tasks-content, #multiplier-confirm-content,
  #diamond-purchase-content, #settings-content, #chapter-content, #path-content, #reward-content,
  #dc-lb-content {
    max-width: 100%; max-height: 100%; height: 100%;
    border-radius: 0; border: none;
    /* Android safe areas + iOS fallback - content divs are fullscreen on mobile */
    padding: max(28px, var(--safe-top), env(safe-area-inset-top, 0px))
             20px
             max(28px, var(--safe-bottom), var(--ime-bottom), env(safe-area-inset-bottom, 0px))
             20px;
    box-sizing: border-box;
  }
  #help-close, #story-close, #energy-close, #achieve-close, #scoreboard-close,
  #profile-close, #auth-close, #messages-close, #tasks-close, #settings-close, #dc-lb-close {
    top: max(8px, var(--safe-top), env(safe-area-inset-top, 0px));
  }
}

