:root {
  --ink: #1a1a2e;
  --muted: #5c6578;
  --line: #e4e7ef;
  --bg: #f4f6fb;
  --card: #ffffff;
  --blue: #3a86ff;
  --ok: #1b7f4e;
  --ok-bg: #e8f7ee;
  --info: #1d4e89;
  --info-bg: #e8f1fb;
  --cell: 32px;
  --cols: 10;
  --rows: 8;
  --wide: 6;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", "Helvetica Neue", sans-serif;
  font-size: 1.125rem;
  color: var(--ink);
  background: var(--bg);
}

button { font: inherit; touch-action: manipulation; }

.site-header {
  text-align: center;
  padding: 28px 16px 8px;
}

.site-header .mark { font-size: 3rem; }

.site-header h1 {
  margin: 4px 0 0;
  font-size: 2.75rem;
  line-height: 1.1;
}

.site-header p {
  margin: 6px 0 0;
  color: var(--muted);
}

.tagline {
  margin: 10px 0 0;
  font-size: 1.35rem;
  font-weight: 700;
  color: #5b2dbe;
}

.lab { font-size: 1rem; }

main {
  width: min(1400px, calc(100% - 32px));
  margin: 0 auto 48px;
}

.banner {
  background: linear-gradient(135deg, #3a86ff 0%, #8338ec 100%);
  color: white;
  border-radius: 16px;
  padding: 20px 24px;
  margin: 18px 0;
  font-size: 1.2rem;
  line-height: 1.45;
}

.banner p { margin: 0 0 8px; }
.banner p:last-child { margin-bottom: 0; }

.banner.error {
  background: #fde8e8;
  color: #8d1d1d;
}

.panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 18px 18px 16px;
  margin-bottom: 18px;
}

.panel h2, .results-title {
  margin: 0 0 8px;
  font-size: 1.6rem;
  line-height: 1.25;
}

.stage-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.clock {
  flex: 0 0 auto;
  min-width: 11rem;
  margin: 0;
  padding: 10px 16px 12px;
  border: 2px solid var(--line);
  border-radius: 14px;
  background: #f8fafc;
  text-align: center;
}

.clock-face {
  margin: 0;
  font-size: 3.25rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.03em;
  line-height: 1;
}

.clock-label {
  margin: 6px 0 0;
  max-width: 14rem;
  color: var(--muted);
  font-size: 1.05rem;
  line-height: 1.3;
}

.clock.running {
  border-color: #3a86ff;
}

.clock.urgent {
  border-color: #e15759;
  background: #fff6f6;
}

