:root {
  --bg-base: #0a0d14;
  --bg-surface: #131824;
  --bg-surface-elevated: #1c2333;
  --bg-surface-hover: #242d42;
  --border-subtle: #2a344b;
  --border-highlight: #4f638c;

  --text-primary: #eef2f9;
  --text-secondary: #9aa7c2;
  --text-muted: #64718f;

  --accent-primary: #6366f1;
  --accent-primary-hover: #4f46e5;
  --accent-gold: #f59e0b;
  --accent-danger: #ef4444;
  --accent-danger-dark: #991b1b;
  --accent-success: #10b981;
  --accent-villager: #3b82f6;
  --accent-werewolf: #e11d48;

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;

  --shadow-card: 0 8px 24px rgba(0, 0, 0, 0.45);
}

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  height: 100%;
  background-color: var(--bg-base);
  color: var(--text-primary);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", Meiryo, sans-serif;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  user-select: none;
}

.app-shell {
  max-width: 440px;
  min-height: 100dvh;
  margin: 0 auto;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  display: flex;
  flex-direction: column;
  background: radial-gradient(circle at 50% 0%, #171e30 0%, var(--bg-base) 70%);
  border-left: 1px solid rgba(255, 255, 255, 0.04);
  border-right: 1px solid rgba(255, 255, 255, 0.04);
}

/* Header */
.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: rgba(13, 17, 26, 0.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border-subtle);
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 8px;
}

.brand-icon {
  font-size: 1.35rem;
}

.brand-title {
  font-size: 1.05rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  color: var(--text-primary);
}

.header-status {
  display: flex;
  align-items: center;
  gap: 6px;
}

.btn-icon-header {
  background: var(--bg-surface-elevated);
  color: var(--text-secondary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 5px 9px;
  font-size: 0.75rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.btn-icon-header:active {
  background: var(--bg-surface-hover);
  color: var(--text-primary);
}

.btn-icon-header.btn-abort {
  color: #fca5a5;
  border-color: rgba(239, 68, 68, 0.35);
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
}

.badge-phase {
  background: rgba(99, 102, 241, 0.2);
  color: #a5b4fc;
  border: 1px solid rgba(99, 102, 241, 0.4);
}

.badge-villager {
  background: rgba(59, 130, 246, 0.18);
  color: #93c5fd;
  border: 1px solid rgba(59, 130, 246, 0.4);
}

.badge-werewolf {
  background: rgba(225, 29, 72, 0.2);
  color: #fda4af;
  border: 1px solid rgba(225, 29, 72, 0.45);
}

.badge-alive {
  background: rgba(16, 185, 129, 0.16);
  color: #6ee7b7;
  border: 1px solid rgba(16, 185, 129, 0.35);
}

.badge-dead {
  background: rgba(100, 113, 143, 0.2);
  color: var(--text-muted);
  border: 1px solid rgba(100, 113, 143, 0.3);
}

/* Main Area */
.app-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 14px;
  gap: 14px;
}

/* Cards & Sections */
.card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 16px;
  box-shadow: var(--shadow-card);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.card-title {
  font-size: 0.98rem;
  font-weight: 800;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 6px;
}

.card-subtitle {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-top: 2px;
}

/* Setup Screen: Player Input & List */
.input-group {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}

.text-input {
  flex: 1;
  background: var(--bg-base);
  color: var(--text-primary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  font-size: 0.95rem;
  outline: none;
  user-select: text;
}

.text-input:focus {
  border-color: var(--accent-primary);
}

.error-msg {
  font-size: 0.8rem;
  color: #f87171;
  margin-bottom: 8px;
  min-height: 1.2em;
}

.player-setup-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 230px;
  overflow-y: auto;
  padding-right: 2px;
}

.player-setup-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 7px 10px;
}

