:root {
  --bg: #f5f5f7;
  --fg: #1c1c1e;
  --panel: #ffffff;
  --muted: #6b6b70;
  --line: #d8d8dd;
  --accent: #0b6e4f;
  --warn: #b3261e;
  --ok: #14a37f;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b0b0d;
    --fg: #ececee;
    --panel: #17171a;
    --muted: #9a9aa0;
    --line: #2c2c31;
    --accent: #35d29b;
    --warn: #ff6b5e;
    --ok: #35d29b;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Pretendard", system-ui, sans-serif;
  overscroll-behavior: none;
}

body {
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

/* ── 상단 바 ─────────────────────────────────────────── */
#bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
}

.spacer { flex: 1; }

.dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--muted);
  flex: 0 0 auto;
}
.dot.ok { background: var(--ok); }
.dot.bad { background: var(--warn); }

#stat {
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#bar select,
#bar button {
  background: transparent;
  color: var(--fg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 4px 8px;
  font: inherit;
  cursor: pointer;
}

/* ── 화면 ────────────────────────────────────────────── */
#stage {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000;
  position: relative;
}

#screen {
  max-width: 100%;
  max-height: 100%;
  display: block;
  touch-action: none;
  cursor: crosshair;
}

.veil {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #8a8a90;
  background: #000;
  pointer-events: none;
  text-align: center;
  padding: 20px;
}
.veil[hidden] { display: none; }

/* ── 키 바 ───────────────────────────────────────────── */
#keys {
  display: flex;
  gap: 6px;
  padding: 8px;
  background: var(--panel);
  border-top: 1px solid var(--line);
  flex: 0 0 auto;
  overflow-x: auto;
}

#keys button {
  flex: 1 0 auto;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: transparent;
  color: var(--fg);
  font: inherit;
  cursor: pointer;
  white-space: nowrap;
}
#keys button:active { background: var(--line); }
#keys button.warn { color: var(--warn); border-color: var(--warn); }

/* ── 상태 상세 ───────────────────────────────────────── */
#detail {
  margin: 0;
  padding: 12px;
  background: var(--panel);
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  max-height: 34vh;
  overflow: auto;
  white-space: pre-wrap;
  flex: 0 0 auto;
}

/* ── 초기 설정 ───────────────────────────────────────── */
.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  z-index: 10;
  padding: 20px;
}
.overlay[hidden] { display: none; }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 24px;
  width: min(360px, 100%);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.card h1 { margin: 0; font-size: 20px; }

.card label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

.card input {
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  color: var(--fg);
  font: inherit;
}

.card button {
  padding: 11px;
  border: 0;
  border-radius: 9px;
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.hint { margin: 0; color: var(--muted); font-size: 12px; }
