:root {
  --bg: #f6f7fb;
  --panel: #ffffff;
  --ink: #111827;
  --ink2: #4b5563;
  --muted: #8a8fa3;
  --line: #e7e9f1;
  --brand: #10b981;
  --brand-ink: #065f46;
  --run: #111827;
  --bad: #dc2626;
  --warn: #b45309;
  --code-size: 18px;
  --mono: ui-monospace, "Cascadia Code", "JetBrains Mono", Menlo, Consolas, "Microsoft YaHei Mono", monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", "Noto Sans SC", Roboto, sans-serif;
  --r: 16px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: var(--sans); color: var(--ink); background: var(--bg); -webkit-font-smoothing: antialiased; }
button { font: inherit; cursor: pointer; }
[lang="zh"] { color: var(--muted); font-size: .92em; }
.muted { color: var(--muted); }
.small { font-size: 14px; }

/* buttons */
.run {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  border: 0; border-radius: 14px; padding: 14px 22px; min-height: 52px;
  background: var(--run); color: #fff; font-weight: 700; font-size: 18px;
  transition: transform .12s ease, box-shadow .2s ease, background .2s;
  box-shadow: 0 6px 18px rgba(17, 24, 39, .18);
}
.run [lang="zh"] { color: #c7cbe0; }
.run:hover { transform: translateY(-1px); box-shadow: 0 10px 24px rgba(17, 24, 39, .22); }
.run:active { transform: translateY(1px) scale(.99); }
.run .play { color: #6ee7b7; }
.run .spin { display: none; width: 18px; height: 18px; border-radius: 50%; border: 3px solid rgba(255,255,255,.3); border-top-color: #fff; animation: spin .8s linear infinite; }
.run.busy .spin { display: inline-block; }
.run.busy .play { display: none; }
.run:disabled { opacity: .85; cursor: progress; }
@keyframes spin { to { transform: rotate(360deg); } }
.ghost { border: 1px solid var(--line); background: #fff; color: var(--ink2); border-radius: 10px; padding: 8px 12px; font-weight: 600; transition: background .15s, border-color .15s; }
.ghost:hover { background: #f3f4f8; border-color: #d9dceb; }
.ghost.sm { font-size: 14px; padding: 7px 11px; }
#biggerBtn span { font-size: .75em; }

/* ---------- home ---------- */
.home { display: grid; place-items: center; min-height: 100vh; padding: 24px; background: radial-gradient(1200px 600px at 50% -10%, #e8fbf3, var(--bg)); }
.hero { width: min(560px, 100%); text-align: center; animation: rise .6s ease both; }
.hero .logo svg { width: 76px; height: 76px; }
.hero h1 { font-size: clamp(40px, 7vw, 56px); margin: 18px 0 8px; letter-spacing: -.02em; }
.hero .sub { font-size: 19px; line-height: 1.55; color: var(--ink2); margin: 0 0 28px; }
.join { display: flex; gap: 10px; }
.join input { flex: 1; min-width: 0; font: inherit; font-size: 20px; padding: 14px 18px; border-radius: 14px; border: 1.5px solid var(--line); background: #fff; outline: none; }
.join input:focus { border-color: var(--brand); box-shadow: 0 0 0 4px #10b98122; }
@keyframes rise { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }

/* ---------- room ---------- */
.room { display: flex; flex-direction: column; height: 100vh; height: 100dvh; overflow: hidden; }
.room main { opacity: 0; transition: opacity .35s ease; }
.room.ready main { opacity: 1; }
.top { display: flex; align-items: center; gap: 16px; padding: 10px 18px; background: #fff; border-bottom: 1px solid var(--line); min-height: 62px; }
.brand { display: flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; font-weight: 800; font-size: 18px; white-space: nowrap; }
.brand svg { width: 32px; height: 32px; }
.roomname { display: flex; flex-direction: column; min-width: 0; padding-left: 16px; border-left: 1px solid var(--line); }
.roomname b { font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.roomname .now { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top .right { margin-left: auto; display: flex; align-items: center; gap: 12px; min-width: 0; }
.people { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.chip { display: inline-flex; align-items: center; gap: 7px; padding: 6px 12px 6px 9px; border-radius: 999px; background: color-mix(in srgb, var(--c) 10%, #fff); color: var(--ink); font-weight: 600; font-size: 14px; border: 1px solid color-mix(in srgb, var(--c) 30%, #fff); animation: rise .3s ease both; }
.chip i { width: 9px; height: 9px; border-radius: 50%; background: var(--c); box-shadow: 0 0 0 3px color-mix(in srgb, var(--c) 25%, transparent); }
.chip em { font-style: normal; color: var(--muted); font-weight: 500; }
.sync { width: 12px; height: 12px; border-radius: 50%; background: #d1d5db; flex: none; transition: background .3s; }
.sync[data-state="synced"], .sync[data-state="online"] { background: var(--brand); box-shadow: 0 0 0 4px #10b98122; }
.sync[data-state="retrying"] { background: #f59e0b; }
.sync[data-state="offline"] { background: var(--bad); }

.stage { flex: 1; display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(320px, 1fr); gap: 14px; padding: 14px; min-height: 0; }
.pane { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); min-height: 0; display: flex; flex-direction: column; overflow: hidden; box-shadow: 0 1px 2px rgba(17,24,39,.04); }
.bar { display: flex; align-items: center; gap: 10px; padding: 10px 12px 10px 16px; border-bottom: 1px solid var(--line); }
.file { font-family: var(--mono); font-weight: 700; font-size: 14px; color: var(--ink2); }
.tools { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.hostonly { display: none; }
.host .hostonly { display: inline-block; }
.editor { flex: 1; min-height: 0; }
.editor .cm-editor { height: 100%; }
.editor .cm-editor.cm-focused { outline: none; }
.cm-ySelectionInfo { font-family: var(--sans) !important; font-size: 12px !important; padding: 2px 6px !important; border-radius: 6px 6px 6px 0; opacity: 1 !important; }

.side .tabs { display: flex; gap: 6px; padding: 8px; border-bottom: 1px solid var(--line); }
.tabs button { flex: 1; border: 0; background: transparent; border-radius: 10px; padding: 10px; font-weight: 700; color: var(--ink2); font-size: 15px; }
.tabs button.on { background: #f1f2f7; color: var(--ink); }
.tab-run, .tab-missions { flex: 1; min-height: 0; overflow: auto; padding: 14px 16px 18px; display: none; flex-direction: column; gap: 10px; }
body[data-tab="run"] .tab-run, body[data-tab="missions"] .tab-missions { display: flex; }
.lbl { font-weight: 700; font-size: 14px; color: var(--ink2); }
.lbl small { font-weight: 500; color: var(--muted); }
#stdin { font-family: var(--mono); font-size: 16px; min-height: 76px; max-height: 160px; resize: vertical; border: 1.5px solid var(--line); border-radius: 12px; padding: 10px 12px; outline: none; background: #fbfbfe; }
#stdin:focus { border-color: var(--brand); background: #fff; }
.output { display: flex; flex-direction: column; gap: 10px; min-height: 140px; }
.output .meta { font-size: 12.5px; color: var(--muted); }
.console { margin: 0; padding: 14px 16px; border-radius: 12px; background: #0f172a; color: #e5e7eb; font-family: var(--mono); font-size: 16px; line-height: 1.55; white-space: pre-wrap; word-break: break-word; min-height: 110px; animation: rise .25s ease both; }
.console .muted { color: #94a3b8; }
.console .err { color: #fca5a5; }
.card { border-radius: 12px; padding: 12px 14px; line-height: 1.5; font-size: 15px; animation: rise .25s ease both; }
.card.bad { background: #fef2f2; border: 1px solid #fecaca; }
.card.warn { background: #fffbeb; border: 1px solid #fde68a; color: #78350f; }
.card .tag { font-weight: 800; color: var(--bad); font-size: 13px; text-transform: uppercase; letter-spacing: .04em; margin-bottom: 4px; }
.card .hint { margin: 0 0 8px; font-size: 16px; font-weight: 600; color: #7f1d1d; }
.card details summary { cursor: pointer; color: var(--ink2); font-size: 13.5px; }
.card pre { margin: 8px 0 0; white-space: pre-wrap; font-family: var(--mono); font-size: 13px; color: #450a0a; max-height: 220px; overflow: auto; }

.missions { display: flex; flex-direction: column; gap: 12px; }
.mission { border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; background: #fff; transition: border-color .2s, box-shadow .2s; }
.mission.on { border-color: #a7f3d0; box-shadow: 0 0 0 4px #10b98114; }
.mission .lvl { font-size: 12px; font-weight: 800; color: var(--brand-ink); text-transform: uppercase; letter-spacing: .05em; }
.mission h3 { margin: 4px 0 6px; font-size: 18px; }
.mission h3 small { font-weight: 600; }
.mission .goal { margin: 0 0 8px; color: var(--ink2); line-height: 1.5; }
.mission ol { margin: 6px 0 10px 18px; padding: 0; line-height: 1.6; }
.mission .load { margin-top: 4px; }

dialog { border: 0; border-radius: 20px; padding: 28px; width: min(420px, 92vw); box-shadow: 0 24px 60px rgba(17,24,39,.25); }
dialog::backdrop { background: rgba(17,24,39,.35); backdrop-filter: blur(3px); }
dialog h2 { margin: 0 0 6px; }
dialog form { display: flex; flex-direction: column; gap: 12px; }
dialog input { font: inherit; font-size: 20px; padding: 12px 14px; border-radius: 12px; border: 1.5px solid var(--line); outline: none; }
dialog input:focus { border-color: var(--brand); }

@media (max-width: 900px) {
  .stage { grid-template-columns: 1fr; grid-template-rows: minmax(300px, 1.3fr) minmax(300px, 1fr); overflow: auto; }
  .roomname { display: none; }
  .brand span { display: none; }
}
@media (max-width: 560px) {
  .top { padding: 8px 12px; }
  .tools .ghost.sm:not(#biggerBtn):not(#copyBtn) { display: none; }
  .join { flex-direction: column; }
}
