:root {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --ink: #1c2321;
  --muted: #5d6a66;
  --line: #dcded8;
  --brand: #0f766e;
  --brand-ink: #ffffff;
  --done: #15803d;
  --claim: #b45309;
  --mine: #1d4ed8;
  --danger: #b91c1c;
  --shadow: 0 6px 24px rgba(20, 30, 28, .18);
  --radius: 14px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #131816; --surface: #1d2421; --ink: #ecf1ee; --muted: #9aa8a3; --line: #2d3733;
    --brand: #2dd4bf; --brand-ink: #062c27; --done: #4ade80; --claim: #fbbf24; --mine: #60a5fa; --danger: #f87171;
    --shadow: 0 6px 24px rgba(0, 0, 0, .5);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--ink);
  -webkit-text-size-adjust: 100%;
}
.muted { color: var(--muted); }
.error { color: var(--danger); margin: .5rem 0; }

button { font: inherit; color: inherit; cursor: pointer; }
.btn {
  border: 1px solid var(--line); background: var(--surface); border-radius: 10px;
  padding: .65rem 1rem; min-height: 44px; font-weight: 600;
}
.btn.primary { background: var(--brand); color: var(--brand-ink); border-color: transparent; }
.btn.done { background: var(--done); color: #fff; border-color: transparent; }
.btn.warn { color: var(--danger); }
.btn:disabled { opacity: .55; cursor: progress; }
.icon { border: 0; background: transparent; font-size: 1.4rem; width: 44px; height: 44px; border-radius: 10px; }

/* ── login ── */
#login { min-height: 100%; display: grid; place-items: center; padding: 1rem; }
.card {
  width: min(420px, 100%); background: var(--surface); border-radius: var(--radius);
  padding: 1.5rem; box-shadow: var(--shadow); display: grid; gap: .8rem;
}
.card h1 { margin: 0; font-size: 1.5rem; }
.card p { margin: 0; }
label { display: grid; gap: .25rem; font-size: .9rem; color: var(--muted); }
input[type=text], input[type=password], input:not([type]), textarea {
  font: inherit; color: var(--ink); background: var(--bg);
  border: 1px solid var(--line); border-radius: 10px; padding: .7rem .8rem; min-height: 44px; width: 100%;
}
input:focus, textarea:focus, button:focus-visible { outline: 3px solid color-mix(in srgb, var(--brand) 45%, transparent); outline-offset: 1px; }
.tabs { display: flex; gap: .25rem; background: var(--bg); padding: .25rem; border-radius: 10px; }
.tabs button { flex: 1; border: 0; background: transparent; padding: .5rem; border-radius: 8px; font-weight: 600; color: var(--muted); min-height: 40px; }
.tabs button.on { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.15); }

/* ── app shell ── */
#app { position: fixed; inset: 0; }
#map { position: absolute; inset: 0; z-index: 0; background: #dfe5e1; }
#top {
  position: absolute; z-index: 800; top: 0; left: 0; right: 0;
  padding: calc(env(safe-area-inset-top) + .4rem) .6rem .5rem 1rem;
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  backdrop-filter: blur(6px); box-shadow: 0 1px 0 var(--line);
  display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 0 .5rem;
}
#top .title { display: flex; flex-wrap: wrap; gap: .1rem .7rem; align-items: baseline; font-size: .95rem; }
#top .bar { grid-column: 1; height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; margin-top: .3rem; }
#top #progressFill { height: 100%; width: 0; background: var(--done); transition: width .5s; }
#top .icon { grid-row: 1 / span 2; grid-column: 2; }

#banner {
  position: absolute; z-index: 790; top: calc(env(safe-area-inset-top) + 4.2rem); left: 50%; transform: translateX(-50%);
  width: min(520px, calc(100% - 1.5rem)); background: var(--surface); border-radius: var(--radius);
  padding: 1rem; box-shadow: var(--shadow); display: grid; gap: .6rem;
}

