/* ── Reset & Base ───────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --navy:       #000033;
  --navy-mid:   #1a3a6b;
  --steel:      #4682B4;
  --steel-light:#7ab3d9;
  --orange:     #ffa500;
  --gold:       #FFD700;
  --cell-bg:    #f0f8ff;
  --cell-border:#aaa;
  --text-white: #ffffff;
  --cell-size:  48px;
  --grid-gap:   6px;
  --wrapper-pad:24px;
}

body {
  font-family: Arial, sans-serif;
  background: linear-gradient(160deg, var(--navy) 0%, var(--navy-mid) 55%, var(--steel) 100%);
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  padding-top:    env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
  padding-left:   env(safe-area-inset-left);
  padding-right:  env(safe-area-inset-right);
}

button {
  cursor: pointer;
  border: none;
  border-radius: 6px;
  font-family: inherit;
}

/* ── MENU ───────────────────────────────────────────────── */
#menu {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 2em 1em;
}

/* ── TITLE RING (animated opening, replaces old text title) ── */
.title-ring-wrap {
  width: clamp(200px, 52vw, 300px);
  aspect-ratio: 1 / 1;
  margin: 0 auto;
  opacity: 0;
  filter: brightness(0.2);
  transition: transform 0.8s ease;
}

.title-ring-svg {
  width: 100%;
  height: 100%;
  display: block;
}

.title-ring-wrap.intro-playing {
  animation: titleRingGlowIn 4s ease forwards;
}

.title-ring-wrap.ring-lit {
  opacity: 1;
  filter: brightness(1.4) drop-shadow(0 0 18px var(--gold));
}

.title-ring-wrap.settled {
  transform: translateY(-14px);
}

@keyframes titleRingGlowIn {
  0%   { opacity: 0;    filter: brightness(0.2); }
  30%  { opacity: 0.4;  filter: brightness(0.5); }
  60%  { opacity: 0.85; filter: brightness(1);   }
  80%  { opacity: 1;    filter: brightness(1.3) drop-shadow(0 0 12px var(--gold)); }
  100% { opacity: 1;    filter: brightness(1.4) drop-shadow(0 0 18px var(--gold)); }
}

.player-bar,
.menu-buttons {
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 0.7s ease, transform 0.7s ease;
}

.player-bar.revealed,
.menu-buttons.revealed {
  opacity: 1;
  transform: translateY(0);
}

.menu-buttons {
  display: flex;
  flex-direction: column;
  gap: clamp(0.6em, 1.5vh, 0.85em);
  margin-top: clamp(1.2em, 2.5vh, 2em);
  width: 100%;
  max-width: 300px;
}

.menu-buttons button {
  padding: clamp(0.6em, 1.5vh, 0.75em) 1em;
  font-size: clamp(0.95rem, 2.5vh, 1.05rem);
  border-left: 5px solid var(--orange);
  border-radius: 6px;
  background: rgba(70,130,180,0.85);
  color: var(--text-white);
  text-align: left;
  letter-spacing: 0.02em;
  box-shadow: 0 3px 8px rgba(0,0,0,0.3);
  transition: background 0.2s, border-color 0.2s;
}

.menu-buttons button:hover,
.menu-buttons button:active {
  background: rgba(90,155,211,0.95);
  border-left-color: var(--gold);
}

/* ── PLAYER BAR (menu) ───────────────────────────────────── */
.player-bar {
  display: flex;
  align-items: center;
  gap: 0.6em;
  margin-top: clamp(0.8em, 2vh, 1.2em);
  max-width: 300px;
}

.player-chip {
  display: flex;
  align-items: center;
  gap: 0.35em;
  padding: 0.4em 0.9em;
  font-size: 0.85rem;
  background: rgba(70,130,180,0.4);
  color: var(--text-white);
  border-radius: 20px;
  border: 1px solid rgba(255,255,255,0.2);
  min-width: 0;
}

