:root {
  --ink: #1d2733;
  --ink-2: #4a5866;
  --paper: rgba(255, 255, 255, 0.9);
  --line: rgba(29, 39, 51, 0.16);
  --c1: #e04848;
  --c2: #2f6fe4;
  --font: "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", "Microsoft YaHei", system-ui, -apple-system, "Segoe UI", sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body {
  font-family: var(--font); color: var(--ink); -webkit-tap-highlight-color: transparent;
  background: radial-gradient(120% 90% at 50% 10%, #f1f4f7 0%, #d5dde4 60%, #bfcad4 100%);
}
#c { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; outline: none; }
button, input { font: inherit; color: inherit; }
button {
  appearance: none; border: 1px solid var(--ink); background: var(--ink); color: #fff; border-radius: 8px;
  padding: 0.6em 1.1em; cursor: pointer; font-weight: 600; transition: transform 0.08s, opacity 0.15s;
}
button:hover { opacity: 0.9; }
button:active { transform: translateY(1px); }
button:disabled { opacity: 0.4; cursor: default; }
button.ghost { background: var(--paper); color: var(--ink); border-color: var(--line); }
button:focus-visible, input:focus-visible { outline: 2px solid #2f6fe4; outline-offset: 2px; }

#hud {
  position: fixed; top: 0; left: 0; right: 0; display: flex; gap: 10px; align-items: center; justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) calc(12px + env(safe-area-inset-right)) 10px calc(12px + env(safe-area-inset-left));
  pointer-events: none; flex-wrap: wrap;
}
#hud > * { pointer-events: auto; }
#status {
  background: var(--paper); border: 1px solid var(--line); border-radius: 999px; padding: 0.45em 1.1em; font-weight: 700;
  backdrop-filter: blur(8px); min-height: 2.2em; display: flex; align-items: center;
}
#side { display: flex; gap: 8px; align-items: center; }
#chips { display: flex; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 6px; background: var(--paper); border: 1px solid var(--line); border-radius: 999px; padding: 0.35em 0.8em; font-size: 0.9rem; }
.chip i { width: 14px; height: 14px; border-radius: 50%; background: var(--dot, #999); display: inline-block; }
.chip.active { border-color: var(--ink); box-shadow: 0 0 0 2px var(--ink); }

#endbar {
  position: fixed; left: 50%; bottom: calc(22px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  display: flex; gap: 10px; padding: 10px; background: var(--paper); border: 1px solid var(--line); border-radius: 12px; backdrop-filter: blur(8px);
}
#dialog { position: fixed; inset: 0; display: grid; place-items: center; background: rgba(214, 222, 229, 0.45); backdrop-filter: blur(3px); padding: 16px; }
#dialog[hidden], #hud[hidden], #endbar[hidden], [hidden] { display: none !important; }
.card {
  width: min(420px, 100%); max-height: 92vh; overflow: auto; background: var(--paper); border: 1px solid var(--line);
  border-radius: 14px; padding: 22px; box-shadow: 0 18px 50px rgba(29, 39, 51, 0.18);
}
.card h1 { margin: 0 0 4px; font-size: 1.9rem; letter-spacing: 0.04em; }
.card h2 { margin: 0 0 12px; font-size: 1.25rem; }
.card p.sub, .note { color: var(--ink-2); font-size: 0.88rem; line-height: 1.55; margin: 0 0 14px; }
.stack { display: grid; gap: 10px; }
.row { display: flex; gap: 10px; align-items: center; justify-content: space-between; }
.row > label { display: flex; gap: 8px; align-items: center; }
.field { display: grid; gap: 6px; margin: 0 0 14px; }
.field > span { font-weight: 600; font-size: 0.9rem; }
.seg { display: flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: #fff; }
.seg button { flex: 1; border: 0; border-radius: 0; background: transparent; color: var(--ink); padding: 0.55em 0.4em; font-weight: 500; }
.seg button.on { background: var(--ink); color: #fff; }
input[type="text"] { width: 100%; padding: 0.6em 0.8em; border: 1px solid var(--line); border-radius: 8px; background: #fff; letter-spacing: 0.25em; text-transform: uppercase; font-weight: 700; }
input[type="color"] { width: 46px; height: 32px; padding: 0; border: 1px solid var(--line); border-radius: 6px; background: #fff; }
hr { border: 0; border-top: 1px solid var(--line); margin: 16px 0; }
.code { font-size: 2.6rem; font-weight: 800; letter-spacing: 0.3em; text-align: center; padding: 6px 0 6px 0.3em; }
.rooms { display: grid; gap: 6px; min-height: 2.2em; }
.rooms button { text-align: left; display: flex; justify-content: space-between; background: #fff; color: var(--ink); border-color: var(--line); font-weight: 600; }
.rooms small { color: var(--ink-2); font-weight: 400; }
#toast {
  position: fixed; left: 50%; top: calc(64px + env(safe-area-inset-top)); transform: translate(-50%, -10px); opacity: 0; pointer-events: none;
  background: var(--ink); color: #fff; padding: 0.6em 1.1em; border-radius: 8px; transition: opacity 0.2s, transform 0.2s; max-width: 90vw; text-align: center; z-index: 5;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#boot { position: fixed; inset: 0; display: grid; place-items: center; text-align: center; padding: 24px; color: var(--ink-2); }
#boot.fail { color: #fff; background: #b3261e; z-index: 50; inset: 0 0 auto 0; padding: 12px 16px; font-weight: 600; }
@media (max-width: 560px) { #status { order: 3; width: 100%; justify-content: center; } }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
