/* Debris Clearer — calm Minesweeper retheme */

:root,
html.day-tide {
  --sand-50: #faf8f5;
  --sand-100: #f3efe8;
  --sand-200: #e8e0d4;
  --tide-50: #f0faf8;
  --tide-100: #d5f0ea;
  --tide-200: #a8e0d4;
  --tide-500: #2a9d8f;
  --tide-600: #1f7a6f;
  --tide-700: #1a6158;
  --tide-800: #164e47;
  --tide-900: #0f332f;
  --tide-950: #0a2220;
  --bg: var(--sand-50);
  --surface: #fff;
  --surface-2: var(--sand-100);
  --border: var(--sand-200);
  --text: var(--tide-900);
  --muted: rgba(15, 51, 47, 0.55);
  --cell: #eef6f4;
  --cell-hover: #e2f0ec;
  --cell-open: #ffffff;
  --cell-flag: #f7f1e8;
  --cell-hit: #f3e8e6;
  --num-1: #1f7a6f;
  --num-2: #2a7a4b;
  --num-3: #b45309;
  --num-4: #1d4ed8;
  --num-5: #9f1239;
  --num-6: #0e7490;
  --num-7: #334155;
  --num-8: #57534e;
  --shadow: 0 16px 40px -24px rgba(15, 51, 47, 0.28);
  --font: Inter, system-ui, sans-serif;
  --display: "Cormorant Garamond", Georgia, serif;
  --radius: 1.15rem;
}

html.night-tide {
  --bg: #0a2220;
  --surface: #0f332f;
  --surface-2: #164e47;
  --border: rgba(168, 224, 212, 0.18);
  --text: #e8f5f2;
  --muted: rgba(232, 245, 242, 0.55);
  --cell: #143832;
  --cell-hover: #1a4540;
  --cell-open: #0c2a26;
  --cell-flag: #1f4038;
  --cell-hit: #3a2826;
  --num-1: #7dd3c7;
  --num-2: #86efac;
  --num-3: #fdba74;
  --num-4: #93c5fd;
  --num-5: #f9a8d4;
  --num-6: #67e8f9;
  --num-7: #e2e8f0;
  --num-8: #d6d3d1;
  --shadow: 0 18px 48px -20px rgba(0, 0, 0, 0.55);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  line-height: 1.45;
}

.bg-wash {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    radial-gradient(ellipse 90% 50% at 50% -8%, rgba(42, 157, 143, 0.12), transparent 55%),
    radial-gradient(ellipse 60% 35% at 100% 100%, rgba(168, 224, 212, 0.16), transparent 50%),
    linear-gradient(180deg, var(--bg), var(--sand-100, #f3efe8));
}

html.night-tide .bg-wash {
  background:
    radial-gradient(ellipse 80% 45% at 50% -5%, rgba(42, 157, 143, 0.18), transparent 55%),
    linear-gradient(180deg, #071816, #0a2220 55%, #0f332f);
}

.app {
  position: relative;
  z-index: 1;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.7rem 1rem;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface) 90%, transparent);
  backdrop-filter: blur(12px);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  text-decoration: none;
  color: inherit;
  min-width: 0;
}

.brand img {
  height: 1.8rem;
  width: auto;
}

.brand strong {
  display: block;
  font-family: var(--display);
  font-size: 1.15rem;
  font-weight: 600;
  line-height: 1.1;
}

.brand span {
  font-size: 0.62rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 600;
}

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

.icon-btn,
.btn,
.mode-btn,
.tool-btn {
  font-family: inherit;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  border-radius: 0.75rem;
  transition: background 0.12s, border-color 0.12s, transform 0.08s;
}

.icon-btn {
  width: 2.3rem;
  height: 2.3rem;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--surface);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  padding: 0.55rem 0.95rem;
  font-size: 0.84rem;
  font-weight: 600;
  text-decoration: none;
  border-radius: 999px;
}

.btn-sm {
  min-height: 2.15rem;
  padding: 0.4rem 0.8rem;
  font-size: 0.78rem;
}

.btn-primary {
  background: var(--tide-700);
  border-color: var(--tide-700);
  color: #fff;
}

.btn-primary:hover {
  background: var(--tide-800);
}

.btn-ghost {
  background: transparent;
}

.btn-ghost:hover,
.icon-btn:hover {
  background: var(--tide-50, var(--surface-2));
  border-color: color-mix(in srgb, var(--tide-500) 30%, var(--border));
}

html.night-tide .btn-ghost:hover,
html.night-tide .icon-btn:hover {
  background: rgba(42, 157, 143, 0.12);
}

.main {
  flex: 1;
  width: 100%;
  max-width: 88rem;
  margin: 0 auto;
  padding: 1rem 0.85rem 2rem;
  display: grid;
  gap: 1rem;
}

