/* 無機質な工場のUI。情報密度は高く、色は抑えめに。 */
:root {
  --bg: #14161b;
  --panel: #1b1e25;
  --panel-2: #21252d;
  --line: #2e333d;
  --text: #dfe3ea;
  --muted: #8b93a3;
  --accent: #7fd7ff;
  --good: #5fd39a;
  --warn: #e8c05a;
  --danger: #e05a5a;
  --gold: #c9a227;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", "Hiragino Sans", "Noto Sans JP", system-ui, sans-serif;
  font-size: 13px;
  overflow: hidden;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
}

h2 {
  margin: 14px 0 6px;
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
  padding-bottom: 4px;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100%;
}
#app.hidden {
  display: none;
}

/* ------------------------------------------------------------ トップバー */

#topbar {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 8px 14px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
}

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

.stats {
  display: flex;
  gap: 16px;
}
.stat {
  display: flex;
  flex-direction: column;
  min-width: 74px;
}
.stat label {
  font-size: 10px;
  color: var(--muted);
  letter-spacing: 0.1em;
}
.stat span {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}
.stat span.negative {
  color: var(--danger);
}
.stat.rank {
  min-width: 190px;
}
.stat.rank small {
  color: var(--muted);
  font-size: 9.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 190px;
}
.rank-bar {
  height: 3px;
  background: var(--panel-2);
  border-radius: 2px;
  overflow: hidden;
  margin: 3px 0 2px;
}
#rank-fill {
  height: 100%;
  width: 0%;
  background: var(--gold);
}

.phase-block {
  flex: 1 1 auto;
  min-width: 240px;
}
#phase-badges {
  display: flex;
  gap: 4px;
}
.badge {
  flex: 1;
  text-align: center;
  padding: 3px 6px;
  font-size: 11px;
  border-radius: 3px;
  background: var(--panel-2);
  color: var(--muted);
  border: 1px solid transparent;
  white-space: nowrap;
}
.badge.active {
  background: #2b3a44;
  color: var(--accent);
  border-color: var(--accent);
}
#shift-bar {
  margin-top: 5px;
  height: 4px;
  background: var(--panel-2);
  border-radius: 2px;
  overflow: hidden;
}
#shift-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  transition: width 0.1s linear;
}

.controls {
  display: flex;
  align-items: center;
  gap: 8px;
}
button.primary {
  background: #2f6d52;
  border: 1px solid #48a077;
  border-radius: 4px;
  padding: 7px 14px;
  font-weight: 600;
  white-space: nowrap;
}
button.primary:hover {
  background: #3b8767;
}
button.primary:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
button.ghost {
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 4px;
  width: 28px;
  height: 28px;
}
#btn-flow {
  width: auto;
  padding: 0 10px;
  font-size: 11px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 4px;
}
#btn-flow.active {
  background: rgba(56, 189, 248, 0.2);
  border-color: #38bdf8;
  color: #38bdf8;
}
.audio {
  display: flex;
  align-items: center;
  gap: 5px;
}
.audio input[type='range'] {
  width: 64px;
  accent-color: var(--accent);
  cursor: pointer;
}
button.ghost.off {
  opacity: 0.4;
}

.speeds {
  display: flex;
  gap: 2px;
}
button.speed {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 5px 8px;
  font-size: 11px;
}
button.speed.active {
  border-color: var(--accent);
  color: var(--accent);
}

/* ------------------------------------------------------------ レイアウト */

main {
  display: flex;
  flex: 1 1 auto;
  min-height: 0;
}

#palette,
#sidebar {
  background: var(--panel);
  padding: 6px 10px 14px;
  overflow-y: auto;
  flex: 0 0 auto;
}
#palette {
  width: 218px;
  border-right: 1px solid var(--line);
}
#sidebar {
  width: 276px;
  border-left: 1px solid var(--line);
}

.hint {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.5;
  margin: 0 0 8px;
}

#stage {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
  min-width: 0;
  background:
    radial-gradient(circle at 50% 30%, #1c1f26 0%, #101216 100%);
}
#canvas {
  /* ドット絵なので拡大時に補間させない */
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  box-shadow: 0 0 0 1px var(--line), 0 18px 50px #0008;
}

