:root {
  --bg: #f6f7f9;
  --card: #ffffff;
  --text: #1a1d21;
  --muted: #6b7280;
  --accent: #2563eb;
  --accent-dark: #1d4ed8;
  --border: #e5e7eb;
  --good: #16a34a;
  --bad: #dc2626;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Pretendard", "Apple SD Gothic Neo", "Noto Sans KR", sans-serif;
  overscroll-behavior: none;
}

.app { max-width: 560px; margin: 0 auto; padding: 12px 16px 32px; }

.topbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 4px;
}
.logo { font-weight: 800; font-size: 18px; }
.top-status { font-size: 13px; color: var(--muted); }

.screen { display: none; }
.screen.active { display: block; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 20px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.04);
}
.card h1 { margin: 0 0 8px; font-size: 24px; }
.card h2 { margin: 0 0 12px; font-size: 20px; }
.muted { color: var(--muted); }
.center { text-align: center; }
.error { color: var(--bad); min-height: 1.2em; }

.field { display: block; margin: 12px 0; }
.field span { display: block; font-size: 13px; margin-bottom: 6px; color: var(--muted); }
.field input {
  width: 100%; padding: 12px; font-size: 16px;
  border: 1px solid var(--border); border-radius: 10px;
}

.row { display: flex; gap: 8px; margin-top: 10px; }
.btn {
  flex: 1; padding: 13px; font-size: 16px; font-weight: 700;
  border-radius: 10px; border: 1px solid var(--border);
  background: #fff; color: var(--text); cursor: pointer;
  touch-action: manipulation;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:disabled { background: #93c5fd; border-color: #93c5fd; cursor: not-allowed; }
.btn.ghost { flex: 0.6; }
.btn:active { transform: scale(0.99); }

.divider { text-align: center; color: var(--muted); margin: 14px 0 4px; font-size: 13px; }
.help { margin-top: 14px; font-size: 14px; }
.players { list-style: none; padding: 0; margin: 8px 0; }
.players li { padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; margin-bottom: 6px; }

/* game */
.game-head { text-align: center; margin: 6px 0; }
.round-label { font-weight: 800; font-size: 15px; }
.phase-label { font-size: 22px; font-weight: 800; margin-top: 4px; }
.role-label { font-size: 13px; margin-top: 2px; }
.hint { text-align: center; min-height: 1.6em; font-size: 14px; }

.timer-bar { height: 6px; background: var(--border); border-radius: 4px; overflow: hidden; margin: 8px 0 4px; }
.timer-fill { height: 100%; width: 0%; background: var(--accent); transition: width 0.1s linear; }

/* 판정선 */
.judge-wrap { margin: 4px 0 6px; }
.judge-wrap.hidden { display: none; }
.judge-track {
  position: relative;
  height: 64px;
  background: #0f172a;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid #1e293b;
}
.judge-markers, .judge-taps { position: absolute; inset: 0; pointer-events: none; }
.judge-note {
  position: absolute;
  top: 50%;
  width: 12px; height: 12px;
  border-radius: 50%;
  background: #fbbf24;
  border: 2px solid #fff7;
  transform: translate(-50%, -50%);
  box-shadow: 0 0 6px #fbbf24aa;
}
.judge-note.hit-perfect { background: #22d3ee; box-shadow: 0 0 8px #22d3ee; }
.judge-note.hit-great { background: #22c55e; box-shadow: 0 0 8px #22c55e; }
.judge-note.hit-good { background: #fb923c; box-shadow: 0 0 8px #fb923c; }
.judge-note.hit-miss { background: #334155; box-shadow: none; opacity: 0.6; }
.judge-note.played { animation: note-pop 0.3s ease; }
@keyframes note-pop {
  0% { transform: translate(-50%, -50%) scale(1.8); }
  100% { transform: translate(-50%, -50%) scale(1); }
}
.judge-tap {
  position: absolute;
  top: 50%;
  width: 10px; height: 26px;
  border-radius: 5px;
  background: #60a5fa;
  transform: translate(-50%, -50%);
  opacity: 0.9;
}
.judge-tap.extra { background: #f87171; }
.judge-line {
  position: absolute;
  top: 0; bottom: 0;
  width: 3px;
  background: #fff;
  box-shadow: 0 0 8px #fff;
  transform: translateX(-50%);
  pointer-events: none;
}
.judge-line::after {
  content: "판정선";
  position: absolute;
  top: 2px; left: 6px;
  font-size: 10px; color: #fff; opacity: 0.8; white-space: nowrap;
}
.judge-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 30px; margin-top: 6px; }
.judge-popup { font-weight: 900; font-size: 20px; min-height: 1.4em; flex: 1; text-align: center; }
.judge-popup.pop { animation: judge-pop 0.45s ease; }
@keyframes judge-pop {
  0% { transform: scale(1.5); opacity: 0; }
  30% { transform: scale(1); opacity: 1; }
  100% { transform: scale(0.95); opacity: 0.9; }
}
.judge-popup.g-perfect { color: #0891b2; }
.judge-popup.g-great { color: var(--good); }
.judge-popup.g-good { color: #ea580c; }
.judge-popup.g-miss { color: var(--bad); }
.judge-popup.g-extra { color: #9333ea; }
.judge-legend { font-size: 11px; text-align: right; flex: 1; }

.pad-wrap {
  position: relative;
  display: flex; justify-content: center; align-items: center;
  margin: 18px 0;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
.pulse-layer { position: absolute; inset: 0; pointer-events: none; display: flex; justify-content: center; align-items: center; }
.pulse {
  position: absolute;
  width: 220px; height: 220px; border-radius: 50%;
  border: 3px solid var(--accent);
  opacity: 0.7;
  animation: pulse-out 0.5s ease-out forwards;
  pointer-events: none;
}
@keyframes pulse-out {
  from { transform: scale(0.55); opacity: 0.7; }
  to { transform: scale(1.15); opacity: 0; }
}

.tap-pad {
  width: 220px; height: 220px; border-radius: 50%;
  border: none; background: var(--accent); color: #fff;
  font-size: 28px; font-weight: 800; cursor: pointer;
  display: flex; flex-direction: column; justify-content: center; align-items: center; gap: 4px;
  touch-action: none; user-select: none; -webkit-user-select: none;
  transition: transform 0.05s ease, background 0.15s ease;
}
.tap-pad:disabled { background: #cbd5e1; cursor: not-allowed; }
.tap-pad:not(:disabled):active { transform: scale(0.94); background: var(--accent-dark); }
.tap-count { font-size: 15px; font-weight: 600; opacity: 0.9; }

.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 10px 0; }
.stat { border: 1px solid var(--border); border-radius: 10px; padding: 10px; text-align: center; }
.stat .v { font-size: 20px; font-weight: 800; }
.stat .k { font-size: 12px; color: var(--muted); }

.conn-banner {
  position: sticky; top: 0; z-index: 50;
  background: #fef3c7; color: #92400e;
  text-align: center; padding: 8px; font-size: 14px;
}
.conn-banner.hidden { display: none; }

table.rounds { width: 100%; border-collapse: collapse; font-size: 13px; margin-top: 10px; }
table.rounds th, table.rounds td { border-top: 1px solid var(--border); padding: 6px 4px; text-align: center; }

@media (max-width: 420px) {
  .tap-pad, .pulse { width: min(72vw, 260px); height: min(72vw, 260px); }
  .pulse { width: min(72vw, 260px); height: min(72vw, 260px); }
}
