:root {
  --bg: #14171a;
  --panel: #1e2327;
  --line: #333a40;
  --text: #e9e6df;
  --muted: #9aa3ab;
  --accent: #e0b354;
  --felt: #0e3a2a;
  --felt-dark: #0a2b1f;

  --chip-purple: #7b3fa8;
  --chip-black: #1b1b1e;
  --chip-orange: #e07a1f;
  --chip-green: #1e8a4c;
  --chip-blue: #2459c4;
  --chip-red: #c8262c;
  --chip-white: #f1efe8;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
}

header { padding: 20px 24px 4px; }
h1 { margin: 0; font-size: 22px; letter-spacing: .01em; }
header p { margin: 4px 0 0; color: var(--muted); }
h2 { margin: 0 0 12px; font-size: 17px; }
h3 { margin: 20px 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }

main {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 20px;
  padding: 16px 24px 40px;
  max-width: 1200px;
}
.results { grid-column: 1 / -1; }

@media (max-width: 820px) {
  main { grid-template-columns: minmax(0, 1fr); padding: 12px; }
  header { padding: 14px 12px 0; }
}

/* ── The case ─────────────────────────────────────────────────────────────── */

.case {
  background: linear-gradient(#c9ced3, #8d949b);
  border-radius: 14px;
  padding: 10px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .5), inset 0 0 0 1px rgba(255, 255, 255, .35);
}
.columns {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  background: linear-gradient(var(--felt), var(--felt-dark));
  border-radius: 8px;
  padding: 12px;
  box-shadow: inset 0 2px 10px rgba(0, 0, 0, .6);
}

.col {
  flex: 1 0 58px;
  max-width: 92px;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 6px;
}
.col-head {
  text-align: center;
  font-weight: 600;
  font-size: 13px;
  white-space: nowrap;
}
.col-head small { display: block; font-weight: 400; color: #b9c9c0; font-size: 11px; }

.stack {
  height: 300px;
  display: flex;
  flex-direction: column-reverse;
  gap: 1px;
  padding: 3px;
  background: rgba(0, 0, 0, .35);
  border-radius: 5px;
}
.chip {
  flex: 1 1 0;
  min-height: 2px;
  border-radius: 2px;
  background: repeating-linear-gradient(90deg, var(--c) 0 13px, var(--stripe, #f1efe8) 13px 19px);
  box-shadow: inset 0 -1px 0 rgba(0, 0, 0, .35);
}
.chip.rebuy { opacity: .6; outline: 1px solid var(--accent); outline-offset: -1px; }
.chip.bank { opacity: .22; }

[data-color="purple"] { --c: var(--chip-purple); }
[data-color="black"] { --c: var(--chip-black); --stripe: #b9b9b9; }
[data-color="orange"] { --c: var(--chip-orange); }
[data-color="green"] { --c: var(--chip-green); }
[data-color="blue"] { --c: var(--chip-blue); }
[data-color="red"] { --c: var(--chip-red); }
[data-color="white"] { --c: var(--chip-white); --stripe: #7f8fa8; }

.col-foot { display: flex; gap: 4px; justify-content: center; min-height: 28px; }

.col.ghost { flex: 0 0 112px; max-width: 112px; }
.col.ghost .col-head { color: #9fb3a8; font-weight: 400; }
.col.ghost .stack {
  background: none;
  border: 2px dashed rgba(255, 255, 255, .25);
  gap: 1px;
}
.col.ghost .chip { opacity: .3; filter: saturate(.5); }
.col.ghost select { min-width: 0; flex: 1; }

/* ── Controls ─────────────────────────────────────────────────────────────── */

button, select, input[type="number"] {
  font: inherit;
  color: var(--text);
  background: #2a3036;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 3px 8px;
}
button { cursor: pointer; }
button:hover { border-color: var(--muted); }
button:focus-visible, select:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.del, .add { width: 28px; height: 28px; padding: 0; line-height: 1; font-size: 16px; }
.del { background: rgba(0, 0, 0, .35); border-color: rgba(255, 255, 255, .2); color: #d8dedb; }
.del:hover { background: var(--chip-red); color: #fff; }
.add { background: var(--accent); border-color: var(--accent); color: #1b1b1e; font-weight: 700; }

.case-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 16px;
  margin-top: 12px;
  color: var(--muted);
  font-size: 13px;
}
.case-meta input { width: 64px; margin-left: 6px; }
.case-total { margin-left: auto; }
.swatch { display: inline-block; width: 18px; height: 8px; border-radius: 2px; margin-right: 5px; background: var(--chip-red); }
.swatch.rebuy { opacity: .6; outline: 1px solid var(--accent); }
.swatch.bank { opacity: .25; }

.controls {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  align-self: start;
}
.control { display: flex; flex-direction: column; gap: 8px; }
.control > label, .control > .label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 600;
}
.control output { color: var(--accent); font-size: 18px; }
input[type="range"] { width: 100%; accent-color: var(--accent); }
.money-input { color: var(--accent); font-size: 18px; }
.money-input input { width: 76px; margin-left: 2px; color: var(--accent); font-weight: 600; }

.segmented { display: flex; }
.segmented button { flex: 1; border-radius: 0; margin-left: -1px; padding: 5px 0; }
.segmented button:first-child { border-radius: 6px 0 0 6px; margin-left: 0; }
.segmented button:last-child { border-radius: 0 6px 6px 0; }
.segmented button[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #1b1b1e; font-weight: 600; }

.values { display: grid; grid-template-columns: auto 1fr auto; gap: 6px 10px; align-items: center; }
.secondary { padding: 6px 8px; }
.check { font-size: 13px; color: var(--muted); display: flex; gap: 6px; align-items: center; }
.link { background: none; border: none; color: var(--muted); text-decoration: underline; padding: 0; align-self: flex-start; font-size: 13px; }

.dot {
  display: inline-block;
  width: 1.5em;
  height: 1.5em;
  border-radius: 50%;
  background: var(--c);
  border: .22em dashed var(--stripe, #f1efe8);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, .5);
  vertical-align: middle;
  flex: none;
}

/* ── Results ──────────────────────────────────────────────────────────────── */

.results {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 18px;
}
.results .sub { color: var(--muted); font-weight: 400; font-size: 14px; }

.hand { display: flex; flex-wrap: wrap; gap: 10px; }
.hand-chip {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-width: 84px;
  padding: 12px 10px 10px;
  background: #262c31;
  border: 1px solid var(--line);
  border-radius: 10px;
}
.hand-chip.zero { opacity: .4; }
.hand-chip .dot { font-size: 22px; }
.hand-chip .count { font-size: 26px; font-weight: 700; line-height: 1.1; margin-top: 6px; }
.hand-chip .each, .hand-chip .subtotal { font-size: 12px; color: var(--muted); }

table { border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { text-align: right; padding: 5px 14px 5px 0; border-bottom: 1px solid var(--line); }
th { font-size: 12px; color: var(--muted); font-weight: 500; }
th:first-child, td:first-child { text-align: left; }
td .dot { font-size: 11px; margin-right: 8px; }
tfoot td { font-weight: 600; border-bottom: none; }

.rebuy-list { margin: 0; padding-left: 20px; }
.rebuy-list li { margin: 3px 0; }
.note { color: var(--muted); font-size: 13px; margin: 8px 0 0; }
.warn {
  border-left: 3px solid var(--accent);
  background: rgba(224, 179, 84, .1);
  padding: 10px 12px;
  border-radius: 0 6px 6px 0;
  margin: 12px 0 0;
}
.warn button { margin-top: 8px; }