.player-chip span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.switch-player-button {
  padding: 0.4em 0.8em;
  font-size: 0.8rem;
  background: rgba(255,165,0,0.15);
  color: var(--gold);
  border: 1px solid rgba(255,215,0,0.4);
  border-radius: 20px;
  white-space: nowrap;
  transition: background 0.2s, color 0.2s;
}

.switch-player-button:hover,
.switch-player-button:active {
  background: var(--orange);
  color: #00143a;
}

/* ── DIFFICULTY SELECTION ───────────────────────────────── */
#difficulty-selection {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  min-height: 100dvh;
  gap: 1em;
  padding: 2em 1em;
}

#difficulty-selection h2 {
  color: var(--gold);
  font-size: clamp(1.3rem, 4vw, 1.8rem);
  margin-bottom: 0.5em;
  letter-spacing: 0.05em;
}

#difficulty-selection button {
  width: 280px;
  padding: 0.75em 1em;
  font-size: 1rem;
  border-left: 5px solid var(--orange);
  background: rgba(70,130,180,0.85);
  color: var(--text-white);
  text-align: left;
  box-shadow: 0 3px 8px rgba(0,0,0,0.3);
  transition: background 0.2s, border-color 0.2s;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.mode-name {
  font-weight: bold;
  font-size: 1rem;
}

.mode-desc {
  font-size: 0.75rem;
  opacity: 0.8;
  font-weight: normal;
}

#difficulty-selection button:hover {
  background: rgba(90,155,211,0.95);
  border-left-color: var(--gold);
}

/* ── GAME LAYOUT ────────────────────────────────────────── */
#game {
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

.game-container {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  padding: 4px;
  gap: 6px;
  overflow: hidden;
}

.game-container.portrait  { flex-direction: column; }
.game-container.landscape { flex-direction: row; }

/* ── GRID ───────────────────────────────────────────────── */
#grid-wrapper {
  padding: 4px;
  border: 4px solid var(--orange);
  background: var(--steel);
  border-radius: 10px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.3);
  flex-shrink: 0;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

#grid-container {
  background: #fff;
  padding: 2px;
  border-radius: 6px;
  display: grid;
  grid-template-columns: repeat(var(--grid-cols, 9), var(--cell-size, 48px));
  grid-template-rows:    repeat(var(--grid-rows, 9), var(--cell-size, 48px));
  gap: var(--grid-gap, 6px);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.grid-cell {
  width:  var(--cell-size, 48px);
  height: var(--cell-size, 48px);
  font-size: calc(var(--cell-size, 48px) * 0.46);
  font-weight: bold;
  background: var(--cell-bg);
  border: 1px solid var(--cell-border);
  border-radius: 10px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
  display: flex;
  justify-content: center;
  align-items: center;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  transition: background 0.12s, color 0.12s;
}

.grid-cell.selected { background: #4A90E2; color: #fff; }
.grid-cell.valid    { background: #2ECC71; color: #fff; }
.grid-cell.invalid  { background: #E74C3C; color: #fff; }
.grid-cell.hint-highlight { background: var(--orange); color: #fff; }

/* ── INFO PANEL ─────────────────────────────────────────── */
#info-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 10px 8px;
  background: rgba(20, 55, 120, 0.82);
  border: 2px solid var(--orange);
  border-radius: 10px;
  color: var(--text-white);
  flex-shrink: 0;
}

/* Landscape: panel beside grid */
.game-container.landscape #info-panel {
  width: clamp(160px, 22vw, 260px);
  flex: 0 0 clamp(160px, 22vw, 260px);
  overflow-y: auto;
}

/* Portrait: panel below grid */
.game-container.portrait #info-panel {
  width: 100%;
  max-width: 500px;
  flex-direction: row;
  flex-wrap: wrap;
  justify-content: space-around;
  align-items: center;
  padding: 5px 6px 8px;
  overflow: hidden;
}

/* ── BEST TARGET ─────────────────────────────────────────── */
#best-target-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
}

