:root {
  --bg: #0f1115;
  --surface: #1a1d26;
  --surface-2: #232735;
  --border: #2e3342;
  --text: #f2f3f7;
  --text-dim: #9a9fb0;
  --accent: #8b5cf6;
  --accent-dim: #6d28d9;
  --danger: #ef4444;
  --danger-dim: #b91c1c;
  --radius: 18px;
}

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

html, body {
  height: 100%;
}

body {
  margin: 0;
  background: radial-gradient(circle at top, #1c1030 0%, var(--bg) 55%);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  min-height: 100vh;
  display: flex;
  justify-content: center;
}

#app {
  width: 100%;
  max-width: 480px;
  min-height: 100vh;
  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);
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 20px 8px;
}

header h1 {
  font-size: 22px;
  margin: 0;
  letter-spacing: 0.02em;
}

.icon-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 18px;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  cursor: pointer;
}

main {
  flex: 1;
  padding: 12px 20px 32px;
  display: flex;
  flex-direction: column;
}

.screen {
  display: none;
  flex: 1;
  flex-direction: column;
}

.screen.active {
  display: flex;
}

h2 {
  margin: 8px 0 20px;
  font-size: 20px;
  text-align: center;
}

.field {
  margin-bottom: 24px;
}

.field > label {
  display: block;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  margin-bottom: 10px;
}

.stepper {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
}

.stepper button {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: none;
  background: var(--surface-2);
  color: var(--text);
  font-size: 22px;
  cursor: pointer;
}

.stepper button:active {
  background: var(--accent-dim);
}

#player-count {
  font-size: 30px;
  font-weight: 700;
  min-width: 44px;
  text-align: center;
}

.name-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.name-list input {
  width: 100%;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 15px;
}

.chip-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.chip {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 14px;
  cursor: pointer;
}

.chip.selected {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

#custom-category-wrap {
  margin-top: 12px;
}

#custom-category-wrap.hidden {
  display: none;
}

#custom-category {
  width: 100%;
  padding: 14px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 15px;
}

.primary-btn {
  background: linear-gradient(135deg, var(--accent), var(--accent-dim));
  color: white;
  border: none;
  padding: 16px;
  border-radius: var(--radius);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  margin-top: auto;
}

.primary-btn:active {
  opacity: 0.85;
}

.secondary-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 14px;
  border-radius: var(--radius);
  font-size: 15px;
  cursor: pointer;
  margin-top: 10px;
}

.error {
  color: var(--danger);
  text-align: center;
  margin-top: 12px;
}

.hidden {
  display: none !important;
}

/* Reveal screen */
.pass-hint {
  text-align: center;
  color: var(--text-dim);
  margin: 0;
}

#current-player {
  text-align: center;
  font-size: 26px;
  margin-top: 4px;
}

.reveal-card {
  flex: 1;
  min-height: 280px;
  perspective: 1200px;
  margin: 16px 0;
  cursor: pointer;
  user-select: none;
}

.card-face {
  position: absolute;
  inset: 0;
  border-radius: 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  backface-visibility: hidden;
  transition: transform 0.5s cubic-bezier(0.4, 0.2, 0.2, 1);
}

.card-front {
  background: linear-gradient(160deg, var(--surface-2), var(--surface));
  border: 1px solid var(--border);
  transform: rotateY(0deg);
}

.card-front .lock {
  font-size: 48px;
}

.card-front p {
  color: var(--text-dim);
}

.card-back {
  background: linear-gradient(160deg, #2b2140, #1a1d26);
  border: 1px solid var(--accent-dim);
  transform: rotateY(180deg);
  padding: 24px;
  text-align: center;
}

.reveal-card {
  position: relative;
}

.reveal-card.flipped .card-front {
  transform: rotateY(-180deg);
}

.reveal-card.flipped .card-back {
  transform: rotateY(0deg);
}

.reveal-card.imposter .card-back {
  background: linear-gradient(160deg, #3a1616, #1a1d26);
  border-color: var(--danger-dim);
}

#card-content .role-tag {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-dim);
}

#card-content .role-tag.imposter-tag {
  color: var(--danger);
  font-weight: 700;
}

#card-content .secret-word {
  font-size: 32px;
  font-weight: 700;
  margin: 10px 0;
}

#card-content .secret-hint {
  font-size: 15px;
  color: var(--text-dim);
}

/* Wheel screen */
.wheel-copy {
  text-align: center;
  color: var(--text-dim);
  margin-bottom: 8px;
}

#wheel-wrap {
  position: relative;
  width: 250px;
  height: 250px;
  margin: 24px auto;
}

#wheel-pointer {
  position: absolute;
  top: -16px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 26px;
  color: var(--accent);
  z-index: 2;
  filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.5));
}

#wheel {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  border: 4px solid var(--border);
  position: relative;
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.45);
  transform: rotate(0deg);
}

.wheel-label {
  position: absolute;
  top: 50%;
  left: 50%;
  font-size: 11px;
  font-weight: 700;
  color: white;
  white-space: nowrap;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.7);
  transform-origin: 0 0;
}

.wheel-result {
  text-align: center;
  font-size: 22px;
  font-weight: 700;
  margin: 4px 0 16px;
  min-height: 28px;
}

/* Discuss screen */
.discuss-copy {
  text-align: center;
  color: var(--text-dim);
  line-height: 1.5;
}

/* Answer screen */
.answer-category {
  text-align: center;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 13px;
  margin-bottom: 4px;
}

.answer-word {
  text-align: center;
  font-size: 34px;
  font-weight: 700;
  margin: 0 0 6px;
}

.answer-hint {
  text-align: center;
  color: var(--text-dim);
  margin: 0 0 20px;
}

.answer-imposter {
  text-align: center;
  font-size: 18px;
  color: var(--danger);
  font-weight: 600;
  margin-bottom: auto;
}

/* Loading overlay */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 10, 14, 0.85);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  z-index: 50;
  color: var(--text);
}

.spinner {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 4px solid var(--surface-2);
  border-top-color: var(--accent);
  animation: spin 0.9s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* History modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(10, 10, 14, 0.8);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 60;
}

.modal-content {
  background: var(--surface);
  border-top-left-radius: 24px;
  border-top-right-radius: 24px;
  width: 100%;
  max-width: 480px;
  max-height: 80vh;
  padding: 20px;
  display: flex;
  flex-direction: column;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-header h2 {
  margin: 0;
}

.modal-header button {
  background: none;
  border: none;
  color: var(--text);
  font-size: 20px;
  cursor: pointer;
}

.modal-subtitle {
  color: var(--text-dim);
  font-size: 13px;
  margin: 6px 0 14px;
}

#history-list {
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.history-item {
  background: var(--surface-2);
  border-radius: 12px;
  padding: 12px 14px;
}

.history-item .h-cat {
  font-size: 12px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.history-item .h-word {
  font-size: 17px;
  font-weight: 600;
  margin: 2px 0;
}

.history-item .h-date {
  font-size: 11px;
  color: var(--text-dim);
}

.history-empty {
  text-align: center;
  color: var(--text-dim);
  padding: 20px 0;
}
