:root {
  color-scheme: dark;
  --bg: #0b0f1d;
  --panel: #151b30;
  --panel-2: #1d2440;
  --line: #2b3557;
  --text: #eef2ff;
  --muted: #a6b0d0;
  --accent: #7aa2ff;
  --accent-2: #4dd4ac;
  --danger: #ff6b6b;
  --radius: 16px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background:
    radial-gradient(circle at 15% 0%, #1b2550 0, transparent 45%),
    radial-gradient(circle at 85% 100%, #13313a 0, transparent 40%),
    var(--bg);
}

button, input, select { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .45; }
[hidden], .hidden { display: none !important; }

.screen {
  width: min(1100px, 100%);
  margin: 0 auto;
  padding: clamp(16px, 3vw, 36px);
}

.hero { text-align: center; margin: 12px 0 28px; }
.eyebrow { margin: 0; color: var(--accent-2); letter-spacing: .18em; text-transform: uppercase; font-size: .75rem; }
.hero h1 { margin: 6px 0 4px; font-size: clamp(2.6rem, 7vw, 4.5rem); line-height: 1; letter-spacing: -.04em; }
.tagline { margin: 0 auto; max-width: 620px; color: var(--muted); }

.section-title { font-size: .85rem; text-transform: uppercase; letter-spacing: .12em; color: var(--muted); margin: 0 0 12px; }

.mode-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.mode-card {
  display: flex; flex-direction: column; gap: 6px; text-align: left;
  padding: 18px; min-height: 148px;
  color: var(--text); background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); transition: border-color .15s, transform .15s, background .15s;
}
.mode-card:hover { transform: translateY(-2px); border-color: var(--accent); }
.mode-card.active { border-color: var(--accent); background: linear-gradient(160deg, #202b52, var(--panel)); box-shadow: 0 0 0 1px var(--accent) inset; }
.mode-card strong { font-size: 1.05rem; }
.mode-card > span:last-child { color: var(--muted); font-size: .84rem; line-height: 1.35; }
.mode-icon { font-size: 1.9rem; color: var(--accent-2); }

.setup-panel {
  margin-top: 20px; padding: 20px;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
}
.field { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.field > label { font-size: .9rem; font-weight: 600; }
.hint { color: var(--muted); font-size: .8rem; font-weight: 400; margin: 0; }
.field-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 16px; margin-top: 18px; align-items: start; }
.checkline { display: flex; gap: 8px; align-items: flex-start; line-height: 1.35; }
.checkline input { margin-top: 2px; }

select, input[type="text"], input[type="number"] {
  width: 100%; padding: 10px 12px; border-radius: 10px;
  color: var(--text); background: var(--panel-2); border: 1px solid var(--line);
}

.players { display: grid; gap: 8px; }
.player-row { display: flex; gap: 8px; align-items: center; }
.player-row .p-name { flex: 1 1 150px; min-width: 90px; }
.player-row .p-type { flex: 0 1 110px; }
.player-row .p-level { flex: 0 1 110px; }
.swatch {
  width: 14px; height: 14px; flex: 0 0 14px; border-radius: 50%;
  background: var(--c, #fff); box-shadow: 0 0 10px var(--c, #fff);
}
.p-remove { width: 34px; height: 34px; flex: 0 0 34px; border-radius: 9px; background: transparent; color: var(--muted); border: 1px solid var(--line); font-size: 1.2rem; line-height: 1; }

.primary, .ghost { border-radius: 10px; padding: 10px 16px; font-weight: 600; }
.primary { background: var(--accent); color: #0a1024; border: 0; }
.primary:hover { filter: brightness(1.08); }
.ghost { background: var(--panel-2); color: var(--text); border: 1px solid var(--line); }
.ghost:hover:not(:disabled) { border-color: var(--accent); }
.setup-panel > .primary { margin-top: 20px; width: 100%; padding: 14px; font-size: 1.05rem; }
#add-player { align-self: flex-start; margin-top: 4px; font-size: .85rem; }

.rules { margin-top: 20px; color: var(--muted); font-size: .9rem; }
.rules summary { cursor: pointer; padding: 10px 0; font-weight: 600; color: var(--text); }
.rules li { margin-bottom: 6px; line-height: 1.45; }

/* ---- Partida ---- */
#game { width: min(900px, 100%); }
.topbar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.topbar .mode-label { flex: 1; text-align: center; color: var(--muted); font-size: .9rem; }
.top-actions { display: flex; gap: 8px; }
.top-actions .share { border-color: var(--accent); }

.scoreboard { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.score-chip {
  display: flex; align-items: center; gap: 8px; padding: 7px 11px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 999px; font-size: .86rem;
}
.score-chip.active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.score-name { font-weight: 600; }
.badge { color: var(--muted); font-size: .72rem; }
.score-value { color: var(--accent-2); min-width: 1.2em; text-align: right; }
.status { text-align: center; color: var(--muted); margin: 14px 0 8px; min-height: 1.4em; }

.board-wrap {
  position: relative;
  width: min(100%, 76vh); aspect-ratio: 1; margin: 0 auto;
  background: linear-gradient(160deg, rgba(29, 36, 64, .9), rgba(14, 20, 38, .95));
  border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden;
}
#board { width: 100%; height: 100%; display: block; touch-action: none; user-select: none; }

.dot { fill: #d9e4ff; pointer-events: none; }
.dot.selected { fill: #fff; stroke: var(--accent); stroke-width: 2; vector-effect: non-scaling-stroke; }
.dot-hit { fill: transparent; pointer-events: all; cursor: crosshair; }
.drawn-line { stroke-width: 3.5; stroke-linecap: round; vector-effect: non-scaling-stroke; }
.drawn-line.flash { animation: line-flash .5s ease-out; }
@keyframes line-flash {
  0% { stroke-width: 9; filter: drop-shadow(0 0 7px #fff); opacity: 1; }
  100% { stroke-width: 3.5; filter: drop-shadow(0 0 0 transparent); opacity: 1; }
}
.figure { opacity: .3; pointer-events: none; }
.preview-line { stroke: #fff; stroke-width: 2; stroke-dasharray: 5 4; opacity: .75; pointer-events: none; vector-effect: non-scaling-stroke; }
.preview-line.invalid { stroke: var(--danger); opacity: .9; }

.bot-banner {
  position: absolute; inset: 0; z-index: 5;
  display: grid; place-items: center;
  background: rgba(8, 12, 26, .72);
  backdrop-filter: blur(2px); pointer-events: none;
}
.bot-banner-inner {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 20px; border-radius: 999px;
  background: var(--panel-2); border: 1px solid var(--accent);
  font-weight: 600; box-shadow: 0 10px 30px rgba(0, 0, 0, .5);
}
.bot-banner-pulse {
  width: 11px; height: 11px; flex: 0 0 11px; border-radius: 50%;
  background: var(--accent-2);
  animation: bot-pulse 1s ease-in-out infinite alternate;
}
@keyframes bot-pulse {
  from { opacity: .35; transform: scale(.8); }
  to { opacity: 1; transform: scale(1.25); }
}

.dice-area { display: flex; flex-direction: column; align-items: center; gap: 4px; margin-top: 14px; }
.die {
  width: 74px; height: 74px; border-radius: 16px; border: 1px solid var(--line);
  background: linear-gradient(160deg, #f7f9ff, #cfd8f5); color: #141a30;
  font-size: 2.7rem; line-height: 1; box-shadow: 0 8px 20px rgba(0, 0, 0, .35);
}
.die:hover:not(:disabled) { transform: translateY(-2px); }
.die.rolling { animation: shake .16s linear infinite alternate; }
@keyframes shake { from { transform: rotate(-7deg) scale(.96); } to { transform: rotate(7deg) scale(1.04); } }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  padding: 10px 18px; border-radius: 999px; background: #232d52; border: 1px solid var(--accent);
  font-size: .9rem; z-index: 20; box-shadow: 0 8px 24px rgba(0, 0, 0, .4);
}

.modal { position: fixed; inset: 0; background: rgba(5, 8, 18, .78); display: grid; place-items: center; padding: 20px; z-index: 30; }
.modal-card {
  width: min(420px, 100%); padding: 24px; border-radius: var(--radius);
  background: var(--panel); border: 1px solid var(--line); text-align: center;
}
.modal-card h2 { margin: 0 0 18px; font-size: 1.8rem; }
.result-list { display: grid; gap: 8px; margin-bottom: 20px; }
.result-row { display: flex; align-items: center; gap: 10px; padding: 9px 12px; background: var(--panel-2); border-radius: 10px; }
.result-name { flex: 1; text-align: left; font-weight: 600; }
.rank { color: var(--muted); width: 1.2em; text-align: right; }
.modal-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }

@media (max-width: 760px) {
  .mode-grid { grid-template-columns: repeat(2, 1fr); }
  .mode-card { min-height: 130px; padding: 14px; }
  .player-row { flex-wrap: wrap; }
  .player-row .p-name { flex-basis: 100%; }
  .player-row .p-type, .player-row .p-level { flex: 1 1 90px; }
  .board-wrap { width: 100%; }
  .topbar .mode-label { order: -1; flex-basis: 100%; }
}
