:root {
  --bg-top: #0d0b22;
  --bg-bottom: #2a1748;
  --horizon: #6b2f5c;
  --ink: #f3eefe;
  --muted: #a99fc9;
  --line: rgba(255, 255, 255, 0.09);
  --cell: rgba(255, 255, 255, 0.035);
  --cell-on: rgba(255, 197, 107, 0.09);
  --star: #ffd88a;
  --star-ink: #241536;
  --violet: #8b6cff;
  --amber: #ffc56b;
  --surface: rgba(24, 19, 52, 0.92);
  --radius: 14px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

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

body {
  background: linear-gradient(180deg, var(--bg-top) 0%, var(--bg-bottom) 75%, var(--horizon) 130%) fixed;
  background-color: var(--bg-top);
  color: var(--ink);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 100dvh;
  padding: env(safe-area-inset-top) 16px env(safe-area-inset-bottom);
  -webkit-tap-highlight-color: transparent;
}

.sky {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background-image:
    radial-gradient(1px 1px at 12% 18%, #fff8 50%, transparent 51%),
    radial-gradient(1px 1px at 72% 9%, #fff9 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 33% 42%, #fff6 50%, transparent 51%),
    radial-gradient(1px 1px at 88% 36%, #fff8 50%, transparent 51%),
    radial-gradient(1px 1px at 55% 24%, #fff5 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 6% 68%, #fff6 50%, transparent 51%),
    radial-gradient(1px 1px at 93% 74%, #fff7 50%, transparent 51%),
    radial-gradient(1px 1px at 46% 88%, #fff4 50%, transparent 51%);
  animation: twinkle 6s ease-in-out infinite alternate;
}

@keyframes twinkle { from { opacity: 0.55; } to { opacity: 1; } }

button {
  font: inherit;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 16px;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}
button:hover { background: rgba(255, 255, 255, 0.13); }
button:active { transform: scale(0.97); }
button:focus-visible, .board:focus-visible { outline: 2px solid var(--amber); outline-offset: 3px; }
button.primary {
  background: linear-gradient(135deg, var(--violet), #d0609a 60%, var(--amber));
  border-color: transparent;
  color: #fff;
  font-weight: 600;
}
button.wide { width: 100%; }

.top {
  width: 100%;
  max-width: 520px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 0 6px;
}
.brand { display: flex; align-items: center; gap: 10px; }
.logo { width: 34px; height: 34px; fill: var(--amber); filter: drop-shadow(0 0 8px #ffc56b99); }
h1, h2 { font-family: Fraunces, Georgia, serif; font-weight: 700; margin: 0; letter-spacing: 0.01em; }
h1 { font-size: 1.6rem; line-height: 1.1; }
h2 { font-size: 1.4rem; margin-bottom: 12px; }
.tagline { margin: 0; color: var(--muted); font-size: 0.82rem; }
.actions { display: flex; gap: 6px; }
button.icon {
  width: 38px; height: 38px; padding: 0;
  display: grid; place-items: center;
  font-weight: 700;
}
button.icon svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; }
button.lang { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.05em; }

main {
  width: 100%;
  max-width: 520px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  flex: 1;
}

.modes {
  display: flex;
  gap: 4px;
  padding: 4px;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 999px;
  align-self: center;
}
.modes button { border: 0; background: transparent; padding: 6px 16px; }
.modes.small { margin: 4px auto 10px; display: flex; width: fit-content; }
.modes.small button { padding: 4px 14px; font-size: 0.9rem; }
.modes button[aria-selected="true"] { background: rgba(255, 255, 255, 0.14); font-weight: 600; }

.meta {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  color: var(--muted);
  font-size: 0.92rem;
}
.timer { font-variant-numeric: tabular-nums; color: var(--ink); font-weight: 600; font-size: 1.05rem; }

.board-wrap {
  width: 100%;
  aspect-ratio: 1;
  border-radius: 22px;
  background: radial-gradient(circle at 50% 30%, rgba(139, 108, 255, 0.12), transparent 70%), rgba(10, 8, 28, 0.5);
  border: 1px solid var(--line);
  box-shadow: 0 30px 80px -30px rgba(0, 0, 0, 0.8), inset 0 0 40px rgba(139, 108, 255, 0.08);
  padding: 8px;
}
.board { width: 100%; height: 100%; position: relative; touch-action: none; user-select: none; -webkit-user-select: none; cursor: pointer; border-radius: 16px; }
.board-svg, .board-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.board-wrap:has(.board[data-renderer="3d"]) { background: transparent; border-color: transparent; box-shadow: none; padding: 0; }

.cell { fill: var(--cell); transition: fill 0.2s; }
.cell.on { fill: var(--cell-on); }
.dust { fill: #ffffff55; }
.dust.on { fill: #fff; }

.star circle { fill: rgba(255, 216, 138, 0.16); stroke: var(--star); stroke-width: 3; }
.star text { fill: var(--star); font: 700 34px Fraunces, Georgia, serif; text-anchor: middle; dominant-baseline: central; }
.star.lit circle { fill: var(--star); }
.star.lit text { fill: var(--star-ink); }
.star.next circle { animation: pulse 1.4s ease-in-out infinite; transform-box: fill-box; transform-origin: center; }
@keyframes pulse { 50% { stroke-width: 6; transform: scale(1.08); } }

.head { fill: #fff; }
.wall { stroke: #b6a4ff; stroke-width: 9; stroke-linecap: round; filter: drop-shadow(0 0 6px #8b6cff); }
.solved .cell.on { fill: rgba(255, 197, 107, 0.16); }

.progress { height: 4px; border-radius: 4px; background: rgba(255, 255, 255, 0.07); overflow: hidden; }
#progress-bar { height: 100%; width: 0; background: linear-gradient(90deg, var(--violet), #d0609a, var(--amber)); transition: width 0.15s; }

.controls { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; align-items: center; }
.sizes { display: flex; gap: 4px; }
.sizes button { padding: 6px 10px; font-size: 0.85rem; }
.sizes button[aria-pressed="true"] { background: rgba(255, 255, 255, 0.2); border-color: #ffffff44; }

body:not(.mode-practice) .practice-only,
body:not(.mode-daily) .daily-only { display: none !important; }
#btn-walls[aria-pressed="true"] { background: rgba(139, 108, 255, 0.35); border-color: #b6a4ff88; }

.notice { text-align: center; color: var(--amber); margin: 0; }

footer { color: var(--muted); font-size: 0.8rem; padding: 24px 0 16px; text-align: center; }

dialog {
  width: min(420px, calc(100vw - 32px));
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--surface);
  color: var(--ink);
  padding: 24px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6);
}
dialog::backdrop { background: rgba(5, 4, 15, 0.6); backdrop-filter: blur(3px); }
dialog form { margin: 0; }
.rules { padding-left: 1.2em; margin: 0 0 18px; display: grid; gap: 8px; color: #ddd5f5; }
.rules b { color: var(--amber); }

.tiles { display: flex; gap: 10px; margin-bottom: 14px; }
.tile {
  flex: 1;
  text-align: center;
  background: rgba(255, 255, 255, 0.05);
  border-radius: var(--radius);
  padding: 12px 6px;
  display: flex;
  flex-direction: column;
}
.tile strong { font: 700 1.6rem Fraunces, Georgia, serif; font-variant-numeric: tabular-nums; }
.tile span { color: var(--muted); font-size: 0.8rem; }
.global { color: #ddd5f5; margin: 0 0 14px; min-height: 1.5em; font-size: 0.92rem; }
.global:empty { display: none; }
.next { color: var(--muted); margin-bottom: 16px; font-size: 0.92rem; }
.next strong { color: var(--ink); font-variant-numeric: tabular-nums; }
.row { display: flex; gap: 8px; justify-content: flex-end; }
.row .primary { flex: 1; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 32px;
  transform: translate(-50%, 20px);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 10px 18px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

dialog { max-height: calc(100dvh - 32px); overflow-y: auto; }
h3 { font: 600 1rem Fraunces, Georgia, serif; margin: 14px 0 8px; }
.empty { color: var(--muted); text-align: center; padding: 12px 0; margin: 0; list-style: none; }

.nick-form { margin: 0 0 14px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 6px; font-size: 0.9rem; color: #ddd5f5; }
.nick-form[hidden] { display: none; }
.nick-row { display: flex; gap: 8px; min-width: 0; }
.nick-row button { flex-shrink: 0; }
.nick-row input {
  flex: 1;
  min-width: 0;
  font: inherit;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 14px;
}
.nick-row input:focus { outline: 2px solid var(--violet); outline-offset: 1px; }

.ranking { list-style: none; margin: 0 0 16px; padding: 0; display: grid; gap: 4px; min-height: 3em; }
.ranking li:not(.empty) {
  display: grid;
  grid-template-columns: 2em 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 8px 12px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.04);
}
.ranking li.me { background: rgba(255, 197, 107, 0.14); outline: 1px solid #ffc56b55; }
.ranking .rank { color: var(--muted); font-variant-numeric: tabular-nums; }
.ranking li:nth-child(-n + 3) .rank { color: var(--amber); font-weight: 700; }
.ranking .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ranking .score { font-variant-numeric: tabular-nums; color: #ddd5f5; font-size: 0.9rem; }

.archive { margin-bottom: 16px; }
.calendar { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.calendar .wd { text-align: center; color: var(--muted); font-size: 0.75rem; padding-bottom: 2px; }
.calendar button, .calendar .off {
  aspect-ratio: 1;
  padding: 0;
  border-radius: 10px;
  display: grid;
  place-items: center;
  font-size: 0.9rem;
  font-variant-numeric: tabular-nums;
}
.calendar .off { color: #ffffff2a; }
.calendar button.solved { background: rgba(255, 197, 107, 0.22); border-color: #ffc56b66; color: var(--amber); font-weight: 700; }

.setting { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.seg { display: flex; gap: 2px; padding: 3px; background: rgba(255, 255, 255, 0.05); border-radius: 999px; }
.seg button { border: 0; background: transparent; padding: 6px 14px; font-size: 0.9rem; }
.seg button[aria-pressed="true"] { background: rgba(255, 255, 255, 0.16); font-weight: 600; }
.seg button:disabled { opacity: 0.35; cursor: not-allowed; }

@media (prefers-reduced-motion: reduce) {
  *, .sky { animation: none !important; transition: none !important; }
}
