/* How a Kart Works — dark precision-engineering theme */
:root {
  --bg: #10141a;
  --panel: rgba(22, 27, 34, 0.86);
  --panel-border: rgba(140, 160, 180, 0.14);
  --text: #dde4ea;
  --text-dim: #8b97a3;
  --accent: #2ecc71;
  --accent-dim: #1f7a46;
  --hot: #ff9f43;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, monospace;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Noto Sans JP", "Segoe UI", sans-serif;
  font-size: 14px;
  display: flex;
  flex-direction: column;
}

/* ---------------- header */
header {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 10px 18px;
  border-bottom: 1px solid var(--panel-border);
  background: rgba(16, 20, 26, 0.9);
  z-index: 20;
}
.brand h1 { font-size: 17px; font-weight: 700; letter-spacing: 0.02em; }
.brand p { font-size: 11px; color: var(--text-dim); margin-top: 1px; }
.tabs { display: flex; gap: 4px; margin-left: 12px; }
.tab {
  appearance: none; border: 1px solid transparent; background: transparent;
  color: var(--text-dim); font-size: 13px; font-weight: 600;
  padding: 7px 16px; border-radius: 8px; cursor: pointer;
}
.tab:hover { color: var(--text); }
.tab.active {
  color: var(--accent);
  background: rgba(46, 204, 113, 0.09);
  border-color: rgba(46, 204, 113, 0.3);
}
.header-actions { margin-left: auto; display: flex; gap: 8px; }
.icon-btn {
  appearance: none; border: 1px solid var(--panel-border); background: var(--panel);
  color: var(--text); font-size: 13px; padding: 6px 12px; border-radius: 8px; cursor: pointer;
}
.icon-btn:hover { border-color: var(--accent-dim); }
.icon-btn.off { opacity: 0.4; text-decoration: line-through; }
.icon-btn.lang { font-weight: 700; min-width: 64px; }

/* view (panel) toggles */
.view-toggles { display: flex; gap: 6px; align-items: center; }
.vt {
  appearance: none; border: 1px solid var(--panel-border); background: var(--panel);
  color: var(--text-dim); font-size: 12.5px; font-weight: 600;
  padding: 6px 12px; border-radius: 8px; cursor: pointer; white-space: nowrap;
}
.vt:hover { color: var(--text); border-color: var(--accent-dim); }
.vt.on { color: var(--accent); background: rgba(46, 204, 113, 0.10); border-color: rgba(46, 204, 113, 0.32); }

/* ---------------- main / canvas */
main { position: relative; flex: 1; min-height: 0; }
#c { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
#labels { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
#loading {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-size: 15px; color: var(--text-dim); background: var(--bg); z-index: 30;
}

/* ---------------- panels */
.panel {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  padding: 14px;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}
.panel h2 {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.12em;
  color: var(--text-dim); margin-bottom: 10px;
}
#left {
  position: absolute; top: 14px; left: 14px; bottom: 14px;
  width: 268px; display: flex; flex-direction: column; gap: 12px; z-index: 10;
  pointer-events: none;
}
#left .panel { pointer-events: auto; max-height: 100%; overflow: hidden auto; }
#right {
  position: absolute; top: 14px; right: 14px; bottom: 14px;
  width: 288px; display: flex; flex-direction: column; gap: 12px; z-index: 10;
  overflow: hidden auto; pointer-events: none;
}
#right .panel { pointer-events: auto; flex-shrink: 0; }

/* panel show/hide (toggleable overlays) */
#left, #right, #stepCard { transition: opacity 0.2s ease, visibility 0.2s; }
#left.off, #right.off, #stepCard.off { opacity: 0; visibility: hidden; pointer-events: none; }

/* mode visibility */
body[data-mode="learn"] .viewer-only { display: none !important; }
body[data-mode="viewer"] .learn-only { display: none !important; }

/* ---------------- chapters */
.chapter {
  display: flex; align-items: baseline; gap: 10px; width: 100%;
  appearance: none; background: transparent; border: none; text-align: left;
  color: var(--text-dim); font-size: 13px; line-height: 1.4;
  padding: 8px 8px; border-radius: 8px; cursor: pointer;
}
.chapter:hover { background: rgba(140, 160, 180, 0.08); color: var(--text); }
.chapter.active { color: var(--accent); background: rgba(46, 204, 113, 0.08); }
.chapter .num { font-family: var(--mono); font-size: 11px; opacity: 0.7; }