.fabs { position: absolute; z-index: 700; right: .8rem; bottom: calc(env(safe-area-inset-bottom) + 2.8rem); display: grid; gap: .5rem; justify-items: end; transition: bottom .2s; }
.fab {
  border: 0; border-radius: 999px; background: var(--brand); color: var(--brand-ink);
  padding: .85rem 1.2rem; font-weight: 700; box-shadow: var(--shadow); min-height: 48px;
}
.fab.small { background: var(--surface); color: var(--ink); padding: .55rem .9rem; min-height: 40px; font-size: .9rem; }
.fab.small[aria-pressed=true] { background: var(--mine); color: #fff; }

#legend {
  position: absolute; z-index: 700; left: .6rem; bottom: calc(env(safe-area-inset-bottom) + .6rem);
  background: color-mix(in srgb, var(--surface) 92%, transparent); border-radius: 999px; padding: .3rem .8rem;
  display: flex; flex-wrap: wrap; gap: .2rem .8rem; font-size: .78rem; align-items: center; box-shadow: var(--shadow);
  max-width: calc(100% - 1.2rem);
}
#legend label { display: flex; grid-template: none; align-items: center; gap: .3rem; font-size: .78rem; color: var(--ink); }
.sw { display: inline-block; width: .8rem; height: .8rem; border-radius: 3px; margin-right: .3rem; vertical-align: -1px; border: 2px solid; }
.sw.free { border-color: #64748b; background: rgba(148,163,184,.25); }
.sw.claimed { border-color: var(--claim); background: rgba(245,158,11,.4); border-style: dashed; }
.sw.mine { border-color: var(--mine); background: rgba(37,99,235,.4); border-style: dashed; }
.sw.done { border-color: var(--done); background: rgba(22,163,74,.55); }

/* ── area sheet ── */
#sheet {
  position: absolute; z-index: 900; left: 0; right: 0; bottom: 0;
  background: var(--surface); border-radius: var(--radius) var(--radius) 0 0; box-shadow: var(--shadow);
  padding: 1rem 1rem calc(env(safe-area-inset-bottom) + 1rem); display: grid; gap: .7rem;
  max-height: 60vh; overflow: auto;
}
#sheet h2 { margin: 0; font-size: 1.25rem; padding-right: 2.5rem; }
#sheet .close { position: absolute; right: .4rem; top: .4rem; }
.status { display: flex; gap: .5rem; align-items: flex-start; padding: .6rem .8rem; border-radius: 10px; background: var(--bg); }
.status.done { border-left: 5px solid var(--done); }
.status.claimed { border-left: 5px solid var(--claim); }
.status.mine { border-left: 5px solid var(--mine); }
.status.free { border-left: 5px solid #94a3b8; }
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; }
.actions .wide { grid-column: 1 / -1; }
.actions .btn { width: 100%; }
body.sheet-open .fabs { bottom: calc(var(--sheet-h, 20rem) + .8rem); }
body.sheet-open #legend { display: none; }

#multibar {
  position: absolute; z-index: 900; left: .6rem; right: .6rem; bottom: calc(env(safe-area-inset-bottom) + .6rem);
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: .6rem .8rem;
  display: flex; gap: .5rem; align-items: center;
}
#multibar span { flex: 1; font-weight: 600; }
body.multi .fabs { bottom: calc(env(safe-area-inset-bottom) + 5rem); }

/* ── side panel ── */
#panel {
  position: absolute; z-index: 1000; top: 0; right: 0; bottom: 0; width: min(420px, 100%);
  background: var(--surface); box-shadow: var(--shadow); display: grid; grid-template-rows: auto 1fr auto;
  padding-top: env(safe-area-inset-top);
}
.panel-head { display: flex; gap: .4rem; align-items: center; padding: .5rem .5rem .5rem .8rem; border-bottom: 1px solid var(--line); }
.panel-head .tabs { flex: 1; }
#panelBody { overflow: auto; padding: .8rem 1rem; display: grid; gap: .5rem; align-content: start; }
.panel-foot { display: flex; justify-content: space-between; align-items: center; gap: .5rem; padding: .6rem 1rem calc(env(safe-area-inset-bottom) + .6rem); border-top: 1px solid var(--line); }
.row { display: flex; justify-content: space-between; gap: .8rem; padding: .5rem 0; border-bottom: 1px solid var(--line); font-size: .92rem; }
.row button.link { border: 0; background: none; color: var(--brand); padding: 0; text-align: left; font-weight: 600; }
.row time { color: var(--muted); white-space: nowrap; font-size: .8rem; }
#panelBody h3 { margin: .6rem 0 0; font-size: .95rem; }
pre.msg { white-space: pre-wrap; margin: 0; font: inherit; }

#toast {
  position: absolute; z-index: 1100; left: 50%; transform: translateX(-50%); bottom: calc(env(safe-area-inset-bottom) + 5.5rem);
  background: #1c2321; color: #fff; padding: .7rem 1rem; border-radius: 12px; box-shadow: var(--shadow);
  display: flex; gap: 1rem; align-items: center; max-width: calc(100% - 1.5rem);
}
#toast.err { background: var(--danger); }
#toast button { border: 0; background: transparent; color: #7dd3fc; font-weight: 700; padding: 0; }

.leaflet-top.leaflet-right { margin-top: calc(env(safe-area-inset-top) + 3.6rem); }
.you-dot { width: 16px; height: 16px; border-radius: 50%; background: #2563eb; border: 3px solid #fff; box-shadow: 0 0 0 2px #2563eb; }

@media (min-width: 760px) {
  #sheet { left: 1rem; right: auto; bottom: 1rem; width: 380px; border-radius: var(--radius); max-height: calc(100% - 7rem); }
  body.sheet-open .fabs { bottom: calc(env(safe-area-inset-bottom) + 2.8rem); }
  body.sheet-open #legend { display: flex; left: auto; right: 6.5rem; }
  #multibar { left: 50%; right: auto; transform: translateX(-50%); width: 460px; }
}
