:root {
  --bg: #1a1017;
  --bg-2: #241720;
  --card: #2c1d27;
  --line: rgba(246, 234, 217, 0.12);
  --text: #f6ead9;
  --muted: #b8a39e;
  --gold: #f2b56b;
  --gold-2: #ffd9a0;
  --late: #ef8a7c;
  --ok: #9fd3a6;
  --fog: 26, 16, 23;
  --tabs-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --serif: 'Cormorant Garamond', Georgia, serif;
  --sans: 'Manrope', system-ui, -apple-system, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 var(--sans);
  overflow: hidden;
  overscroll-behavior: none;
}
button { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* ---------- header ---------- */
.top {
  position: fixed; inset: 0 0 auto 0; z-index: 1000;
  padding: calc(var(--safe-t) + 10px) 16px 10px;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: linear-gradient(var(--bg) 40%, rgba(26, 16, 23, 0));
  pointer-events: none;
}
.brand {
  font: 600 22px/1 var(--serif); letter-spacing: .01em;
  display: flex; align-items: center; gap: 8px;
  text-shadow: 0 1px 12px rgba(0,0,0,.6);
}
.star { color: var(--gold); font-size: 16px; }
.pace {
  pointer-events: auto;
  font-size: 13px; font-weight: 600; white-space: nowrap;
  padding: 6px 11px; border-radius: 999px;
  background: rgba(44, 29, 39, .92); border: 1px solid var(--line);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  font-variant-numeric: tabular-nums;
}
.pace.late { color: #2a1414; background: var(--late); border-color: transparent; }

/* ---------- views ---------- */
main { position: fixed; inset: 0 0 calc(var(--tabs-h) + var(--safe-b)) 0; }
.view { position: absolute; inset: 0; display: none; }
.view.active { display: block; }
.scroll {
  height: 100%; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: calc(var(--safe-t) + 64px) 16px 32px;
  max-width: 560px; margin: 0 auto;
}
.h { font: 600 34px/1.1 var(--serif); margin: 0 0 6px; }
.h.small { font-size: 26px; margin-top: 36px; }
.muted { color: var(--muted); margin: 0 0 18px; font-size: 14px; }
.hint { color: var(--muted); font-size: 13px; margin: 14px 2px 20px; }

/* ---------- map ---------- */
#map { position: absolute; inset: 0; background: #120b10; }
.leaflet-container { font-family: var(--sans); background: #120b10; }
.leaflet-tile-pane { filter: invert(.93) hue-rotate(190deg) sepia(.5) saturate(1.3) brightness(.92) contrast(.92); }
.leaflet-control-attribution {
  background: rgba(26,16,23,.7) !important; color: var(--muted) !important; font-size: 9px;
}
.leaflet-control-attribution a { color: var(--muted) !important; }
.leaflet-control-zoom { display: none; }
.fog-canvas { pointer-events: none; }

.pin { position: relative; width: 34px; height: 34px; }
.pin .dot {
  position: absolute; inset: 0; border-radius: 50%;
  display: grid; place-items: center;
  font: 700 13px/1 var(--sans);
  background: var(--card); color: var(--text);
  border: 2px solid rgba(246,234,217,.55);
  box-shadow: 0 3px 10px rgba(0,0,0,.5);
}
.pin.small { width: 26px; height: 26px; }
.pin.small .dot { font-size: 12px; }
.pin.done .dot { background: var(--gold); color: #3a2310; border-color: var(--gold-2); }
.pin.current .dot { background: var(--gold-2); color: #3a2310; border-color: #fff4e0; }
.pin.current::before {
  content: ''; position: absolute; inset: -14px; border-radius: 50%;
  background: radial-gradient(circle, rgba(255,217,160,.55), rgba(255,217,160,0) 70%);
  animation: glow 2.2s ease-in-out infinite;
}
.pin.known .dot { border-style: dashed; border-color: var(--gold); color: var(--gold); }
.pin.hard .dot::after {
  content: ''; position: absolute; top: -3px; right: -3px; width: 9px; height: 9px;
  border-radius: 50%; background: var(--late); border: 2px solid var(--bg);
}
.pin svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
@keyframes glow { 50% { transform: scale(1.25); opacity: .55; } }

.now-card {
  position: absolute; left: 12px; right: 12px; bottom: 12px; z-index: 900;
  display: flex; align-items: center; gap: 14px; text-align: left;
  padding: 14px 16px; border-radius: 18px; cursor: pointer;
  background: rgba(44, 29, 39, .94); border: 1px solid var(--line);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  box-shadow: 0 10px 30px rgba(0,0,0,.45);
  max-width: 540px; margin: 0 auto;
}
.now-card .num {
  flex: none; width: 44px; height: 44px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--gold-2); color: #3a2310; font-weight: 700;
}
.now-card .meta { font-size: 12px; color: var(--muted); letter-spacing: .04em; text-transform: uppercase; }
.now-card .meta .hard-tag { color: var(--late); }
.now-card .title { font: 600 21px/1.15 var(--serif); margin-top: 2px; }
.now-card .count { font-size: 13px; color: var(--gold); margin-top: 3px; font-variant-numeric: tabular-nums; }
.now-card .go { margin-left: auto; color: var(--gold); font-size: 22px; }

/* ---------- tabs ---------- */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 1000;
  height: calc(var(--tabs-h) + var(--safe-b)); padding-bottom: var(--safe-b);
  display: flex; background: var(--bg-2); border-top: 1px solid var(--line);
}
.tabs button {
  flex: 1; border: 0; background: none; cursor: pointer; position: relative;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  font-size: 12px; font-weight: 600; color: var(--muted);
}
.tabs button.active { color: var(--gold); }
.tabs svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linejoin: round; stroke-linecap: round; }
.badge {
  position: absolute; top: 8px; left: calc(50% + 6px);
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  background: var(--gold); color: #3a2310; font-size: 11px; line-height: 18px; text-align: center;
}
.badge:empty { display: none; }

/* ---------- sheet ---------- */
.sheet-backdrop { position: fixed; inset: 0; z-index: 1100; background: rgba(10,5,9,.55); }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 1200;
  max-height: calc(100% - var(--safe-t) - 40px); overflow-y: auto;
  background: var(--card); border-radius: 22px 22px 0 0; border-top: 1px solid var(--line);
  padding: 10px 20px calc(24px + var(--safe-b));
  max-width: 600px; margin: 0 auto;
  animation: up .28s cubic-bezier(.2,.8,.2,1);
}
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
.grab { width: 40px; height: 4px; border-radius: 2px; background: var(--line); margin: 0 auto 8px; }
.x {
  position: absolute; top: 10px; right: 12px; width: 36px; height: 36px; border-radius: 50%;
  border: 0; background: rgba(246,234,217,.08); font-size: 22px; line-height: 1; cursor: pointer;
}
.sheet .meta { font-size: 12px; color: var(--muted); letter-spacing: .05em; text-transform: uppercase; margin-top: 6px; padding-right: 40px; }
.sheet .meta .hard-tag { color: var(--late); }
.sheet h2 { font: 600 30px/1.1 var(--serif); margin: 6px 0 2px; padding-right: 30px; }
.sheet .sub { color: var(--muted); font-size: 14px; margin: 0 0 6px; }
.sheet .body { margin: 14px 0 0; }
.sheet .body p { margin: 0 0 10px; }
.sheet .body ol { margin: 0 0 10px; padding-left: 20px; }
.sheet .body li { margin-bottom: 6px; }
.sheet .body b { color: var(--gold-2); font-weight: 600; }
.sheet .countline { font-size: 14px; color: var(--gold); margin-top: 6px; font-variant-numeric: tabular-nums; }
.sheet .countline.late { color: var(--late); }

.task {
  margin-top: 18px; padding: 16px; border-radius: 16px;
  background: rgba(242,181,107,.08); border: 1px solid rgba(242,181,107,.25);
}
.task .label { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--gold); font-weight: 700; }
.task .what { font: 600 22px/1.2 var(--serif); margin: 4px 0 12px; }
.task .pieces { font-size: 13px; color: var(--muted); margin: 10px 0 0; }
.task img.result { width: 100%; border-radius: 12px; display: block; margin-top: 4px; }
.task input[type=text] {
  width: 100%; padding: 13px 14px; border-radius: 12px; margin-bottom: 10px;
  border: 1px solid var(--line); background: rgba(0,0,0,.25); color: var(--text); font: inherit;
}
.note-was { margin-top: 12px; padding: 12px 14px; border-radius: 12px; background: rgba(246,234,217,.06); font-size: 15px; }

