:root {
  --bg1: #0d1117;
  --bg2: #161b22;
  --panel: #21262d;
  --cell: #30363d;
  --cell-hover: #3d444d;
  --fill: #0d0d0d;
  --fill-edge: #1a1a1a;
  --mark: #8b949e;
  --text: #f0f3f6;
  --muted: #8b949e;
  --accent: #58a6ff;
  --accent-soft: rgba(88, 166, 255, 0.2);
  --clue: #c9d1d9;
  --border: #484f58;
  --win: #3fb950;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Outfit", sans-serif;
  background:
    radial-gradient(ellipse at 20% 0%, rgba(88, 166, 255, 0.12), transparent 50%),
    radial-gradient(ellipse at 80% 100%, rgba(63, 185, 80, 0.08), transparent 45%),
    linear-gradient(165deg, var(--bg1), var(--bg2));
  min-height: 100vh;
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.wrapper {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 12px;
}

.hidden {
  display: none !important;
}

.level-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 80vh;
  text-align: center;
}

.level-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
}

.level-header h1,
.header h1 {
  margin: 0;
  font-size: clamp(1.4rem, 4vw, 2rem);
}

.level-screen > p {
  margin: 0 0 24px;
  opacity: 0.9;
}

.level-buttons {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
  max-width: 320px;
}

.level-btn {
  padding: 16px 20px;
  border: 2px solid rgba(255, 255, 255, 0.25);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.06);
  color: inherit;
  font-family: inherit;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.level-btn:hover {
  background: var(--accent-soft);
  border-color: var(--accent);
}

.level-name {
  font-weight: 700;
  font-size: 1.1rem;
}

.level-desc {
  font-size: 0.85rem;
  opacity: 0.85;
}

.help-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.4);
  background: rgba(255, 255, 255, 0.1);
  color: inherit;
  font-size: 1.1rem;
  font-weight: 700;
  cursor: pointer;
}

.game-screen {
  width: 100%;
  max-width: 720px;
  flex: 1;
  display: flex;
  flex-direction: column;
}

.game-screen.size-15 {
  max-width: 900px;
}

.header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.level-badge {
  padding: 4px 10px;
  border-radius: 20px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.8rem;
  font-weight: 600;
}

.header-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-left: auto;
  align-items: center;
}

.hud {
  font-weight: 700;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
  min-width: 4.5rem;
}

.btn {
  padding: 10px 14px;
  min-height: 44px;
  border: none;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.18);
  color: inherit;
  font-family: inherit;
  font-weight: 600;
  cursor: pointer;
}

.btn:hover {
  background: rgba(255, 255, 255, 0.28);
}

.btn-ghost {
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.4);
}

.btn-ghost:hover {
  background: rgba(255, 255, 255, 0.08);
}

.btn-large {
  padding: 12px 22px;
}

.board-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  overflow: auto;
  padding-bottom: 16px;
}

.board {
  display: grid;
  gap: 0;
  width: max-content;
  max-width: 100%;
  background: var(--panel);
  border: 2px solid var(--border);
  border-radius: 10px;
  padding: 6px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.45);
}

.clue-corner {
  background: transparent;
}

.col-clues {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  gap: 1px;
  padding: 2px 1px 4px;
  min-height: 2.5rem;
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--clue);
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

.row-clues {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  padding: 0 6px 0 2px;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--clue);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.col-clues span,
.row-clues span {
  display: block;
}

.cell {
  width: var(--cell-size, 28px);
  height: var(--cell-size, 28px);
  border: 1px solid var(--border);
  background: var(--cell);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  transition: background 0.08s ease;
  touch-action: manipulation;
}

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

.cell.filled {
  background: var(--fill);
  border-color: var(--fill-edge);
  box-shadow: inset 0 0 0 1px #000;
}

.cell.filled:hover {
  background: #1a1a1a;
}

.cell.marked::after {
  content: "×";
  color: var(--mark);
  font-size: calc(var(--cell-size, 28px) * 0.7);
  font-weight: 700;
  line-height: 1;
  pointer-events: none;
}

.cell.hint-flash {
  animation: hintPulse 0.6s ease;
}

@keyframes hintPulse {
  0%,
  100% {
    box-shadow: none;
  }
  50% {
    box-shadow: 0 0 0 3px var(--accent);
  }
}

.board.size-5 {
  --cell-size: 36px;
}

.board.size-10 {
  --cell-size: 28px;
}

.board.size-15 {
  --cell-size: 20px;
}

.board.size-15 .col-clues {
  font-size: 0.55rem;
  min-height: 3.2rem;
  gap: 0;
}

.board.size-15 .row-clues {
  font-size: 0.6rem;
  gap: 2px;
  padding-right: 4px;
}

.cell.grid-thick-left {
  border-left-width: 2px;
  border-left-color: #6e7681;
}

.cell.grid-thick-top {
  border-top-width: 2px;
  border-top-color: #6e7681;
}

.status-text {
  margin: 0;
  text-align: center;
  color: var(--muted);
  font-size: 0.9rem;
  min-height: 1.4em;
}

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

.result-overlay,
.help-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 20px;
}

.help-overlay {
  z-index: 300;
}

.result-box,
.help-modal {
  background: linear-gradient(145deg, #161b22, #21262d);
  border: 2px solid rgba(255, 255, 255, 0.15);
  border-radius: 16px;
  padding: 28px;
  max-width: 400px;
  width: 100%;
  color: var(--text);
}

.result-box h2 {
  color: var(--win);
  margin: 0 0 8px;
}

.result-box p {
  margin: 0;
  opacity: 0.9;
}

.result-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 16px;
}

.help-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.help-header h2 {
  margin: 0;
}

.help-close {
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.1);
  color: inherit;
  font-size: 1.4rem;
  cursor: pointer;
  line-height: 1;
}

.help-body {
  font-size: 0.95rem;
  line-height: 1.45;
}

.help-body p {
  margin: 0 0 12px;
}

.help-body ul {
  margin: 0;
  padding-left: 1.2rem;
}

.help-body li {
  margin-bottom: 8px;
}

@media (max-width: 520px) {
  .board.size-5 {
    --cell-size: 32px;
  }

  .board.size-10 {
    --cell-size: 24px;
  }

  .board.size-15 {
    --cell-size: 16px;
  }

  .board.size-15 .col-clues {
    font-size: 0.48rem;
    min-height: 2.8rem;
  }

  .board.size-15 .row-clues {
    font-size: 0.52rem;
  }

  .header-actions {
    width: 100%;
    margin-left: 0;
  }

  .btn {
    padding: 8px 12px;
    min-height: 40px;
    font-size: 0.85rem;
  }
}