/* ------------------------------------------------------------ パレット */

.tool {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 2px 6px;
  width: 100%;
  text-align: left;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 7px 9px;
  margin-bottom: 5px;
}
.tool:hover {
  border-color: #4a5364;
}
.tool.active {
  border-color: var(--accent);
  background: #23323b;
}
.tool-name {
  font-weight: 600;
}
.tool-cost {
  color: var(--gold);
  font-variant-numeric: tabular-nums;
  font-size: 11px;
}
.tool-desc {
  grid-column: 1 / -1;
  color: var(--muted);
  font-size: 10.5px;
  line-height: 1.45;
}
.tool-key {
  color: var(--muted);
  font-size: 10px;
}

.tool.locked {
  opacity: 0.42;
  cursor: not-allowed;
}
.tool .lock {
  color: var(--muted);
  font-size: 10px;
}

#stat-power.short {
  color: var(--danger);
}

.mat {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 1px 6px;
  width: 100%;
  text-align: left;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 5px 8px;
  margin-bottom: 4px;
}
.mat.active {
  border-color: var(--accent);
  background: #23323b;
}
.mat.locked {
  opacity: 0.4;
  cursor: not-allowed;
}
.mat .price {
  color: var(--gold);
  font-size: 10.5px;
  font-variant-numeric: tabular-nums;
}
.mat .detail {
  grid-column: 1 / -1;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.4;
}

/* --- 開発ツリー --- */
.tech-tree {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding-bottom: 6px;
}
.tech-col {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 210px;
}
.tech-node {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 8px 10px;
  text-align: left;
  width: 100%;
}
.tech-node.done {
  border-color: var(--good);
  background: #1f2d26;
}
.tech-node.ready {
  border-color: var(--accent);
}
.tech-node.locked {
  opacity: 0.45;
}
.tech-node h4 {
  margin: 0 0 3px;
  font-size: 12.5px;
}
.tech-node p {
  margin: 0 0 5px;
  font-size: 10.5px;
  line-height: 1.5;
  color: var(--muted);
}
.tech-node .rp {
  color: var(--gold);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}
.tech-node .req {
  color: var(--danger);
  font-size: 10px;
}

.break-plan {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 1px 6px;
  width: 100%;
  text-align: left;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 5px 8px;
  margin-bottom: 4px;
}
.break-plan.active {
  border-color: var(--accent);
  background: #23323b;
}
.break-plan .len {
  color: var(--gold);
  font-size: 10.5px;
  font-variant-numeric: tabular-nums;
}
.break-plan .desc {
  grid-column: 1 / -1;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.4;
}

#stat-paper.warn {
  color: var(--warn);
}
#stat-paper.bad {
  color: var(--danger);
}
#stat-safe.warn {
  color: var(--danger);
}
#stat-safe.good {
  color: var(--good);
}

.toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 10px;
  color: var(--muted);
  font-size: 11px;
  cursor: pointer;
}

/* ------------------------------------------------------------ サイドバー */

.cat-card {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 7px 9px;
  margin-bottom: 5px;
  cursor: pointer;
}
.cat-card.selected {
  border-color: var(--accent);
}
.cat-card.offduty {
  opacity: 0.45;
}
.cat-head {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 5px;
}
.cat-swatch {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  flex: 0 0 auto;
}
.cat-name {
  font-weight: 600;
}
.cat-state {
  margin-left: auto;
  font-size: 10.5px;
  color: var(--muted);
}
.cat-lives {
  font-size: 10.5px;
  color: var(--gold);
}
.meter {
  display: grid;
  grid-template-columns: 38px 1fr;
  align-items: center;
  gap: 5px;
  font-size: 10px;
  color: var(--muted);
  margin-bottom: 2px;
}
.meter-bar {
  display: block;
  height: 5px;
  background: #00000055;
  border-radius: 3px;
  overflow: hidden;
}
.meter-fill {
  display: block;
  height: 100%;
}

