:root {
  --accent: #1a8c33;
  --accent-soft: rgba(26, 140, 51, 0.15);
  --bg: #f2f3f5;
  --card: #ffffff;
  --text: #1c1c1e;
  --muted: #8a8a8e;
  --line: #e3e3e6;
  --green: #1a8c33;
  --red: #d23a3a;
  --gold: #d9a400;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --card: #1c1c1e;
    --text: #f2f2f7;
    --muted: #98989f;
    --line: #2c2c2e;
    --accent-soft: rgba(48, 209, 88, 0.22);
    --accent: #30d158;
    --green: #30d158;
    --red: #ff453a;
    --gold: #ffd60a;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

#app {
  max-width: 480px;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right))
           max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}

button {
  font-family: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
  transition: transform 0.08s ease, opacity 0.12s ease, background 0.12s ease;
}
button:active { transform: scale(0.97); }

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

.card {
  background: var(--card);
  border-radius: 18px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
  animation: cardIn 0.22s ease;
}

@keyframes cardIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

.title { font-size: 26px; text-align: center; margin: 4px 0 8px; }

.field-label, .bank-label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin-top: 4px;
}

.hint { font-size: 13px; color: var(--muted); margin: 0; text-align: center; }
.subtitle { font-size: 16px; color: var(--muted); text-align: center; margin: 0; }

.players { display: flex; flex-direction: column; gap: 8px; }
.player-row { display: flex; gap: 8px; align-items: center; }

.input {
  flex: 1;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 16px;
  background: var(--bg);
  color: var(--text);
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 12px;
  padding: 16px;
  font-size: 17px;
  font-weight: 600;
  margin-top: 6px;
}
.btn-primary:disabled { opacity: 0.4; }

.btn-secondary {
  background: var(--accent-soft);
  color: var(--accent);
  border: none;
  border-radius: 10px;
  padding: 12px;
  font-size: 15px;
  font-weight: 600;
}

.btn-undo {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  font-size: 14px;
  font-weight: 600;
}

.icon-btn {
  background: transparent;
  border: none;
  color: var(--red);
  font-size: 18px;
  padding: 8px;
}

.link-btn { background: none; border: none; color: var(--accent); font-size: 16px; padding: 4px; }

.topbar { display: flex; justify-content: space-between; align-items: center; }
.topbar-right { display: flex; gap: 12px; align-items: center; }
.round { font-weight: 600; }
.edit-tag {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 4px 8px;
  border-radius: 8px;
  white-space: nowrap;
}

.bank {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 18px 16px;
  border-radius: 16px;
  color: #fff;
  background: linear-gradient(135deg, var(--accent), color-mix(in srgb, var(--accent), #000 30%));
  box-shadow: 0 6px 18px color-mix(in srgb, var(--accent), transparent 70%);
}
.bank .bank-label { color: rgba(255, 255, 255, 0.85); margin: 0; }
.bank-amount {
  font-size: 56px;
  font-weight: 800;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.bank-amount.pulse { animation: pulse 0.45s ease; }
@keyframes pulse {
  0% { transform: scale(1); }
  35% { transform: scale(1.15); }
  100% { transform: scale(1); }
}
.current {
  font-weight: 700;
  font-size: 15px;
  background: rgba(255, 255, 255, 0.18);
  padding: 6px 12px;
  border-radius: 999px;
}

.sep { border: none; border-top: 1px solid var(--line); margin: 6px 0; width: 100%; }

.phase { display: flex; flex-direction: column; gap: 12px; }

.die-picker { display: flex; gap: 6px; }
.die {
  flex: 1;
  aspect-ratio: 1;
  padding: 7px;
  border: 2px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  display: flex;
}
.die.selected {
  border-color: var(--accent);
  background: var(--accent-soft);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent), transparent 80%);
}
.die-face {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
}
.pip-cell { display: flex; align-items: center; justify-content: center; }
.pip {
  width: 56%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: var(--text);
}
.die.selected .pip { background: var(--accent); }

.stepper { display: flex; align-items: center; gap: 16px; justify-content: center; }
.step-btn {
  width: 48px; height: 48px; border-radius: 24px;
  border: none; background: var(--accent-soft); color: var(--accent);
  font-size: 24px; font-weight: 700;
}
.step-val { font-size: 24px; font-weight: 700; min-width: 60px; text-align: center; }

.outcome { align-items: center; text-align: center; animation: pop 0.28s cubic-bezier(0.2, 0.8, 0.3, 1.2); }
@keyframes pop {
  from { opacity: 0; transform: scale(0.85); }
  to { opacity: 1; transform: none; }
}
.outcome-icon { font-size: 52px; }
.outcome-icon.gold { color: var(--gold); }
.outcome-icon.green { color: var(--green); }
.outcome-icon.red { color: var(--red); }
.outcome-icon.muted { color: var(--muted); }
.outcome-title { margin: 0; font-size: 22px; }

.scoreboard {
  background: var(--bg);
  border-radius: 12px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.score-row { display: flex; justify-content: space-between; }
.score-name.cur { font-weight: 700; color: var(--accent); }
.score-bal { font-variant-numeric: tabular-nums; font-weight: 600; }
.score-bal.pos { color: var(--green); }
.score-bal.neg { color: var(--red); }
.score-bal.zero { color: var(--muted); }

.overlay {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex; align-items: flex-end; justify-content: center;
  z-index: 10;
  animation: fade 0.15s ease;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.modal {
  background: var(--card);
  width: 100%; max-width: 480px;
  border-radius: 18px 18px 0 0;
  padding: 16px;
  padding-bottom: max(16px, env(safe-area-inset-bottom));
  max-height: 80vh; overflow-y: auto;
  display: flex; flex-direction: column; gap: 10px;
  animation: slideUp 0.22s ease;
}
@keyframes slideUp {
  from { transform: translateY(24px); opacity: 0.4; }
  to { transform: none; opacity: 1; }
}
.history { display: flex; flex-direction: column; gap: 8px; }
.log { font-size: 14px; padding: 8px 0; border-bottom: 1px solid var(--line); }

/* Lobby */
.spacer { width: 48px; }
.game-list { display: flex; flex-direction: column; gap: 10px; }
.game-item {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg);
  border-radius: 12px;
  padding: 12px 14px;
}
.game-main { flex: 1; cursor: pointer; display: flex; flex-direction: column; gap: 2px; }
.game-name { font-size: 17px; font-weight: 700; }
.game-sub { font-size: 13px; color: var(--muted); }
.game-meta { font-size: 13px; color: var(--accent); font-weight: 600; }

/* Vyrovnání */
.settle-list { display: flex; flex-direction: column; gap: 8px; }
.settle-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--bg);
  border-radius: 10px;
  padding: 12px 14px;
}
.settle-names { font-weight: 600; }
.settle-amount {
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
}
