:root {
  --ink: #111111;
  --line: #1a1a1a;
  --bg: #f4f4f1;
  --panel: #ffffff;
  --accent: #d8b400;
  --accent-soft: #fff4c2;
  --blue: #2b6cff;
  --red: #e23b3b;
  --muted: #777777;
  --radius: 10px;
  --gap: 8px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  line-height: 1.4;
}

/* Page wrapper hugs the content width so the top bar and the columns
   share the same right edge (tabs end up above the results column). */
.page {
  width: fit-content;
  max-width: 100%;
  margin: 0 auto;
}

/* Slim top bar: title on the left, Play/Config tabs on the right */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 8px 16px;
}

.topbar h1 {
  margin: 0;
  font-family: "Exo 2", "Segoe UI", sans-serif;
  font-style: italic;
  font-weight: 800;
  font-size: 1.5rem;
  letter-spacing: 3px;
  text-transform: uppercase;
}

/* Tabs */
.tabs {
  display: flex;
  gap: 6px;
}

.tab {
  font: inherit;
  font-weight: 600;
  padding: 6px 16px;
  border: 2px solid var(--ink);
  border-radius: var(--radius);
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.tab:hover:not(.is-active) { background: #faf8ec; }

.tab.is-active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--ink);
}

/* Tab panels */
.tab-panel { display: none; }
.tab-panel.is-active { display: block; }

main {
  padding: 8px 16px 16px;
}

/* Two-column layout: controls on the left, results on the right */
.layout {
  display: grid;
  grid-template-columns: max-content 280px;
  gap: 12px;
  justify-content: start;
  align-items: start;
}

/* The four play sections tile as a 2×2 grid inside the left column.
   Left column hugs its content (Speed / Lost control) so the right column
   (Stability / Damage) sits right beside it with no empty gap. */
.col-main {
  display: grid;
  grid-template-columns: max-content max-content;
  gap: 12px;
  align-items: start;
}

.col-results {
  position: sticky;
  top: 8px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.result-card {
  margin-bottom: 0;
  text-align: center;
}

.result-card h2 {
  margin-bottom: 6px;
}

.result-card .result-hex {
  margin: 0 auto;
}

.result-line {
  font-weight: 700;
  font-size: 1.15rem;
  min-height: 1.3em;
  word-break: break-word;
}

@media (max-width: 820px) {
  .layout { grid-template-columns: 1fr; }
  .col-main { grid-template-columns: 1fr; }
  .col-results { position: static; }
}

.section {
  background: var(--panel);
  border: 1px solid #e2e2dd;
  border-radius: var(--radius);
  padding: 10px 14px;
  margin-bottom: 0;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.section h2 {
  margin: 0 0 6px;
  font-size: 1.1rem;
}

/* Inline info marker that replaces the per-section hint paragraph */
.hint-i {
  cursor: help;
  font-size: 0.85rem;
  font-weight: 400;
  color: var(--muted);
  vertical-align: middle;
}

.hint {
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 0.9rem;
}

/* --- Dice rows --- */
.dice-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--gap);
  align-items: flex-start;
}

/* Every dice pool lays out as fixed rows of three (never 4 + 2). For Speed and
   Lost control this also keeps the left grid column at a tight, predictable width;
   Stability and Damage match so their dice (plus the "+" add cube) wrap 3 per row. */
#speed-dice,
#lost-dice,
#stability-dice,
#damage-dice {
  display: grid;
  grid-template-columns: repeat(3, max-content);
  justify-content: start;
  gap: var(--gap);
}