.risk-row {
  display: grid;
  grid-template-columns: 1fr 46px;
  align-items: center;
  gap: 6px;
  margin-bottom: 3px;
  font-size: 11px;
}
.risk-bar {
  display: block;
  height: 6px;
  background: #00000055;
  border-radius: 3px;
  overflow: hidden;
}
.risk-fill {
  display: block;
  height: 100%;
}
.risk-mitigated {
  color: var(--good);
  font-size: 10px;
}

#log-list {
  font-size: 11px;
  line-height: 1.55;
  max-height: 260px;
  overflow-y: auto;
}
.log-line {
  padding: 2px 0;
  border-bottom: 1px solid #ffffff08;
}
.log-line.warn {
  color: var(--warn);
}
.log-line.danger {
  color: var(--danger);
}
.log-line.good {
  color: var(--good);
}
.log-time {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  margin-right: 6px;
}

/* ------------------------------------------------------------ トースト・ツールチップ */

#toast {
  position: absolute;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: #000000cc;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 7px 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}
#toast.show {
  opacity: 1;
}

#tooltip {
  position: absolute;
  background: #000000e0;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 5px 8px;
  font-size: 11px;
  line-height: 1.5;
  pointer-events: none;
  white-space: pre;
  display: none;
  z-index: 5;
}

/* ------------------------------------------------------------ タイトル画面 */

#title-screen {
  position: fixed;
  inset: 0;
  z-index: 30;
  background:
    radial-gradient(circle at 50% 28%, #23262f 0%, #14161b 68%);
  /* flexでの中央寄せは中身が画面より縦長になった時に上端が画面外へ押し出されて
     戻れなくなる (overflow時のクリッピング問題) ため、block auto-margin で寄せる。
     これなら中身が伸びても常に上からスクロールして全部見える。 */
  overflow-y: auto;
}
#title-screen.hidden {
  display: none;
}

.title-card {
  width: min(440px, 92vw);
  margin: 8vh auto;
  text-align: center;
  padding: 40px 32px;
}
.title-logo {
  font-size: 48px;
  margin-bottom: 6px;
  filter: drop-shadow(0 4px 12px #000a);
}
.title-heading {
  margin: 0 0 8px;
  font-size: 26px;
  letter-spacing: 0.06em;
  font-weight: 700;
}
.title-tagline {
  margin: 0 0 28px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.6;
}

.title-menu {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.title-menu.hidden {
  display: none;
}
.title-btn {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 12px;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.03em;
}
.title-btn:hover:not(:disabled) {
  border-color: #4a5364;
}
.title-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.title-btn.primary {
  background: #2f6d52;
  border-color: #48a077;
}
.title-btn.primary:hover:not(:disabled) {
  background: #3b8767;
}
.title-btn.ghost {
  background: transparent;
  width: auto;
  height: auto;
}

.title-save-info {
  margin: 12px 0 0;
  min-height: 1.4em;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.6;
}

.title-credits {
  margin-top: 26px;
  text-align: left;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 18px 20px;
}
.title-credits.hidden {
  display: none;
}
.title-credits h2 {
  margin: 0 0 12px;
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
  padding-bottom: 6px;
}
.title-credits dl {
  margin: 0 0 16px;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 14px;
}
.title-credits dt {
  color: var(--accent);
  font-size: 11px;
  white-space: nowrap;
}
.title-credits dd {
  margin: 0;
  font-size: 12px;
  line-height: 1.6;
  color: var(--text);
}
.title-credits .title-btn {
  width: 100%;
}

.title-confirm {
  margin-top: 26px;
  text-align: left;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 18px 20px;
}
.title-confirm.hidden {
  display: none;
}
.title-confirm p {
  margin: 0 0 16px;
  font-size: 12.5px;
  line-height: 1.6;
  color: var(--text);
}
.title-confirm-actions {
  display: flex;
  gap: 8px;
}
.title-confirm-actions .title-btn {
  flex: 1;
  font-size: 12.5px;
  padding: 10px;
}

.title-version {
  margin: 26px 0 0;
  color: var(--muted);
  font-size: 10.5px;
  letter-spacing: 0.05em;
}

/* ------------------------------------------------------------ モーダル */

#modal-root {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
}
#modal-root.hidden {
  display: none;
}
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: #000a;
}
.modal {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  width: min(880px, 92vw);
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 24px 70px #000c;
}
.modal header {
  padding: 12px 18px;
  border-bottom: 1px solid var(--line);
}
.modal header h3 {
  margin: 0;
  font-size: 15px;
  letter-spacing: 0.06em;
}
#modal-body {
  padding: 14px 18px;
  overflow-y: auto;
}
#modal-footer {
  padding: 10px 18px;
  border-top: 1px solid var(--line);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.report-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 8px;
  margin-bottom: 14px;
}
.report-cell {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 8px 10px;
}
.report-cell label {
  display: block;
  font-size: 10px;
  color: var(--muted);
  letter-spacing: 0.1em;
  margin-bottom: 3px;
}
.report-cell strong {
  font-size: 18px;
  font-variant-numeric: tabular-nums;
}
.pos {
  color: var(--good);
}
.neg {
  color: var(--danger);
}

