* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg: #0d1117;
  --bg-card: #161b22;
  --bg-hover: #1c2333;
  --text: #c9d1d9;
  --text-dim: #8b949e;
  --accent: #238636;
  --accent-hover: #2ea043;
  --border: #30363d;
  --gold: #f0c040;
  --silver: #c0c0c0;
  --radius: 12px;
  --shadow: 0 4px 24px rgba(0,0,0,0.4);
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

/* Screens */
.screen {
  display: none;
  height: 100%;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.screen.active {
  display: flex;
}
.screen-inner {
  width: 100%;
  max-width: 420px;
  text-align: center;
}

h1 {
  font-size: 2rem;
  font-weight: 800;
  background: linear-gradient(135deg, var(--gold), #e0a030);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-bottom: 8px;
}
h2 {
  font-size: 1.4rem;
  margin-bottom: 16px;
}
h3 {
  font-size: 1rem;
  color: var(--text-dim);
  margin-bottom: 8px;
}
.subtitle {
  color: var(--text-dim);
  margin-bottom: 32px;
}

/* Buttons */
.btn-group {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.btn-primary, .btn-secondary {
  padding: 14px 24px;
  border: none;
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, opacity 0.2s;
}
.btn-primary {
  background: var(--accent);
  color: #fff;
}
.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
}
.btn-primary:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.btn-secondary {
  background: var(--bg-card);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover {
  background: var(--bg-hover);
}

/* QR section */
.qr-section {
  background: #fff;
  border-radius: var(--radius);
  padding: 16px;
  display: inline-block;
  margin-bottom: 16px;
}
.qr-section canvas, .qr-section img {
  display: block;
  margin: 0 auto;
}
.hint {
  color: var(--text-dim);
  font-size: 0.85rem;
  margin-top: 8px;
}

/* Player list */
.player-section {
  margin: 16px 0;
}
.player-list {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}
.player-chip {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 6px 16px;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  gap: 6px;
}
.player-chip .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}
.player-chip .dot.online {
  background: var(--accent);
}
.player-chip .dot.waiting {
  background: #f0c040;
}
.player-chip.self {
  border-color: var(--accent);
}

/* Camera section */
.camera-section {
  position: relative;
  margin-bottom: 16px;
}
.camera-section video {
  width: 100%;
  max-width: 320px;
  border-radius: var(--radius);
  border: 2px solid var(--border);
}

/* Protocol status */
.protocol-status {
  display: flex;
  justify-content: center;
  gap: 4px;
  margin: 20px 0;
}
.phase {
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 0.75rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-dim);
  transition: all 0.3s;
}
.phase.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.phase.done {
  background: #1a4a1a;
  border-color: var(--accent);
  color: var(--accent);
}

.protocol-text {
  margin: 12px 0;
  color: var(--text-dim);
  font-size: 0.9rem;
}

/* Coin flip animation */
.coin {
  width: 120px;
  height: 120px;
  margin: 24px auto;
  perspective: 600px;
  cursor: default;
}
.coin.large {
  width: 160px;
  height: 160px;
}
.coin-inner {
  width: 100%;
  height: 100%;
  position: relative;
  transform-style: preserve-3d;
  transition: transform 1.5s cubic-bezier(0.22, 1, 0.36, 1);
}
.coin-face {
  position: absolute;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  backface-visibility: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.5rem;
  font-weight: 900;
  color: #333;
}
.coin.large .coin-face {
  font-size: 3.5rem;
}
.coin-face.front {
  background: radial-gradient(circle at 40% 35%, #ffe066, #f0c040 50%, #c89020);
  border: 4px solid #b8860b;
  transform: rotateY(0deg);
}
.coin-face.back {
  background: radial-gradient(circle at 40% 35%, #e8e8e8, #c0c0c0 50%, #909090);
  border: 4px solid #707070;
  transform: rotateY(180deg);
}
.coin.flipping .coin-inner {
  animation: coinFlip 1.5s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}
@keyframes coinFlip {
  0%   { transform: rotateY(0deg); }
  60%  { transform: rotateY(720deg); }
  80%  { transform: rotateY(800deg); }
  100% { transform: rotateY(720deg); }
}
.coin.result-kopf .coin-inner {
  transform: rotateY(0deg);
}
.coin.result-zahl .coin-inner {
  transform: rotateY(180deg);
}

/* Result area */
#result-area {
  margin-top: 24px;
}
#result-text {
  font-size: 2rem;
  margin-bottom: 16px;
}
#result-title {
  font-size: 3rem;
  margin: 24px 0 8px;
}
#result-detail {
  color: var(--text-dim);
  margin-bottom: 24px;
  font-size: 0.9rem;
}

/* Host camera (scan answer) */
#host-scan-answer {
  margin: 12px 0;
}
#host-camera {
  width: 100%;
  max-width: 240px;
  border-radius: var(--radius);
  display: none;
  margin: 8px auto;
}
#host-camera.active {
  display: block;
}
#host-scan-status {
  color: var(--text-dim);
  font-size: 0.85rem;
}

/* Join answer QR */
#join-answer-section {
  margin: 16px 0;
}
#join-answer-section .qr-section {
  background: #fff;
  border-radius: var(--radius);
  padding: 16px;
  display: inline-block;
}

/* Responsive */
@media (max-width: 480px) {
  .screen {
    padding: 16px;
  }
  h1 { font-size: 1.6rem; }
  .phase {
    font-size: 0.65rem;
    padding: 4px 8px;
  }
  .coin { width: 100px; height: 100px; }
  .coin.large { width: 140px; height: 140px; }
  .coin-face { font-size: 2rem; }
  .coin.large .coin-face { font-size: 3rem; }
}

/* Debug helpers (visible only in ?debug mode) */
.debug-only { display: none; }
.debug-mode .debug-only { display: revert; }

.debug-helper {
  margin-top: 12px;
  text-align: left;
  font-size: 0.8rem;
}
.debug-helper summary {
  cursor: pointer;
  color: var(--text-dim);
}
.debug-helper summary:hover {
  color: var(--text);
}
.raw-data {
  margin-top: 6px;
  padding: 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-family: monospace;
  font-size: 0.7rem;
  word-break: break-all;
  white-space: pre-wrap;
  color: var(--text-dim);
  max-height: 100px;
  overflow: auto;
}
.debug-helper textarea {
  width: 100%;
  margin-top: 6px;
  padding: 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-family: monospace;
  font-size: 0.75rem;
  resize: vertical;
}
.btn-small {
  margin-top: 6px;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-card);
  color: var(--text);
  cursor: pointer;
  font-size: 0.75rem;
}
.btn-small:hover {
  background: var(--bg-hover);
}

/* Room code (debug mode) */
.room-code {
  margin: 16px 0;
  text-align: center;
}
.room-code-label {
  display: block;
  font-size: 0.8rem;
  color: var(--text-dim);
  margin-bottom: 4px;
}
.room-code-value {
  display: inline-block;
  font-family: 'Courier New', monospace;
  font-size: 2.5rem;
  font-weight: 800;
  letter-spacing: 6px;
  color: var(--gold);
  background: var(--bg-card);
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 8px 24px;
  user-select: all;
}

/* Utility */
.hidden { display: none !important; }