#best-target-value {
  font-size: clamp(1.1rem, 3vw, 1.6rem);
  font-weight: bold;
  color: var(--gold);
  line-height: 1;
}

/* ── TARGET DISPLAY — signature element ─────────────────── */
#target-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: rgba(0,0,0,0.25);
  border: 2px solid var(--orange);
  border-radius: 10px;
  padding: 8px 18px;
  gap: 2px;
  width: 100%;
}

.game-container.portrait #target-box {
  width: auto;
  padding: 4px 14px;
}

.target-label {
  font-size: clamp(0.55rem, 1.4vw, 0.72rem);
  letter-spacing: 0.18em;
  color: var(--orange);
  font-weight: bold;
  text-transform: uppercase;
}

#target-value {
  font-size: clamp(2.4rem, 6vw, 4rem);
  font-weight: bold;
  color: var(--text-white);
  line-height: 1;
  text-shadow: 0 0 18px rgba(255,165,0,0.4);
  letter-spacing: -0.02em;
}

/* ── CONFIRM BUTTON ──────────────────────────────────────── */
#confirm-button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ── TIMER BOX ───────────────────────────────────────────── */
#timer-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
}

#timer-value {
  font-size: clamp(1.1rem, 3vw, 1.6rem);
  font-weight: bold;
  color: var(--steel-light);
  line-height: 1;
  font-variant-numeric: tabular-nums;
  transition: color 0.2s;
}

#timer-value.timer-low {
  color: #E74C3C;
  animation: timer-pulse 0.6s ease infinite;
}

@keyframes timer-pulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.4; }
}

/* ── INFO LABEL ──────────────────────────────────────────── */
.info-label {
  font-size: clamp(0.55rem, 1.4vw, 0.7rem);
  letter-spacing: 0.12em;
  color: rgba(255,255,255,0.55);
  text-transform: uppercase;
}

/* ── ACTION ROW (Go / Clear) ─────────────────────────────── */
#action-row {
  display: flex;
  gap: 6px;
  width: 100%;
  margin-bottom: 5px;
}

#action-row button {
  flex: 1;
  padding: 9px 6px;
  font-size: clamp(0.85rem, 2.2vw, 1rem);
  font-weight: bold;
  border-radius: 6px;
  background: var(--steel-light);
  color: #00143a;
  transition: background 0.15s;
}

#action-row button:hover  { background: #a0cce8; }
#action-row button:active { background: var(--gold); }

/* ── BUTTON ROW ──────────────────────────────────────────── */
#button-row-container {
  position: relative;
  width: 100%;
}

#button-row {
  display: flex;
  gap: 4px;
  justify-content: center;
  width: 100%;
  align-items: stretch;
  height: 36px;
}

#button-row button {
  flex: 1;
  padding: 6px 4px;
  font-size: clamp(0.9rem, 2.2vw, 1.05rem);
  border-radius: 5px;
  background: var(--steel-light);
  color: #00143a;
  font-weight: bold;
  white-space: nowrap;
  min-width: 0;
  transition: background 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

#button-row button:hover  { background: #a0cce8; }
#button-row button:active { background: var(--gold); }

#button-row button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* Hint button once free hints are used up and a rewarded ad is offered */
#hint-button.hint-ad-mode {
  background: #2a9d8f;
  color: #fff;
  font-size: clamp(0.72rem, 2vw, 0.85rem);
}

#hint-button.hint-ad-mode:hover  { background: #1f7a70; }
#hint-button.hint-ad-mode:active { background: #175c54; }

/* Clear button warning state */
#clear-button.confirm {
  background: #E74C3C;
  color: #fff;
}

#pause-button {
  font-size: clamp(1.4rem, 4vw, 1.8rem) !important;
}

#in-game-settings-button {
  flex: 0 0 auto;
  min-width: 2.6em;
  font-size: clamp(1.6rem, 4vw, 2rem) !important;
  line-height: 1 !important;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ── FLOATING MESSAGE ────────────────────────────────────── */
