:root {
  --ground: #0c0d10; --bg: #141519; --bg2: #1b1c22; --bg3: #23252d; --line: #272a33; --line2: #343846;
  --fg: #eceef2; --fg2: #b7bcc8; --muted: #7f8594; --faint: #5b6070;
  --accent: #6ea8ff; --amber: #f3c06b; --amber-bg: rgba(243,192,107,.10); --red: #ff6b7a;
  --r: 14px; --rail-w: 372px;
  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --shadow: 0 1px 2px rgba(0,0,0,.5), 0 12px 40px rgba(0,0,0,.5);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--ground); color: var(--fg); font: 14px/1.45 var(--font); font-variant-numeric: tabular-nums; color-scheme: dark; -webkit-font-smoothing: antialiased; }
button { font: inherit; color: inherit; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
#map { position: absolute; inset: 0; }

/* ---------- rail ---------- */
#rail { position: absolute; top: 14px; left: 14px; bottom: 14px; width: var(--rail-w); background: var(--bg); border-radius: var(--r); box-shadow: var(--shadow); display: flex; flex-direction: column; overflow: hidden; z-index: 6; }
#rail-head { padding: 16px 18px 12px; border-bottom: 1px solid var(--line); }
.trip-row { position: relative; display: flex; align-items: center; gap: 8px; }
.trip-btn { display: flex; align-items: center; gap: 8px; background: none; border: 0; padding: 0; cursor: pointer; font-size: 18px; font-weight: 600; letter-spacing: -.01em; min-width: 0; text-align: left; }
.trip-btn #trip-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.trip-btn .chev { color: var(--muted); font-size: 12px; }
.menu { position: absolute; top: 30px; left: 0; min-width: 260px; background: var(--bg2); border: 1px solid var(--line2); border-radius: 10px; box-shadow: var(--shadow); padding: 6px; z-index: 10; }
.menu .item { display: flex; justify-content: space-between; gap: 10px; padding: 7px 10px; border-radius: 7px; cursor: pointer; font-size: 13px; }
.menu .item:hover { background: var(--bg3); }
.menu .item.on { color: var(--accent); }
.menu .item small { color: var(--muted); }
.menu .sep { height: 1px; background: var(--line); margin: 6px 4px; }
.meta { color: var(--muted); font-size: 13px; margin-top: 2px; }
.tools { display: flex; gap: 6px; margin-top: 10px; }
.tbtn { background: var(--bg2); border: 1px solid var(--line); color: var(--fg2); border-radius: 8px; padding: 4px 10px; font-size: 12px; cursor: pointer; }
.tbtn:hover { background: var(--bg3); color: var(--fg); }
.warn { margin-top: 10px; background: var(--amber-bg); color: var(--amber); border-radius: 8px; padding: 7px 10px; font-size: 12.5px; line-height: 1.4; }

#timeline { flex: 1; overflow-y: auto; padding: 6px 0 18px; scrollbar-width: thin; scrollbar-color: var(--line2) transparent; }
.day { padding: 12px 18px 6px 18px; }
.day + .day { border-top: 1px solid var(--line); }
.day-head { display: flex; align-items: baseline; gap: 10px; }
.day-head .n { font-size: 22px; font-weight: 600; letter-spacing: -.02em; line-height: 1; color: var(--c); }
.day-head .d { font-size: 13px; color: var(--fg2); font-weight: 500; }
.day-head .drive { margin-left: auto; font-size: 12.5px; color: var(--muted); white-space: nowrap; }
.day-wx { display: flex; align-items: center; gap: 10px; margin: 6px 0 8px 0; font-size: 12.5px; color: var(--muted); flex-wrap: wrap; }
.day-wx .flag { color: var(--amber); }
.day-alert { font-size: 12.5px; color: var(--amber); margin: 0 0 6px 0; }

.tl { position: relative; margin-left: 6px; }
.tl::before { content: ""; position: absolute; left: 9px; top: 10px; bottom: 10px; width: 2px; background: var(--line2); border-radius: 1px; }
.node { position: relative; display: grid; grid-template-columns: 20px 46px 1fr auto; align-items: center; gap: 8px; padding: 7px 6px 7px 0; border-radius: 8px; cursor: pointer; }
.node:hover, .node.sel { background: var(--bg2); }
.node .dot { width: 12px; height: 12px; border-radius: 50%; background: var(--bg); border: 2px solid var(--c); justify-self: center; box-sizing: border-box; position: relative; z-index: 1; }
.node.end .dot { background: var(--fg); border-color: var(--fg); border-radius: 3px; }
.node.night .dot { background: var(--c); border-color: var(--c); border-radius: 4px; width: 14px; height: 14px; }
.node.night .dot::after { content: "☾"; position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 9px; color: #0c0d10; line-height: 1; }
.node.via .dot { width: 8px; height: 8px; background: var(--c); }
.node .t { font-size: 12px; color: var(--muted); }
.node .name { min-width: 0; font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.node .sub { font-size: 11.5px; color: var(--muted); margin-top: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.node .sub .flag { color: var(--amber); }
.node .ctl { display: none; gap: 2px; }
.node:hover .ctl { display: flex; }
.node .ctl button { background: none; border: 0; color: var(--muted); cursor: pointer; padding: 2px 5px; border-radius: 6px; font-size: 13px; }
.node .ctl button:hover { background: var(--bg3); color: var(--fg); }
.node .ctl .night.on { color: var(--accent); }
.node.depart { cursor: default; opacity: .7; }
.node.depart .name { font-size: 12.5px; color: var(--muted); }
.node.dragging { opacity: .35; }
.node.drop-before { box-shadow: inset 0 2px 0 var(--accent); }
.leg { display: grid; grid-template-columns: 20px 46px 1fr; gap: 8px; align-items: center; padding: 0 0 0 0; height: 18px; }
.leg span { grid-column: 3; font-size: 11px; color: var(--faint); }

/* detail card */
#detail { flex: 1; overflow-y: auto; padding: 12px 18px 20px; }
#detail .back { background: none; border: 0; color: var(--muted); cursor: pointer; padding: 0; font-size: 13px; margin-bottom: 12px; }
#detail .back:hover { color: var(--fg); }
#detail h2 { font-size: 18px; font-weight: 600; margin: 0 0 2px; letter-spacing: -.01em; line-height: 1.25; }
#detail .cat { color: var(--muted); font-size: 13px; margin-bottom: 14px; }
#detail .cat b { color: var(--c); font-weight: 500; }
.kv { display: grid; grid-template-columns: 92px 1fr; gap: 4px 12px; font-size: 13px; margin-bottom: 14px; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; }
.kv .flag { color: var(--amber); }
#detail p.desc { color: var(--fg2); font-size: 13px; margin: 0 0 14px; }
#detail .links { display: flex; gap: 14px; font-size: 13px; margin-bottom: 16px; }
#detail a { color: var(--accent); text-decoration: none; }
.field { display: flex; align-items: center; gap: 10px; font-size: 13px; margin: 8px 0; }
.field label { color: var(--muted); width: 70px; }
.field input[type=number] { width: 72px; background: var(--bg2); border: 1px solid var(--line2); color: var(--fg); border-radius: 7px; padding: 5px 8px; }
.field input[type=checkbox] { accent-color: var(--accent); width: 15px; height: 15px; }
#detail textarea { width: 100%; background: var(--bg2); border: 1px solid var(--line2); color: var(--fg); border-radius: 8px; padding: 7px 9px; font: inherit; font-size: 13px; resize: vertical; min-height: 54px; }
#detail .actions { display: flex; gap: 8px; margin-top: 12px; }
.btn { border: 0; border-radius: 9px; padding: 7px 13px; cursor: pointer; font-size: 13px; background: var(--bg3); color: var(--fg); }
.btn.primary { background: var(--fg); color: var(--ground); font-weight: 500; }
.btn.ghost { background: transparent; color: var(--muted); }
.btn.danger { color: var(--red); }
.btn:hover { filter: brightness(1.12); }
.note-rules { background: var(--amber-bg); color: var(--amber); border-radius: 8px; padding: 7px 10px; font-size: 12.5px; margin-bottom: 14px; }

/* ---------- command bar ---------- */
#cmd { position: absolute; left: calc(var(--rail-w) + 28px); right: 28px; bottom: 18px; max-width: 640px; margin: 0 auto; z-index: 7; display: flex; flex-direction: column; gap: 8px; }
#cmd-form { display: flex; align-items: flex-end; gap: 6px; background: var(--bg); border-radius: 14px; box-shadow: var(--shadow); padding: 6px; }
#cmd-input { flex: 1; resize: none; background: transparent; border: 0; outline: none; color: var(--fg); font: inherit; font-size: 14px; padding: 8px 8px; max-height: 140px; }
#cmd-input::placeholder { color: var(--faint); }
.cbtn { width: 34px; height: 34px; border-radius: 10px; border: 0; background: transparent; color: var(--muted); cursor: pointer; font-size: 16px; flex-shrink: 0; }
.cbtn:hover { background: var(--bg3); color: var(--fg); }
.cbtn.send { background: var(--fg); color: var(--ground); }
.cbtn.send:disabled { opacity: .35; }
#reply, #history { background: var(--bg); border-radius: 14px; box-shadow: var(--shadow); padding: 12px 14px; font-size: 13.5px; line-height: 1.5; }
#reply { position: relative; }
#reply .a, #reply .c, #reply .err { white-space: pre-wrap; }
#reply .x { position: absolute; top: 8px; right: 10px; background: none; border: 0; color: var(--muted); cursor: pointer; font-size: 14px; }
#reply .q { color: var(--muted); font-size: 12.5px; margin-bottom: 4px; padding-right: 20px; }
#reply .c { color: var(--faint); font-size: 12.5px; font-style: italic; }
#reply .work { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12.5px; margin: 2px 0 4px; }
#reply .work .st { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#reply .work .elapsed { color: var(--faint); font-variant-numeric: tabular-nums; }
.spin { width: 11px; height: 11px; border-radius: 50%; border: 2px solid var(--line2); border-top-color: var(--accent); animation: spin .8s linear infinite; flex-shrink: 0; }
@keyframes spin { to { transform: rotate(360deg); } }
#reply .steps { display: flex; flex-direction: column; gap: 2px; margin: 2px 0 6px; }
#reply .steps:empty { display: none; }
.step { display: flex; align-items: center; gap: 7px; font-size: 12px; color: var(--fg2); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.step .ic { width: 8px; height: 8px; border-radius: 50%; background: var(--line2); flex-shrink: 0; }
.step.run .ic { background: var(--accent); animation: blink 1s steps(1) infinite; }
.step.ok .ic { background: #3fd0a0; }
.step.fail .ic { background: var(--red); }
.step .dur { color: var(--faint); margin-left: auto; font-size: 11px; }
#cmd-form.busy #cmd-input::placeholder { color: var(--faint); }
#history .hfoot { display: flex; justify-content: flex-end; margin-top: 6px; }
#reply .tools-line { display: flex; flex-wrap: wrap; gap: 4px; margin: 4px 0 6px; }
.tchip { font-size: 11px; color: var(--fg2); background: var(--bg3); border-radius: 999px; padding: 1px 8px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
#reply .a.cursor::after { content: "▍"; color: var(--muted); animation: blink 1s steps(1) infinite; }
#reply .err { color: var(--red); }
@keyframes blink { 50% { opacity: 0; } }
#history { max-height: 46vh; overflow-y: auto; }
#history .m { margin-bottom: 10px; white-space: pre-wrap; }
#history .m.user { color: var(--muted); }
#history .m.user::before { content: "› "; }

/* ---------- map UI ---------- */
.maplibregl-ctrl-top-right { top: 14px; right: 14px; }
.maplibregl-ctrl-group { background: var(--bg) !important; border-radius: 10px !important; box-shadow: var(--shadow) !important; overflow: hidden; }
.maplibregl-ctrl-group button { width: 34px; height: 34px; }
.maplibregl-ctrl-group button + button { border-top: 1px solid var(--line) !important; }
.maplibregl-ctrl-zoom-in .maplibregl-ctrl-icon, .maplibregl-ctrl-zoom-out .maplibregl-ctrl-icon { filter: invert(.8); }
.layers-ctrl button { font-size: 15px; color: var(--fg2); background: none; border: 0; cursor: pointer; }
.layers-pop { position: absolute; top: 0; right: 42px; width: 210px; background: var(--bg); border-radius: 12px; box-shadow: var(--shadow); padding: 8px; }
.layers-pop .grp { font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em; color: var(--faint); padding: 6px 8px 2px; }
.layers-pop .row { display: flex; align-items: center; gap: 8px; padding: 5px 8px; border-radius: 7px; cursor: pointer; font-size: 12.5px; color: var(--fg2); user-select: none; }
.layers-pop .row:hover { background: var(--bg2); }
.layers-pop .row.off { color: var(--faint); }
.layers-pop .row .sw { width: 9px; height: 9px; border-radius: 50%; background: var(--c); }
.layers-pop .row.off .sw { opacity: .3; }
.maplibregl-ctrl-attrib { background: rgba(12,13,16,.6) !important; color: var(--faint); font-size: 10px; }
.maplibregl-ctrl-attrib a { color: var(--faint); }

.mk { width: 20px; height: 20px; border-radius: 50%; background: var(--c); color: #0c0d10; font-size: 10.5px; font-weight: 600; display: flex; align-items: center; justify-content: center; border: 2px solid #0c0d10; box-shadow: 0 0 0 1.5px var(--c), 0 2px 8px rgba(0,0,0,.6); cursor: pointer; transition: transform .12s; }
.mk.night { border-radius: 6px; width: 22px; height: 22px; box-shadow: 0 0 0 1.5px var(--c), 0 0 0 6px color-mix(in srgb, var(--c) 22%, transparent), 0 2px 8px rgba(0,0,0,.6); }
.mk.end { background: var(--fg); box-shadow: 0 0 0 1.5px var(--fg), 0 2px 8px rgba(0,0,0,.6); border-radius: 5px; }
.mk.via { width: 10px; height: 10px; font-size: 0; }
.mk.hl, .mk.sel { transform: scale(1.3); }
.wx-mk { font-size: 11px; color: var(--fg2); background: rgba(20,21,25,.9); border: 1px solid var(--line2); border-radius: 6px; padding: 1px 6px; white-space: nowrap; pointer-events: none; }
.maplibregl-popup-content { background: var(--bg); color: var(--fg); border-radius: 12px; padding: 12px 14px; font-family: var(--font); font-size: 13px; box-shadow: var(--shadow); min-width: 210px; }
.maplibregl-popup-anchor-bottom .maplibregl-popup-tip { border-top-color: var(--bg); } .maplibregl-popup-anchor-top .maplibregl-popup-tip { border-bottom-color: var(--bg); } .maplibregl-popup-anchor-left .maplibregl-popup-tip { border-right-color: var(--bg); } .maplibregl-popup-anchor-right .maplibregl-popup-tip { border-left-color: var(--bg); }
.maplibregl-popup-close-button { color: var(--muted); font-size: 16px; padding: 2px 7px; }
.maplibregl-popup-close-button:hover { background: var(--bg3); color: var(--fg); }
.pop h3 { margin: 0 0 2px; font-size: 14px; font-weight: 600; padding-right: 16px; }
.pop .sub { color: var(--muted); font-size: 12px; margin-bottom: 8px; }
.pop .sub b { color: var(--c); font-weight: 500; }
.pop .desc { color: var(--fg2); font-size: 12.5px; margin-bottom: 8px; }
.pop .row { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.pop a { color: var(--accent); text-decoration: none; font-size: 12px; margin-left: auto; }

/* ---------- modal ---------- */
#modal { position: absolute; inset: 0; background: rgba(0,0,0,.55); display: flex; align-items: center; justify-content: center; z-index: 20; }
#new-form { width: 360px; background: var(--bg); border-radius: 16px; box-shadow: var(--shadow); padding: 20px 22px 18px; display: flex; flex-direction: column; gap: 12px; }
#new-form h2 { margin: 0 0 2px; font-size: 17px; font-weight: 600; }
#new-form label { display: flex; flex-direction: column; gap: 5px; font-size: 12px; color: var(--muted); }
#new-form input { background: var(--bg2); border: 1px solid var(--line2); border-radius: 9px; padding: 9px 11px; font: inherit; font-size: 14px; color: var(--fg); }
#new-form input:focus { outline: none; border-color: #4a5470; }
#new-form .row { display: flex; justify-content: flex-end; gap: 8px; margin-top: 2px; }
#new-log { background: var(--bg2); border-radius: 9px; padding: 9px 11px; font-size: 11.5px; color: var(--fg2); max-height: 160px; overflow: auto; margin: 0; white-space: pre-wrap; }
.toast { position: absolute; top: 16px; left: 50%; transform: translateX(-50%); background: var(--fg); color: var(--ground); padding: 6px 12px; border-radius: 999px; font-size: 12.5px; z-index: 30; }
.toast.err { background: var(--red); color: #fff; }

@media (max-width: 860px) {
  :root { --rail-w: 100vw; }
  #rail { top: auto; left: 0; right: 0; bottom: 0; width: auto; height: 52%; border-radius: 16px 16px 0 0; }
  #cmd { left: 10px; right: 10px; bottom: calc(52% + 10px); }
  .maplibregl-ctrl-top-right { top: 10px; right: 10px; }
}
