:root {
  --bg: #121418;
  --surface: #1c1f25;
  --surface-2: #252931;
  --line: #30353f;
  --text: #eceef2;
  --muted: #9aa1ad;
  --accent: #ff7a3d;
  --accent-ink: #1a0d05;
  --flash: #f5c518;
  --top: #2fb35a;
  --project: #8a8f98;
  --danger: #e0413a;
  --radius: 14px;
  --tabbar-h: 60px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}
a { color: inherit; text-decoration: none; }

.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: rgba(18, 20, 24, .92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 800; letter-spacing: -.02em; }
.brand::before { content: ""; display: inline-block; width: 10px; height: 10px; border-radius: 3px; background: var(--accent); margin-right: 8px; transform: rotate(45deg); }

main { max-width: 720px; margin: 0 auto; padding: 12px 16px calc(var(--tabbar-h) + 24px + env(safe-area-inset-bottom)); }
h1 { font-size: 26px; margin: 8px 0 4px; letter-spacing: -.02em; }
h2 { font-size: 17px; margin: 0 0 10px; }
h3 { font-size: 14px; margin: 18px 0 8px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.muted { color: var(--muted); font-size: 14px; }
.crumbs { color: var(--muted); font-size: 14px; }
.crumbs a { text-decoration: underline; text-underline-offset: 3px; }
.empty { color: var(--muted); text-align: center; padding: 20px 8px; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin: 12px 0; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.chev { color: var(--muted); font-size: 22px; }
.list > .card { margin: 8px 0; }

.form { display: grid; gap: 10px; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
input, select, textarea, button, .btn {
  font: inherit; color: inherit; width: 100%;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px;
  padding: 11px 12px; min-height: 44px;
}
textarea { min-height: 70px; resize: vertical; }
label.field { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
button, .btn { background: var(--accent); color: var(--accent-ink); border: none; font-weight: 700; cursor: pointer; text-align: center; }
button:disabled { opacity: .5; }
button.ghost, .btn.ghost { background: var(--surface-2); color: var(--text); border: 1px solid var(--line); font-weight: 600; }
button.danger { background: transparent; color: var(--danger); border: 1px solid var(--line); font-weight: 600; }
button.small { width: auto; min-height: 34px; padding: 6px 12px; font-size: 14px; }
.btns { display: flex; gap: 8px; flex-wrap: wrap; }
.btns > * { flex: 1; }

/* area tiles */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin: 12px 0; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; display: grid; gap: 6px; }
.tile strong { font-size: 18px; }
.bar { height: 6px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--top); }

/* boulder rows */
.boulders { display: grid; gap: 6px; }
.brow { display: flex; align-items: center; gap: 10px; padding: 10px 12px; background: var(--surface-2); border-radius: 10px; }
.dot { display: inline-block; vertical-align: middle; width: 18px; height: 18px; border-radius: 50%; flex: none; border: 2px solid rgba(255,255,255,.25); }
.dot.big { width: 28px; height: 28px; }
.grade { font-weight: 800; min-width: 38px; }
.bname { flex: 1; color: var(--muted); font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge { font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 99px; }
.badge.flash { background: var(--flash); color: #241c00; }
.badge.top { background: var(--top); color: #03200c; }
.badge.project { background: var(--surface); color: var(--muted); border: 1px solid var(--line); }
.vid { width: 18px; height: 18px; color: var(--accent); flex: none; }

/* set history */
details.set { padding: 0; }
details.set > summary { list-style: none; cursor: pointer; padding: 14px; display: flex; justify-content: space-between; align-items: center; gap: 10px; }
details.set > summary::-webkit-details-marker { display: none; }
details.set > summary::after { content: "›"; color: var(--muted); font-size: 22px; transition: transform .15s; }
details.set[open] > summary::after { transform: rotate(90deg); }
details.set > .boulders { padding: 0 14px 14px; }
.timeline { border-left: 2px solid var(--line); margin-left: 6px; padding-left: 14px; }
.toggle { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--muted); }
.toggle input { width: 20px; min-height: 20px; height: 20px; accent-color: var(--accent); }

/* boulder page */
.hero { display: flex; align-items: center; gap: 12px; }
.hero h1 { margin: 0; }
.photo { width: 100%; border-radius: var(--radius); display: block; margin-top: 12px; max-height: 420px; object-fit: cover; }
video { width: 100%; border-radius: 10px; background: #000; margin-top: 10px; max-height: 70vh; }
.status-pick { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.status-pick input { display: none; }
.status-pick span { display: block; text-align: center; padding: 10px; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--line); font-weight: 600; cursor: pointer; }
.status-pick input:checked + span { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

/* progress */
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.stat b { display: block; font-size: 26px; letter-spacing: -.02em; }
.stat span { color: var(--muted); font-size: 13px; }
.chart { width: 100%; height: auto; display: block; }
.chart text { fill: var(--muted); font-size: 11px; }
.pyr { display: grid; grid-template-columns: 40px 1fr 28px; gap: 6px 8px; align-items: center; font-size: 14px; }
.pyr .track { height: 16px; display: flex; border-radius: 4px; overflow: hidden; background: var(--surface-2); }
.pyr .track i { display: block; height: 100%; }
.legend { display: flex; gap: 14px; font-size: 13px; color: var(--muted); margin-top: 8px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; }
.vgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.vcard { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.vcard video { margin: 0; border-radius: 0; aspect-ratio: 9 / 12; object-fit: cover; }
.vcard > div { padding: 8px 10px; font-size: 13px; }

@media (min-width: 560px) { .stats { grid-template-columns: repeat(4, 1fr); } }

/* TopLogger floor plan */
.floor { padding: 6px; background: #0d0f12; overflow: hidden; }
.floor svg { display: block; width: 100%; height: auto; max-height: 75vh; aspect-ratio: auto; }
.small-floor svg { max-height: 300px; }
.floor .plan { filter: invert(.88) hue-rotate(180deg) saturate(.6); }
.floor .region { cursor: pointer; }
.floor .region * { pointer-events: all; }
.floor .region:hover, .floor .region.focus { filter: brightness(.75) sepia(1) hue-rotate(-30deg) saturate(3); }
.floor .wall-label { fill: #fff; font-weight: 700; paint-order: stroke; stroke: rgba(0,0,0,.75); stroke-width: 8px; pointer-events: auto; }
.floor circle { cursor: pointer; }
.floor .pulse { animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .55; } }
.gym-icon { width: 36px; height: 36px; border-radius: 8px; object-fit: cover; background: #fff; flex: none; }
.link { text-decoration: underline; text-underline-offset: 3px; }
.tl-link { display: block; margin-top: 12px; text-align: center; }
.set-date { margin: 12px 0 6px; font-size: 13px; }
.toast { position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: var(--surface-2); border: 1px solid var(--line); padding: 10px 16px; border-radius: 999px; font-size: 14px; z-index: 20; box-shadow: 0 6px 20px rgba(0,0,0,.4); }
details.card > summary { cursor: pointer; }

/* interactive floor plan */
.floor.tlmap { position: relative; padding: 0; height: min(60vh, 640px); touch-action: none; user-select: none; -webkit-user-select: none; }
.floor.tlmap.small-floor { height: 260px; }
.tlmap svg { width: 100%; height: 100%; max-height: none; cursor: grab; }
.tlmap svg:active { cursor: grabbing; }
.tlmap .wall-label { pointer-events: auto; cursor: pointer; }
.tlmap circle { transition: r .12s; }
.tlmap circle.sel { filter: drop-shadow(0 0 6px rgba(255, 122, 61, .9)); }
.map-ctrl { position: absolute; right: 10px; top: 10px; display: grid; gap: 6px; }
.map-ctrl button { width: 38px; min-height: 38px; height: 38px; padding: 0; border-radius: 10px; font-size: 20px; line-height: 1;
  background: rgba(37, 41, 49, .92); color: var(--text); border: 1px solid var(--line); font-weight: 600; }
.map-foot { font-size: 13px; }

/* bottom sheet */
.sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 15; max-width: 720px; margin: 0 auto; max-height: 44vh; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--line); border-bottom: none; border-radius: 18px 18px 0 0;
  padding: 18px 16px calc(16px + env(safe-area-inset-bottom)); box-shadow: 0 -10px 30px rgba(0,0,0,.45); animation: sheet-up .22s ease-out; }
.sheet[hidden] { display: none; }
.sheet::before { content: ""; position: absolute; top: 7px; left: 50%; width: 38px; height: 4px; margin-left: -19px; border-radius: 4px; background: var(--line); }
.sheet-x { position: absolute; top: 10px; right: 10px; width: 34px; min-height: 34px; height: 34px; padding: 0; border-radius: 50%;
  background: var(--surface-2); color: var(--text); border: 1px solid var(--line); font-size: 20px; line-height: 1; }
@keyframes sheet-up { from { transform: translateY(100%); } to { transform: none; } }

/* home gym */
.title-row { justify-content: flex-start; gap: 8px; }
.star { width: 40px; min-height: 40px; height: 40px; padding: 0; font-size: 24px; line-height: 1; background: transparent; color: var(--muted); border: none; }
.star.on { color: var(--flash); }
.home-tag { font-size: 12px; color: var(--flash); font-weight: 700; margin-left: 4px; }
.hint { color: var(--muted); font-size: 14px; }

/* NEW tag + video */
.new { font-size: 10px; font-weight: 800; letter-spacing: .04em; padding: 2px 6px; border-radius: 6px; background: var(--accent); color: var(--accent-ink); vertical-align: middle; }
.quickvid { margin-top: 12px; }
.video-btn { display: flex; align-items: center; justify-content: center; gap: 8px; }
.video-btn .vid { color: var(--accent-ink); width: 20px; height: 20px; }
.va { display: grid; gap: 10px; margin-top: 10px; }
.va:empty { display: none; }
.status-pick.four { grid-template-columns: repeat(4, 1fr); }
.status-pick.four span { padding: 10px 4px; font-size: 14px; }

/* alerts */
.toggle.big { font-size: 15px; color: var(--text); }
.steps { margin: 0; padding-left: 20px; display: grid; gap: 6px; font-size: 14px; }
code.topic { display: inline-block; margin-top: 4px; padding: 4px 8px; border-radius: 6px; background: var(--surface-2); border: 1px solid var(--line); user-select: all; -webkit-user-select: all; word-break: break-all; }

/* time machine */
.tm { display: grid; gap: 10px; }
.tm-row { display: flex; align-items: center; gap: 8px; }
.tm-row input[type=range] { flex: 1; min-height: 36px; padding: 0; background: none; border: none; accent-color: var(--accent); }
.tm-row .tm-step { width: 40px; flex: none; }
.floor.past { outline: 2px solid var(--accent); outline-offset: -2px; }
.floor.past::before { content: attr(data-date); position: absolute; left: 10px; top: 10px; z-index: 2; pointer-events: none;
  background: var(--accent); color: var(--accent-ink); font-weight: 800; font-size: 13px; padding: 4px 10px; border-radius: 99px; }
.sheet-video { margin-top: 10px; max-height: 32vh; }

/* ---------- polish (v5) ---------- */
.topbar { justify-content: center; padding-top: calc(8px + env(safe-area-inset-top)); padding-bottom: 8px; }
.brand { font-size: 15px; }

/* bottom tab bar */
.tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 12; display: grid; grid-template-columns: repeat(4, 1fr);
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); padding: 6px 4px env(safe-area-inset-bottom);
  background: rgba(18, 20, 24, .94); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); border-top: 1px solid var(--line); }
.tabbar a { display: grid; justify-items: center; align-content: center; gap: 3px; font-size: 11px; font-weight: 600; color: var(--muted); border-radius: 12px; }
.tabbar svg { width: 24px; height: 24px; }
.tabbar a.on { color: var(--accent); }
.tabbar a:active { background: var(--surface); }
.sheet { bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); max-height: 46vh; }
.toast { bottom: calc(var(--tabbar-h) + 16px + env(safe-area-inset-bottom)); }

/* gym page */
.gym-head { display: flex; align-items: center; gap: 12px; margin: 2px 0 12px; }
.gym-head .grow { flex: 1; min-width: 0; }
.gym-head h1 { margin: 0; font-size: 22px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.gym-head .gym-icon { width: 44px; height: 44px; border-radius: 12px; }
.gym-head .meta { font-size: 13px; }
.sync-btn { display: inline-grid; place-items: center; width: 24px; min-height: 24px; height: 24px; padding: 0; border-radius: 50%;
  background: var(--surface-2); color: var(--accent); border: 1px solid var(--line); font-size: 14px; vertical-align: middle; }
.sync-btn.spin { animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 3px; padding: 3px; margin-bottom: 10px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; }
.seg button { background: transparent; color: var(--muted); min-height: 36px; padding: 6px; border-radius: 9px; font-weight: 600; font-size: 15px; }
.seg button.on { background: var(--surface-2); color: var(--text); box-shadow: 0 1px 4px rgba(0,0,0,.3); }
.floor.tlmap.main { margin-top: 0; height: max(380px, calc(100dvh - 300px)); }
#tab-map .legend { margin: 6px 2px 0; flex-wrap: wrap; }
#tab-map .tm { margin-top: 10px; }
.gym-actions { margin-top: 14px; }
.gym-actions .btn { display: grid; place-items: center; }

/* boulder page */
.boulder-head { margin: 4px 0 10px; }
.boulder-head .muted { margin-top: 4px; }
.media-btn { display: flex; align-items: center; justify-content: center; gap: 8px; }
.media-btn svg { width: 20px; height: 20px; }
.composer { display: grid; gap: 10px; margin-top: 10px; }
.composer[hidden] { display: none; }
.mc-preview:empty { display: none; }
.mc-preview { display: grid; gap: 4px; justify-items: start; }
.mc-preview .photo, .mc-preview video { margin-top: 0; }
.link-btn { width: auto; min-height: 0; padding: 4px 0; background: none; border: none; color: var(--muted); text-decoration: underline; font-weight: 500; font-size: 14px; }
.entries { display: grid; gap: 8px; }
.entries .entry { margin: 0; }
.entry .photo { margin-top: 10px; max-height: 70vh; object-fit: contain; background: #000; }
.icon-btn { width: 32px; min-height: 32px; height: 32px; padding: 0; border-radius: 50%; background: var(--surface-2); color: var(--muted);
  border: 1px solid var(--line); font-size: 18px; line-height: 1; flex: none; }
.sheet .photo { margin-top: 10px; max-height: 32vh; object-fit: cover; }
.vcard img { display: block; width: 100%; aspect-ratio: 9 / 12; object-fit: cover; background: #000; }

/* settings */
.about { text-align: center; font-size: 12px; margin: 18px 8px; }
.gym-head .meta { white-space: nowrap; }