.floating-message {
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%) translateY(6px);
  font-size: 0.9rem;
  font-weight: bold;
  color: #fff;
  background: rgba(0,0,0,0.78);
  padding: 5px 12px;
  border-radius: 6px;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  white-space: nowrap;
  border: 2px solid limegreen;
  box-shadow: 0 0 8px limegreen;
  transition: opacity 0.25s, transform 0.25s;
  z-index: 5;
}

.floating-message.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ── GAME OVER ───────────────────────────────────────────── */
#game-over {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 1.5em;
}

.gameover-card {
  background: rgba(20,55,120,0.92);
  border: 2px solid var(--orange);
  border-radius: 14px;
  width: 100%;
  max-width: 340px;
  overflow: hidden;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
}

.gameover-header {
  background: var(--orange);
  padding: 14px 20px;
  text-align: center;
}

.gameover-title {
  font-size: 1.3rem;
  font-weight: bold;
  color: #00143a;
  letter-spacing: 0.06em;
}

.gameover-body {
  padding: 16px 20px;
}

.gameover-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 7px 0;
  border-bottom: 0.5px solid rgba(255,255,255,0.12);
  color: var(--text-white);
  font-size: 0.95rem;
}

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

.gameover-label { color: rgba(255,255,255,0.62); }
.gameover-value { font-weight: bold; color: var(--gold); }

.gameover-divider {
  height: 1px;
  background: rgba(255,165,0,0.3);
  margin: 6px 0;
}

.gameover-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 12px 20px 16px;
}

.gameover-buttons button {
  flex: 1;
  padding: 10px;
  font-size: 0.95rem;
  font-weight: bold;
  background: var(--steel-light);
  color: #00143a;
  transition: background 0.15s;
}

.gameover-buttons button:first-child {
  background: var(--orange);
}

.gameover-buttons button:hover { background: var(--gold); }

#go-leaderboard-button {
  flex: 1 1 100%;
  background: #2a9d8f;
  color: #fff;
}

#go-leaderboard-button:hover { background: #1f7a70; }

/* ── LANGUAGE TOGGLE ─────────────────────────────────────── */
.lang-toggle {
  margin-top: 0.4em;
  padding: clamp(0.4em, 1vh, 0.55em) 1em !important;
  font-size: clamp(0.8rem, 2vw, 0.9rem) !important;
  border-left: 3px solid rgba(255,255,255,0.4) !important;
  background: rgba(255,255,255,0.12) !important;
  color: rgba(255,255,255,0.75) !important;
  letter-spacing: 0.06em;
  font-style: italic;
}

.lang-toggle:hover {
  background: rgba(255,255,255,0.22) !important;
  border-left-color: var(--gold) !important;
  color: var(--gold) !important;
}

/* ── NEW RECORD CARD ─────────────────────────────────────── */
.new-record-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 1em 0.5em;
  text-align: center;
}

.new-record-star {
  font-size: 3rem;
  color: var(--gold);
  line-height: 1;
  animation: star-pop 0.5s ease;
}

@keyframes star-pop {
  0%   { transform: scale(0); opacity: 0; }
  70%  { transform: scale(1.3); }
  100% { transform: scale(1); opacity: 1; }
}

.new-record-title {
  font-size: 1.1rem;
  font-weight: bold;
  color: var(--navy-mid);
  letter-spacing: 0.04em;
}

.new-record-target {
  font-size: 4rem;
  font-weight: bold;
  color: var(--orange);
  line-height: 1;
  text-shadow: 0 2px 8px rgba(255,165,0,0.3);
}

.new-record-mode {
  font-size: 0.85rem;
  color: #666;
  margin-bottom: 0.4em;
}

.new-record-card button {
  padding: 10px 32px;
  font-size: 1rem;
  font-weight: bold;
  background: var(--orange);
  color: #00143a;
  border-radius: 6px;
  border: none;
  cursor: pointer;
  transition: background 0.15s;
}

