:root {
  --bg: #0a0e24;
  --panel: #131a3d;
  --panel-2: #1b2350;
  --line: rgba(255, 255, 255, 0.08);
  --text: #eef1ff;
  --muted: #9aa3cc;
  --accent: #ff8c42;
  --danger: #ef4444;
  --ok: #2ec4b6;
  --radius: 16px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }
h1, h2, h3 { margin: 0; font-weight: 700; }
[hidden] { display: none !important; }

#sky { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
#sky.hover { cursor: pointer; }

/* ------------------------------------------------------------- header */
#top {
  position: fixed; top: 0; left: 0; right: 0; z-index: 5;
  display: flex; align-items: center; gap: 12px;
  padding: calc(10px + var(--safe-top)) 14px 10px;
  background: linear-gradient(to bottom, rgba(10, 14, 36, 0.92), rgba(10, 14, 36, 0));
  pointer-events: none;
}
#top > * { pointer-events: auto; }
.brand { display: flex; align-items: center; gap: 8px; }
.brand h1 { font-size: 18px; letter-spacing: 0.2px; }
.logo {
  width: 22px; height: 22px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #ffd9a3, #ff8c42 45%, #8a3a10);
  box-shadow: 0 2px 8px rgba(255, 140, 66, 0.5);
}
.logo.big { width: 56px; height: 56px; margin: 0 auto 8px; }
.counts { flex: 1; min-width: 0; display: flex; gap: 10px; font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; }
.counts b { color: var(--text); }
.counts .overdue b { color: var(--danger); }
@media (max-width: 430px) { .counts span:nth-child(3) { display: none; } }
.actions { flex: 0 0 auto; display: flex; gap: 8px; }
button.primary {
  background: var(--accent); color: #1a0d05; font-weight: 700;
  padding: 8px 14px; border-radius: 999px; box-shadow: 0 4px 14px rgba(255, 140, 66, 0.35);
}
button.primary:active { transform: translateY(1px); }
button.icon {
  width: 36px; height: 36px; border-radius: 50%; background: rgba(255, 255, 255, 0.08);
  font-size: 16px; display: grid; place-items: center;
}
button.icon.on { background: rgba(255, 255, 255, 0.22); }

/* ------------------------------------------------------------- legend */
.legend {
  position: fixed; left: 0; right: 0; z-index: 4;
  top: calc(56px + var(--safe-top));
  display: flex; gap: 6px; padding: 4px 12px 8px; overflow-x: auto; scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.legend::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto; display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px 4px 6px; border-radius: 999px; font-size: 12px; color: var(--muted);
  background: rgba(19, 26, 61, 0.7); border: 1px solid var(--line); backdrop-filter: blur(6px);
  transition: opacity 0.2s;
}
.chip .dot { width: 10px; height: 10px; border-radius: 50%; }
.chip.off { opacity: 0.35; }
.chip.on { color: var(--text); border-color: rgba(255, 255, 255, 0.25); }

/* -------------------------------------------------------------- hint */
.hint {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(64px + var(--safe-bottom));
  z-index: 3; color: var(--muted); font-size: 13px; text-align: center; padding: 8px 14px;
  background: rgba(19, 26, 61, 0.6); border-radius: 999px; backdrop-filter: blur(6px);
  max-width: 90vw;
}

/* --------------------------------------------------------------- list */
.list {
  position: fixed; inset: 0; z-index: 3; overflow-y: auto;
  padding: calc(100px + var(--safe-top)) 14px calc(24px + var(--safe-bottom));
  background: rgba(10, 14, 36, 0.86); backdrop-filter: blur(10px);
}
.list h3 { font-size: 12px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); margin: 18px 4px 8px; }
.list h3:first-child { margin-top: 0; }
.row {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left;
  padding: 12px; border-radius: 12px; background: var(--panel); margin-bottom: 8px;
  border: 1px solid var(--line);
}
.row:active { background: var(--panel-2); }
.row .ball { flex: 0 0 auto; border-radius: 50%; }
.row .ball.S { width: 16px; height: 16px; }
.row .ball.M { width: 24px; height: 24px; }
.row .ball.L { width: 34px; height: 34px; }
.row .txt { flex: 1; min-width: 0; }
.row .txt b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .txt small { color: var(--muted); }
.row.late .txt small { color: var(--danger); }
.row.done { opacity: 0.6; }
.row.done .txt b { text-decoration: line-through; }
.list .tabs { display: flex; gap: 8px; margin-bottom: 14px; }
.list .tabs button { padding: 6px 12px; border-radius: 999px; background: rgba(255,255,255,0.08); color: var(--muted); }
.list .tabs button.on { background: rgba(255,255,255,0.2); color: var(--text); }
.empty { color: var(--muted); text-align: center; padding: 40px 0; }