table.report {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  margin-bottom: 14px;
}
table.report th,
table.report td {
  text-align: left;
  padding: 5px 8px;
  border-bottom: 1px solid var(--line);
}
table.report th {
  color: var(--muted);
  font-weight: 600;
  font-size: 10.5px;
  letter-spacing: 0.08em;
}
td.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.sev {
  display: inline-block;
  min-width: 52px;
  text-align: center;
  border-radius: 3px;
  padding: 1px 5px;
  font-size: 10.5px;
}
.sev.nearmiss {
  background: #4a3f1e;
  color: var(--warn);
}
.sev.minor {
  background: #4a3328;
  color: #ffbb9b;
}
.sev.injury {
  background: #5a2a2a;
  color: #ffa0a0;
}
.sev.serious {
  background: #7a1f1f;
  color: #ffd0d0;
}
.sev.fatal {
  background: #a01414;
  color: #ffffff;
  font-weight: 700;
}

.advice {
  background: #1f2a30;
  border-left: 3px solid var(--accent);
  padding: 8px 12px;
  margin-bottom: 6px;
  font-size: 12px;
  line-height: 1.55;
}
.advice b {
  color: var(--accent);
}

.milestone {
  background: linear-gradient(90deg, #33301f, #23252c);
  border-left: 3px solid var(--gold);
  padding: 10px 14px;
  margin-bottom: 12px;
  font-size: 12.5px;
  line-height: 1.6;
}
.milestone b {
  color: var(--gold);
  font-size: 14px;
}
.milestone .goal-bar {
  height: 5px;
  background: #00000055;
  border-radius: 3px;
  overflow: hidden;
  margin-top: 6px;
}
.milestone .goal-fill {
  height: 100%;
  background: var(--gold);
}

.topic {
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: 4px;
  padding: 10px 12px;
  margin-bottom: 10px;
  background: #1e222a;
}
.topic > header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}
.topic > header b {
  font-size: 13.5px;
}
.topic-risk {
  margin-left: auto;
  font-size: 11px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.topic-advice {
  margin: 0 0 8px;
  font-size: 11.5px;
  line-height: 1.6;
  color: var(--muted);
}

.shop-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 300px));
  justify-content: start;
  gap: 8px;
}
.shop-card {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.shop-card h4 {
  margin: 0;
  font-size: 13px;
}
.shop-card p {
  margin: 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.5;
  flex: 1 1 auto;
}
.shop-card .owned {
  color: var(--good);
  font-size: 11px;
}
.shop-card button {
  background: #33455a;
  border: 1px solid #4a627e;
  border-radius: 3px;
  padding: 6px;
  font-weight: 600;
}
.shop-card button:hover:not(:disabled) {
  background: #3f5670;
}
.shop-card button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.help-body h4 {
  margin: 14px 0 4px;
  font-size: 12.5px;
  color: var(--accent);
}
.help-body p,
.help-body li {
  font-size: 12px;
  line-height: 1.7;
  color: #c8cedb;
}
.help-body ul {
  margin: 4px 0;
  padding-left: 20px;
}