.new-record-card button:hover { background: var(--gold); }

/* ── MODAL DOCUMENT (Rules / Privacy) ───────────────────── */
.modal-doc h2 {
  font-size: 1.3rem;
  color: var(--navy-mid);
  margin-bottom: 0.8em;
  padding-bottom: 0.4em;
  border-bottom: 2px solid var(--orange);
}

.modal-doc h3 {
  font-size: 0.95rem;
  font-weight: bold;
  color: var(--navy-mid);
  margin: 1em 0 0.3em;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.modal-doc p {
  font-size: 0.88rem;
  line-height: 1.6;
  color: #333;
  margin-bottom: 0.5em;
}

.modal-doc ul {
  margin: 0.3em 0 0.6em 1.3em;
}

.modal-doc ul li {
  font-size: 0.88rem;
  line-height: 1.6;
  color: #333;
  margin-bottom: 0.2em;
}

.modal-date {
  font-size: 0.78rem !important;
  color: #888 !important;
  margin-bottom: 1em !important;
}

/* ── MODAL ───────────────────────────────────────────────── */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,30,0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 1em;
}

.modal-content {
  background: #fff;
  border-radius: 10px;
  padding: 1.5em;
  max-width: 480px;
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
  position: relative;
}

.close-button {
  position: absolute;
  top: 10px;
  right: 14px;
  font-size: 1.4rem;
  cursor: pointer;
  color: #666;
  line-height: 1;
}

.close-button:hover { color: #000; }

.modal-body { padding-top: 0.5em; }
.modal-body h2 { margin-bottom: 0.6em; color: var(--navy-mid); }
.modal-body p  { margin-bottom: 0.5em; font-size: 0.95rem; line-height: 1.5; }

/* ── TUTORIAL CLIP ───────────────────────────────────────── */
.tutorial-clip-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.tutorial-clip-wrap h2 { color: var(--navy-mid); margin-bottom: 0.7em; }

.tutorial-clip {
  width: 100%;
  max-width: 380px;
  border-radius: 8px;
  border: 1px solid #c8d8ea;
  box-shadow: 0 2px 10px rgba(0,0,0,0.15);
}

.tutorial-clip-wrap-inline {
  margin-bottom: 0.9em;
}

.tutorial-continue-button {
  margin-top: 1.1em;
  padding: 0.7em 2em;
  font-size: 1rem;
  font-weight: bold;
  background: var(--orange);
  color: #00143a;
  border-radius: 8px;
  transition: background 0.15s;
}

.tutorial-continue-button:hover { background: var(--gold); }

/* ── PAUSE MODAL ─────────────────────────────────────────── */
#pause-modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,30,0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 900;
}

.pause-modal-content {
  background: rgba(20,55,120,0.95);
  border: 2px solid var(--orange);
  border-radius: 12px;
  padding: 2em 2.5em;
  text-align: center;
  color: var(--text-white);
}

.pause-modal-content p {
  font-size: 1.6rem;
  font-weight: bold;
  color: var(--gold);
  margin-bottom: 1em;
  letter-spacing: 0.08em;
}

.pause-modal-content button {
  padding: 10px 28px;
  font-size: 1rem;
  font-weight: bold;
  background: var(--orange);
  color: #00143a;
  border-radius: 6px;
  transition: background 0.15s;
}

.pause-modal-content button:hover { background: var(--gold); }

/* ── SETTINGS MODAL ──────────────────────────────────────── */
.settings-modal {
  display: flex;
  flex-direction: column;
  gap: 0.8em;
}

.settings-modal button {
  padding: 0.65em 1em;
  font-size: 0.95rem;
  background: var(--steel);
  color: #fff;
  border-radius: 6px;
  transition: background 0.15s;
}

.settings-modal button:hover { background: var(--navy-mid); }