.clock.urgent .clock-face { color: #c0392b; }

.clock.done {
  border-color: #1a1a2e;
  background: #1a1a2e;
}

.clock.done .clock-face,
.clock.done .clock-label { color: white; }

body.time-up .piece { cursor: default; }

.results-title { margin-top: 4px; }

.hint, .caption, .summary {
  color: var(--muted);
  margin: 6px 0 12px;
  font-size: 1.125rem;
  line-height: 1.4;
}

.summary.warn { color: #8d4b12; font-weight: 650; }

.picker-actions, .truck-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.picker {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 10px;
}

.type-card {
  display: flex;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px 10px;
  background: #fff;
}

.type-card.off { background: #f7f8fb; }

.swatch {
  width: 12px;
  align-self: stretch;
  border-radius: 6px;
  flex: none;
}

.type-name { flex: 1; min-width: 0; }
.type-name strong { display: block; }
.type-name small { color: var(--muted); }

.stepper {
  display: flex;
  align-items: center;
  gap: 6px;
}

.stepper button, .secondary {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 10px;
  font-weight: 650;
  cursor: pointer;
}

.stepper button {
  width: 36px;
  height: 36px;
  font-size: 1.2rem;
  line-height: 1;
}

.stepper strong {
  min-width: 1.2em;
  text-align: center;
}

.stepper button:disabled, .secondary:disabled, .primary:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.secondary { padding: 8px 12px; }

.play-layout {
  display: grid;
  grid-template-columns: calc(var(--cell) * var(--wide) + 44px) minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

.tray-label, .truck-title {
  font-weight: 700;
  font-size: 1.15rem;
  margin: 0 0 8px;
}

.tray {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
  min-height: 120px;
  max-height: min(640px, 70vh);
  overflow: auto;
  overscroll-behavior: contain;
  padding: 8px;
  border: 2px dashed var(--line);
  border-radius: 12px;
  background: #f8f9fd;
  touch-action: none;
}

.empty-tray {
  margin: 8px;
  color: var(--muted);
}

.rig-body {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

.cargo-frame {
  border: 3px solid #444;
  background: #fff;
}

#cargo {
  position: relative;
  width: calc(var(--cell) * var(--cols));
  height: calc(var(--cell) * var(--rows));
  background-color: #fff;
  background-image:
    linear-gradient(to right, #e4e7ef 1px, transparent 1px),
    linear-gradient(to bottom, #e4e7ef 1px, transparent 1px);
  background-size: var(--cell) var(--cell);
  touch-action: none;
}

.cargo-hint {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0;
  color: var(--muted);
  pointer-events: none;
}

.cab {
  width: calc(var(--cell) * 2.4);
  height: calc(var(--cell) * (var(--rows) - 1.4));
  background: var(--blue);
  border: 3px solid #444;
  border-radius: 16px;
  display: flex;
  justify-content: center;
  padding-top: 10px;
}

.window {
  width: 68%;
  height: 34%;
  background: #b8e0ff;
  border-radius: 8px;
}

.axle {
  height: calc(var(--cell) * 1.15);
  display: flex;
  justify-content: space-evenly;
  align-items: center;
}

.wheel {
  width: calc(var(--cell) * 0.85);
  height: calc(var(--cell) * 0.85);
  background: #2d2d2d;
  border-radius: 50%;
  box-shadow: inset 0 0 0 calc(var(--cell) * 0.22) #888;
}

.piece, #ghost {
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  width: calc(var(--w) * var(--cell));
  height: calc(var(--h) * var(--cell));
  border-radius: 6px;
  font-weight: 700;
  line-height: 1.1;
  font-size: clamp(12px, calc(var(--cell) * 0.48), 18px);
  overflow: hidden;
  user-select: none;
  box-sizing: border-box;
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.85);
  flex: none;
}

.piece {
  cursor: grab;
  touch-action: none;
  padding: 2px;
}

.piece.flat, #ghost.flat {
  white-space: nowrap;
  font-size: clamp(12px, calc(var(--cell) * 0.34), 15px);
}

.piece.on-truck {
  position: absolute;
  left: calc(var(--x) * var(--cell));
  bottom: calc(var(--y) * var(--cell));
  z-index: 1;
}

.piece.lifting { opacity: 0.35; }

#ghost {
  position: fixed;
  z-index: 50;
  margin: 0;
  padding: 2px;
  pointer-events: none;
  box-shadow:
    inset 0 0 0 2px rgba(255, 255, 255, 0.85),
    0 10px 24px rgba(26, 26, 46, 0.2);
}

#ghost.bad { outline: 3px solid #c0392b; }

#preview {
  position: absolute;
  z-index: 3;
  border-radius: 6px;
  pointer-events: none;
}

#preview.ok { background: rgba(27, 127, 78, 0.28); outline: 3px solid var(--ok); }
#preview.bad { background: rgba(192, 57, 43, 0.22); outline: 3px solid #c0392b; }

#ghost[hidden], #preview[hidden] { display: none !important; }

body.dragging, body.dragging .piece { cursor: grabbing; }
body.dragging { touch-action: none; }

#unload { margin-top: 8px; }

.primary {
  width: 100%;
  margin-top: 16px;
  border: 0;
  border-radius: 12px;
  background: linear-gradient(135deg, #3a86ff, #8338ec);
  color: white;
  font-size: 1.25rem;
  font-weight: 700;
  padding: 16px 18px;
  cursor: pointer;
}

.compare {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 16px;
}

.compare h2 { margin: 0 0 8px; font-size: 1.45rem; }

.panel.you {
  border-color: #f0c36a;
  background: #fffaf2;
}

.panel.simple {
  border-color: #d5deee;
  background: #f8fafc;
}

.panel.ai {
  border-color: #c9b6f2;
  background: #f7f2ff;
  box-shadow: 0 0 0 4px rgba(131, 56, 236, 0.16);
}

.role-chip, .ai-badge {
  display: inline-block;
  margin-right: 8px;
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  vertical-align: 3px;
}

.role-chip.you { background: #f6e2b3; color: #7a4e00; }
.role-chip.simple { background: #e4ebf7; color: #1d4e89; }

.ai-badge {
  background: linear-gradient(135deg, #3a86ff, #8338ec);
  color: white;
}

.idea {
  margin: 0 0 8px;
  font-size: 1.125rem;
  line-height: 1.35;
}

.idea strong { color: #5b2dbe; }

.metric.you {
  border-color: #f0c36a;
  background: #fffaf2;
}

.metric.you strong { color: #7a4e00; }

.metric.simple {
  border-color: #d5deee;
  background: #f8fafc;
}

.metric.simple strong { color: #1d4e89; }

.metric.ai {
  border-color: #c9b6f2;
  background: #f7f2ff;
}

.metric.ai strong { color: #5b2dbe; }
.compare .panel { margin-bottom: 0; }

.truck-svg { width: 100%; height: auto; display: block; }

.missed {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 1.05rem;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-top: 16px;
}

.metric {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 1rem;
}

.metric strong { font-size: 2rem; }

.verdict {
  margin: 14px 0 0;
  border-radius: 12px;
  padding: 16px 18px;
  font-size: 1.25rem;
  font-weight: 650;
  line-height: 1.4;
}

.verdict.ok { background: var(--ok-bg); color: var(--ok); }
.verdict.info { background: var(--info-bg); color: var(--info); }

@media (max-width: 980px) {
  .compare { grid-template-columns: 1fr; }
  .metrics { grid-template-columns: 1fr 1fr; }
  .site-header h1 { font-size: 2.2rem; }
  .tagline { font-size: 1.15rem; }
}

@media (max-width: 760px) {
  .stage-head { flex-direction: column; }
  .clock { align-self: stretch; }
  .play-layout { grid-template-columns: minmax(0, 1fr); }
  .tray-column,
  #truck-column {
    min-width: 0;
    max-width: 100%;
  }
  .tray {
    flex-direction: row;
    align-items: flex-end;
    width: 100%;
    max-height: none;
    overflow-x: auto;
    overflow-y: hidden;
  }
}
