:root {
  --page: #1b1c21;
  --panel: #26272e;
  --panel-light: #30313a;
  --ink: #f1f1f4;
  --muted: rgba(241, 241, 244, 0.6);
  --blue: #4da3ff;
  --gold: #ffd65a;
  --danger: #ff6b6b;
  --cell: 32px;
  --gap: 3px;
  --footer-height: 22px;
  --n1: #6cb6ff;
  --n2: #69db7c;
  --n3: #ff8787;
  --n4: #b197fc;
  --n5: #ffa94d;
  --n6: #3bc9db;
  --n7: #f783ac;
  --n8: #ced4da;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  background: radial-gradient(ellipse at 50% 0%, #262833, var(--page) 70%) fixed;
  background-color: var(--page);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-tap-highlight-color: transparent;
}

.app {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) var(--footer-height);
  grid-template-columns: minmax(0, 1fr);
  height: 100vh;
  height: 100dvh;
  user-select: none;
  -webkit-user-select: none;
}

html.booting .app {
  opacity: 0;
}

.app {
  transition: opacity 0.25s ease-out;
}

button {
  position: relative;
  display: inline-flex;
  white-space: nowrap;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 36px;
  padding: 0 14px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.07);
  color: inherit;
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition:
    background 0.15s,
    transform 0.1s;
}

button:hover {
  background: rgba(255, 255, 255, 0.13);
}

button:active {
  transform: scale(0.96);
}

button:focus-visible,
.difficulty-option:has(input:focus-visible),
.mode-option:has(input:focus-visible) {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
}

button.primary {
  border-color: transparent;
  background: var(--blue);
  color: #0b1a2c;
}

button.primary:hover {
  background: #74b8ff;
}

button svg,
.counter svg,
.mode-option svg {
  width: 18px;
  height: 18px;
  flex: none;
}

.icon-button {
  width: 36px;
  padding: 0;
  border-color: transparent;
  background: transparent;
  color: var(--muted);
}

.icon-button:hover {
  color: var(--ink);
}

[data-tooltip]::after {
  content: attr(data-tooltip);
  position: absolute;
  top: calc(100% + 8px);
  left: 50%;
  z-index: 20;
  padding: 5px 9px;
  border-radius: 7px;
  background: #0e0f12;
  color: var(--ink);
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, -4px);
  transition:
    opacity 0.15s,
    transform 0.15s;
}

@media (hover: hover) {
  [data-tooltip]:hover::after {
    opacity: 1;
    transform: translate(-50%, 0);
    transition-delay: 0.4s;
  }
}

.top-bar {
  display: flex;
  align-items: center;
  gap: 16px;
  min-height: 60px;
  padding: 8px 18px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: inherit;
  text-decoration: none;
}

.brand-icon {
  width: 32px;
  height: 32px;
}

.brand h1 {
  margin: 0;
  font-size: 19px;
  font-weight: 800;
}

.counters {
  display: flex;
  gap: 8px;
  margin-left: auto;
}

