:root {
  --bg: #1b1410; --panel: #261b15; --ink: #f1e6da; --muted: #b8a595; --line: #4a382c;
  --accent: #e0683a; --ok: #6cc08b; --warn: #f0b34a; --bad: #e5534b; --route: #5cc8ff;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); font: 15px/1.45 system-ui, sans-serif; }
body { display: flex; flex-direction: column; padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); }
[hidden] { display: none !important; }
button, select { font: inherit; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); color: var(--ink); padding: 7px 11px; cursor: pointer; }
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: .45; cursor: not-allowed; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button[aria-pressed="true"]:not(.primary) { border-color: var(--accent); }
kbd { font: 11px ui-monospace, monospace; border: 1px solid var(--line); border-radius: 4px; padding: 0 4px; color: var(--muted); }
.stars { color: var(--warn); letter-spacing: 1px; }
.stars .off { color: var(--line); }

#topbar { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; justify-content: space-between; padding: 8px 14px; border-bottom: 1px solid var(--line); }
#brand { border: 0; background: none; font-size: 18px; font-weight: 700; display: flex; align-items: center; gap: 8px; padding: 4px; }
.logo { width: 20px; height: 20px; border-radius: 50%; background: radial-gradient(circle at 35% 35%, #b94d27 0 22%, transparent 24%), var(--accent); }
#topnav { display: flex; gap: 6px; flex-wrap: wrap; }

/* picker */
#picker { flex: 1; min-height: 0; display: grid; grid-template-columns: 1fr minmax(320px, 420px); }
#globe-wrap { position: relative; min-height: 340px; background: radial-gradient(circle at 50% 40%, #2c1d15, #0c0806 70%); }
#globe { position: absolute; inset: 0; }
#globe-tip { position: fixed; z-index: 5; pointer-events: none; background: rgba(0,0,0,.8); color: #fff; font-size: 12px; padding: 3px 8px; border-radius: 6px; transform: translate(10px, -26px); }
#globe-hint { position: absolute; left: 12px; bottom: 6px; margin: 0; font-size: 12px; color: var(--muted); pointer-events: none; }
#sites { overflow: auto; padding: 12px; border-left: 1px solid var(--line); background: var(--panel); display: flex; flex-direction: column; gap: 12px; }
#daily-card { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; display: flex; gap: 10px; align-items: center; justify-content: space-between; background: var(--bg); }
#daily-card b { color: var(--accent); }
#daily-card small { color: var(--muted); display: block; }
#site-detail { border: 1px solid var(--accent); border-radius: 10px; padding: 10px 12px; background: var(--bg); }
#site-detail:empty { display: none; }
#site-detail h2 { margin: 0 0 4px; font-size: 17px; }
#site-detail p { margin: 4px 0 8px; color: var(--muted); font-size: 13px; }
#site-detail img { width: 100%; height: 150px; object-fit: cover; border-radius: 8px; display: block; margin-bottom: 8px; }
#filters { display: flex; flex-wrap: wrap; gap: 6px; }
#filters button { padding: 4px 10px; font-size: 12px; }
#site-list { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
#site-list button { width: 100%; text-align: left; padding: 0; overflow: hidden; display: block; }
#site-list button[aria-current="true"] { border-color: var(--accent); }
#site-list img { width: 100%; height: 84px; object-fit: cover; display: block; background: #000; }
.card-body { padding: 6px 8px 8px; font-size: 13px; line-height: 1.3; }
.card-body small { color: var(--muted); display: block; }

/* ranking */
#ranking { flex: 1; min-height: 0; display: grid; grid-template-columns: 1fr minmax(320px, 400px); }
#board-panel { padding: 14px 16px; overflow: auto; display: flex; flex-direction: column; gap: 10px; }
#board-panel label { color: var(--muted); font-size: 13px; }
#board-you { color: var(--muted); font-size: 14px; }
#board-you b { color: var(--ink); }
#board-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
#board-list li { display: grid; grid-template-columns: 2.6em 1fr auto auto; gap: 10px; align-items: center; padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); }
#board-list li.me { border-color: var(--accent); }
#board-list .rank { font-weight: 700; color: var(--muted); text-align: right; }
#board-list li:nth-child(-n+3) .rank { color: var(--warn); }
#board-list .who small { color: var(--muted); margin-left: 6px; }
#board-list .score { font-variant-numeric: tabular-nums; font-weight: 600; }
#board-list button { padding: 3px 8px; font-size: 12px; }
#profile-panel { padding: 14px 16px; border-left: 1px solid var(--line); background: var(--panel); overflow: auto; display: grid; gap: 12px; align-content: start; }
#profile-panel h2 { margin: 0; font-size: 17px; } #profile-panel h3 { margin: 4px 0 0; font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
#profile-panel small, .muted { color: var(--muted); }
.meter { height: 8px; border-radius: 4px; background: var(--bg); border: 1px solid var(--line); overflow: hidden; }
.meter > div { height: 100%; background: var(--accent); }
.badges { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 6px; }
.badge { border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; font-size: 12px; opacity: .45; }
.badge.earned { opacity: 1; border-color: var(--warn); }
.badge b { display: block; font-size: 13px; }
.field { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.field input[type="text"], .field input[type="password"], .field input[type="number"], .field select { flex: 1; min-width: 8em; background: var(--bg); color: var(--ink); border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; font: inherit; }
.danger { border-color: var(--bad); color: var(--bad); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.chip { border: 1px solid var(--warn); color: var(--warn); border-radius: 999px; padding: 2px 10px; font-size: 12px; }

/* play */
#play { flex: 1; min-height: 0; display: grid; grid-template-columns: 1fr 340px; }
#stage { position: relative; min-height: 0; overflow: hidden; background: #000; touch-action: none; }
#map2d { width: 100%; height: 100%; display: block; cursor: crosshair; }
#view3d { position: absolute; inset: 0; }
#readout, #legend, #view-options { position: absolute; background: rgba(0,0,0,.66); color: #fff; font-size: 12px; padding: 4px 8px; border-radius: 6px; }
#readout { top: 8px; left: 8px; pointer-events: none; }
#readout:empty { display: none; }
#view-options { top: 8px; right: 8px; display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center; max-width: 70%; justify-content: flex-end; }
#view-options select, #view-options button { padding: 2px 6px; font-size: 12px; }
#view-options label { white-space: nowrap; }
.seg { display: flex; }
.seg button { border-radius: 0; } .seg button:first-child { border-radius: 6px 0 0 6px; } .seg button:last-child { border-radius: 0 6px 6px 0; }
#opt-toggle { display: none; }
#view-options.collapsed > :not(.seg):not(#opt-toggle) { display: none; }
#legend { bottom: 8px; left: 8px; display: flex; gap: 12px; pointer-events: none; }
.sw { display: inline-block; width: 10px; height: 10px; margin-right: 5px; border-radius: 2px; }
.sw.steep { background: rgba(240,179,74,.8); } .sw.blocked { background: rgba(229,83,75,.9); }
.sw.dust { background: rgba(214,150,80,.8); } .sw.shade { background: rgba(40,50,120,.8); margin-left: 8px; }
#loading { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(0,0,0,.6); font-size: 18px; }
#panel { padding: 12px 16px 14px; background: var(--panel); border-left: 1px solid var(--line); display: grid; gap: 8px; align-content: start; overflow: auto; }
#briefing b { color: var(--accent); }
#briefing small { color: var(--muted); display: block; margin-top: 4px; }
#battery { position: relative; height: 22px; border-radius: 6px; border: 1px solid var(--line); overflow: hidden; background: var(--bg); }
#battery-fill { position: absolute; inset: 0 auto 0 0; width: 0; background: var(--ok); transition: width .15s, background .15s; }
#battery-text { position: absolute; inset: 0; display: grid; place-items: center; font-size: 12px; font-weight: 600; text-shadow: 0 1px 2px rgba(0,0,0,.6); }
#stats { color: var(--muted); font-size: 13px; }
#buttons { display: flex; flex-wrap: wrap; gap: 8px; }
#buttons .primary { margin-left: auto; }
#result { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; background: var(--bg); }
#result.win { border-color: var(--ok); } #result.fail { border-color: var(--bad); }
#result h2 { margin: 0 0 4px; font-size: 16px; }
.row { margin-top: 8px; display: flex; flex-wrap: wrap; gap: 8px; }
#howto { margin: 0; color: var(--muted); font-size: 12px; }
#fatal { margin: 24px; padding: 16px; border: 2px solid var(--bad); border-radius: 8px; }
#toast { position: fixed; left: 50%; bottom: 52px; transform: translateX(-50%); background: #000d; color: #fff; padding: 8px 14px; border-radius: 8px; z-index: 10; }
footer { padding: 6px 16px; font-size: 11px; color: var(--muted); border-top: 1px solid var(--line); }
footer a { color: var(--muted); }
#top-explorers { border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; background: var(--bg); font-size: 13px; }
#top-explorers ol { margin: 4px 0 0; padding-left: 1.4em; } #top-explorers li { display: flex; justify-content: space-between; gap: 8px; } #top-explorers li span:last-child { color: var(--muted); }

@media (max-width: 899px) {
  html, body { height: auto; min-height: 100%; }
  #picker, #play, #ranking { display: block; flex: none; }
  #profile-panel { border-left: 0; border-top: 1px solid var(--line); }
  #board-list li { grid-template-columns: 2.2em 1fr auto; } #board-list li > :nth-child(4) { grid-column: 2 / -1; justify-self: start; }
  #globe-wrap { height: 52vh; }
  #sites { border-left: 0; }
  #stage { height: 62vh; min-height: 320px; }
  #panel { border-left: 0; border-top: 1px solid var(--line); }
  #topbar { padding: 6px 10px; } #topnav button { padding: 5px 8px; font-size: 13px; }
  #view-options { max-width: none; left: 8px; right: 8px; top: 8px; justify-content: flex-start; }
  #readout { top: 52px; max-width: calc(100% - 16px); }
  #legend { flex-wrap: wrap; gap: 2px 10px; max-width: 70%; }
  #nav-sites, #globe-hint { display: none; }
  #opt-toggle { display: inline-block; }
}
