:root {
  color-scheme: light;
  --bg: #f6f3ef;
  --panel: #fff;
  --line: #e6e0d8;
  --text: #1c1612;
  --muted: #6f645c;
  --faint: #9a8d84;
  --brand: #9E3D32;
  --brand-ink: #7d2e26;
  --ok: #2f7d4a;
  --danger: #b42318;
  --shadow: 0 1px 2px rgba(40, 24, 16, .06);
  --font: "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", "Helvetica Neue", system-ui, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --side-w: 220px;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.45;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; cursor: pointer; }
h1, h2, p { margin: 0; }

.shell {
  display: grid;
  grid-template-columns: var(--side-w) minmax(0, 1fr);
  height: 100%;
  min-height: 0;
}
.nav {
  display: flex;
  flex-direction: column;
  height: 100vh;
  padding: 18px 12px 16px;
  background: #fff;
  border-right: 1px solid var(--line);
}
.brand { display: flex; gap: 10px; align-items: center; padding: 4px 8px 18px; }
.mark { width: 36px; height: 36px; display: grid; }
.mark img, .mark svg { width: 36px; height: 36px; display: block; }
.brand b { display: block; font-size: 16px; font-weight: 650; }
.brand small { color: var(--muted); font-size: 12px; }
.menu { display: grid; gap: 4px; }
.menu button {
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 15px;
}
.menu button:hover,
.menu button.on { background: #f3eee8; font-weight: 600; }
.side-status {
  margin-top: auto;
  padding-top: 12px;
  border-top: 1px solid var(--line);
  display: grid;
  gap: 6px;
}
.svc { display: flex; justify-content: space-between; gap: 8px; padding: 0 4px; }
.svc span { color: var(--muted); font-size: 12px; }
.svc b { font-size: 12px; font-variant-numeric: tabular-nums; }

.workspace { min-width: 0; display: flex; flex-direction: column; height: 100%; min-height: 0; }
.topbar {
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 22px;
  background: #fff;
  border-bottom: 1px solid var(--line);
}
.crumb { color: var(--faint); font-size: 12px; margin-bottom: 2px; }
.topbar h1 { font-size: 18px; font-weight: 600; }
.live { display: flex; align-items: center; gap: 8px; color: var(--muted); font-family: var(--mono); font-size: 13px; }
.live i { width: 8px; height: 8px; border-radius: 50%; background: #d9d0c8; }
.live i.on { background: var(--brand); box-shadow: 0 0 0 4px #9E3D3222; }
#logout {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px;
  color: var(--muted);
}
.login {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--bg);
}
.login[hidden] { display: none; }
.login-card {
  width: min(360px, 100%);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 28px 24px 22px;
  box-shadow: 0 8px 24px rgba(40, 24, 16, .12);
  display: grid;
  gap: 10px;
  justify-items: start;
}
.login-card .mark, .login-card .mark svg { width: 48px; height: 48px; }
.login-card h1 { font-size: 22px; }
.login-card p { color: var(--muted); font-size: 14px; }
.login-card input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 16px;
  background: #fff;
}
.login-card button {
  height: 36px;
  border: 1px solid var(--brand);
  border-radius: 999px;
  background: var(--brand);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  padding: 0 16px;
}
.login-msg { min-height: 1.2em; }
.login-msg.bad { color: var(--danger); }

.views { flex: 1; min-height: 0; overflow: auto; padding: 18px 22px 28px; }
.view { display: none; }
.view.on { display: block; }
.split { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.cards { display: grid; gap: 12px; }

.stage, .panel, .ep {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 16px;
  min-width: 0;
}
.stage[data-kind="make"] { --accent: var(--brand); }
.stage[data-kind="upload"] { --accent: #8a5a2b; }
.stage-top, .ep-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 8px; }
.tag { font-family: var(--mono); font-size: 12px; letter-spacing: 1px; color: var(--accent, var(--brand)); font-weight: 700; }
.state {
  font-size: 12px;
  padding: 3px 8px;
  border-radius: 999px;
  background: #f3eee8;
  color: var(--muted);
}
.state.working { background: #f8e8e5; color: var(--brand); }
.state.done { background: #e7f4ec; color: var(--ok); }
.state.ready { background: #f3e0cc; color: #6d4318; }
.state.paused { background: #f3eee8; color: var(--text); }
.stage h2, .ep h2 { font-size: 18px; font-weight: 650; margin-bottom: 10px; }
.ep h2 { font-size: 16px; margin: 0; }
.sub { color: var(--muted); font-size: 13px; margin: -4px 0 10px; }

.bar { height: 6px; background: #e4ddd4; border-radius: 99px; overflow: hidden; margin: 0 0 12px; }
.bar i { display: block; height: 100%; width: 0; background: var(--accent, var(--brand)); }
.row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 12px; }
.row div, .metric {
  background: #f7f3ee;
  border: 1px solid #efe8e0;
  border-radius: 8px;
  padding: 8px 6px;
  text-align: center;
}
.row em, .metric em {
  display: block;
  font-style: normal;
  font-family: var(--mono);
  font-size: 22px;
  font-weight: 700;
}
.row span, .metric span { color: var(--muted); font-size: 12px; }

.steps { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.steps li {
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr) auto;
  gap: 8px;
  align-items: baseline;
  padding: 7px 8px;
  border-radius: 8px;
  background: #faf7f4;
}
.steps .name { font-weight: 600; }
.steps .detail { min-width: 0; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.steps .flag { font-size: 12px; color: var(--faint); }
.steps li.done .flag { color: var(--ok); }
.steps li.working .flag { color: var(--brand); font-weight: 650; }
.steps li.ready .flag { color: #8a5a2b; }
.steps li.working { outline: 1px solid #f0d2cc; }

.panel { margin-top: 16px; }
.panel h2 { font-size: 15px; margin-bottom: 8px; }
.log { margin: 0; font-family: var(--mono); font-size: 12px; line-height: 1.7; color: var(--muted); white-space: pre-wrap; }
.log b { color: var(--text); font-weight: 600; }

.link { color: var(--brand-ink); }
.empty { padding: 28px 8px; color: var(--muted); }

@media (max-width: 860px) {
  html, body { height: 100%; overflow: hidden; }
  .shell {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(0, 1fr);
    height: 100dvh;
  }
  .nav {
    height: auto;
    padding: max(10px, env(safe-area-inset-top)) 12px 8px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
  .brand { padding: 0 4px 8px; }
  .menu { grid-template-columns: repeat(3, 1fr); }
  .menu button {
    min-height: 44px;
    text-align: center;
    padding: 10px 8px;
  }
  .side-status {
    margin-top: 8px;
    padding-top: 8px;
    grid-template-columns: repeat(3, 1fr);
  }
  .svc { flex-direction: column; align-items: center; gap: 2px; }
  .workspace { height: auto; }
  .topbar {
    height: auto;
    min-height: 52px;
    padding: 10px 16px;
  }
  .topbar h1 { font-size: 17px; }
  .views {
    padding: 12px 12px calc(16px + env(safe-area-inset-bottom));
    -webkit-overflow-scrolling: touch;
  }
  .split { grid-template-columns: 1fr; }
  .stage, .panel, .ep { padding: 14px 12px; }
  .stage h2 { font-size: 17px; }
  .row { gap: 6px; }
  .row em { font-size: 18px; }
  .steps li {
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: start;
  }
  .steps .name { grid-column: 1; }
  .steps .flag { grid-column: 2; }
  .steps .detail {
    grid-column: 1 / -1;
    white-space: normal;
  }
}
