:root {
  --bg: #0b0e14;
  --bg-dot: #131722;
  --panel: #11151c;
  --panel-header: #171c25;
  --border: #232a35;
  --text: #d7dee6;
  --muted: #6b7785;
  --green: #59e3a6;
  --amber: #ffb454;
  --pink: #ff6fae;
  --blue: #62a6ff;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow-x: hidden; }
body {
  min-height: 100dvh;
  background: radial-gradient(circle at 1px 1px, var(--bg-dot) 1px, transparent 0) 0 0/22px 22px, var(--bg);
  color: var(--text);
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 1.2rem;
  user-select: none;
}
.hidden { display: none !important; }

.wordmark { font-size: clamp(1.1rem, 4vw, 1.5rem); font-weight: 700; letter-spacing: -0.02em; margin-bottom: 1rem; display: flex; align-items: baseline; gap: 2px; }
.wordmark .dim { color: var(--muted); font-weight: 500; }
.wordmark a { color: inherit; text-decoration: none; }

.card { width: 100%; max-width: 480px; background: var(--panel); border: 1px solid var(--border); border-radius: 14px; box-shadow: 0 20px 60px rgba(0,0,0,0.5); overflow: hidden; display: flex; flex-direction: column; }
.card-header { background: var(--panel-header); padding: 0.6rem 0.8rem; display: flex; align-items: center; gap: 0.6rem; border-bottom: 1px solid var(--border); font-size: 0.78rem; color: var(--muted); }
.card-header .term-icon { color: var(--green); }
.card-header .fill { flex: 1; }
.card-body { padding: 1.4rem 1.3rem; display: flex; flex-direction: column; gap: 1rem; }

h1 { font-size: 1.25rem; margin: 0; text-align: center; }
h2 { font-size: 0.85rem; margin: 0 0 0.4rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; }

.players-list { display: flex; flex-direction: column; gap: 6px; }
.player-row { display: flex; align-items: center; gap: 6px; }
.player-row input[type=text] {
  flex: 1; background: var(--panel-header); border: 1px solid var(--border); border-radius: 8px;
  color: var(--text); font-family: inherit; font-size: 0.9rem; padding: 0.55rem 0.7rem;
}
.player-row .removeBtn {
  width: 34px; height: 34px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--panel-header); color: var(--muted); font-size: 1rem; cursor: pointer;
}
.player-row .removeBtn:active { background: rgba(255,255,255,0.06); }

.btn { width: 100%; padding: 0.85rem; border-radius: 10px; border: none; font-family: inherit; font-size: 0.95rem; font-weight: 600; cursor: pointer; color: #0b0e14; background: var(--green); }
.btn:active { filter: brightness(0.9); }
.btn.secondary { background: transparent; color: var(--text); border: 1px solid var(--border); }
.btn.small { padding: 0.55rem; font-size: 0.85rem; }

.time-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.6rem; }
.time-field { display: flex; flex-direction: column; gap: 3px; }
.time-field label { font-size: 0.72rem; color: var(--muted); }
.time-field .pair { display: flex; align-items: center; gap: 4px; }
.time-field input[type=number] {
  width: 100%; background: var(--panel-header); border: 1px solid var(--border); border-radius: 8px;
  color: var(--text); font-family: inherit; font-size: 0.95rem; padding: 0.5rem; text-align: center;
  -moz-appearance: textfield;
}
.time-field input::-webkit-outer-spin-button, .time-field input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.time-field .unit { font-size: 0.75rem; color: var(--muted); }

.toggle-row { display: flex; align-items: center; justify-content: space-between; padding: 0.6rem 0.1rem; }
.toggle-row span { font-size: 0.88rem; }
.switch { position: relative; width: 44px; height: 24px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; inset: 0; background: var(--border); border-radius: 999px; cursor: pointer; transition: 0.15s; }
.slider::before { content: ""; position: absolute; width: 18px; height: 18px; left: 3px; top: 3px; background: var(--text); border-radius: 50%; transition: 0.15s; }
.switch input:checked + .slider { background: var(--green); }
.switch input:checked + .slider::before { transform: translateX(20px); background: #0b0e14; }

.dice-count-row { display: flex; align-items: center; justify-content: space-between; gap: 0.6rem; padding: 0.3rem 0.1rem 0.1rem; }
.dice-count-row span { font-size: 0.82rem; color: var(--muted); }
.stepper-inline { display: flex; align-items: center; gap: 0.5rem; }
.stepper-inline button { width: 30px; height: 30px; border-radius: 6px; border: 1px solid var(--border); background: var(--panel-header); color: var(--text); font-size: 1rem; cursor: pointer; }
.stepper-inline .val { min-width: 1.5ch; text-align: center; font-weight: 700; }

.hint { font-size: 0.78rem; color: var(--muted); text-align: center; }

/* --- Arena (fullscreen playing view) --- */
.arena {
  position: fixed; inset: 0; z-index: 50;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: var(--bg);
}
.arena-controls {
  position: fixed; top: 0; left: 0; right: 0;
  display: flex; justify-content: space-between; padding: 0.8rem;
  z-index: 51;
}
.arena-controls button {
  background: rgba(255,255,255,0.05); border: 1px solid var(--border); color: var(--text);
  border-radius: 8px; width: 42px; height: 42px; font-size: 1.1rem; cursor: pointer;
}
.arena-content { display: flex; flex-direction: column; align-items: center; gap: 0.6rem; padding: 1rem; text-align: center; }
.arena-name { font-size: 1.1rem; color: var(--muted); letter-spacing: 0.03em; }
.arena-time { font-size: clamp(3.2rem, 18vw, 5.5rem); font-weight: 700; letter-spacing: 0.02em; color: var(--green); }
.arena-time.warn { color: var(--amber); }
.arena-time.critical { color: var(--pink); }
.arena-dice { font-size: 3.2rem; font-weight: 700; min-height: 3.5rem; letter-spacing: 0.05em; }
.arena-others { display: flex; flex-wrap: wrap; gap: 0.4rem 0.8rem; justify-content: center; margin-top: 0.4rem; max-width: 90vw; }
.arena-others .op { font-size: 0.78rem; color: var(--muted); }
.arena-others .op.out { text-decoration: line-through; color: var(--pink); opacity: 0.6; }
.arena-hint { font-size: 0.75rem; color: var(--muted); margin-top: 0.8rem; }
.arena-winner { font-size: 1.4rem; color: var(--green); font-weight: 700; }
.arena.paused .arena-content { opacity: 0.5; }

@keyframes blinkRed {
  50% { background: rgba(255, 55, 88, 0.35); }
}
.arena.time-up-blink { animation: blinkRed 0.55s steps(2, start) infinite; }
.arena.time-up-blink .arena-content { opacity: 1; }

footer { margin-top: 1.2rem; color: var(--muted); font-size: 0.72rem; text-align: center; }

.arena-event-die {min-height: 1.6rem; margin-top: 0.2rem;}
.event-badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 14px; border-radius: 999px;
  font-weight: 700; font-size: 0.9rem; letter-spacing: 0.03em;
}
.event-badge svg { flex-shrink: 0; }
.event-badge.ship {background: rgba(255, 111, 174, 0.15); color: var(--pink);}
.event-badge.trade {background: rgba(255, 180, 84, 0.15); color: var(--amber);}
.event-badge.politics {background: rgba(98, 166, 255, 0.15); color: var(--blue);}
.event-badge.science {background: rgba(89, 227, 166, 0.15); color: var(--green);}