.side-left { order: 1; }
.play-panel { order: 2; }
.side-right { order: 3; }

@media (min-width: 1100px) {
  .main {
    grid-template-columns: 15rem minmax(0, 1fr) 16.5rem;
    gap: 1.1rem;
    padding: 1.25rem 1.25rem 2.5rem;
    align-items: start;
  }

  .side-left,
  .side-right {
    position: sticky;
    top: 4.25rem;
    max-height: calc(100vh - 5rem);
    overflow-y: auto;
    align-self: start;
  }
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.play-panel {
  padding: 1rem;
}

@media (min-width: 640px) {
  .play-panel {
    padding: 1.15rem 1.25rem 1.35rem;
  }
}

.tagline {
  margin: 0 0 0.75rem;
  font-size: 0.86rem;
  color: var(--muted);
}

.meta-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.55rem;
  margin-bottom: 0.85rem;
}

.pills {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 0.32rem 0.65rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
}

.pill.accent {
  background: var(--tide-50, rgba(42, 157, 143, 0.12));
  border-color: color-mix(in srgb, var(--tide-500) 35%, var(--border));
  color: var(--tide-800, var(--tide-200));
}

html.night-tide .pill.accent {
  color: var(--tide-200);
}

/* Board */
.board-shell {
  display: flex;
  justify-content: center;
  overflow: auto;
  padding: 0.15rem;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
}

.board {
  --size: min(9.5vw, 2.35rem);
  display: grid;
  gap: 3px;
  padding: 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 0.85rem;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.35);
}

.board.rows-9 {
  --size: min(9.8vw, 2.55rem);
}
.board.rows-12 {
  --size: min(7.4vw, 2.2rem);
}
.board.rows-16 {
  --size: min(5.6vw, 1.95rem);
}

@media (min-width: 640px) {
  .board.rows-9 {
    --size: 2.55rem;
  }
  .board.rows-12 {
    --size: 2.25rem;
  }
  .board.rows-16 {
    --size: 2rem;
  }
}

.board.won {
  animation: tide-wash 1s ease;
}

@keyframes tide-wash {
  0% {
    box-shadow: 0 0 0 0 rgba(42, 157, 143, 0.35);
  }
  55% {
    box-shadow: 0 0 0 14px rgba(42, 157, 143, 0);
  }
  100% {
    box-shadow: none;
  }
}

.board.lost {
  opacity: 0.92;
  filter: saturate(0.85);
}

.cell {
  width: var(--size);
  height: var(--size);
  border: none;
  border-radius: 0.35rem;
  background: var(--cell);
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: calc(var(--size) * 0.42);
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  padding: 0;
  position: relative;
  transition: background 0.1s, transform 0.08s, box-shadow 0.15s;
  box-shadow: 0 1px 0 rgba(15, 51, 47, 0.06);
}

.cell:hover:not(.open):not(:disabled) {
  background: var(--cell-hover);
}

.cell:active:not(.open) {
  transform: scale(0.96);
}

.cell.open {
  background: var(--cell-open);
  box-shadow: none;
  cursor: default;
  animation: ripple-open 0.28s ease;
}

@keyframes ripple-open {
  from {
    box-shadow: inset 0 0 0 0 rgba(42, 157, 143, 0.2);
  }
  to {
    box-shadow: inset 0 0 0 0 transparent;
  }
}

.cell.flagged {
  background: var(--cell-flag);
}

.cell.hit {
  background: var(--cell-hit);
}

.cell.n1 {
  color: var(--num-1);
}
.cell.n2 {
  color: var(--num-2);
}
.cell.n3 {
  color: var(--num-3);
}
.cell.n4 {
  color: var(--num-4);
}
.cell.n5 {
  color: var(--num-5);
}
.cell.n6 {
  color: var(--num-6);
}
.cell.n7 {
  color: var(--num-7);
}
.cell.n8 {
  color: var(--num-8);
}

.cell .debris-icon,
.cell .flag-icon {
  font-size: calc(var(--size) * 0.48);
  line-height: 1;
  opacity: 0.92;
}

.cell.scan-flash {
  box-shadow: inset 0 0 0 2px var(--tide-500);
  background: color-mix(in srgb, var(--tide-200) 45%, var(--cell));
}

.tools {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.45rem;
  margin-top: 0.9rem;
}

.tool-btn {
  min-height: 2.7rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.12rem;
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  padding: 0.35rem;
}

.tool-btn i {
  font-size: 0.95rem;
  color: var(--tide-700);
}

html.night-tide .tool-btn i {
  color: var(--tide-200);
}

.tool-btn.on {
  background: var(--tide-700);
  border-color: var(--tide-700);
  color: #fff;
}