.player-setup-left {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.player-index {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: rgba(99, 102, 241, 0.2);
  color: #a5b4fc;
  font-size: 0.72rem;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.player-setup-name {
  font-size: 0.92rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.player-setup-controls {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.btn-mini {
  width: 30px;
  height: 30px;
  border-radius: 6px;
  border: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  color: var(--text-secondary);
  font-size: 0.8rem;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.btn-mini:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.btn-mini.danger {
  color: #f87171;
  border-color: rgba(239, 68, 68, 0.3);
}

/* Role Config Grid */
.role-config-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.role-config-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
}

.role-info {
  display: flex;
  align-items: center;
  gap: 8px;
}

.role-icon {
  font-size: 1.25rem;
}

.role-name-wrap {
  display: flex;
  flex-direction: column;
}

.role-name {
  font-size: 0.9rem;
  font-weight: 700;
}

.role-team-label {
  font-size: 0.7rem;
  color: var(--text-secondary);
}

.stepper {
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-stepper {
  width: 34px;
  height: 34px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-highlight);
  background: var(--bg-surface);
  color: var(--text-primary);
  font-size: 1.1rem;
  font-weight: 800;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.btn-stepper:disabled {
  opacity: 0.3;
  border-color: var(--border-subtle);
  cursor: not-allowed;
}

.stepper-val {
  min-width: 24px;
  text-align: center;
  font-size: 1rem;
  font-weight: 800;
}

.validation-box {
  margin-top: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  font-weight: 600;
}

.validation-box.valid {
  background: rgba(16, 185, 129, 0.12);
  border: 1px solid rgba(16, 185, 129, 0.35);
  color: #6ee7b7;
}

.validation-box.invalid {
  background: rgba(239, 68, 68, 0.12);
  border: 1px solid rgba(239, 68, 68, 0.35);
  color: #fca5a5;
}

/* Discussion Time Selector */
.time-options {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.btn-time-opt {
  padding: 10px 6px;
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 0.88rem;
  font-weight: 700;
  cursor: pointer;
  text-align: center;
}

.btn-time-opt.active {
  background: rgba(99, 102, 241, 0.25);
  border-color: var(--accent-primary);
  color: #ffffff;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 48px;
  padding: 11px 18px;
  border-radius: var(--radius-md);
  font-size: 0.96rem;
  font-weight: 800;
  border: 1px solid transparent;
  cursor: pointer;
  transition: transform 0.1s, opacity 0.15s, background 0.15s;
}

.btn:active:not(:disabled) {
  transform: scale(0.98);
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn-block {
  width: 100%;
}

.btn-primary {
  background: linear-gradient(135deg, #6366f1 0%, #4f46e5 100%);
  color: #ffffff;
  box-shadow: 0 4px 14px rgba(79, 70, 229, 0.4);
}

.btn-danger {
  background: linear-gradient(135deg, #e11d48 0%, #be123c 100%);
  color: #ffffff;
  box-shadow: 0 4px 14px rgba(225, 29, 72, 0.4);
}

.btn-secondary {
  background: var(--bg-surface-elevated);
  color: var(--text-primary);
  border-color: var(--border-highlight);
}

.btn-outline-gold {
  background: rgba(245, 158, 11, 0.14);
  color: #fcd34d;
  border: 1px solid rgba(245, 158, 11, 0.45);
  min-height: 36px;
  padding: 6px 11px;
  font-size: 0.78rem;
}

.btn-outline-danger {
  background: rgba(239, 68, 68, 0.12);
  color: #fca5a5;
  border: 1px solid rgba(239, 68, 68, 0.4);
  min-height: 34px;
  padding: 5px 10px;
  font-size: 0.76rem;
  flex-shrink: 0;
}

.storage-note {
  margin-top: 8px;
  font-size: 0.72rem;
  color: var(--text-muted);
  text-align: right;
}

/* Interstitial / Pass Phone Screen */
.interstitial-card {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: center;
  text-align: center;
  padding: 26px 20px;
  background: linear-gradient(180deg, #151b2b 0%, #0e131f 100%);
  border: 1px solid var(--border-highlight);
}

.step-progress {
  font-size: 0.78rem;
  color: var(--text-secondary);
  background: rgba(255, 255, 255, 0.05);
  padding: 4px 12px;
  border-radius: 999px;
}

.pass-icon-wrap {
  width: 78px;
  height: 78px;
  border-radius: 50%;
  background: rgba(99, 102, 241, 0.14);
  border: 2px solid rgba(99, 102, 241, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.3rem;
  margin: 12px 0;
}

.pass-player-name {
  font-size: 1.55rem;
  font-weight: 900;
  color: #ffffff;
  margin: 6px 0;
  word-break: break-word;
}

.pass-instruction {
  font-size: 0.95rem;
  color: var(--text-secondary);
}

.privacy-notice {
  width: 100%;
  background: rgba(245, 158, 11, 0.1);
  border: 1px solid rgba(245, 158, 11, 0.35);
  border-radius: var(--radius-md);
  padding: 11px 14px;
  font-size: 0.82rem;
  color: #fde68a;
  margin: 16px 0;
}

/* Secret Role & Night Action Box (Low Glare / Anti-peeking) */
.secret-card {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  background: #101420;
  border: 1px solid #26304a;
}

.role-reveal-box {
  text-align: center;
  padding: 18px 14px;
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border-subtle);
  margin: 10px 0;
}

.role-reveal-box.werewolf-theme {
  background: rgba(225, 29, 72, 0.08);
  border-color: rgba(225, 29, 72, 0.35);
}

.role-reveal-icon {
  font-size: 2.8rem;
  margin-bottom: 6px;
}

.role-reveal-title {
  font-size: 1.5rem;
  font-weight: 900;
  margin-bottom: 6px;
}

.role-reveal-desc {
  font-size: 0.86rem;
  color: var(--text-secondary);
  text-align: left;
  margin-top: 12px;
  line-height: 1.55;
}

.fellow-wolves-box {
  margin-top: 12px;
  padding: 10px 12px;
  background: rgba(225, 29, 72, 0.14);
  border: 1px solid rgba(225, 29, 72, 0.4);
  border-radius: var(--radius-sm);
  text-align: left;
  font-size: 0.85rem;
}

/* Timer & Discussion */
.timer-display-box {
  text-align: center;
  padding: 20px 12px;
  background: var(--bg-base);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  margin: 10px 0;
}

.timer-digits {
  font-size: 3.4rem;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.04em;
  color: #ffffff;
}

.timer-digits.warning {
  color: var(--accent-gold);
}

.timer-digits.urgent {
  color: var(--accent-danger);
  animation: pulseUrgent 1s infinite;
}

@keyframes pulseUrgent {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.55; }
}

.timer-controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 12px;
}

/* Player Grid / Target Selection */
.target-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 12px 0;
  max-height: 310px;
  overflow-y: auto;
}

.target-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 12px 14px;
  background: var(--bg-surface-elevated);
  border: 2px solid var(--border-subtle);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 0.96rem;
  font-weight: 700;
  cursor: pointer;
  text-align: left;
  transition: border-color 0.15s, background 0.15s;
}

.target-btn.selected {
  border-color: var(--accent-primary);
  background: rgba(99, 102, 241, 0.22);
}

.target-btn:disabled {
  opacity: 0.42;
  cursor: not-allowed;
  background: #111520;
}

/* Status Chips & Alive Grid */
.survivor-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.survivor-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-subtle);
  font-size: 0.86rem;
  font-weight: 600;
}

.survivor-item.dead {
  opacity: 0.48;
  text-decoration: line-through;
}

/* Vote Tally Bars */
.tally-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 12px 0;
}

.tally-row {
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
}

.tally-row.top-getter {
  border-color: var(--accent-danger);
  background: rgba(239, 68, 68, 0.12);
}

.tally-row-header {
  display: flex;
  justify-content: space-between;
  font-size: 0.92rem;
  font-weight: 700;
}

.tally-voters {
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-top: 3px;
}

/* Announcement / Result Banner */
.result-hero {
  text-align: center;
  padding: 22px 14px;
  border-radius: var(--radius-lg);
  margin-bottom: 12px;
  border: 1px solid var(--border-subtle);
  background: rgba(255, 255, 255, 0.03);
}

.result-hero.villagers-win {
  background: linear-gradient(180deg, rgba(59, 130, 246, 0.22) 0%, rgba(16, 185, 129, 0.1) 100%);
  border-color: rgba(59, 130, 246, 0.5);
}

.result-hero.werewolves-win {
  background: linear-gradient(180deg, rgba(225, 29, 72, 0.25) 0%, rgba(153, 27, 27, 0.12) 100%);
  border-color: rgba(225, 29, 72, 0.55);
}

.result-hero-icon {
  font-size: 3rem;
  margin-bottom: 6px;
}

.result-hero-title {
  font-size: 1.55rem;
  font-weight: 900;
}

.result-hero-sub {
  font-size: 0.88rem;
  color: var(--text-secondary);
  margin-top: 6px;
}

/* Final Result Table */
.result-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.result-table th,
.result-table td {
  padding: 9px 8px;
  border-bottom: 1px solid var(--border-subtle);
  text-align: left;
}

.result-table th {
  color: var(--text-secondary);
  font-weight: 700;
  font-size: 0.76rem;
}

/* Modals */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(5, 7, 12, 0.82);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
}

.modal-card {
  width: 100%;
  max-width: 360px;
  background: var(--bg-surface);
  border: 1px solid var(--border-highlight);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.65);
}

.modal-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.modal-title {
  font-size: 1.08rem;
  font-weight: 800;
}

.btn-close-modal {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 1.1rem;
  cursor: pointer;
  padding: 4px;
}

.modal-message {
  font-size: 0.92rem;
  color: var(--text-secondary);
  margin: 12px 0 18px;
  white-space: pre-line;
}

.modal-body {
  font-size: 0.88rem;
  color: var(--text-primary);
  margin-bottom: 16px;
  max-height: 60vh;
  overflow-y: auto;
}

.modal-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.modal-actions.single {
  grid-template-columns: 1fr;
}

/* Title Screen */
.title-screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: center;
  text-align: center;
  padding: 28px 18px 22px;
  border-radius: var(--radius-xl);
  background:
    radial-gradient(circle at 50% 24%, rgba(225, 29, 72, 0.22) 0%, rgba(99, 102, 241, 0.12) 38%, rgba(10, 13, 20, 0.96) 76%),
    linear-gradient(180deg, #131829 0%, #090c14 100%);
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.65);
  position: relative;
  overflow: hidden;
}