.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; padding: 15px 18px; border-radius: 14px; border: 0; cursor: pointer;
  font-weight: 700; font-size: 16px;
  background: rgba(246,234,217,.1); color: var(--text);
}
.btn-gold { background: linear-gradient(135deg, var(--gold-2), var(--gold)); color: #3a2310; box-shadow: 0 6px 20px rgba(242,181,107,.25); }
.btn + .btn, .btn + .link { margin-top: 10px; }
.btn[disabled] { opacity: .5; }
.link {
  display: block; width: 100%; background: none; border: 0; padding: 8px; cursor: pointer;
  color: var(--muted); font-size: 14px; text-decoration: underline; text-underline-offset: 3px;
}
.done-tag { display: inline-flex; align-items: center; gap: 6px; color: var(--ok); font-weight: 600; font-size: 14px; margin-top: 10px; }

/* ---------- puzzle ---------- */
.board {
  display: grid; grid-template-columns: repeat(6, 1fr); gap: 3px;
  aspect-ratio: 1; width: 100%; max-width: 480px; margin: 0 auto;
  padding: 3px; border-radius: 14px; background: rgba(0,0,0,.3); border: 1px solid var(--line);
  transition: gap .6s, padding .6s;
}
.cell {
  border: 0; padding: 0; border-radius: 4px; cursor: pointer; position: relative;
  background: rgba(246,234,217,.04);
  background-size: 600% 600%; background-repeat: no-repeat;
  transition: transform .15s, border-radius .4s, box-shadow .15s;
}
.cell.empty { background-image: none !important; }
.cell.empty::after {
  content: ''; position: absolute; inset: 35%; border-radius: 50%; border: 1px dashed rgba(246,234,217,.15);
}
.cell.piece { box-shadow: inset 0 0 0 1px rgba(255,255,255,.18), 0 2px 5px rgba(0,0,0,.4); }
.cell.right { border-radius: 0; box-shadow: none; }
.cell.sel { transform: scale(.88); box-shadow: 0 0 0 3px var(--gold-2), 0 0 18px rgba(255,217,160,.6); z-index: 2; }
.board.solved { gap: 0; padding: 0; overflow: hidden; }
.board.solved .cell { border-radius: 0; }

/* ---------- album ---------- */
.album { display: grid; gap: 18px; }
.shot { margin: 0; }
.shot img { width: 100%; display: block; border-radius: 14px; background: var(--card); cursor: zoom-in; }
.shot figcaption { display: flex; justify-content: space-between; gap: 10px; font-size: 13px; color: var(--muted); margin-top: 7px; }
.shot figcaption b { color: var(--text); font-weight: 600; }
.song-card {
  padding: 18px; border-radius: 14px; background: var(--card); border: 1px solid var(--line);
  font: italic 500 24px/1.2 var(--serif);
}
.song-card small { display: block; font: 600 12px var(--sans); letter-spacing: .06em; text-transform: uppercase; color: var(--gold); margin-bottom: 6px; font-style: normal; }
.empty-state { color: var(--muted); text-align: center; padding: 40px 10px; font-family: var(--serif); font-size: 22px; }

/* ---------- finale ---------- */
.letter {
  font: 500 21px/1.55 var(--serif); white-space: pre-wrap;
  padding: 26px 22px; border-radius: 18px;
  background: linear-gradient(180deg, #f7ecdc, #efdcc2); color: #3b2618;
  box-shadow: 0 20px 50px rgba(0,0,0,.45);
}
.collage { columns: 2; column-gap: 8px; }
.collage img { width: 100%; display: block; margin-bottom: 8px; border-radius: 10px; break-inside: avoid; cursor: zoom-in; }
.collage img:nth-child(3n+1) { transform: rotate(-1deg); }
.collage img:nth-child(3n+2) { transform: rotate(1.2deg); }

/* ---------- toast / lightbox / preview ---------- */
.toast {
  position: fixed; left: 50%; top: calc(var(--safe-t) + 60px); transform: translateX(-50%); z-index: 1500;
  padding: 12px 18px; border-radius: 14px; max-width: calc(100% - 32px);
  background: var(--gold-2); color: #3a2310; font-weight: 700; text-align: center;
  box-shadow: 0 10px 30px rgba(0,0,0,.4);
  animation: drop .35s cubic-bezier(.2,.8,.2,1);
}
@keyframes drop { from { transform: translate(-50%, -20px); opacity: 0; } }
.lightbox { position: fixed; inset: 0; z-index: 1600; background: rgba(8,4,7,.94); display: grid; place-items: center; padding: 16px; }
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 10px; }
.preview-bar {
  position: fixed; z-index: 1300; left: 8px; right: 8px; top: calc(var(--safe-t) + 52px);
  display: flex; gap: 6px; align-items: center; flex-wrap: wrap;
  padding: 6px 8px; border-radius: 12px; font-size: 12px;
  background: rgba(239,138,124,.92); color: #2a1414; font-weight: 700;
}
.preview-bar span { margin-right: auto; }
.preview-bar button { border: 0; border-radius: 8px; padding: 6px 9px; background: rgba(255,255,255,.55); font-size: 12px; font-weight: 700; cursor: pointer; }
.has-preview .scroll { padding-top: calc(var(--safe-t) + 100px); }
.vh { position: absolute; width: 1px; height: 1px; opacity: 0; overflow: hidden; pointer-events: none; }
label.btn, label.link { position: relative; text-align: center; }
.pin.mystery .dot {
  background: rgba(44,29,39,.85); color: var(--gold);
  border: 2px dashed rgba(242,181,107,.7);
  font: 600 20px/1 var(--serif);
}
.ticket {
  margin-top: 22px; padding: 22px; border-radius: 18px; position: relative;
  background: linear-gradient(135deg, #3a2232, #2a1a26);
  border: 1px dashed rgba(242,181,107,.55);
}
.ticket:empty { display: none; }
.ticket-kicker { font-size: 12px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--gold); }
.ticket-place { font: 600 30px/1.1 var(--serif); margin: 6px 0 8px; color: var(--gold-2); }
.ticket p { margin: 0 0 14px; color: var(--muted); font-size: 15px; }
.ticket dl { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; margin: 0 0 16px; font-size: 15px; }
.ticket dt { color: var(--muted); }
.ticket dd { margin: 0; font-weight: 600; }
.ticket-links { display: flex; gap: 10px; }
.ticket-links a {
  flex: 1; text-align: center; padding: 11px; border-radius: 12px; text-decoration: none;
  background: rgba(242,181,107,.14); color: var(--gold-2); font-weight: 700; font-size: 14px;
}
