:root {
  --bg: #e8edf3;
  --ink: #1d2433;
  --muted: #5b6475;
  --line: #d7dde6;
  --card: #ffffff;
  --soft: #f4f6f9;
  --accent: #2f6fed;
  --accent-ink: #ffffff;
  --danger: #d6453d;
  --warn: #c98a0a;
  --ok: #1f9d6b;
  --radius: 14px;
  --shadow: 0 10px 30px rgba(20, 30, 50, .14);
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font: 14px/1.5 Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--bg);
  overflow: hidden;
}
button, input, textarea, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* buttons */
.btn {
  border: 1px solid var(--line); background: var(--card); border-radius: 10px;
  padding: 8px 14px; cursor: pointer; font-weight: 600; min-height: 38px;
  transition: background .15s, border-color .15s, transform .05s;
}
.btn:hover { border-color: #b9c2cf; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.danger { color: var(--danger); }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: rgba(0,0,0,.05); }
.btn.icon { padding: 6px 10px; min-width: 38px; }
.btn:disabled { opacity: .55; cursor: progress; }
.btn:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* login */
.login { position: fixed; inset: 0; display: grid; place-items: center; padding: 16px;
  background: radial-gradient(circle at 30% 20%, #f7f9fc, #dfe6ef); }
.login-card { width: min(380px, 100%); background: var(--card); border-radius: 20px; padding: 28px;
  box-shadow: var(--shadow); display: grid; gap: 10px; }
.login-card h1 { margin: 6px 0 0; font-size: 22px; }
.login-card p { margin: 0 0 8px; color: var(--muted); }
.login-card label { font-weight: 600; font-size: 13px; }
.login-card input { padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; }
.error { color: var(--danger); min-height: 1.2em; font-size: 13px; }

.brand-mark { width: 26px; height: 26px; border-radius: 8px; display: inline-block;
  background: conic-gradient(from 210deg, #2f6fed, #ec4899, #f59e0b, #10b981, #2f6fed); }

/* layout */
.topbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 20; height: 60px;
  display: flex; align-items: center; gap: 12px; padding: 0 16px;
  background: rgba(255,255,255,.86); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; white-space: nowrap; }
.chips { display: flex; gap: 8px; overflow-x: auto; flex: 1; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  display: inline-flex; align-items: center; gap: 8px; padding: 6px 12px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--card); cursor: pointer; white-space: nowrap; font-weight: 600;
}
.chip .dot { width: 8px; height: 8px; border-radius: 50%; background: #b9c2cf; }
.chip .dot.working { background: var(--ok); box-shadow: 0 0 0 4px rgba(31,157,107,.18); animation: pulse 1.4s infinite; }
.chip .dot.paused { background: var(--warn); }
.chip .badge { background: var(--danger); color: #fff; border-radius: 999px; padding: 0 7px; font-size: 12px; }
.chip.active { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(47,111,237,.15); }
.top-actions { display: flex; gap: 6px; align-items: center; }

.stage { position: fixed; inset: 60px 0 0 0; }
#scene { width: 100%; height: 100%; display: block; touch-action: none; }
.hint { position: absolute; left: 16px; bottom: 16px; max-width: 420px; font-size: 12px; color: var(--muted);
  background: rgba(255,255,255,.8); padding: 8px 12px; border-radius: 10px; pointer-events: none; }

/* 3D labels */
.labels { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.lbl { position: absolute; transform: translate(-50%, -100%); white-space: nowrap; will-change: transform; }
.tag { font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 999px; color: #fff;
  box-shadow: 0 2px 6px rgba(0,0,0,.18); }
.tag small { font-weight: 600; opacity: .85; margin-left: 4px; }
.bubble { max-width: 230px; white-space: normal; font-size: 12px; line-height: 1.35; background: #fff; color: var(--ink);
  border-radius: 12px; padding: 7px 10px; box-shadow: 0 6px 16px rgba(20,30,50,.18); position: relative; margin-bottom: 6px; }
.bubble::after { content: ""; position: absolute; left: 50%; bottom: -6px; transform: translateX(-50%);
  border: 6px solid transparent; border-top-color: #fff; border-bottom: 0; }
.bubble .task { display: block; font-weight: 700; font-size: 11px; color: var(--muted); margin-bottom: 2px; }
.bubble.queued { background: #fff7e6; }
.bubble.queued::after { border-top-color: #fff7e6; }
.sign-wrap { pointer-events: auto; cursor: pointer; }
.sign { font-size: 15px; font-weight: 800; background: rgba(255,255,255,.95); padding: 6px 14px; border-radius: 12px;
  box-shadow: 0 4px 14px rgba(20,30,50,.15); text-align: center; }
.sign .sub { display: block; font-size: 11px; font-weight: 600; color: var(--muted); }
.sign .need { color: var(--danger); }

/* side panel */
.panel {
  position: fixed; z-index: 25; top: 72px; right: 12px; bottom: 12px; width: min(400px, calc(100vw - 24px));
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); overflow: auto; padding: 18px;
}
.panel .close { position: sticky; top: 0; float: right; margin: -6px -6px 0 0; background: var(--card); }
.panel h2 { margin: 0 0 2px; font-size: 19px; }
.panel h3 { margin: 18px 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.panel .row-actions { display: flex; gap: 8px; flex-wrap: wrap; margin: 12px 0; }
.status-line { color: var(--muted); }
.status-line strong { color: var(--ink); }

.task-list { display: grid; gap: 8px; }
.task-row { display: grid; gap: 4px; text-align: left; width: 100%; border: 1px solid var(--line); background: var(--soft);
  border-radius: 12px; padding: 10px 12px; cursor: pointer; }
.task-row:hover { border-color: #b9c2cf; background: #fff; }
.task-row .t { font-weight: 600; }
.task-row .m { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; font-size: 12px; color: var(--muted); }
.task-row .ev { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.empty { color: var(--muted); font-size: 13px; padding: 8px 0; }

.stage-chip { display: inline-block; font-size: 11px; font-weight: 700; padding: 1px 8px; border-radius: 999px; background: #e7ebf1; color: #3b4558; }
.stage-chip.owner { background: #fde7e5; color: var(--danger); }
.stage-chip.active { background: #e3f4ec; color: var(--ok); }
.stage-chip.done { background: #e8eefc; color: var(--accent); }
.repo-chip { font-family: ui-monospace, Menlo, monospace; font-size: 11px; background: #fff; border: 1px solid var(--line); border-radius: 6px; padding: 0 6px; }

/* modal */
.modal { position: fixed; inset: 0; z-index: 40; background: rgba(15, 22, 35, .45); display: grid; place-items: center; padding: 16px; }
.modal-card { width: min(980px, 100%); max-height: calc(100vh - 32px); background: var(--card); border-radius: 18px;
  box-shadow: var(--shadow); display: flex; flex-direction: column; overflow: hidden; }
.modal-head { display: flex; justify-content: space-between; gap: 12px; padding: 18px 20px 10px; border-bottom: 1px solid var(--line); }
.modal-head h2 { margin: 0; font-size: 19px; }
.meta { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 6px; color: var(--muted); font-size: 12px; }
.modal-body { overflow: auto; padding: 0 20px 20px; flex: 1; }
.modal-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: flex-end; padding: 12px 20px; border-top: 1px solid var(--line); background: var(--soft); }
.modal-actions:empty { display: none; }
.modal-actions textarea { flex: 1 1 320px; min-height: 64px; }

.tabs { display: flex; gap: 4px; position: sticky; top: 0; background: var(--card); padding: 10px 0; z-index: 1; overflow-x: auto; }
.tab { border: 0; background: transparent; padding: 8px 12px; border-radius: 9px; cursor: pointer; font-weight: 600; color: var(--muted); white-space: nowrap; }
.tab[aria-selected="true"] { background: #eaf0fd; color: var(--accent); }

.md { line-height: 1.6; }
.md h1 { font-size: 20px; } .md h2 { font-size: 17px; } .md h3 { font-size: 15px; }
.md table { border-collapse: collapse; width: 100%; font-size: 13px; display: block; overflow-x: auto; }
.md th, .md td { border: 1px solid var(--line); padding: 6px 8px; text-align: left; vertical-align: top; }
.md code { background: #f1f3f7; padding: 1px 5px; border-radius: 5px; font-size: 12.5px; }
.md pre { background: #f1f3f7; padding: 12px; border-radius: 10px; overflow: auto; }
.md pre code { background: none; padding: 0; }

.design-files { display: flex; gap: 6px; flex-wrap: wrap; margin: 4px 0 10px; }
.frame-wrap { border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: #fff; }
.frame-wrap iframe { width: 100%; height: min(70vh, 720px); border: 0; display: block; }
.frame-tools { display: flex; gap: 6px; padding: 6px; border-bottom: 1px solid var(--line); background: var(--soft); align-items: center; }
.frame-tools .sp { flex: 1; }
.frame-wrap.mobile iframe { width: 390px; max-width: 100%; margin: 0 auto; }
.shots { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; }
.shots figure { margin: 0; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.shots img { width: 100%; display: block; }
.shots figcaption { font-size: 11px; color: var(--muted); padding: 4px 8px; }

/* forms */
.form { display: grid; gap: 12px; padding-top: 14px; }
.form label { display: grid; gap: 6px; font-weight: 600; font-size: 13px; }
.form input, .form textarea, .form select, .modal-actions textarea {
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; font-weight: 400; background: #fff; width: 100%;
}
.form textarea { min-height: 180px; resize: vertical; }
.form .help { font-weight: 400; color: var(--muted); font-size: 12px; }

.toast { position: fixed; z-index: 60; left: 50%; bottom: 20px; transform: translateX(-50%) translateY(20px); opacity: 0;
  background: #1d2433; color: #fff; padding: 10px 16px; border-radius: 12px; max-width: min(560px, calc(100vw - 32px));
  transition: opacity .2s, transform .2s; pointer-events: none; white-space: pre-wrap; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.err { background: var(--danger); }

@keyframes pulse { 50% { box-shadow: 0 0 0 7px rgba(31,157,107,.05); } }

/* login: who is this */
.who-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 6px; }
.who { display: grid; justify-items: center; gap: 6px; padding: 12px; border-radius: 14px; border: 2px solid var(--line);
  background: var(--soft); cursor: pointer; font-weight: 700; font-size: 15px; }
.who[aria-pressed="true"] { border-color: var(--accent); background: #eef3fe; }
.face { width: 46px; height: 46px; border-radius: 50%; position: relative; background: #f1c9a5; overflow: hidden; }
.face::before { content: ""; position: absolute; left: 0; right: 0; top: 0; height: 42%; background: #1b1410; border-radius: 0 0 40% 40%; }
.face.mei { background: #f3cfb0; }
.face.mei::before { height: 100%; background: linear-gradient(#2a1a12 40%, transparent 40%), linear-gradient(90deg, #2a1a12 18%, transparent 18%, transparent 82%, #2a1a12 82%); border-radius: 0; }
.face::after { content: ""; position: absolute; left: 0; right: 0; bottom: -8px; height: 16px; background: #1e3a8a; border-radius: 50% 50% 0 0; }
.face.mei::after { background: #c8402f; }
.me { font-weight: 700; font-size: 13px; padding: 4px 10px; border-radius: 999px; background: var(--soft); border: 1px solid var(--line); }
.me:empty { display: none; }
button.me { cursor: pointer; }
button.me:hover { border-color: #b9c2cf; }

/* building labels */
.sign .floor { display: block; font-size: 10px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.sign.cards { border-top: 4px solid #d4a017; background: #fffaf0; }
.tag.user { background: #fff; border: 2px solid; padding: 1px 9px; }
.zzz-wrap { pointer-events: none; }
.zzz { font-weight: 800; color: #64748b; font-size: 15px; letter-spacing: 2px; text-shadow: 0 1px 0 #fff; }
.zzz, .zzz span { display: inline-block; animation: zzz 2.4s ease-in-out infinite; }
.zzz span:nth-child(1) { font-size: 12px; animation-delay: .4s; }
.zzz span:nth-child(2) { font-size: 10px; animation-delay: .8s; }
@keyframes zzz { 0%, 100% { transform: translateY(0); opacity: .35; } 50% { transform: translateY(-6px); opacity: 1; } }
.chip .lvl { font-size: 11px; font-weight: 700; color: var(--muted); }
.repo-list { display: grid; gap: 6px; }
.repo-row { display: flex; justify-content: space-between; align-items: center; gap: 8px; width: 100%; text-align: left;
  border: 1px solid var(--line); background: var(--soft); border-radius: 10px; padding: 8px 10px; cursor: pointer; }
.repo-row:hover { background: #fff; border-color: #b9c2cf; }
.deploy-state { font-size: 11px; color: var(--warn); font-weight: 600; }
.deploy-state.set { color: var(--ok); }
.form-group { display: grid; gap: 12px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (max-width: 560px) { .grid2 { grid-template-columns: 1fr; } }
label.check { display: flex; gap: 8px; align-items: flex-start; font-weight: 500; }
label.check input { width: auto; margin-top: 3px; }
.keybox { display: grid; gap: 6px; background: var(--soft); border: 1px dashed var(--line); border-radius: 10px; padding: 10px 12px; }
.keybox code { font-size: 11.5px; word-break: break-all; background: #fff; padding: 6px 8px; border-radius: 6px; }
.keybox .btn { justify-self: start; }
.deploy-out { background: #0f172a; color: #e2e8f0; padding: 10px 12px; border-radius: 10px; font-size: 12px; white-space: pre-wrap; margin: 0; }
.key-row { display: grid; gap: 6px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--soft); }
.key-head { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; align-items: baseline; }
.key-status { font-size: 12px; color: var(--warn); font-weight: 600; }
.key-status.set { color: var(--ok); }
.key-input { display: flex; gap: 6px; }
.key-input input { flex: 1; min-width: 0; }
@media (max-width: 720px) { #btn-keys { display: none; } }
.eyebrow { font-size: 11px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; margin-bottom: 2px; }

@media (max-width: 720px) {
  .brand span:last-child { display: none; }
  #btn-overview { display: none; }
  .hint { display: none; }
  .panel { top: auto; left: 8px; right: 8px; bottom: 8px; width: auto; max-height: 62vh; border-radius: 18px 18px 14px 14px; }
  .modal { padding: 0; }
  .modal-card { max-height: 100vh; height: 100%; border-radius: 0; }
  .bubble { max-width: 160px; font-size: 11px; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