.tool-btn.on i {
  color: #fff;
}

.tool-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.side {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.side .panel {
  padding: 1rem 1.05rem;
}

.side h2 {
  margin: 0 0 0.3rem;
  font-family: var(--display);
  font-size: 1.25rem;
  font-weight: 600;
}

.side p {
  margin: 0;
  font-size: 0.84rem;
  color: var(--muted);
}

.mode-list {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin-top: 0.7rem;
}

.mode-btn {
  text-align: left;
  padding: 0.65rem 0.8rem;
  border-radius: 0.85rem;
}

.mode-btn strong {
  display: block;
  font-size: 0.9rem;
  margin-bottom: 0.08rem;
}

.mode-btn span {
  font-size: 0.74rem;
  color: var(--muted);
}

.mode-btn:hover,
.mode-btn.active {
  border-color: color-mix(in srgb, var(--tide-500) 40%, var(--border));
  background: var(--tide-50, rgba(42, 157, 143, 0.1));
}

.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.45rem;
  margin-top: 0.7rem;
}

.stat {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 0.7rem;
  padding: 0.5rem 0.6rem;
}

.stat b {
  display: block;
  font-size: 1.05rem;
  color: var(--tide-700);
  font-variant-numeric: tabular-nums;
}

html.night-tide .stat b {
  color: var(--tide-200);
}

.stat span {
  font-size: 0.65rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  font-weight: 600;
  color: var(--muted);
}

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.48rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
}

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

.switch {
  width: 2.45rem;
  height: 1.35rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--sand-200, var(--border));
  position: relative;
  cursor: pointer;
  padding: 0;
  flex-shrink: 0;
}

.switch::after {
  content: "";
  position: absolute;
  top: 0.12rem;
  left: 0.12rem;
  width: 1.05rem;
  height: 1.05rem;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
  transition: transform 0.15s;
}

.switch[aria-checked="true"] {
  background: var(--tide-600);
  border-color: var(--tide-600);
}

.switch[aria-checked="true"]::after {
  transform: translateX(1.05rem);
}

.footer-mini {
  text-align: center;
  padding: 0.35rem 1rem 1.2rem;
  font-size: 0.74rem;
  color: var(--muted);
}

.footer-mini a {
  color: var(--tide-700);
  font-weight: 600;
  text-decoration: none;
}

html.night-tide .footer-mini a {
  color: var(--tide-200);
}

/* Modal */
.modal-root {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: rgba(15, 51, 47, 0.35);
  backdrop-filter: blur(6px);
}

html.night-tide .modal-root {
  background: rgba(5, 16, 14, 0.6);
}

.modal-root.open {
  display: flex;
}

.modal {
  width: min(100%, 25rem);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 1.25rem;
  padding: 1.4rem 1.25rem 1.2rem;
  box-shadow: var(--shadow);
}

.modal .kicker {
  margin: 0 0 0.3rem;
  font-size: 0.68rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  font-weight: 700;
  color: var(--tide-600);
}

.modal h2 {
  margin: 0 0 0.4rem;
  font-family: var(--display);
  font-size: 1.75rem;
  font-weight: 600;
}

.modal .line {
  margin: 0 0 0.85rem;
  color: var(--muted);
  font-size: 0.95rem;
}

.next-block {
  margin: 0 0 0.9rem;
  padding: 0.75rem 0.85rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 0.9rem;
}

.next-label {
  margin: 0 0 0.45rem;
  font-size: 0.68rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  font-weight: 700;
  color: var(--tide-600);
}

.next-games {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.4rem;
}

.next-games a {
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 0.55rem 0.4rem;
  font-size: 0.8rem;
  font-weight: 600;
  text-decoration: none;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0.65rem;
  transition: border-color 0.15s, background 0.15s;
}

.next-games a:hover {
  border-color: color-mix(in srgb, var(--tide-500) 45%, var(--border));
  background: color-mix(in srgb, var(--tide-500) 8%, var(--surface));
}

.btn-soft {
  background: var(--surface-2);
  border-color: var(--border);
  color: var(--text);
}

.btn-soft:hover {
  background: color-mix(in srgb, var(--tide-500) 10%, var(--surface-2));
}

.modal-actions {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.splash {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.55rem;
  background: var(--bg);
  transition: opacity 0.4s, visibility 0.4s;
}

.splash.hide {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.splash p {
  margin: 0;
  font-family: var(--display);
  font-size: 1.45rem;
  color: var(--tide-800, var(--text));
}

.splash span {
  font-size: 0.75rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 600;
}

@media (prefers-reduced-motion: reduce) {
  .cell.open,
  .board.won,
  .cell.scan-flash {
    animation: none !important;
  }
}
