:root {
  color-scheme: dark;
  --bg: #0b0d12;
  --panel: #151923;
  --panel-2: #1c2230;
  --line: #2a3345;
  --text: #f5f1e8;
  --muted: #9ca7ba;
  --gold: #f1be62;
  --red: #e35d61;
  --green: #62c49a;
  --blue: #6da9e4;
  --shadow: 0 18px 60px rgba(0, 0, 0, .35);
}

* { box-sizing: border-box; }

html, body { min-height: 100%; }

body {
  margin: 0;
  background:
    radial-gradient(circle at 20% 0%, rgba(227, 93, 97, .12), transparent 32rem),
    radial-gradient(circle at 90% 20%, rgba(109, 169, 228, .10), transparent 28rem),
    var(--bg);
  color: var(--text);
  font-family: "Microsoft YaHei", "PingFang SC", system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

button, input, select { font: inherit; }
button { touch-action: manipulation; }

.app-shell {
  width: min(100%, 760px);
  min-height: 100vh;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  padding: max(18px, env(safe-area-inset-top)) 16px max(14px, env(safe-area-inset-bottom));
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.eyebrow {
  margin: 0 0 3px;
  color: var(--gold);
  font-size: 11px;
  letter-spacing: .18em;
  font-weight: 800;
}

h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: clamp(22px, 6vw, 30px); }
h2 { font-size: clamp(24px, 7vw, 36px); line-height: 1.16; }
h3 { margin-bottom: 10px; }

.top-actions { display: flex; gap: 8px; }
.icon-btn {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(21, 25, 35, .88);
  color: var(--muted);
  padding: 8px 12px;
  font-size: 13px;
}
.icon-btn.danger { color: #f19a9d; }

main { flex: 1; }
footer {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 18px;
  color: #69758b;
  font-size: 11px;
}

.panel {
  background: linear-gradient(145deg, rgba(28, 34, 48, .98), rgba(18, 22, 31, .98));
  border: 1px solid var(--line);
  border-radius: 24px;
  box-shadow: var(--shadow);
  padding: clamp(18px, 5vw, 30px);
}

.panel + .panel { margin-top: 14px; }
.lead { color: var(--muted); line-height: 1.7; }
.hint { color: var(--muted); font-size: 13px; line-height: 1.65; }
.warning { color: #f0a6a8; }
.success { color: var(--green); }
.center { text-align: center; }

.badge-row { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.badge {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 10px;
  color: var(--muted);
  background: rgba(9, 11, 16, .35);
  font-size: 12px;
}
.badge.gold { color: var(--gold); border-color: rgba(241, 190, 98, .45); }
.badge.red { color: #f39a9d; border-color: rgba(227, 93, 97, .45); }

.field-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.field { display: grid; gap: 6px; }
.field[hidden] { display: none; }
.field label { color: var(--muted); font-size: 12px; }
.field input, .field select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 13px;
  color: var(--text);
  background: #0f131b;
  outline: none;
}
.field input:focus, .field select:focus { border-color: var(--gold); }
.full { grid-column: 1 / -1; }

.timing-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 9px;
}
.timing-grid label {
  display: grid;
  gap: 5px;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 9px;
  background: #0f131b;
  color: var(--muted);
  text-align: center;
}
.timing-grid input {
  min-width: 0;
  padding: 8px 6px;
  text-align: center;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 9px;
  color: var(--muted);
  font-size: 13px;
  margin-top: 14px;
}
.check-row input { width: 18px; height: 18px; accent-color: var(--gold); }

.setup-section-title {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 18px;
}
.setup-section-title h3 { margin-bottom: 5px; }
.setup-section-title .hint { margin-bottom: 0; }
.role-config-section + .role-config-section { margin-top: 22px; }
.role-config-section h4 { margin: 0 0 10px; color: var(--gold); }
.role-config-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; }
.role-config-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 66px;
  align-items: center;
  gap: 10px;
  min-height: 88px;
  border: 1px solid color-mix(in srgb, var(--role-color, var(--line)) 55%, var(--line));
  border-radius: 14px;
  padding: 11px;
  background: color-mix(in srgb, var(--role-color, #777) 8%, #10141d);
}
.role-config-card strong { display: block; color: var(--role-color, var(--text)); }
.role-config-card small { display: block; margin-top: 4px; color: var(--muted); font-size: 10px; line-height: 1.45; }
.role-config-card input {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 5px;
  background: #0b0f16;
  color: var(--text);
  text-align: center;
}
.role-count-status {
  margin-top: 18px;
  border: 1px solid var(--line);
  border-radius: 13px;
  padding: 12px 14px;
  font-weight: 750;
}
.role-count-status.valid { border-color: rgba(98, 196, 154, .5); color: var(--green); background: rgba(98, 196, 154, .08); }
.role-count-status.invalid { border-color: rgba(227, 93, 97, .5); color: #f0a6a8; background: rgba(227, 93, 97, .07); }

.btn-row { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 18px; }
.btn {
  min-height: 48px;
  border: 1px solid transparent;
  border-radius: 14px;
  padding: 12px 17px;
  background: var(--panel-2);
  color: var(--text);
  font-weight: 750;
  cursor: pointer;
}
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn.primary { background: linear-gradient(135deg, #f2c66e, #d89c42); color: #241a0c; }
.btn.secondary { border-color: var(--line); background: transparent; }
.btn.danger { background: rgba(227, 93, 97, .13); border-color: rgba(227, 93, 97, .45); color: #ff9ca0; }
.btn.success { background: rgba(98, 196, 154, .14); border-color: rgba(98, 196, 154, .45); color: #8ce1ba; }
.btn.block { width: 100%; }

.privacy-gate {
  min-height: 58vh;
  display: grid;
  place-items: center;
  text-align: center;
}
.privacy-icon {
  width: 82px;
  height: 82px;
  display: grid;
  place-items: center;
  margin: 0 auto 18px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: #0f131b;
  font-size: 34px;
}

.role-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.role-card {
  min-height: 210px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  border: 1px solid var(--role-color, var(--line));
  border-radius: 18px;
  padding: 16px;
  background: linear-gradient(160deg, color-mix(in srgb, var(--role-color, #777) 18%, #171b25), #10131a 72%);
}
.role-name { font-size: 23px; font-weight: 900; color: var(--role-color, var(--text)); }
.role-copy { font-size: 13px; color: var(--gold); margin-top: 4px; }
.role-skill { margin: 16px 0; color: #c6cedb; font-size: 13px; line-height: 1.6; }

.seat-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.seat-btn {
  min-height: 58px;
  border: 1px solid var(--line);
  border-radius: 13px;
  padding: 8px 5px;
  background: #111620;
  color: var(--text);
  font-weight: 750;
}
.seat-btn small { display: block; color: var(--muted); font-size: 10px; font-weight: 500; margin-top: 3px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.seat-btn.selected { border-color: var(--gold); background: rgba(241, 190, 98, .12); color: var(--gold); }
.seat-btn.out { opacity: .34; text-decoration: line-through; }

.player-status-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; margin: 16px 0; }
.player-status {
  border: 1px solid var(--line);
  border-radius: 13px;
  padding: 10px 7px;
  text-align: center;
  background: #111620;
}
.player-status strong { display: block; font-size: 14px; }
.player-status span { display: block; margin-top: 5px; color: var(--muted); font-size: 11px; }
.player-status.out { opacity: .38; }

.phase-title { color: var(--gold); font-size: 13px; font-weight: 850; letter-spacing: .08em; }
.instruction {
  margin: 18px 0;
  border-left: 3px solid var(--gold);
  padding: 12px 14px;
  background: rgba(241, 190, 98, .07);
  color: #e5dccb;
  line-height: 1.7;
}

.countdown {
  display: inline-grid;
  grid-template-columns: auto auto;
  align-items: baseline;
  gap: 8px;
  margin: 14px 0;
  padding: 10px 14px;
  border: 1px solid rgba(241, 190, 98, .35);
  border-radius: 999px;
  background: rgba(241, 190, 98, .08);
  color: var(--muted);
  font-size: 12px;
}
.countdown strong { color: var(--gold); font-size: 26px; line-height: 1; }

.return-phone { background: linear-gradient(145deg, rgba(34, 43, 57, .99), rgba(12, 16, 23, .99)); }
.return-phone h2 { color: var(--gold); }

.choice-list { display: grid; gap: 9px; margin-top: 14px; }
.choice {
  width: 100%;
  text-align: left;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #111620;
  color: var(--text);
  padding: 13px 14px;
}

.log-list { display: grid; gap: 8px; max-height: 230px; overflow: auto; }
.log-item { border-left: 2px solid var(--line); padding: 5px 0 5px 11px; color: #aeb8c8; font-size: 13px; line-height: 1.5; white-space: pre-line; }

.dawn-lines { display: grid; gap: 12px; margin: 18px 0; }
.dawn-line { border: 1px solid var(--line); border-radius: 14px; padding: 14px; background: #10141d; line-height: 1.6; }

.result-good { color: #8bbdf0; }
.result-wolf { color: #ff777b; }
.winner { font-size: clamp(38px, 12vw, 64px); margin: 10px 0 18px; }

.target-confirm-overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(4, 7, 11, .82);
  backdrop-filter: blur(5px);
}
.target-confirm-dialog {
  width: min(100%, 440px);
  border: 1px solid var(--gold);
  border-radius: 20px;
  padding: 24px;
  background: #171c27;
  box-shadow: var(--shadow);
}
.target-confirm-dialog h2 { margin-bottom: 10px; }
.target-confirm-dialog .btn-row { margin-bottom: 0; }

.toast {
  position: fixed;
  left: 50%;
  bottom: max(28px, env(safe-area-inset-bottom));
  z-index: 30;
  transform: translate(-50%, 18px);
  max-width: min(88vw, 540px);
  padding: 12px 16px;
  border-radius: 12px;
  background: #f2ece1;
  color: #241b13;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: .2s ease;
  font-weight: 700;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 520px) {
  .field-grid { grid-template-columns: 1fr; }
  .full { grid-column: auto; }
  .seat-grid, .player-status-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .role-grid { grid-template-columns: 1fr; }
  .role-card { min-height: 175px; }
  .timing-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .setup-section-title { display: grid; }
  .role-config-grid { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
