/* Bar Dice — single shared stylesheet for every page. Mobile-first, dark, tight. */

:root {
  --bg: #0f1419;
  --panel: #1b232c;
  --panel-2: #232e39;
  --ink: #e8eef4;
  --muted: #8b9aa9;
  --line: #2c3845;
  --accent: #4cc38a; /* recommend / good */
  --accent-ink: #03160d;
  --warn: #e5534b; /* bust */
  --one: #f2c14e; /* wild 1s */
  --lock: #4cc38a;
  --pip: #e8eef4;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  overscroll-behavior: none;
}

body {
  max-width: 520px;
  margin: 0 auto;
  padding: env(safe-area-inset-top) 14px calc(env(safe-area-inset-bottom) + 14px);
}

/* --- Shared app bar + nav (injected by nav.js) ------------------------- */
.appbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px 12px;
  flex-wrap: wrap;
  padding: 12px 2px 10px;
  margin-bottom: 14px;
  border-bottom: 1px solid var(--line);
}
.brand {
  display: inline-flex;
  align-items: baseline;
  gap: 7px;
  text-decoration: none;
  color: var(--ink);
  font-weight: 800;
  font-size: 1.2rem;
  letter-spacing: 0.3px;
}
.brand .die-emoji { font-size: 1.2rem; }
.nav { display: flex; gap: 4px; flex-wrap: wrap; }
.nav a {
  text-decoration: none;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 600;
  padding: 5px 9px;
  border-radius: 8px;
}
.nav a:active { background: var(--panel-2); }
.nav a.active { color: var(--accent-ink); background: var(--accent); }

/* --- Generic content: pages, panels, prose ----------------------------- */
.page-title { font-size: 1.35rem; font-weight: 800; margin: 2px 0 12px; }
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px;
  margin-bottom: 12px;
}
.panel > h2, .panel > h3 { margin: 0 0 8px; font-size: 1rem; }
.prose p { color: var(--muted); line-height: 1.5; margin: 0 0 10px; }
.prose p:last-child { margin-bottom: 0; }
.prose h3 { color: var(--ink); font-size: 1rem; margin: 16px 0 6px; }
.prose h3:first-child { margin-top: 0; }
.prose b, .prose strong { color: var(--ink); }
a.link { color: var(--accent); text-decoration: none; font-weight: 600; }
.note { font-size: 0.8rem; color: var(--muted); margin: 0 0 10px; line-height: 1.4; }

.cta {
  display: inline-block;
  background: var(--accent);
  color: var(--accent-ink);
  text-decoration: none;
  font-weight: 800;
  padding: 13px 18px;
  border-radius: 12px;
}
.cta.ghost { background: var(--panel-2); color: var(--ink); border: 1px solid var(--line); }

/* Generic data table (theory page, etc.) */
.data-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.data-table th, .data-table td { padding: 8px 6px; text-align: right; border-bottom: 1px solid var(--line); }
.data-table th { color: var(--muted); font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.3px; font-weight: 600; }
.data-table th:first-child, .data-table td:first-child { text-align: left; }
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tr.active td { background: rgba(76, 195, 138, 0.12); color: var(--accent); }

/* Theory explorer controls */
.ex-controls { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; margin: 12px 0; }
.ex-controls label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--muted);
}
.ex-controls select {
  background: var(--panel-2);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 10px;
  font: inherit;
  font-size: 0.95rem;
}
.ex-controls .btn { flex: 0 0 auto; padding: 9px 14px; }
#exDice .die { cursor: pointer; }

.hidden { display: none !important; }

/* ======================================================================= */
/* Trainer-specific widgets                                                */
/* ======================================================================= */

/* --- Setup row --------------------------------------------------------- */
.setup { display: flex; gap: 8px; margin-bottom: 12px; }
.seg-field {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 3px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px 10px;
  color: var(--ink);
  font: inherit;
  text-align: left;
  min-height: 56px;
  justify-content: center;
}
button.seg-field:active { background: var(--panel-2); }
.seg-field.disabled { opacity: 0.45; }
.seg-field.disabled:active { background: var(--panel); }
.seg-label { font-size: 0.7rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; }
.seg-value { font-size: 1.4rem; font-weight: 700; line-height: 1; }
.tone-field { flex: 1.4; }
.tone-seg { display: flex; gap: 4px; }
.tone-seg button {
  flex: 1;
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--ink);
  border-radius: 8px;
  padding: 7px 0;
  font-size: 0.95rem;
  font-weight: 600;
}
.tone-seg button.active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