.title-top-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 14px;
  border-radius: 999px;
  background: rgba(225, 29, 72, 0.16);
  border: 1px solid rgba(225, 29, 72, 0.45);
  color: #fda4af;
  font-size: 0.74rem;
  font-weight: 800;
  letter-spacing: 0.08em;
}

.title-moon-stage {
  position: relative;
  width: 148px;
  height: 148px;
  margin: 18px auto 14px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.title-moon-glow {
  position: absolute;
  inset: -14px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(244, 63, 94, 0.38) 0%, rgba(245, 158, 11, 0.15) 50%, transparent 72%);
  animation: moonPulse 4s ease-in-out infinite;
}

.title-moon {
  position: relative;
  width: 126px;
  height: 126px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fde68a 0%, #f59e0b 42%, #be123c 92%);
  box-shadow:
    0 0 36px rgba(225, 29, 72, 0.55),
    inset -10px -10px 24px rgba(15, 23, 42, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
}

.title-wolf-icon {
  font-size: 4rem;
  filter: drop-shadow(0 6px 12px rgba(0, 0, 0, 0.55));
  transform: translateY(2px);
}

@keyframes moonPulse {
  0%, 100% {
    transform: scale(1);
    opacity: 0.85;
  }
  50% {
    transform: scale(1.08);
    opacity: 1;
  }
}

.title-logo-sub {
  font-size: 0.82rem;
  font-weight: 700;
  color: #a5b4fc;
  letter-spacing: 0.15em;
  margin-bottom: 4px;
}

.title-logo-main {
  font-size: 2.35rem;
  font-weight: 900;
  letter-spacing: 0.06em;
  line-height: 1.15;
  background: linear-gradient(180deg, #ffffff 0%, #cbd5e1 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  text-shadow: 0 6px 24px rgba(0, 0, 0, 0.5);
}

.title-catchcopy {
  font-size: 0.86rem;
  color: var(--text-secondary);
  margin-top: 8px;
  line-height: 1.55;
}

.title-feature-grid {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin: 18px 0;
}

.title-feature-item {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 10px;
  display: flex;
  align-items: center;
  gap: 8px;
  text-align: left;
}

.title-feature-icon {
  font-size: 1.25rem;
  flex-shrink: 0;
}

.title-feature-text {
  font-size: 0.76rem;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.3;
}

.title-feature-text small {
  display: block;
  font-size: 0.68rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-top: 1px;
}

.title-cta-group {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.btn-title-start {
  min-height: 56px;
  font-size: 1.08rem;
  letter-spacing: 0.04em;
  background: linear-gradient(135deg, #e11d48 0%, #6366f1 100%);
  color: #ffffff;
  box-shadow: 0 8px 24px rgba(225, 29, 72, 0.4);
}

.hidden {
  display: none !important;
}
