:root {
  --team-1: #e63946;
  --team-2: #457b9d;
  --team-3: #f4a300;
  --team-4: #2a9d8f;
  --bg: #101318;
  --panel: #1b1f27;
  --text: #f4f6fb;
  --muted: #9aa3b2;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Hiragino Sans", "Noto Sans JP", system-ui, sans-serif;
  min-height: 100%;
  -webkit-tap-highlight-color: transparent;
}

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

h1,
h2,
h3 {
  margin: 0 0 0.5em;
}

a {
  color: inherit;
}

button {
  font-family: inherit;
  border: none;
  border-radius: 12px;
  padding: 0.9em 1.4em;
  font-size: 1.05rem;
  font-weight: 700;
  cursor: pointer;
  background: #2d3340;
  color: var(--text);
  touch-action: manipulation;
}

button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

button.primary {
  background: #4361ee;
  color: white;
}

button.correct {
  background: #2a9d8f;
  color: white;
}

button.incorrect {
  background: #e63946;
  color: white;
}

button.ghost {
  background: transparent;
  border: 1px solid #3a4150;
}

input[type="text"],
input[type="file"] {
  font-family: inherit;
  font-size: 1rem;
  padding: 0.6em 0.8em;
  border-radius: 8px;
  border: 1px solid #3a4150;
  background: #0d1016;
  color: var(--text);
  width: 100%;
}

.panel {
  background: var(--panel);
  border-radius: 16px;
  padding: 1.2rem;
  margin-bottom: 1rem;
}

.muted {
  color: var(--muted);
  font-size: 0.9rem;
}

/* -------- scoreboard -------- */
.scoreboard {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.6rem;
}

.score-card {
  border-radius: 14px;
  padding: 0.8rem;
  text-align: center;
  background: #14181f;
  border-top: 6px solid var(--c);
}

.score-card .name {
  font-size: 0.85rem;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.score-card .score {
  font-size: 1.6rem;
  font-weight: 800;
}

.score-card.buzzed {
  outline: 3px solid var(--c);
  animation: pulse 0.6s ease-in-out infinite alternate;
}

@keyframes pulse {
  from {
    box-shadow: 0 0 0 rgba(255, 255, 255, 0);
  }
  to {
    box-shadow: 0 0 24px var(--c);
  }
}

/* -------- video -------- */
video {
  width: 100%;
  border-radius: 12px;
  background: black;
  display: block;
}

/* -------- team buzz button -------- */
.buzz-wrap {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.2rem;
  padding: 1.5rem;
  text-align: center;
  background: var(--c, var(--bg));
  transition: background 0.25s ease;
}

.buzz-button {
  width: min(70vw, 320px);
  height: min(70vw, 320px);
  border-radius: 50%;
  border: none;
  font-size: 1.6rem;
  font-weight: 900;
  background: rgba(0, 0, 0, 0.35);
  color: white;
  box-shadow: 0 0 0 8px rgba(255, 255, 255, 0.15);
}

.buzz-button:active:not(:disabled) {
  transform: scale(0.96);
}

.status-label {
  font-size: 1.3rem;
  font-weight: 700;
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
}

.team-name-label {
  font-size: 1.1rem;
  opacity: 0.9;
}

.my-score {
  font-size: 2.4rem;
  font-weight: 900;
}

.speed-timer {
  text-align: center;
  background: rgba(0, 0, 0, 0.45);
  border-radius: 16px;
  padding: 0.6rem 1rem;
}

.speed-timer-value {
  font-family: "SF Mono", "Menlo", "Consolas", monospace;
  font-size: 2.6rem;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.6);
}

.speed-timer-points {
  font-size: 1.1rem;
  font-weight: 700;
}

/* -------- confetti -------- */
.confetti-piece {
  position: absolute;
  top: -10px;
  width: 10px;
  height: 16px;
  opacity: 0.9;
  transform: rotate(var(--rot, 0deg));
  animation-name: confetti-fall;
  animation-timing-function: ease-in;
  animation-fill-mode: forwards;
  pointer-events: none;
}

@keyframes confetti-fall {
  to {
    transform: translateY(110vh) rotate(calc(var(--rot, 0deg) + 360deg));
    opacity: 0.2;
  }
}

.incorrect-flash {
  position: absolute;
  inset: 0;
  background: rgba(230, 57, 70, 0.55);
  animation: flash-fade 0.6s ease-out forwards;
  pointer-events: none;
}

@keyframes flash-fade {
  from {
    opacity: 1;
  }
  to {
    opacity: 0;
  }
}

.effect-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 999;
}

/* -------- setup grid -------- */
.team-name-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.6rem;
}

.tier-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  gap: 0.6rem;
}

.tier-item {
  border-top: 4px solid var(--c, #4361ee);
  background: #14181f;
  border-radius: 8px;
  padding: 0.6rem;
}

.tier-item input {
  margin-top: 0.3rem;
}

.qr-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 1rem;
}

.qr-card {
  background: white;
  color: #111;
  border-radius: 12px;
  padding: 0.8rem;
  text-align: center;
}

.qr-card svg {
  width: 100%;
  height: auto;
}

.qr-card .qr-url {
  color: #444;
  font-size: 0.72rem;
  word-break: break-all;
  margin-top: 4px;
}

.line-invite-card {
  background: #14181f;
  border-radius: 12px;
  padding: 0.9rem;
  border-top: 4px solid var(--c, #4361ee);
}

.line-invite-card textarea {
  width: 100%;
  min-height: 110px;
  resize: vertical;
  font-family: inherit;
  font-size: 0.9rem;
  padding: 0.6em 0.7em;
  border-radius: 8px;
  border: 1px solid #3a4150;
  background: #0d1016;
  color: var(--text);
}

.controls-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin-top: 0.8rem;
}

.room-code {
  font-size: 2.2rem;
  font-weight: 900;
  letter-spacing: 0.15em;
}

.double-badge {
  display: inline-block;
  background: #f4a300;
  color: #111;
  font-weight: 800;
  padding: 0.2em 0.7em;
  border-radius: 999px;
  font-size: 0.85rem;
}

/* -------- presentation (projector) view -------- */
.presentation {
  padding: 2rem;
  min-height: 100vh;
}

.presentation .scoreboard {
  gap: 1.2rem;
  margin-bottom: 1.5rem;
}

.presentation .score-card {
  padding: 1.4rem;
  border-radius: 20px;
  border-top-width: 10px;
}

.presentation .score-card .name {
  font-size: 1.4rem;
}

.presentation .score-card .score {
  font-size: 3.2rem;
}

.presentation video {
  max-height: 62vh;
  object-fit: contain;
  margin: 0 auto;
}

.presentation-status {
  text-align: center;
  font-size: 2.2rem;
  font-weight: 800;
  margin: 1rem 0;
  min-height: 1.4em;
}

.back-to-setup {
  position: fixed;
  top: 10px;
  right: 10px;
  opacity: 0.35;
  font-size: 0.8rem;
  z-index: 1000;
}

.back-to-setup:hover {
  opacity: 1;
}