.die-cell {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.die {
  display: block;
  background: transparent;
}

.die-label {
  font-size: 0.78rem;
  color: var(--muted);
  text-align: center;
  max-width: 110px;
}

/* Selectable speed dice */
.selectable .die-cell {
  cursor: pointer;
  padding: 8px;
  border: 2px solid transparent;
  border-radius: var(--radius);
  transition: border-color 0.15s, background 0.15s;
}

.selectable .die-cell:hover {
  background: #faf8ec;
}

.selectable .die-cell.selected {
  border-color: var(--accent);
  background: var(--accent-soft);
}

/* Speed-level hexagon tiles (Section 1) */
.speed-tile {
  cursor: pointer;
  padding: 2px;
  border-radius: 10px;
  transition: background 0.15s;
}
.speed-tile:hover { background: #faf8ec; }
.speed-tile.selected { background: #f6f6f0; }

.range-rect {
  margin-top: 6px;
  min-width: 62px;
  padding: 3px 10px;
  text-align: center;
  font-weight: 800;
  font-size: 0.95rem;
  letter-spacing: 0.5px;
  background: #ffffff;
  border: 2px solid #999;
  border-radius: 7px;
}

/* Detailed stability breakdown kept at the bottom of the left column */
.stability-total {
  margin-top: 8px;
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--muted);
  min-height: 1.2em;
  /* Fill the section width but don't drive it: the long breakdown line wraps
     instead of widening the (content-sized) column and stretching Damage. */
  width: 0;
  min-width: 100%;
}

/* Selectable damage dice (Section 4) */
.damage-die {
  cursor: pointer;
  padding: 2px;
  border: 2px solid transparent;
  border-radius: 8px;
  transition: background 0.15s, border-color 0.15s;
}
.damage-die:hover { background: #faf8ec; }
.damage-die.selected {
  border-color: var(--accent);
  background: var(--accent-soft);
}

/* --- Buttons --- */
.btn {
  font: inherit;
  font-weight: 600;
  padding: 10px 20px;
  border: 2px solid var(--ink);
  border-radius: var(--radius);
  background: var(--ink);
  color: #fff;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.05s;
}

.btn:hover:not(:disabled) { opacity: 0.88; }
.btn:active:not(:disabled) { transform: translateY(1px); }

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn-ghost {
  background: transparent;
  color: var(--ink);
}

.speed-controls,
.stability-controls,
.lost-controls,
.damage-controls,
.config-controls {
  margin: 8px 0 0;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.damage-controls label { font-weight: 600; }

.damage-controls select {
  font: inherit;
  padding: 8px 10px;
  border: 1px solid #ccc;
  border-radius: 8px;
}

/* --- Movement result hexagon (right column) --- */
.result-hex { display: block; }
.result-hex.flash { animation: pop 0.35s ease; }

@keyframes pop {
  0% { transform: scale(0.85); }
  60% { transform: scale(1.06); }
  100% { transform: scale(1); }
}

.empty-note {
  color: var(--muted);
  font-style: italic;
}

/* --- Stability / lost-control pools --- */
.stability-cell,
.lost-cell { cursor: pointer; }

.add-die {
  cursor: pointer;
  opacity: 0.65;
  transition: opacity 0.15s;
}
.add-die:hover { opacity: 1; }

/* Stability result swatch is a <canvas> — triangles/label are drawn in JS */
.result-swatch {
  margin-top: 8px;
  display: block;
  border-radius: 6px;
}

/* --- Config tables (Section 5) --- */
.config-tables {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 18px;
}

.config-table {
  border: 1px solid #e2e2dd;
  border-radius: var(--radius);
  overflow: hidden;
}

.config-table h3 {
  margin: 0;
  padding: 8px 10px;
  background: var(--ink);
  color: #fff;
  font-size: 0.9rem;
}

.config-table table {
  width: 100%;
  border-collapse: collapse;
}

.config-table td {
  padding: 3px 8px;
  border-top: 1px solid #efefe9;
  font-size: 0.85rem;
}

.config-table td:first-child {
  color: var(--muted);
  white-space: nowrap;
  width: 1%;
}

.config-table input,
.config-table select {
  width: 100%;
  font: inherit;
  font-size: 0.85rem;
  padding: 3px 5px;
  border: 1px solid #ddd;
  border-radius: 5px;
  background: #fff;
}

.config-table input:focus,
.config-table select:focus {
  outline: none;
  border-color: var(--accent);
}

.config-table .face-rows {
  max-height: 260px;
  overflow-y: auto;
  display: block;
}
