:root {
  --bg: #eef3f7;
  --bar: rgba(255, 255, 255, 0.92);
  --text: #1d2733;
  --muted: #5d6b7a;
  --accent: #1e5aa8;
  --accent-text: #fff;
  --danger: #c62828;
  --chip: #e3e9f0;
  --radius: 14px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  -webkit-user-select: none;
  user-select: none;
  touch-action: none;
}

#view {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.bar {
  position: fixed;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: var(--bar);
  box-shadow: 0 1px 8px rgba(0, 0, 0, 0.12);
  z-index: 2;
}
.bar.top { top: 0; }
.bar.bottom { position: relative; flex-wrap: wrap; } /* in the dock */

/* bottom of the screen: the step's parts, then the bar (they never overlap) */
.dock {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 10px;
  pointer-events: none; /* the 3D view beside the parts panel stays usable */
}
.dock > * { pointer-events: auto; }
.dock > .bar { align-self: stretch; }

button {
  font: inherit;
  font-size: 18px;
  min-height: 52px;
  min-width: 52px;
  padding: 0 18px;
  border: 0;
  border-radius: var(--radius);
  background: var(--chip);
  color: var(--text);
  cursor: pointer;
  touch-action: manipulation;
}
button:active { transform: scale(0.97); }
button.primary { background: var(--accent); color: var(--accent-text); font-weight: 600; }
button.danger { background: var(--danger); color: #fff; font-weight: 600; }
button.icon { padding: 0 12px; font-size: 22px; margin-left: auto; }
button.toggle.on, button.mode.active { background: var(--text); color: #fff; }
/* buttons whose text changes keep one width: all texts on top of each other */
.steady { display: inline-grid; justify-items: center; }
.steady > span { grid-area: 1 / 1; display: inline-flex; justify-content: center; }
.steady > .hidden-label { visibility: hidden; }
/* an icon in front of a text, a little apart (the colour toggles: a light picture of bricks, a groove) */
.with-icon { display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
.mode-icon { width: 26px; height: 26px; flex: none; fill: #f4f6f8; stroke: #a9b4bf; stroke-width: 1.2; stroke-linejoin: round; }
button:disabled { opacity: 0.4; }

.run-info {
  flex: 1;
  min-width: 0;
  font-size: 16px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.bar.top button.icon { margin-left: 0; }
button.star { font-size: 26px; color: #c9a227; }

/* the saved runs cover the screen: the current run need not be visible meanwhile */
.panel.saved { left: 14px; right: 14px; bottom: 14px; width: auto; max-height: none; }
.saved-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 12px;
  overflow-y: auto;
  color: var(--muted);
  align-content: start;
  flex: 1;
  min-height: 0;
}
.saved-run {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px;
  border-radius: 12px;
  background: var(--chip);
  color: var(--text);
  cursor: pointer;
  font-size: 15px;
}
.saved-run .run-picture { width: 100%; aspect-ratio: 4 / 3; border-radius: 8px; object-fit: cover; background: var(--bg); }
.saved-run .run-line { display: flex; align-items: center; gap: 8px; }
.saved-run .run-line span { flex: 1; min-width: 0; }
.saved-run small { display: block; color: var(--muted); font-family: ui-monospace, monospace; }
.saved-run .run-icon { font-size: 36px; min-width: 56px; min-height: 56px; padding: 0; background: #fff; flex: none; }
.saved-run .remove { min-height: 40px; min-width: 40px; font-size: 18px; background: transparent; }
.icon-picker { display: grid; grid-template-columns: repeat(auto-fill, minmax(44px, 1fr)); gap: 4px; padding: 6px; background: #fff; border-radius: 10px; }
.icon-picker button { font-size: 26px; min-width: 44px; min-height: 44px; padding: 0; background: transparent; }
.icon-picker button.on { background: var(--accent); }
.icon-picker button.used { opacity: 0.35; }

.modes, .tools { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.tools { margin-left: auto; }
/* view / build: one control of two halves */
.segmented { display: flex; }
.segmented button { border-radius: 0; }
.segmented button:first-child { border-radius: var(--radius) 0 0 var(--radius); }
.segmented button:last-child { border-radius: 0 var(--radius) var(--radius) 0; }
.colors { display: flex; flex-wrap: wrap; gap: 8px; }
.colors-toggle { display: none; }

/* compact bar (app.js: the bar did not fit on one row) */
/* about 366 px wide when building; narrower phones get two rows */
.bar.compact { padding: 8px 10px; gap: 6px; }
.bar.compact .modes, .bar.compact .tools { gap: 6px; flex-wrap: nowrap; }
.bar.compact button { min-width: 44px; min-height: 44px; padding: 0 10px; }
.bar.compact .label { display: none; }
.bar.compact .tools { margin-left: auto; }
.bar.compact .step-label { min-width: 52px; font-size: 16px; }
.bar.compact .colors-toggle { display: inline-block; }
.bar.compact .colors {
  display: none;
  position: absolute;
  left: 14px;
  bottom: calc(100% + 8px);
  flex-direction: column;
  align-items: stretch;
  padding: 10px;
  background: var(--bar);
  border-radius: var(--radius);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.18);
  z-index: 3;
}
.bar.compact .colors.open { display: flex; }
.step { font-size: 26px; padding: 0 24px; }
.step-label { font-size: 18px; font-weight: 600; min-width: 140px; text-align: center; }

.panel {
  position: fixed;
  top: 78px;
  right: 14px;
  width: min(340px, calc(100% - 28px));
  padding: 16px 18px 18px;
  background: var(--bar);
  border-radius: var(--radius);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.18);
  z-index: 3;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.panel h2 { margin: 0; font-size: 20px; }
.panel label { display: flex; flex-direction: column; gap: 6px; font-size: 16px; color: var(--muted); }
.panel output { color: var(--text); font-weight: 600; }
.panel .hint { font-size: 13px; line-height: 1.3; }
.panel input[type="range"] { width: 100%; height: 36px; }
.panel input[type="text"] { font: inherit; font-size: 18px; padding: 10px; border-radius: 10px; border: 1px solid #c8d1db; }

.step-parts {
  margin-left: 14px;
  max-width: min(560px, calc(100% - 28px));
  /* up to the top bar (app.js measures both bars): eight parts fit without scrolling */
  max-height: calc(100vh - var(--top-bar, 72px) - var(--bottom-bar, 72px) - 20px);
  max-height: calc(100dvh - var(--top-bar, 72px) - var(--bottom-bar, 72px) - 20px);
  overflow-y: auto;
  padding: 12px 14px;
  background: var(--bar);
  border-radius: var(--radius);
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.15);
  z-index: 2;
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 17px;
}
.parts-list { display: flex; flex-direction: column; gap: 8px; }
.step-parts .row { display: flex; align-items: center; gap: 10px; }
.step-parts .count { font-weight: 700; min-width: 34px; }
.step-parts .thumb { width: 60px; height: 45px; flex: none; }
.step-parts .row small { display: block; font-size: 13px; color: var(--muted); }
.part-name { display: none; }
/* small screens: the parts as one row of pictures; a tap shows a part's name below */
@media (max-width: 700px), (max-height: 500px) {
  .step-parts { max-width: calc(100% - 28px); padding: 8px 10px; gap: 4px; font-size: 15px; }
  .parts-list { flex-direction: row; overflow-x: auto; gap: 12px; }
  .step-parts .row { flex-direction: column; gap: 2px; flex: none; padding: 2px 4px; border-radius: 8px; }
  .step-parts .row.open { background: var(--chip); }
  .step-parts .row > span:last-child { display: none; }
  .step-parts .count { min-width: 0; }
  .part-name { display: block; font-size: 14px; color: var(--muted); min-height: 1.2em; }
}
.swatch { width: 26px; height: 20px; border-radius: 5px; border: 1px solid rgba(0, 0, 0, 0.2); flex: none; }


.status {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  padding: 14px 22px;
  background: var(--bar);
  border-radius: var(--radius);
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.15);
  font-size: 18px;
  z-index: 4;
}
.status:empty { display: none; }

@media (max-width: 700px) {
  button { font-size: 16px; min-height: 46px; padding: 0 12px; }
  .step { padding: 0 16px; }
  .step-label { min-width: 90px; font-size: 16px; }
  .bar.bottom .tools { margin-left: 0; }
}

.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.panel-head .close { margin-left: auto; font-size: 22px; }

/* dialogs: confirmations, a saved run large */
.modal {
  position: fixed;
  inset: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(20, 30, 40, 0.45);
}
.modal-box {
  max-width: min(900px, 100%);
  max-height: 100%;
  overflow-y: auto;
  padding: 18px;
  background: var(--bar);
  border-radius: var(--radius);
  box-shadow: 0 6px 28px rgba(0, 0, 0, 0.25);
  display: flex;
  flex-direction: column;
  gap: 14px;
  font-size: 18px;
}
.modal-box p { margin: 0; }
.modal-buttons { display: flex; justify-content: flex-end; gap: 10px; }
.run-detail img { width: 100%; max-height: calc(100vh - 220px); object-fit: contain; border-radius: 10px; background: var(--bg); }
.run-detail .run-line { display: flex; align-items: center; gap: 12px; }
.run-detail .big-icon { font-size: 44px; }
.run-detail small { display: block; color: var(--muted); font-family: ui-monospace, monospace; }
