:root {
  --bg: #1b1d1f; --panel: rgba(24, 26, 28, 0.92); --line: #34383c; --text: #e8e4dc; --muted: #9a958c;
  --accent: #f2b33d; --accent2: #3d7fd6; --on: #f2b33d;
}
:root[data-theme="light"] { --bg: #ece8df; --panel: rgba(250, 248, 243, 0.94); --line: #d4cec2; --text: #22201c; --muted: #6c675e; }
@media (prefers-color-scheme: light) { :root:not([data-theme="dark"]) { --bg: #ece8df; --panel: rgba(250, 248, 243, 0.94); --line: #d4cec2; --text: #22201c; --muted: #6c675e; } }
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 13px/1.35 "Inter", system-ui, -apple-system, "Segoe UI", sans-serif; overflow: hidden; }
#app { position: fixed; inset: 0; }
#c3d, #c2d { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#c2d { background: #f4f1ea; cursor: grab; }
#splitter { position: absolute; top: 0; bottom: 0; width: 6px; background: var(--accent); cursor: ew-resize; z-index: 4; }
#panel { position: absolute; left: 12px; top: 12px; bottom: 12px; width: 300px; overflow: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; z-index: 5; backdrop-filter: blur(6px); }
#panel header h1 { font-size: 17px; margin: 0; letter-spacing: .2px; }
.sub { color: var(--muted); margin: 2px 0 8px; font-size: 12px; }
section { border-top: 1px solid var(--line); padding: 8px 0 6px; }
h2 { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 2px 0 6px; }
h3 { font-size: 12px; margin: 8px 0 4px; } h3 small { color: var(--muted); font-weight: 400; }
.row { display: grid; grid-template-columns: 96px 1fr auto; align-items: center; gap: 6px; margin: 4px 0; }
.row input[type=range] { width: 100%; accent-color: var(--accent); }
.row select, .row input[type=file] { width: 100%; background: transparent; color: var(--text); border: 1px solid var(--line); border-radius: 6px; padding: 3px; font: inherit; }
.chk { display: flex; gap: 6px; align-items: center; margin: 3px 0; }
.seg { display: flex; flex-wrap: wrap; gap: 3px; margin: 4px 0 6px; }
button { background: transparent; color: var(--text); border: 1px solid var(--line); border-radius: 6px; padding: 4px 8px; font: inherit; cursor: pointer; }
button:hover { border-color: var(--accent); }
button.on { background: var(--accent); color: #1b1b1b; border-color: var(--accent); }
.btns { display: flex; flex-wrap: wrap; gap: 4px; margin: 4px 0; }
.grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 3px; }
.grid button { padding: 3px 2px; font-size: 11px; }
.grid button.div { background: var(--accent2); color: #fff; border-color: var(--accent2); }
.status { color: var(--muted); margin: 2px 0 6px; font-size: 12px; min-height: 16px; }
footer { border-top: 1px solid var(--line); padding-top: 8px; } footer a { color: var(--accent); }
#info { position: absolute; right: 12px; top: 12px; width: 300px; max-height: calc(100% - 24px); overflow: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; z-index: 5; }
#info h2 { font-size: 14px; text-transform: none; letter-spacing: 0; color: var(--text); margin-right: 24px; }
#infoBody { color: var(--muted); } #infoBody b { color: var(--text); font-weight: 600; }
#infoClose { position: absolute; right: 8px; top: 8px; border: 0; font-size: 18px; }
#hud { position: absolute; right: 12px; bottom: 10px; color: var(--muted); font-size: 11px; z-index: 3; background: var(--panel); padding: 3px 8px; border-radius: 6px; }
#loading { position: absolute; inset: 0; display: grid; place-items: center; background: var(--bg); z-index: 10; }
#loading .box { text-align: center; } #loading p { color: var(--muted); }
.spin { width: 34px; height: 34px; margin: 0 auto 10px; border: 3px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: s 1s linear infinite; }
@keyframes s { to { transform: rotate(360deg); } }
@media (max-width: 760px) {
  #panel { left: 8px; right: 8px; top: auto; bottom: 8px; width: auto; max-height: 46%; }
  #info { left: 8px; right: 8px; width: auto; top: 8px; max-height: 40%; }
  #hud { display: none; }
}

/* driving panel */
#panel header { display: flex; align-items: center; justify-content: space-between; }
#panelToggle { font-size: 16px; padding: 2px 9px; }
body.collapsed .more { display: none; }
body.collapsed #panel { bottom: auto; max-height: calc(100% - 24px); }
.drive { border-top: 0; }
.selname { text-transform: none; letter-spacing: 0; color: var(--text); font-weight: 600; margin-left: 4px; }
.locos { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; margin-bottom: 6px; }
.locos button { display: flex; flex-direction: column; align-items: center; padding: 5px 2px; line-height: 1.1; }
.locos button b { font-size: 15px; font-variant-numeric: tabular-nums; }
.locos button span { font-size: 10px; color: var(--muted); min-height: 11px; }
.locos button.on span { color: #1b1b1b; }
.locos button.run:not(.on) { border-color: #3fbf6a; box-shadow: inset 0 0 0 1px #3fbf6a; }
.btns.big button { flex: 1; padding: 7px 6px; font-weight: 600; }
details { border-top: 1px solid var(--line); padding: 6px 0; }
summary { cursor: pointer; font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); padding: 2px 0; }
details[open] summary { margin-bottom: 6px; }

.hint { font-size: 11px; color: var(--muted); margin: 4px 0; line-height: 1.3; }
.locos { grid-template-columns: repeat(4, 1fr); }

/* ---------------------------------------------------------------- touch / small screens */
#mbar, #sheetShade, #sheetClose { display: none; }
@media (pointer: coarse), (max-width: 900px) {
  html, body { font-size: 15px; }
  #hud { display: none; }
  /* compact driving bar */
  #mbar { display: block; position: absolute; left: 0; right: 0; bottom: 0; z-index: 6; background: var(--panel); border-top: 1px solid var(--line);
    padding: 6px max(10px, env(safe-area-inset-right)) calc(6px + env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left)); backdrop-filter: blur(8px); }
  .mlocos { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 6px; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
  .mlocos::-webkit-scrollbar { display: none; }
  .mlocos button { flex: 0 0 auto; min-width: 58px; min-height: 40px; display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1.05; padding: 3px 8px; }
  .mlocos button b { font-size: 15px; } .mlocos button span { font-size: 10px; color: var(--muted); min-height: 10px; }
  .mlocos button.on span { color: #1b1b1b; } .mlocos button.run:not(.on) { border-color: #3fbf6a; box-shadow: inset 0 0 0 1px #3fbf6a; }
  .mrow { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
  .mrow #mSpeed { order: 10; flex: 1 0 100%; margin: 2px 0 0; }
  .mrow .mkmh { flex: 1; text-align: center; font-size: 17px; }
  .mrow button { min-width: 46px; min-height: 46px; font-size: 20px; padding: 0; border-radius: 10px; }
  .mrow .mgo { min-width: 64px; font-size: 22px; background: #2f8f4e; border-color: #2f8f4e; color: #fff; }
  .mrow .mgo.on { background: #c0392b; border-color: #c0392b; color: #fff; }
  .mrow input[type=range] { flex: 1; min-width: 60px; height: 32px; accent-color: var(--accent); }
  .mkmh { min-width: 58px; text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
  .mstatus { color: var(--muted); font-size: 12px; min-height: 15px; margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  /* the full menu: hidden until opened, then a bottom sheet */
  #panel { display: none; left: 0; right: 0; bottom: 0; top: auto; width: auto; max-height: 72vh; border-radius: 16px 16px 0 0; padding: 10px 16px calc(16px + env(safe-area-inset-bottom)); z-index: 8; }
  body.sheet #panel, body.sheet.collapsed #panel { display: block; top: auto; bottom: 0; max-height: 72vh; }
  body.sheet #sheetShade { display: block; position: absolute; inset: 0; background: rgba(0, 0, 0, 0.35); z-index: 7; }
  body.collapsed .more { display: block; }          /* everything is available in the sheet */
  #panel .drive .locos, #panel .drive .btns.big, #panel .drive > label.row, #panel #panelToggle { display: none; }
  #sheetClose { display: inline-block; min-width: 44px; min-height: 40px; font-size: 18px; }
  #panel button { min-height: 40px; } .grid button { min-height: 38px; font-size: 13px; }
  .chk { min-height: 34px; } .chk input { width: 20px; height: 20px; }
  details { padding: 10px 0; } summary { font-size: 13px; padding: 6px 0; }
  /* object info: small card at the top */
  #info { left: 8px; right: 8px; top: calc(8px + env(safe-area-inset-top)); width: auto; max-height: 34%; z-index: 6; }
  #infoActions button { min-height: 40px; }
}
