/* styles.css — the 積み付けシミュレータ web planner.
   Layout mirrors the iOS tab: settings bar on top, Create rail on the left,
   the 3D stage in the middle, the Simulate bar at the bottom. */

:root {
  color-scheme: light dark;
  --bg: #eef1f5;
  --panel: #ffffff;
  --panel-2: #e4eaf1;
  --border: #c7d2de;
  --text: #0d141c;
  --text-dim: #566573;
  --accent: #0b8f79;
  --accent-text: #ffffff;
  --canvas: #cbd4de;
  --canvas-line: #7a8b9c;
  --good: #2c7a51;
  --warn: #a96410;
  --bad: #a93226;
  --shadow: 0 8px 28px rgba(13, 20, 28, 0.12);
  --radius: 14px;
  --rail: 168px;
  --editor: 340px;
  --ui: "Noto Sans JP", system-ui, -apple-system, "Hiragino Sans", "Yu Gothic", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d141c;
    --panel: #16202b;
    --panel-2: #1e2a38;
    --border: #2b3a4a;
    --text: #e9eff5;
    --text-dim: #93a4b5;
    --accent: #47dbc4;
    --accent-text: #06231f;
    --canvas: #1b2733;
    --canvas-line: #55697d;
    --good: #4cc98a;
    --warn: #e3a44a;
    --bad: #e8705f;
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  }
}

:root[data-theme="dark"] {
  --bg: #0d141c;
  --panel: #16202b;
  --panel-2: #1e2a38;
  --border: #2b3a4a;
  --text: #e9eff5;
  --text-dim: #93a4b5;
  --accent: #47dbc4;
  --accent-text: #06231f;
  --canvas: #1b2733;
  --canvas-line: #55697d;
  --good: #4cc98a;
  --warn: #e3a44a;
  --bad: #e8705f;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
}

* { box-sizing: border-box; }

/* Component styles set display, so [hidden] needs to win over them. */
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--ui);
  font-size: 14px;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
}

button, input, select, textarea { font: inherit; color: inherit; }

button { cursor: pointer; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.app {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  height: 100%;
  gap: 0;
}

/* ---------------------------------------------------------- settings bar */

.bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}

.bar.bottom {
  border-bottom: none;
  border-top: 1px solid var(--border);
  padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px));
  gap: 6px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  letter-spacing: 0.01em;
  white-space: nowrap;
}

.brand svg { width: 22px; height: 22px; color: var(--accent); }

.spacer { flex: 1 1 auto; }

.tool {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel-2);
  color: var(--text);
  white-space: nowrap;
}

.tool:hover { border-color: var(--accent); }

.tool.icon { padding: 6px 8px; }

.tool svg { width: 16px; height: 16px; }

.tool select {
  border: none;
  background: transparent;
  padding: 0;
  max-width: 128px;
}

.tool-label {
  font-size: 11px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.tool[aria-pressed="true"] { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }

details.menu { position: relative; }

details.menu > summary { list-style: none; cursor: pointer; }

details.menu > summary::-webkit-details-marker { display: none; }

/* ------------------------------------------------------------- workspace */

.workspace {
  position: relative;
  display: grid;
  grid-template-columns: var(--rail) minmax(0, 1fr);
  min-height: 0;
  gap: 10px;
  padding: 10px;
}

.workspace.with-editor { grid-template-columns: var(--rail) var(--editor) minmax(0, 1fr); }

.rail {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}

.rail-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  padding-left: 4px;
}

.rail button {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
  text-align: left;
}

.rail button svg { width: 20px; height: 20px; flex: none; color: var(--accent); }

.rail-text { min-width: 0; }

.rail button strong { display: block; font-size: 13px; font-weight: 600; }

.rail button .rail-detail { display: block; font-size: 11px; color: var(--text-dim); }

.rail button[aria-expanded="true"] { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }

/* ---------------------------------------------------------------- editor */

.editor {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.editor-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--panel-2);
}

.editor-head h2 { margin: 0; font-size: 14px; }

.editor-body { overflow: auto; padding: 12px; display: flex; flex-direction: column; gap: 14px; }

.group {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--panel);
}

.group > h3 {
  margin: 0;
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-dim);
}

.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.row > label { flex: 1 1 120px; font-size: 13px; }