/* ---------------- part tree */
#partTree details { margin-bottom: 2px; }
#partTree summary {
  display: flex; align-items: center; gap: 8px;
  list-style: none; cursor: pointer; padding: 7px 6px; border-radius: 8px;
  font-weight: 600; font-size: 13px;
}
#partTree summary::-webkit-details-marker { display: none; }
#partTree summary:hover { background: rgba(140, 160, 180, 0.08); }
#partTree summary .count {
  margin-left: auto; font-family: var(--mono); font-size: 10px;
  color: var(--text-dim); background: rgba(140, 160, 180, 0.12);
  padding: 1px 7px; border-radius: 8px;
}
.part-row {
  display: flex; align-items: center; gap: 8px;
  padding: 4px 6px 4px 24px; font-size: 12.5px; color: var(--text-dim);
  border-radius: 6px; cursor: pointer;
}
.part-row:hover { background: rgba(46, 204, 113, 0.08); color: var(--text); }
input[type="checkbox"] { accent-color: var(--accent); }

/* ---------------- viewer controls */
button.big {
  width: 100%; padding: 11px; font-size: 14px; font-weight: 700;
  border-radius: 10px; border: 1px solid rgba(46, 204, 113, 0.4);
  background: rgba(46, 204, 113, 0.12); color: var(--accent); cursor: pointer;
  margin-bottom: 12px;
}
button.big.on {
  background: rgba(255, 90, 70, 0.12); border-color: rgba(255, 90, 70, 0.4); color: #ff6b5b;
}
button.small, .hold {
  appearance: none; border: 1px solid var(--panel-border); background: rgba(140,160,180,0.08);
  color: var(--text); font-size: 12px; padding: 6px 12px; border-radius: 8px; cursor: pointer;
  white-space: nowrap;
}
button.small:hover, .hold:hover { border-color: var(--accent-dim); }
button.small.primary {
  background: rgba(46, 204, 113, 0.14); border-color: rgba(46, 204, 113, 0.4); color: var(--accent);
}
button.small:disabled { opacity: 0.3; cursor: default; }
.hold:active { background: rgba(46, 204, 113, 0.25); }
.ctl { margin-bottom: 10px; }
.ctl label { display: block; font-size: 11.5px; color: var(--text-dim); margin-bottom: 4px; }
.ctl .row { display: flex; gap: 8px; align-items: center; }
.ctl input[type="range"] { flex: 1; }
input[type="range"] { accent-color: var(--accent); height: 22px; }
.ctl-grid { display: flex; gap: 10px; margin-bottom: 10px; }
.ctl-grid label { flex: 1; font-size: 11.5px; color: var(--text-dim); display: flex; flex-direction: column; gap: 4px; }
select {
  background: #1a2028; color: var(--text); border: 1px solid var(--panel-border);
  border-radius: 7px; padding: 5px 8px; font-size: 12px; width: 100%;
}
.toggles { display: flex; flex-direction: column; gap: 6px; margin-bottom: 10px; }
.toggles label { display: flex; gap: 8px; align-items: center; font-size: 12.5px; color: var(--text-dim); cursor: pointer; }
.toggles label:hover { color: var(--text); }

/* ---------------- readouts */
.rpm-bar {
  height: 8px; background: rgba(140, 160, 180, 0.12); border-radius: 4px;
  overflow: hidden; margin-bottom: 10px;
}
#barRpm {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, var(--accent) 0%, var(--accent) 65%, var(--hot) 85%, #ff5a46 100%);
  border-radius: 4px;
}
.r-row {
  display: flex; justify-content: space-between; align-items: baseline;
  padding: 3px 0; font-size: 12px; color: var(--text-dim);
}
.r-row b { font-family: var(--mono); font-size: 12.5px; color: var(--text); font-weight: 600; }
.r-row.hot b { color: var(--hot); }
.r-sep { border-top: 1px dashed var(--panel-border); margin: 7px 0; }
.note { font-size: 10.5px; color: var(--text-dim); margin-top: 6px; line-height: 1.5; }