/* ── STATS ───────────────────────────────────────────────── */
.stats-container {
  font-size: 0.92rem;
  color: #222;
}

.stats-header {
  background: var(--steel);
  color: #fff;
  padding: 10px 14px;
  border-radius: 6px 6px 0 0;
  text-align: center;
  margin-bottom: 0;
}

.stats-header h2 { font-size: 1.1rem; margin: 0; }

.stats-section {
  border: 1px solid #c8d8ea;
  border-top: none;
  padding: 10px 14px;
  background: #fff;
}

.stats-section:last-child { border-radius: 0 0 6px 6px; }

.stats-section-title {
  font-size: 0.75rem;
  font-weight: bold;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #fff;
  background: var(--orange);
  display: inline-block;
  padding: 2px 10px;
  border-radius: 3px;
  margin-bottom: 8px;
}

.stats-row {
  display: flex;
  justify-content: space-between;
  padding: 5px 0;
  border-bottom: 0.5px solid #eee;
  font-size: 0.9rem;
}

.stats-row:last-child { border-bottom: none; }
.stats-label { color: #555; }
.stats-value { font-weight: bold; color: #222; }

/* ── PLAYERS MODAL ───────────────────────────────────────── */
.players-modal {
  display: flex;
  flex-direction: column;
  gap: 0.9em;
}

.players-modal h2 { color: var(--navy-mid); margin-bottom: 0.2em; }

.player-list {
  display: flex;
  flex-direction: column;
  gap: 0.5em;
}

.player-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6em;
  padding: 0.6em 0.8em;
  border: 1px solid #c8d8ea;
  border-radius: 6px;
  background: #f6faff;
}

.player-row.active {
  border-color: var(--steel);
  background: #e8f2fc;
}

.player-row-name {
  font-weight: bold;
  color: #222;
  font-size: 0.95rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.player-row-actions {
  display: flex;
  align-items: center;
  gap: 0.4em;
  flex-shrink: 0;
}

.player-current-tag {
  font-size: 0.72rem;
  font-weight: bold;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #fff;
  background: var(--orange);
  padding: 3px 9px;
  border-radius: 3px;
  white-space: nowrap;
}

.player-select-btn,
.player-rename-btn,
.player-delete-btn {
  padding: 0.4em 0.7em;
  font-size: 0.85rem;
  background: var(--steel);
  color: #fff;
  border-radius: 5px;
  transition: background 0.15s;
}

.player-select-btn:hover { background: var(--navy-mid); }

.player-rename-btn,
.player-delete-btn {
  padding: 0.4em 0.55em;
  background: #7d8fa3;
}

.player-rename-btn:hover { background: #5c6c7d; }
.player-delete-btn:hover { background: #c0392b; }

.player-add-row {
  display: flex;
  gap: 0.5em;
  margin-top: 0.3em;
}

.player-add-row input {
  flex: 1;
  min-width: 0;
  padding: 0.55em 0.7em;
  border: 1px solid #c8d8ea;
  border-radius: 6px;
  font-size: 0.9rem;
}

#add-player-btn {
  padding: 0.55em 1em;
  background: var(--orange);
  color: #00143a;
  font-weight: bold;
  border-radius: 6px;
  white-space: nowrap;
  transition: background 0.15s;
}

#add-player-btn:hover { background: var(--gold); }

.player-max-note {
  font-size: 0.85rem;
  color: #777;
  font-style: italic;
  margin-top: 0.2em;
}

/* ── Y8 PLAYER ROW ───────────────────────────────────────── */
.player-row-y8 {
  border-color: #2a9d8f;
  background: #eafaf7;
}

.player-row-y8.active {
  border-color: #1f7a70;
  background: #d9f5ef;
}

#player-y8-login-btn,
#player-y8-logout-btn {
  padding: 0.4em 0.7em;
  font-size: 0.85rem;
  background: #2a9d8f;
  color: #fff;
  border-radius: 5px;
  transition: background 0.15s;
}

#player-y8-login-btn:hover,
#player-y8-logout-btn:hover { background: #1f7a70; }

/* ── LEADERBOARD MODAL ───────────────────────────────────── */
.leaderboard-modal {
  display: flex;
  flex-direction: column;
  gap: 0.8em;
}

.leaderboard-modal h2 { color: var(--navy-mid); margin-bottom: 0.1em; }

.leaderboard-tabs {
  display: flex;
  gap: 0.4em;
}

.leaderboard-tab {
  flex: 1;
  padding: 0.5em 0.4em;
  font-size: 0.85rem;
  background: #eef4fa;
  color: var(--navy-mid);
  border: 1px solid #c8d8ea;
  border-radius: 6px;
  transition: background 0.15s, color 0.15s;
}

.leaderboard-tab.active {
  background: var(--steel);
  color: #fff;
  border-color: var(--steel);
}

.leaderboard-body {
  display: flex;
  flex-direction: column;
  gap: 0.4em;
  min-height: 120px;
}

.leaderboard-row {
  display: flex;
  align-items: center;
  gap: 0.6em;
  padding: 0.5em 0.7em;
  border: 1px solid #c8d8ea;
  border-radius: 6px;
  background: #f6faff;
}

.leaderboard-rank {
  font-weight: bold;
  color: var(--steel);
  min-width: 2em;
}

.leaderboard-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: bold;
  color: #222;
}

.leaderboard-score {
  font-weight: bold;
  color: var(--navy-mid);
}

.leaderboard-status {
  text-align: center;
  color: #777;
  font-style: italic;
  padding: 1.5em 0;
}

.new-record-leaderboard-btn {
  margin-top: 0.6em;
  padding: 0.5em 1.2em;
  font-size: 0.9rem;
  background: #2a9d8f;
  color: #fff;
  border-radius: 8px;
  transition: background 0.15s;
}

.new-record-leaderboard-btn:hover { background: #1f7a70; }

/* ── TARGET SUB (over/under display) ────────────────────── */
#target-sub {
  font-size: clamp(0.7rem, 1.6vw, 0.85rem);
  font-weight: bold;
  color: #E74C3C;
  letter-spacing: 0.04em;
  min-height: 1em;
  opacity: 0;
  transition: opacity 0.2s;
}

#target-sub.target-sub-visible {
  opacity: 1;
}