/* --- Verdict card ------------------------------------------------------ */
.verdict-card {
  background: linear-gradient(160deg, #1f3b2e, #18222b);
  border: 1px solid var(--accent);
  border-radius: 16px;
  padding: 16px;
  margin-bottom: 14px;
  text-align: center;
  min-height: 92px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 6px;
}
.verdict-card.neutral { background: var(--panel); border-color: var(--line); }
.verdict-card.bust { background: linear-gradient(160deg, #3b1f1f, #18222b); border-color: var(--warn); }
.verdict-move { font-size: 1.5rem; font-weight: 800; line-height: 1.4; }
.kr-label {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin: 0 4px 0 8px;
  vertical-align: middle;
}
.kr-label:first-child { margin-left: 0; }
.kr-none { color: var(--muted); font-weight: 700; }
.dice-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.6rem;
  height: 1.6rem;
  border-radius: 7px;
  margin: 0 2px;
  font-size: 1rem;
  font-weight: 800;
  vertical-align: middle;
  background: #f4f1ea;
  color: #1c1c1c;
}
.dice-chip.keep { background: #fbe9b0; color: #5a3d00; } /* soft gold = keep, matches the pool */
.dice-chip.roll { background: transparent; border: 1px dashed var(--line); color: var(--muted); font-weight: 700; }
.verdict-sub { font-size: 0.9rem; color: var(--muted); }
.verdict-card.bust .verdict-move { color: var(--warn); }
.verdict-pct { color: var(--accent); font-weight: 700; }
.bust-note { color: var(--warn); font-weight: 700; }
.alt-line {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--line);
  font-size: 0.82rem;
  color: var(--muted);
}

/* --- Pool -------------------------------------------------------------- */
.pool-section { margin-bottom: 14px; }
.pool-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.roll-indicator { font-size: 0.85rem; color: var(--muted); font-weight: 600; }
.dice-btn {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 1.2rem;
  width: 44px;
  height: 36px;
  color: var(--ink);
}
.dice-btn:active { background: var(--accent); }

.pool { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; margin-bottom: 12px; }

/* A single die (used in pool and palette) */
.die {
  position: relative;
  aspect-ratio: 1 / 1;
  background: #f4f1ea;
  border: none;
  border-radius: 14px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  grid-template-areas:
    "c1 c2 c3"
    "c4 c5 c6"
    "c7 c8 c9";
  padding: 14%;
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.35);
}
.die .pip { border-radius: 50%; background: transparent; }
.die .pip.on { background: #1c1c1c; }
.die .sparkle {
  position: absolute;
  top: -5px;
  left: -4px;
  font-size: 0.62rem;
  line-height: 1;
  pointer-events: none;
}

/* Pool slot states */
.slot { position: relative; }
.slot .die.empty { background: transparent; border: 2px dashed var(--line); box-shadow: none; }
/* Suggested keep = the die turns soft gold (the "best dice"). */
.slot.filled.recommended .die { background: #fbe9b0; }
.slot.filled.recommended .die .pip.on { background: #8a5b00; }
/* My keep choice = a crisp green outline on top of the gold. */
.slot.kept .die { outline: 3px solid var(--lock); outline-offset: 1px; }
.slot .clear-die {
  position: absolute;
  top: -7px;
  right: -7px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--warn);
  color: #fff;
  border: 2px solid var(--bg);
  font-size: 0.8rem;
  line-height: 1;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.slot.filled .clear-die { display: flex; }

/* Palette of selectable faces */
.palette { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; margin-bottom: 12px; }
.palette .die { border-radius: 10px; padding: 16%; }
.palette .die:active { transform: scale(0.92); }

/* --- Action buttons ---------------------------------------------------- */
.actions { display: flex; gap: 10px; }
.btn {
  flex: 1;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px;
  font-size: 1rem;
  font-weight: 700;
  color: var(--ink);
  background: var(--panel-2);
}
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); flex: 2; }
.btn.primary:disabled { opacity: 0.4; }
.btn.ghost:active { background: var(--panel); }

/* --- Why / stats ------------------------------------------------------- */
.why { margin-top: 4px; }
.committed-line { font-size: 0.9rem; color: var(--muted); text-align: center; margin-bottom: 10px; }
.committed-line b { color: var(--ink); }
.why table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.why th {
  color: var(--muted);
  font-weight: 600;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  text-align: right;
  padding: 6px 6px;
  border-bottom: 1px solid var(--line);
}
.why th:first-child { text-align: left; }
.why td { padding: 9px 6px; text-align: right; border-bottom: 1px solid var(--line); }
.why td:first-child { text-align: left; font-weight: 600; }
.why td.bust-cell { color: var(--warn); font-weight: 700; }
.why tr.best td { background: rgba(76, 195, 138, 0.12); }
.why tr.best td:first-child { color: var(--accent); }
.why .pill {
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 0.65rem;
  font-weight: 700;
  border-radius: 6px;
  padding: 1px 6px;
}
.legend { font-size: 0.75rem; color: var(--muted); margin-top: 10px; line-height: 1.4; }

/* --- Bottom-sheet picker (players / target) ---------------------------- */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: none;
  align-items: flex-end;
  z-index: 20;
}
.sheet-backdrop.open { display: flex; }
.sheet {
  width: 100%;
  max-width: 520px;
  margin: 0 auto;
  background: var(--panel);
  border-radius: 18px 18px 0 0;
  padding: 16px 16px calc(env(safe-area-inset-bottom) + 20px);
  border-top: 1px solid var(--line);
}
.sheet h3 { margin: 4px 0 14px; font-size: 1rem; text-align: center; }
.sheet-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.sheet-grid button {
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--ink);
  border-radius: 12px;
  padding: 16px 0;
  font-size: 1.1rem;
  font-weight: 700;
}
.sheet-grid button.sel { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.sheet-grid button.span-all { grid-column: 1 / -1; }