.row input[type="text"], .row input[type="number"], .row select, .editor-body textarea {
  flex: 1 1 90px;
  min-width: 0;
  padding: 7px 9px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--bg);
}

.row input[type="number"] { font-family: var(--mono); text-align: right; }

.unit { color: var(--text-dim); font-size: 12px; min-width: 22px; }

.list-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  width: 100%;
  text-align: left;
}

.list-item:hover { border-color: var(--accent); }

.list-item .meta { font-size: 11px; color: var(--text-dim); font-family: var(--mono); }

.swatch { width: 20px; height: 20px; border-radius: 5px; border: 1.5px solid #000; flex: none; }

.palette { display: grid; grid-template-columns: repeat(10, 1fr); gap: 5px; }

.palette button {
  aspect-ratio: 1;
  border-radius: 5px;
  border: 1.5px solid #000;
  padding: 0;
  position: relative;
}

.palette button[aria-pressed="true"]::after {
  content: "";
  position: absolute;
  inset: -4px;
  border: 2px solid var(--accent);
  border-radius: 8px;
}

.link { background: none; border: none; color: var(--accent); padding: 4px 0; font-weight: 600; }

.danger { color: var(--bad); }

.aside { color: var(--warn); }

.issue { color: var(--warn); font-size: 12px; display: flex; gap: 6px; align-items: flex-start; }

.hint-text { font-size: 12px; color: var(--text-dim); }

.slider-row { display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; align-items: center; }

.slider-row input[type="range"] { grid-column: 1 / -1; width: 100%; accent-color: var(--accent); }

.slider-row .value { font-family: var(--mono); font-weight: 600; }

/* ----------------------------------------------------------------- stage */

.stage {
  position: relative;
  min-height: 0;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--canvas);
  border: 1px solid var(--border);
}

#scene { display: block; width: 100%; height: 100%; touch-action: none; cursor: grab; }

#scene:active { cursor: grabbing; }

.stage-top, .stage-bottom {
  position: absolute;
  left: 10px;
  right: 10px;
  display: flex;
  gap: 8px;
  pointer-events: none;
}

.stage-top { top: 10px; align-items: flex-start; flex-wrap: wrap; }

.stage-bottom { bottom: 10px; flex-direction: column; align-items: stretch; gap: 8px; }

.stage-top > *, .stage-bottom > * { pointer-events: auto; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--panel) 88%, transparent);
  border: 1px solid var(--border);
  font-size: 12px;
  font-weight: 600;
  backdrop-filter: blur(6px);
}

.chip.warn { background: var(--bad); color: #fff; border-color: transparent; }

.views { margin-left: auto; display: flex; gap: 4px; flex-wrap: wrap; justify-content: flex-end; }

.views button {
  padding: 5px 9px;
  font-size: 12px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: color-mix(in srgb, var(--panel) 88%, transparent);
  backdrop-filter: blur(6px);
}

.views button:hover { border-color: var(--accent); }

.card {
  background: color-mix(in srgb, var(--panel) 92%, transparent);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
  backdrop-filter: blur(8px);
  box-shadow: var(--shadow);
}

.step-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.step-head .num { font-weight: 700; font-family: var(--mono); }

.step-head .dim { color: var(--text-dim); font-size: 12px; margin-left: auto; font-family: var(--mono); }

.checks { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 3px 12px; margin-top: 6px; }

.check { display: flex; align-items: center; gap: 6px; font-size: 12px; }

.check b { font-family: var(--mono); }

.check .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--good); flex: none; }

.results-pill {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: center;
  align-self: center;
  padding: 7px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: color-mix(in srgb, var(--panel) 92%, transparent);
  backdrop-filter: blur(8px);
  font-size: 12px;
}

.results-pill b { font-family: var(--mono); }

.results-pill .off { color: var(--warn); }

.playback { display: flex; align-items: center; gap: 8px; }

.playback input[type="range"] { flex: 1 1 auto; min-width: 60px; accent-color: var(--accent); }

.playback .count { font-family: var(--mono); font-size: 12px; min-width: 52px; text-align: center; }

.icon-button {
  width: 34px;
  height: 34px;
  display: inline-grid;
  place-items: center;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--panel);
  flex: none;
}

.icon-button:hover { border-color: var(--accent); }

.icon-button svg { width: 16px; height: 16px; }