/* ---------------- step card (learn) */
#stepCard {
  position: absolute; left: 50%; bottom: 18px; transform: translateX(-50%);
  width: min(720px, calc(100% - 320px));
  background: var(--panel); border: 1px solid var(--panel-border); border-radius: 14px;
  padding: 16px 20px; z-index: 10;
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
}
#stepCard .pos { font-family: var(--mono); font-size: 11px; color: var(--accent); margin-bottom: 5px; }
#stepCard h3 { font-size: 16px; margin-bottom: 6px; }
#stepCard p { font-size: 13.5px; line-height: 1.75; color: #c3ccd4; }
#stepCard .nav { display: flex; align-items: center; gap: 12px; margin-top: 12px; }
#stepCard .keyhint { flex: 1; text-align: center; font-size: 10.5px; color: var(--text-dim); }

/* ---------------- callouts */
.callout {
  position: absolute; transform: translate(-50%, -130%);
  font-family: var(--mono); font-size: 12px; font-weight: 600;
  background: rgba(20, 26, 32, 0.92); color: var(--text);
  border: 1px solid var(--panel-border); border-radius: 8px;
  padding: 4px 10px; white-space: nowrap; pointer-events: none;
}
.callout.measure { color: var(--accent); border-color: rgba(46, 204, 113, 0.4); }
.callout.measure.hot { color: var(--hot); border-color: rgba(255, 159, 67, 0.45); }
.callout.note { font-family: inherit; font-weight: 500; }
.callout:empty { display: none !important; }
.callout::after {
  content: ""; position: absolute; left: 50%; top: 100%; transform: translateX(-50%);
  border: 5px solid transparent; border-top-color: rgba(20, 26, 32, 0.92);
}

/* ---------------- info card */
#infoCard {
  position: absolute; right: 316px; bottom: 18px; width: 300px;
  background: var(--panel); border: 1px solid var(--panel-border); border-radius: 14px;
  padding: 16px; z-index: 11; display: none;
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
}
body[data-mode="learn"] #infoCard { right: 18px; }
#infoCard.open { display: block; }
#infoCard .close {
  position: absolute; top: 8px; right: 10px; appearance: none; border: none;
  background: transparent; color: var(--text-dim); font-size: 16px; cursor: pointer;
}
#infoCard .sub {
  display: inline-block; font-size: 10px; letter-spacing: 0.08em; color: var(--accent);
  background: rgba(46, 204, 113, 0.1); border-radius: 6px; padding: 2px 8px; margin-bottom: 6px;
}
#infoCard h3 { font-size: 15px; margin-bottom: 6px; }
#infoCard p { font-size: 12.5px; line-height: 1.7; color: #c3ccd4; }

/* ---------------- hint */
#hint {
  position: absolute; left: 50%; top: 12px; transform: translateX(-50%);
  font-size: 11px; color: var(--text-dim); z-index: 5;
  background: rgba(16, 20, 26, 0.6); padding: 4px 14px; border-radius: 12px;
  pointer-events: none;
}

/* ---------------- narrow screens (tablet) */
@media (max-width: 900px) {
  #left { width: 240px; }
  #right { width: 260px; }
  #stepCard { width: calc(100% - 24px); left: 12px; transform: none; bottom: 12px; }
  #hint { display: none; }
}

/* ---------------- phones */
@media (max-width: 640px) {
  header { flex-wrap: wrap; gap: 8px 10px; padding: 8px 10px; }
  .brand p { display: none; }
  .brand h1 { font-size: 15px; }
  .tabs { margin-left: 0; }
  .tab { padding: 6px 11px; font-size: 12px; }
  .header-actions { gap: 6px; }
  .icon-btn { padding: 6px 10px; }
  .icon-btn.lang { min-width: 0; }
  .vt { padding: 6px 10px; font-size: 12px; }

  #left, #right { top: 8px; bottom: 8px; width: min(86vw, 310px); }
  #left { left: 8px; }
  #right { right: 8px; }

  #stepCard {
    width: calc(100% - 16px); left: 8px; bottom: 8px;
    max-height: 44vh; overflow-y: auto; padding: 12px 14px;
  }
  #stepCard h3 { font-size: 15px; }
  #stepCard p { font-size: 13px; line-height: 1.6; }
  #stepCard .nav { margin-top: 10px; }

  #infoCard { left: 8px; right: 8px; width: auto; bottom: 8px; }
  body[data-mode="learn"] #infoCard { right: 8px; }
}
.scroll { overflow-y: auto; }