/* -------------------------------------------------------------- sheet */
.sheet { position: fixed; inset: 0; z-index: 20; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.45); }
.sheet-panel {
  position: absolute; left: 0; right: 0; bottom: 0;
  max-height: 88vh; overflow-y: auto;
  background: var(--panel); border-radius: 22px 22px 0 0;
  padding: 8px 18px calc(20px + var(--safe-bottom));
  box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.5);
  animation: up 0.22s ease-out;
}
@keyframes up { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
.grab { width: 40px; height: 4px; border-radius: 2px; background: rgba(255,255,255,0.2); margin: 4px auto 14px; }
@media (min-width: 760px) {
  .sheet-panel {
    left: auto; right: 24px; bottom: 24px; width: 420px; border-radius: 22px; max-height: calc(100vh - 48px);
    padding-bottom: 20px;
  }
  .grab { display: none; }
  .sheet-panel { padding-top: 18px; }
}

.detail-head { display: flex; gap: 12px; align-items: flex-start; }
.detail-head .dot { flex: 0 0 auto; width: 34px; height: 34px; border-radius: 50%; margin-top: 2px; }
.detail-title h2 { font-size: 19px; line-height: 1.25; overflow-wrap: anywhere; }
.meta { color: var(--muted); font-size: 13px; margin-top: 3px; }
.meta.late { color: var(--danger); }
.notes { white-space: pre-wrap; color: #cfd5f5; font-size: 14px; margin: 12px 0 4px; overflow-wrap: anywhere; }
.notes:empty { display: none; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0 6px; }
.act {
  padding: 10px 14px; border-radius: 12px; background: rgba(255, 255, 255, 0.08); font-weight: 600;
  flex: 1 1 auto; min-width: 30%;
}
.act.pop { background: rgba(46, 196, 182, 0.2); color: #9ff3ea; }
.act.throw { background: rgba(255, 140, 66, 0.2); color: #ffc79a; }
.act.danger { background: rgba(239, 68, 68, 0.15); color: #ffb4b4; }
.history { margin-top: 10px; color: var(--muted); font-size: 13px; }
.history summary { cursor: pointer; }
.history ul { list-style: none; margin: 8px 0 0; padding: 0; }
.history li { padding: 6px 0; border-top: 1px solid var(--line); }
.history li b { color: var(--text); font-weight: 600; }
.history li i { display: block; color: #cfd5f5; font-style: normal; margin-top: 2px; white-space: pre-wrap; }

/* -------------------------------------------------------------- forms */
form.f h2 { font-size: 18px; margin-bottom: 12px; }
form.f label { display: block; font-size: 12px; color: var(--muted); margin: 12px 0 5px; text-transform: uppercase; letter-spacing: 0.5px; }
form.f input[type=text], form.f input[type=datetime-local], form.f input[type=password], form.f textarea, form.f select {
  width: 100%; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.25); color: var(--text); outline: none;
}
form.f input:focus, form.f textarea:focus, form.f select:focus { border-color: var(--accent); }
form.f textarea { min-height: 80px; resize: vertical; }
.seg { display: flex; gap: 6px; }
.seg button { flex: 1; padding: 9px 0; border-radius: 10px; background: rgba(255,255,255,0.07); color: var(--muted); font-weight: 600; }
.seg button.on { background: rgba(255,255,255,0.22); color: var(--text); }
.cats { display: flex; flex-wrap: wrap; gap: 6px; }
.cats button { display: inline-flex; align-items: center; gap: 6px; padding: 6px 10px 6px 7px; border-radius: 999px; background: rgba(255,255,255,0.07); color: var(--muted); font-size: 13px; }
.cats button.on { background: rgba(255,255,255,0.2); color: var(--text); }
.cats .dot { width: 10px; height: 10px; border-radius: 50%; }
.quick { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.quick button { padding: 5px 10px; border-radius: 999px; background: rgba(255,140,66,0.15); color: #ffc79a; font-size: 12px; }
.form-foot { display: flex; gap: 8px; justify-content: flex-end; margin-top: 18px; align-items: center; }
.form-foot .spacer { flex: 1; }
.form-foot button { padding: 10px 16px; border-radius: 12px; background: rgba(255,255,255,0.08); }
.form-foot button.primary { background: var(--accent); color: #1a0d05; }
.form-foot button.link { background: none; color: var(--muted); padding-left: 0; }
.form-foot button.link.danger { color: #ff9c9c; }
.parts .part { display: flex; gap: 6px; margin-bottom: 6px; align-items: center; }
.parts .part input { flex: 1; }
.parts .part select { width: 64px; flex: 0 0 auto; }
.parts .part .rm { width: 32px; color: var(--muted); }
.addpart { color: var(--accent); font-weight: 600; padding: 6px 0; }
.err { color: #ff9c9c; font-size: 13px; margin: 8px 0 0; }

/* --------------------------------------------------------------- gate */
.gate { position: fixed; inset: 0; z-index: 30; display: grid; place-items: center; background: rgba(10, 14, 36, 0.92); padding: 20px; }
.gate-card { width: min(360px, 100%); text-align: center; background: var(--panel); border-radius: 22px; padding: 28px 22px; border: 1px solid var(--line); }
.gate-card p { color: var(--muted); font-size: 14px; }
.gate-card input { width: 100%; padding: 12px; border-radius: 10px; border: 1px solid var(--line); background: rgba(0,0,0,0.25); color: var(--text); margin: 10px 0 12px; text-align: center; }

/* -------------------------------------------------------------- toast */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(70px + var(--safe-bottom)); z-index: 40;
  background: #fff; color: #111; padding: 10px 14px; border-radius: 999px; font-weight: 600; font-size: 14px;
  box-shadow: 0 8px 30px rgba(0,0,0,0.4); display: flex; gap: 12px; align-items: center; max-width: 92vw;
}
.toast button { color: var(--accent); font-weight: 700; }