.stage-hint {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  pointer-events: none;
  padding: 20px;
  text-align: center;
}

.stage-hint span {
  background: color-mix(in srgb, var(--panel) 92%, transparent);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 600;
  backdrop-filter: blur(6px);
}

/* --------------------------------------------------------- simulate bar */

.picker { position: relative; flex: 1 1 0; min-width: 0; }

.picker > summary {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--panel-2);
  cursor: pointer;
  min-height: 48px;
  justify-content: center;
}

.picker > summary::-webkit-details-marker { display: none; }

.picker > summary .label { font-size: 10px; text-transform: uppercase; letter-spacing: 0.07em; color: var(--text-dim); }

.picker > summary .value { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.picker[open] > summary { border-color: var(--accent); }

.picker-menu {
  position: absolute;
  bottom: calc(100% + 6px);
  left: 0;
  min-width: 260px;
  max-width: min(92vw, 380px);
  max-height: min(60vh, 420px);
  overflow: auto;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 8px;
  z-index: 20;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.picker-menu h4 {
  margin: 6px 4px 2px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
}

.option {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 8px;
  border-radius: 9px;
  border: 1px solid transparent;
  background: none;
  width: 100%;
  text-align: left;
}

.option:hover { background: var(--panel-2); }

.option[aria-checked="true"], .option[aria-selected="true"] { border-color: var(--accent); }

.option .meta { margin-left: auto; font-size: 11px; color: var(--text-dim); font-family: var(--mono); }

.run {
  flex: none;
  min-width: 78px;
  min-height: 48px;
  border: none;
  border-radius: 12px;
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.run[disabled] { opacity: 0.45; cursor: not-allowed; }

/* --------------------------------------------------------------- dialogs */

dialog {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--text);
  padding: 0;
  max-width: min(560px, 94vw);
  width: 100%;
  box-shadow: var(--shadow);
}

dialog::backdrop { background: rgba(6, 12, 18, 0.55); }

.dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}

.dialog-head h2 { margin: 0; font-size: 15px; }

.dialog-body { padding: 14px; max-height: min(70vh, 560px); overflow: auto; display: flex; flex-direction: column; gap: 10px; }

.result-row { display: flex; align-items: baseline; gap: 10px; padding: 7px 0; border-bottom: 1px solid var(--border); }

.result-row:last-child { border-bottom: none; }

.result-row .name { flex: 1 1 auto; }

.result-row .value { font-family: var(--mono); font-weight: 600; }

.result-row .note { flex-basis: 100%; font-size: 12px; color: var(--text-dim); }

.badge { font-size: 11px; padding: 1px 7px; border-radius: 999px; font-weight: 700; }

.badge.ok { background: color-mix(in srgb, var(--good) 20%, transparent); color: var(--good); }

.badge.off { background: color-mix(in srgb, var(--warn) 22%, transparent); color: var(--warn); }

.dialog-body textarea { width: 100%; min-height: 220px; font-family: var(--mono); font-size: 12px; }

/* ----------------------------------------------------------- responsive */

@media (max-width: 1100px) {
  :root { --rail: 120px; --editor: 300px; }
}

@media (max-width: 860px) {
  :root { --rail: 62px; }
  .rail-title { display: none; }
  .rail button { flex-direction: column; gap: 3px; padding: 9px 4px; text-align: center; }
  .rail button .rail-detail { display: none; }
  .rail button strong { font-size: 11px; }
  .workspace.with-editor { grid-template-columns: var(--rail) minmax(0, 1fr); }
  /* The editor becomes a sheet over the lower stage, so the 3D view stays visible. */
  .editor {
    position: absolute;
    left: 10px;
    right: 10px;
    bottom: 10px;
    top: 42%;
    z-index: 30;
    box-shadow: var(--shadow);
  }
  .stage-bottom { display: none; }
  .workspace.with-editor .stage-top .views { display: none; }
}

@media (max-width: 620px) {
  .bar.top { flex-wrap: wrap; row-gap: 6px; }
  .brand span { display: none; }
  .tool .tool-label { display: none; }
  .tool select { max-width: 92px; }
  .picker > summary .value { font-size: 12px; }
  .run { min-width: 56px; }
  .run span { display: none; }
  .checks { grid-template-columns: 1fr 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
