:root {
  --bg: #08110e;
  --panel: #101a16;
  --panel-2: #17241e;
  --line: #2a3b33;
  --text: #edf6f1;
  --muted: #93a89d;
  --gold: #e4c27a;
  --felt: #0e3d30;
  --felt-deep: #08261e;
  --hit: #7ddec0;
  --stand: #ff8d86;
  --double: #e4c27a;
  --split: #d3c4ff;
  --ivory: #f7f4ea;
  --shadow: 0 16px 40px rgba(0, 0, 0, 0.28);
  color-scheme: dark;
  font-family: "Segoe UI", "Avenir Next", "Trebuchet MS", sans-serif;
  color: var(--text);
  background: var(--bg);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  background:
    radial-gradient(900px 420px at 50% -12%, #164838 0%, transparent 60%),
    var(--bg);
}
button, select, input { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }

.app {
  width: min(560px, 100%);
  margin: 0 auto;
  padding: 0.75rem 0.9rem calc(6.2rem + env(safe-area-inset-bottom));
}

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.85rem;
}
.top-actions { display: flex; align-items: center; gap: 0.4rem; margin-left: auto; }
.icon-btn {
  width: 2.4rem;
  height: 2.4rem;
  border-radius: 0.75rem;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  display: grid;
  place-items: center;
  padding: 0;
  flex: none;
}
.icon-btn.shop {
  background: #2a2214;
  border-color: var(--gold);
  color: var(--gold);
}
.brand { display: flex; align-items: center; gap: 0.65rem; min-width: 0; flex: 1; }
.brand > div { min-width: 0; }
.mark {
  width: 2.3rem;
  height: 2.3rem;
  border-radius: 0.7rem;
  display: grid;
  place-items: center;
  background: var(--felt);
  color: var(--ivory);
  font-size: 1.25rem;
  box-shadow: inset 0 0 0 1px rgba(228, 194, 122, 0.35);
}
.brand h1 { font-size: 1.05rem; margin: 0; letter-spacing: -0.02em; }
.brand p {
  margin: 0.1rem 0 0;
  color: var(--muted);
  font-size: 0.75rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ghost, .solid {
  border-radius: 999px;
  border: 1px solid var(--line);
  background: transparent;
  padding: 0.45rem 0.75rem;
  font-size: 0.78rem;
}
.solid { background: var(--gold); color: #241a08; border-color: transparent; font-weight: 700; }
.hidden { display: none !important; }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 1.1rem;
  padding: 0.85rem;
  margin-bottom: 0.75rem;
}
.row { display: flex; justify-content: space-between; align-items: center; gap: 0.5rem; }
.tool-buttons { display: flex; flex-wrap: wrap; gap: 0.35rem; justify-content: flex-end; }
.label { margin: 0 0 0.45rem; color: var(--muted); font-size: 0.72rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; }
.linkish { background: none; border: 0; color: var(--gold); padding: 0; font-size: 0.78rem; }

.ranks { display: grid; grid-template-columns: repeat(7, 1fr); gap: 0.35rem; }
.rank, .action, .nav button, .offer {
  touch-action: manipulation;
}
.rank {
  min-height: 2.6rem;
  border-radius: 0.7rem;
  border: 1px solid var(--line);
  background: var(--panel-2);
  font-weight: 750;
}
.rank[data-rank="10"] { font-size: 0.82rem; }
.rank[aria-pressed="true"] { background: var(--ivory); color: #17211c; border-color: var(--ivory); }

.picked { display: flex; flex-wrap: wrap; gap: 0.35rem; min-height: 2.4rem; align-items: center; }
.chip {
  border: 0;
  background: var(--ivory);
  color: #17211c;
  border-radius: 999px;
  padding: 0.28rem 0.6rem;
  font-weight: 750;
}
.quiet { color: var(--muted); font-size: 0.85rem; }

.decision { text-align: center; padding: 1rem 0.8rem 0.9rem; }
.decision .eyebrow { color: var(--muted); font-size: 0.72rem; letter-spacing: 0.12em; text-transform: uppercase; font-weight: 700; }
#actionOutput {
  margin: 0.15rem 0;
  font-family: Palatino, "Palatino Linotype", Georgia, serif;
  font-size: clamp(2.6rem, 12vw, 4.4rem);
  line-height: 0.95;
  letter-spacing: 0.03em;
}
#whyOutput { margin: 0.35rem auto 0; max-width: 36rem; color: var(--muted); font-size: 0.92rem; }
.hit { color: var(--hit); }
.stand { color: var(--stand); }
.double { color: var(--double); }
.split { color: var(--split); }
.idle { color: #66786f; }

.controls { display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem; }
select, input[type="number"] {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 0.7rem;
  padding: 0.55rem 0.6rem;
}
.note { color: var(--muted); font-size: 0.78rem; line-height: 1.45; margin: 0.55rem 0 0; }
.shoe-banner {
  margin: 0.7rem 0 0;
  padding: 0.6rem 0.75rem;
  border-radius: 0.85rem;
  border: 1px solid var(--gold);
  background: #2a2214;
  color: var(--gold);
  font-size: 0.9rem;
}

.offers { display: grid; gap: 0.5rem; }
.offer {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  align-items: center;
  text-decoration: none;
  color: inherit;
  border-radius: 1rem;
  padding: 0.8rem 0.85rem;
  border: 1px solid var(--line);
  background: #1a140c;
}
.offer strong { display: block; font-size: 0.92rem; color: var(--text); }
.panel label { display: grid; gap: 0.35rem; color: var(--muted); font-size: 0.78rem; }
.offer span { color: var(--muted); font-size: 0.78rem; }
.offer b { color: var(--gold); font-size: 0.85rem; white-space: nowrap; }
.offer[aria-disabled="true"] { opacity: 0.72; }
.amazon { margin-top: 0.9rem; padding-top: 0.75rem; border-top: 1px solid var(--line); }
.amazon h3 { margin: 0 0 0.25rem; font-size: 0.95rem; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.4rem; }
.stat { background: var(--bg); border-radius: 0.8rem; padding: 0.45rem 0.35rem; text-align: center; }
.stat b { display: block; font-size: 1.05rem; }
.stat span { color: var(--muted); font-size: 0.68rem; letter-spacing: 0.04em; text-transform: uppercase; }

.stepper { display: flex; align-items: center; gap: 0.4rem; }
.stepper button {
  width: 2rem;
  height: 2rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--panel-2);
}

.felt {
  background:
    radial-gradient(circle at 50% 0%, rgba(255,255,255,0.05), transparent 40%),
    linear-gradient(180deg, var(--felt), var(--felt-deep));
  border-radius: 1.3rem;
  padding: 0.85rem;
  box-shadow: var(--shadow), inset 0 0 0 1px rgba(228, 194, 122, 0.22);
  min-height: 220px;
}
.seat { margin-top: 0.7rem; }
.seat-label { color: #c9e2d6; font-size: 0.72rem; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; margin-bottom: 0.3rem; }
.seat.active { outline: 1px solid rgba(228, 194, 122, 0.8); border-radius: 0.8rem; padding: 0.35rem; }
.cards { display: flex; flex-wrap: wrap; gap: 0.35rem; min-height: 3.3rem; }
.card {
  width: 2.45rem;
  height: 3.35rem;
  border-radius: 0.4rem;
  background: var(--ivory);
  color: #17211c;
  padding: 0.18rem 0.28rem;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  font-weight: 800;
  box-shadow: 0 8px 16px rgba(0,0,0,0.25);
}
.card.red { color: #a3262e; }
.card span { align-self: flex-end; font-size: 0.85rem; }
.card.back {
  background:
    repeating-linear-gradient(135deg, #12382c 0 5px, #1c4d3d 5px 10px);
  box-shadow: inset 0 0 0 2px #e4c27a;
}

.feedback {
  min-height: 3.2rem;
  margin: 0.7rem 0;
  padding: 0.65rem 0.75rem;
  border-radius: 0.9rem;
  background: var(--panel);
  border: 1px solid var(--line);
  font-size: 0.92rem;
}
.feedback.good { border-color: #24664d; }
.feedback.bad { border-color: #7a3b38; }

.actions { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0.4rem; }
.action {
  min-height: 3.1rem;
  border: 0;
  border-radius: 0.85rem;
  font-weight: 800;
  letter-spacing: 0.03em;
}
.action.hit { background: #14684d; color: white; }
.action.stand { background: #8d2f2c; color: white; }
.action.double { background: #e0b34a; color: #241a08; }
.action.split { background: #6d5cae; color: white; }
.action:disabled { opacity: 0.35; }

.deal-row { display: grid; grid-template-columns: auto 1fr; gap: 0.4rem; align-items: end; margin-top: 0.55rem; }
.bet-picker { display: grid; gap: 0.2rem; }
.bet-picker .stepper b { min-width: 2.8rem; text-align: center; }
#useBet { width: 100%; margin-top: 0.4rem; min-height: 2.4rem; }
.deal-row button, .count-row button {
  border: 0;
  border-radius: 0.8rem;
  min-height: 2.8rem;
  background: var(--panel-2);
  border: 1px solid var(--line);
}
.deal-row .stepper button { min-height: 2rem; width: 2rem; border-radius: 999px; }
#dealBtn { background: var(--gold); color: #241a08; font-weight: 800; }
.count-row { display: grid; grid-template-columns: 1fr; gap: 0.4rem; margin-top: 0.55rem; }
.count-actions { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 0.4rem; }
.log-legend { display: flex; align-items: center; gap: 0.35rem; margin: 0.35rem 0 0.2rem; color: var(--muted); font-size: 0.72rem; }
.log-legend .log-card { width: 1.45rem; height: 1.9rem; }
.log-hand {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.6rem;
  align-items: center;
  padding: 0.7rem 0;
  border-bottom: 1px solid var(--line);
}
.log-title { font-size: 0.72rem; font-weight: 800; letter-spacing: 0.06em; text-transform: uppercase; color: var(--gold); }
.log-group { display: grid; grid-template-columns: 3.5rem 1fr; gap: 0.35rem; align-items: start; margin-top: 0.4rem; }
.log-group + .log-group { padding-top: 0.4rem; border-top: 1px solid rgba(42, 59, 51, 0.85); }
.log-name { color: var(--muted); font-size: 0.66rem; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; padding-top: 0.4rem; }
.log-cards { display: flex; flex-wrap: wrap; gap: 0.28rem; }
.log-card {
  width: 1.9rem;
  height: 2.5rem;
  border-radius: 0.28rem;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 0.1rem 0.16rem 0.12rem;
  font-weight: 800;
  font-size: 0.72rem;
  line-height: 1;
}
.log-card i { font-style: normal; font-size: 0.58rem; font-weight: 700; align-self: flex-end; }
.log-card.low { background: #8d2f2c; color: #fff; }
.log-card.high { background: #14684d; color: #fff; }
.log-card.zero { background: var(--ivory); color: #17211c; }
.log-card.zero.red { color: #a3262e; }
.log-card.back {
  background: repeating-linear-gradient(135deg, #12382c 0 4px, #1c4d3d 4px 8px);
  box-shadow: inset 0 0 0 1px #e4c27a;
}
.log-scores { text-align: right; min-width: 3.6rem; }
.log-scores b { display: block; font-size: 1.05rem; }
.log-scores span { display: block; color: var(--muted); font-size: 0.62rem; letter-spacing: 0.04em; text-transform: uppercase; }
.log-scores .running-score { margin-top: 0.45rem; }

dialog {
  width: min(560px, calc(100% - 1.2rem));
  max-height: min(88dvh, 760px);
  margin: auto;
  padding: 0.9rem 0.85rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: 1.15rem;
  background: var(--panel);
  color: inherit;
  box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(4, 10, 8, 0.74); }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 0.6rem; margin-bottom: 0.35rem; }
.sheet-head h2 { margin: 0; font-size: 1.05rem; }
dialog .scroll { max-height: calc(88dvh - 7.5rem); overflow: auto; }
dialog .offers { margin-top: 0.7rem; }
dialog label { display: grid; gap: 0.35rem; color: var(--muted); font-size: 0.78rem; }
#settingsDialog .controls { margin-top: 0.35rem; }

.sheet table { width: 100%; border-collapse: collapse; font-size: 0.75rem; margin-bottom: 0.9rem; }
.sheet th, .sheet td { padding: 0.28rem 0.15rem; text-align: center; border-bottom: 1px solid var(--line); }
.sheet th:first-child, .sheet td:first-child { text-align: left; position: sticky; left: 0; background: var(--panel); font-weight: 700; }
.sheet caption { text-align: left; font-weight: 800; margin: 0 0 0.3rem; }
.scroll { overflow-x: auto; }

.guide p, .guide li, .guide dd { color: var(--muted); line-height: 1.5; }
.guide dt { margin: 0.7rem 0 0.15rem; }
.guide dd { margin: 0; }
.guide h2 { font-size: 1.05rem; margin: 0.2rem 0 0.4rem; }
.legal { color: var(--muted); font-size: 0.75rem; line-height: 1.45; }

.nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.35rem;
  padding: 0.45rem 0.7rem calc(0.45rem + env(safe-area-inset-bottom));
  background: rgba(8, 17, 14, 0.94);
  border-top: 1px solid var(--line);
  backdrop-filter: blur(10px);
}
.nav button {
  border: 0;
  background: transparent;
  border-radius: 0.8rem;
  min-height: 2.8rem;
  color: var(--muted);
  font-weight: 700;
}
.nav button[aria-selected="true"] { background: var(--panel-2); color: var(--text); }

@media (min-width: 720px) {
  .app { padding-top: 1.4rem; }
}