.counter {
  position: relative;
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 78px;
  height: 36px;
  padding: 0 12px;
  border-radius: 10px;
  background: var(--panel);
  font-size: 16px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.counter svg {
  color: var(--muted);
}

.controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.difficulty-picker,
.mode-switch {
  display: flex;
  padding: 3px;
  border-radius: 11px;
  background: var(--panel);
}

.difficulty-option,
.mode-option {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 30px;
  padding: 0 12px;
  border-radius: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition:
    background 0.15s,
    color 0.15s;
}

.difficulty-option input,
.mode-option input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.difficulty-option:has(input:checked),
.mode-option:has(input:checked) {
  background: var(--panel-light);
  color: var(--ink);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
}

.play-area {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  min-height: 0;
  padding: 14px;
}

.daily-banner {
  padding: 4px 12px;
  border-radius: 999px;
  background: rgba(77, 163, 255, 0.14);
  color: var(--blue);
  font-size: 13px;
  font-weight: 700;
}

.daily-banner[hidden] {
  display: none;
}

.board-frame {
  flex: 0 1 auto;
  min-height: 0;
  max-width: 100%;
  max-height: 100%;
  overflow: auto;
  padding: 10px;
  border-radius: 16px;
  background: #15161a;
  box-shadow:
    inset 0 2px 8px rgba(0, 0, 0, 0.5),
    0 0 0 1px rgba(255, 255, 255, 0.05);
  touch-action: manipulation;
}

.board {
  display: grid;
  grid-template-columns: repeat(var(--columns), var(--cell));
  grid-auto-rows: var(--cell);
  gap: var(--gap);
  touch-action: manipulation;
}

.board.shake {
  animation: shake 0.45s cubic-bezier(0.36, 0.07, 0.19, 0.97);
}

.cell {
  position: relative;
  display: grid;
  place-items: center;
  border-radius: calc(var(--cell) * 0.18);
  background: linear-gradient(160deg, #4a4d5c, #363844);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.14),
    inset 0 -2px 0 rgba(0, 0, 0, 0.22),
    0 1px 2px rgba(0, 0, 0, 0.45);
  font-size: calc(var(--cell) * 0.55);
  font-weight: 800;
  line-height: 1;
  cursor: pointer;
  transition:
    background 0.12s,
    transform 0.1s;
}

.cell svg {
  width: 62%;
  height: 62%;
  pointer-events: none;
}

@media (hover: hover) {
  .board.playing .cell:not(.open):hover {
    background: linear-gradient(160deg, #565a6b, #40424f);
  }
}

.cell.pressed:not(.open),
.cell.peek:not(.open):not(.flagged) {
  background: #24252c;
  transform: scale(0.94);
}

.cell.open {
  background: #1a1b20;
  box-shadow: none;
  cursor: default;
  animation: open-cell 0.22s ease-out both;
  animation-delay: var(--delay, 0ms);
}

.cell.open.has-number {
  cursor: pointer;
}

.cell.flagged svg {
  animation: plant-flag 0.25s cubic-bezier(0.2, 1.4, 0.4, 1);
}

.cell.mine {
  background: #3a2328;
  color: #f1f1f4;
  animation: open-cell 0.25s ease-out both;
  animation-delay: var(--delay, 0ms);
}

.cell.exploded {
  background: var(--danger);
  color: #1b1c21;
  animation: explode 0.5s ease-out;
}

.cell.wrong-flag {
  background: #2a2b33;
}

.cell.wrong-flag::after {
  content: "";
  position: absolute;
  inset: 22%;
  background:
    linear-gradient(45deg, transparent 45%, var(--danger) 45% 55%, transparent 55%),
    linear-gradient(-45deg, transparent 45%, var(--danger) 45% 55%, transparent 55%);
}

.cell.hint-safe {
  box-shadow:
    0 0 0 2px var(--gold),
    0 0 14px rgba(255, 214, 90, 0.6);
}

.cell[data-number="1"] { color: var(--n1); }
.cell[data-number="2"] { color: var(--n2); }
.cell[data-number="3"] { color: var(--n3); }
.cell[data-number="4"] { color: var(--n4); }
.cell[data-number="5"] { color: var(--n5); }
.cell[data-number="6"] { color: var(--n6); }
.cell[data-number="7"] { color: var(--n7); }
.cell[data-number="8"] { color: var(--n8); }

.board.won .cell.flagged {
  background: linear-gradient(160deg, #2f5e3e, #23462f);
}

.board-tools,
.tip-touch,
.touch-note {
  display: none;
}

.board-tools {
  align-items: center;
  gap: 8px;
}

.zoom-button {
  height: 36px;
  border-radius: 11px;
  background: var(--panel);
  color: var(--muted);
  font-size: 13px;
}

.zoom-button[aria-pressed="true"] {
  background: var(--panel-light);
  color: var(--ink);
}

.board:focus {
  outline: none;
}

.board.keyboard .cell.cursor {
  outline: 2px solid var(--gold);
  outline-offset: 1px;
  z-index: 1;
}

.daily-calendar {
  display: flex;
  justify-content: center;
  gap: 6px;
  margin-bottom: 14px;
}

.calendar-day {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.06);
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.calendar-day.today {
  box-shadow: 0 0 0 1.5px var(--blue);
}

.calendar-day.done {
  background: #2f9e44;
  color: #fff;
}

.cell.charging::before {
  content: "";
  position: absolute;
  inset: -3px;
  border-radius: inherit;
  background: conic-gradient(var(--gold) calc(var(--charge) * 1%), transparent 0);
  -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 3px), #000 calc(100% - 2px));
  mask: radial-gradient(farthest-side, transparent calc(100% - 3px), #000 calc(100% - 2px));
  animation: charge var(--long-press, 380ms) linear forwards;
  pointer-events: none;
}

@property --charge {
  syntax: "<number>";
  inherits: false;
  initial-value: 0;
}

@keyframes charge {
  from {
    --charge: 0;
  }
  to {
    --charge: 100;
  }
}

.board-frame {
  transition: box-shadow 0.6s ease;
}

.board-frame.won {
  box-shadow:
    inset 0 2px 8px rgba(0, 0, 0, 0.5),
    0 0 0 2px rgba(105, 219, 124, 0.55),
    0 0 40px rgba(105, 219, 124, 0.3);
}

.board-frame.won .cell {
  animation: celebrate 0.55s ease-out both;
  animation-delay: var(--wave, 0ms);
}

.board-frame.won .cell::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: rgba(105, 219, 124, 0.45);
  opacity: 0;
  animation: celebrate-glow 0.55s ease-out both;
  animation-delay: var(--wave, 0ms);
  pointer-events: none;
}

@keyframes celebrate {
  40% {
    transform: scale(1.12);
  }
}

@keyframes celebrate-glow {
  40% {
    opacity: 1;
  }
}

.counter.on-pace {
  color: var(--gold);
}

.counter.on-pace svg {
  color: var(--gold);
}

.dialog .daily-streak {
  margin: -2px 0 10px;
  color: var(--gold);
  font-weight: 700;
}

.confetti-canvas {
  position: fixed;
  inset: 0;
  z-index: 50;
  width: 100vw;
  height: 100vh;
  pointer-events: none;
}

.tip {
  margin: 0;
  color: rgba(241, 241, 244, 0.38);
  font-size: 12px;
}

.site-footer {
  display: flex;
  align-items: center;
  justify-content: safe center;
  gap: 8px;
  padding: 0 10px;
  overflow-x: auto;
  background: rgba(0, 0, 0, 0.18);
  color: rgba(241, 241, 244, 0.38);
  font-size: 10.5px;
  white-space: nowrap;
  scrollbar-width: none;
}

.site-footer a {
  color: rgba(241, 241, 244, 0.5);
  text-decoration: none;
}

.site-footer a:hover {
  color: var(--ink);
  text-decoration: underline;
}

.guide {
  max-width: 720px;
  margin: 0 auto;
  padding: 40px 20px 60px;
  color: var(--muted);
  line-height: 1.6;
}

.guide h2,
.guide h3 {
  color: var(--ink);
}

.dialog {
  min-width: 300px;
  max-width: calc(100vw - 32px);
  padding: 26px 26px 22px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 18px;
  background: linear-gradient(160deg, #2c2d36, #1f2026);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55);
  color: inherit;
  text-align: center;
}

.dialog[open] {
  animation: pop-in 0.3s cubic-bezier(0.2, 1.3, 0.4, 1);
}

.dialog::backdrop {
  background: rgba(0, 0, 0, 0.5);
  animation: fade-in 0.2s ease-out;
}

.dialog h2 {
  margin: 0 0 6px;
  font-size: 20px;
}

.dialog h3 {
  margin: 20px 0 8px;
  font-size: 14px;
  color: var(--muted);
}

.dialog p {
  margin: 0 0 20px;
  color: var(--muted);
  font-size: 14px;
}

.dialog-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  margin-top: 6px;
}

.choice-row {
  display: flex;
  justify-content: center;
  gap: 10px;
}

.choice {
  flex-direction: column;
  gap: 6px;
  width: 120px;
  height: auto;
  padding: 16px 8px 14px;
  border-radius: 14px;
}

.classic {
  position: relative;
  border-color: var(--gold);
  box-shadow: 0 0 0 1px var(--gold), 0 8px 24px rgba(255, 214, 90, 0.18);
}

.classic-badge {
  position: absolute;
  top: -9px;
  left: 50%;
  transform: translateX(-50%);
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--gold);
  color: #1a1b20;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  white-space: nowrap;
}

.choice small {
  color: var(--muted);
  font-size: 11px;
  font-weight: 500;
}

.choice-grid {
  --size: 6;
  width: 44px;
  height: 44px;
  margin-bottom: 4px;
  border-radius: 4px;
  background-color: #4a4d5c;
  background-image:
    linear-gradient(90deg, #2c2d36 2px, transparent 2px),
    linear-gradient(#2c2d36 2px, transparent 2px);
  background-size: calc(100% / var(--size)) calc(100% / var(--size));
}

.choice-grid.easy {
  --size: 4;
}

.choice-grid.medium {
  --size: 6;
}

.choice-grid.hard {
  --size: 9;
}

.result-stats {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  margin-bottom: 20px;
}

.result-stat {
  min-width: 82px;
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.06);
}

.result-stat strong {
  display: block;
  font-size: 20px;
  font-variant-numeric: tabular-nums;
}

.result-stat span {
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.result-stat.record strong {
  color: var(--gold);
}

.stats-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}

.stats-table th,
.stats-table td {
  padding: 7px 10px;
}

.stats-table thead th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.stats-table tbody th {
  color: var(--muted);
  font-weight: 500;
  text-align: left;
}

.stats-table tbody tr + tr {
  border-top: 1px solid rgba(255, 255, 255, 0.06);
}

.daily-status {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-bottom: 16px;
}

.daily-status button {
  flex-direction: column;
  gap: 2px;
  height: auto;
  min-width: 86px;
  padding: 8px 10px;
}

.daily-status small {
  color: var(--muted);
  font-size: 11px;
  font-weight: 500;
}

.daily-status .done small {
  color: #69db7c;
}

.toast {
  position: fixed;
  bottom: 44px;
  left: 50%;
  z-index: 30;
  padding: 10px 16px;
  border-radius: 12px;
  background: #0e0f12;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 10px);
  transition:
    opacity 0.2s,
    transform 0.2s;
}

.toast.visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

.icon-sprite {
  display: none;
}

@keyframes open-cell {
  from {
    transform: scale(0.7);
    opacity: 0.3;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}

@keyframes plant-flag {
  from {
    transform: translateY(-40%) scale(0.6);
    opacity: 0;
  }
}

@keyframes explode {
  0% {
    transform: scale(1);
    box-shadow: 0 0 0 0 rgba(255, 107, 107, 0.9);
  }
  40% {
    transform: scale(1.25);
  }
  100% {
    transform: scale(1);
    box-shadow: 0 0 0 18px rgba(255, 107, 107, 0);
  }
}

@keyframes shake {
  10%, 90% { transform: translateX(-2px); }
  20%, 80% { transform: translateX(4px); }
  30%, 50%, 70% { transform: translateX(-6px); }
  40%, 60% { transform: translateX(6px); }
}

@keyframes pop-in {
  from {
    opacity: 0;
    transform: scale(0.92);
  }
}

@keyframes fade-in {
  from {
    opacity: 0;
  }
}

@media (pointer: coarse) {
  .board-tools {
    display: flex;
  }

  .tip-mouse {
    display: none;
  }

  .tip-touch,
  .touch-note {
    display: block;
  }
}

@media (max-width: 900px) {
  .top-bar {
    flex-wrap: wrap;
    gap: 8px;
    padding: 8px 10px;
  }

  .brand h1 {
    font-size: 16px;
  }

  .controls {
    order: 3;
    width: 100%;
    justify-content: space-between;
  }

  .button-label {
    display: none;
  }

  #new-game {
    width: 36px;
    padding: 0;
  }

  .counter {
    min-width: 0;
  }

  .play-area {
    padding: 8px 6px;
    gap: 8px;
  }

  .board-frame {
    padding: 4px;
    border-radius: 12px;
  }

  .difficulty-option {
    padding: 0 9px;
  }

  .controls {
    gap: 4px;
  }

  .counter {
    gap: 5px;
    height: 32px;
    padding: 0 9px;
    font-size: 15px;
  }

  .counters {
    gap: 6px;
  }
}

@media (max-width: 520px) {
  .footer-extra {
    display: none;
  }
}

@media (max-width: 420px) {
  .choice-row {
    flex-direction: column;
  }

  .choice {
    flex-direction: row;
    justify-content: flex-start;
    width: 100%;
    gap: 12px;
  }

  .choice-grid {
    width: 32px;
    height: 32px;
    margin: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .cell,
  .cell.open,
  .cell.mine,
  .cell.exploded,
  .board.shake,
  .dialog[open] {
    animation: none;
    transition: none;
  }
}

.home-link {
  display: flex;
  align-items: center;
  padding-right: 14px;
  border-right: 1px solid rgba(255, 255, 255, 0.15);
  transition: opacity 0.15s;
}

.home-link:hover {
  opacity: 0.8;
}

.home-link-mark {
  display: block;
  width: 30px;
  height: 30px;
}

.more-games {
  max-width: 760px;
  margin: 0 auto;
  padding: 0 20px 64px;
}

.more-games h2 {
  margin: 0 0 12px;
  font-size: 20px;
}

.more-games ul {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 20px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.more-games a {
  color: #4da3ff;
}