/* ── PANEL FLASH ─────────────────────────────────────────── */
@keyframes flash-correct {
  0%   { background: rgba(20, 55, 120, 0.82); box-shadow: none; }
  25%  { background: rgba(46, 204, 113, 0.65); box-shadow: 0 0 28px rgba(46,204,113,0.8); }
  70%  { background: rgba(46, 204, 113, 0.45); box-shadow: 0 0 20px rgba(46,204,113,0.5); }
  100% { background: rgba(20, 55, 120, 0.82); box-shadow: none; }
}

@keyframes flash-wrong {
  0%   { background: rgba(20, 55, 120, 0.82); box-shadow: none; }
  30%  { background: rgba(231, 76, 60, 0.55); box-shadow: 0 0 24px rgba(231,76,60,0.7); }
  100% { background: rgba(20, 55, 120, 0.82); box-shadow: none; }
}

#info-panel.flash-correct { animation: flash-correct 1.6s ease forwards; }
#info-panel.flash-wrong   { animation: flash-wrong   0.7s ease forwards; }

/* ── ANIMATIONS ──────────────────────────────────────────── */
@keyframes cell-pop {
  0%   { transform: scale(1); }
  40%  { transform: scale(1.18); }
  100% { transform: scale(1); }
}

.grid-cell.pop { animation: cell-pop 0.22s ease; }

@keyframes sum-pulse {
  0%   { transform: scale(1); }
  50%  { transform: scale(1.12); }
  100% { transform: scale(1); }
}

#target-value.solved { animation: sum-pulse 0.35s ease; }
