/* Self-hosted fonts (see THIRD-PARTY.md). Latin + latin-ext subsets only, pulled from the
   Google Fonts CDN once and committed — no runtime CDN, so the app works offline / installed.
   Rubik is the variable build (one file covers 400-800). */
@font-face {
  font-family: 'Bungee';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url(./fonts/bungee-latin.woff2) format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

@font-face {
  font-family: 'Bungee';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url(./fonts/bungee-latin-ext.woff2) format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

@font-face {
  font-family: 'Rubik';
  font-style: normal;
  font-weight: 400 800;
  font-display: swap;
  src: url(./fonts/rubik-latin.woff2) format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

@font-face {
  font-family: 'Rubik';
  font-style: normal;
  font-weight: 400 800;
  font-display: swap;
  src: url(./fonts/rubik-latin-ext.woff2) format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

:root {
  --bg-0: #120d29;
  --bg-1: #1a123c;
  --panel: #241a4d;
  --panel-2: #2c2059;
  --line: #3a2d6e;
  --ink: #f6f1ff;
  --muted: #a99fd4;
  --gold: #ffcb3d;
  --gold-soft: #ffe08a;
  --c-red: #f4453b;
  --c-yellow: #ffd23f;
  --c-green: #26c485;
  --c-blue: #3a86ff;
  --c-pink: #ff5fa2;
  --c-orange: #ff8c1a;
  --radius: 14px;
  --shadow: 0 14px 34px rgba(0, 0, 0, .42);
  --font-sign: 'Bungee', 'Arial Black', system-ui, sans-serif;
  --font: 'Rubik', system-ui, -apple-system, sans-serif;
}

* {
  box-sizing: border-box
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%
}

body {
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(1200px 500px at 50% -10%, #2a1c5e 0%, transparent 60%),
    radial-gradient(900px 600px at 90% 10%, #3a1c52 0%, transparent 55%),
    linear-gradient(180deg, var(--bg-1), var(--bg-0));
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

/* custom scrollbar */
/* Width and height of the scrollbar */
::-webkit-scrollbar {
  width: 12px;
  height: 12px;
}

/* Scrollbar track (the background line) */
::-webkit-scrollbar-track {
  background: transparent;
}

/* Scrollbar thumb (the draggable bar) */
::-webkit-scrollbar-thumb {
  /* Semi-transparent dark color (adjust RGBA to match your theme) */
  background-color: rgba(255, 255, 255, 0.3);

  /* Creates space around the thumb so it feels "floating" */
  border-radius: 10px;
  border: 3px solid transparent;
  background-clip: padding-box;

  /* Smooth color transition when hovering */
  transition: background-color 0.2s ease;
}

/* Make it slightly more visible on hover for better user experience */
::-webkit-scrollbar-thumb:hover {
  background-color: rgba(255, 255, 255, 0.6);
}

/* thin marquee accent */
.marquee {
  height: 8px;
  background-image: radial-gradient(circle, var(--gold-soft) 0 2px, rgba(255, 203, 61, .15) 2.8px, transparent 3.2px);
  background-size: 22px 100%;
  background-position: center;
  filter: drop-shadow(0 0 4px rgba(255, 203, 61, .5));
  animation: twinkle 2.4s ease-in-out infinite;
  flex: 0 0 auto;
}

@keyframes twinkle {

  0%,
  100% {
    opacity: 1
  }

  50% {
    opacity: .55
  }
}

/* ---------- app shell ---------- */
.app {
  height: 100dvh;
  display: grid;
  gap: 10px;
  padding: 8px 12px 12px;
  grid-template-columns: 1fr 1fr 450px;
  grid-template-rows: auto 1fr 1fr;
  grid-template-areas:
    "head head head"
    "hero hero bets"
    "stats stats shop";
}

header {
  grid-area: head;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  padding-top: 6px
}

.brand {
  font-family: var(--font-sign);
  font-size: 22px;
  letter-spacing: .5px;
  background: linear-gradient(180deg, #fff, var(--gold));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  white-space: nowrap
}

.pills {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
  margin-left: auto
}

.actions {
  display: flex;
  gap: 8px;
  flex: none
}

.pill {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 5px 12px;
    font-size: 13px;
    color: var(--muted);
    white-space: nowrap;
    align-items: center;
    display: flex;
    text-align: center;
    gap: 3px;
}

.iconbtn {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 999px;
  width: 32px;
  height: 32px;
  padding: 0;
  color: var(--muted);
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font);
  flex: none
}

/* .iconbtn sets display, which would otherwise beat the UA rule for [hidden]
   (author sheet wins over UA) and leave #installBtn visible. */
.iconbtn[hidden] {
  display: none
}

.iconbtn:hover {
  border-color: var(--gold);
  color: var(--gold-soft)
}

.iconbtn.active {
  border-color: var(--gold);
  color: var(--gold-soft)
}

.pill b {
  color: var(--ink);
  font-weight: 800;
  margin-left: 3px
}

.pill.coins {
  border-color: rgba(255, 203, 61, .4);
  position: relative
}

.pill.coins b {
  color: var(--gold-soft)
}

/* coins-added win effect */
.pill.coins.bump {
  animation: coinbump .4s ease
}

@keyframes coinbump {
  0% { transform: scale(1) }
  35% { transform: scale(1.18) }
  100% { transform: scale(1) }
}

.pill.coins .coin-fly {
  position: absolute;
  bottom: 2px;
  width: 12px;
  height: 12px;
  pointer-events: none;
  animation: coinrise .6s ease-out forwards
}

@keyframes coinrise {
  0% { transform: translateY(10px) scale(.6); opacity: 0 }
  30% { opacity: 1 }
  100% { transform: translateY(-14px) scale(1); opacity: 0 }
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  box-shadow: var(--shadow);
  overflow: auto;
  min-height: 0
}

.panel h2 {
  font-size: 11px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0 0 10px;
  font-weight: 700
}

.panel[data-panel=bets] {
  grid-area: bets
}

.panel[data-panel=shop] {
  grid-area: shop
}

.panel[data-panel=stats] {
  grid-area: stats;
  overflow: hidden;
}

/* ---------- hero / dice ---------- */
.hero {
  grid-area: hero;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: linear-gradient(180deg, #1d1442, #181038);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 8px;
  min-height: 0
}

#diceStage {
  position: relative;
  width: 100%;
  flex: 1;
  min-height: 150px;
  background: radial-gradient(ellipse 55% 40% at 50% 80%, rgba(0, 0, 0, .35), transparent 70%)
}

#diceStage canvas {
  display: block;
  width: 100% !important;
  height: 100% !important
}

.dice-fallback {
  position: absolute;
  inset: 0;
  display: flex;
  gap: 16px;
  align-items: center;
  justify-content: center
}

.die {
  width: 74px;
  height: 74px;
  border-radius: 16px;
  box-shadow: inset 0 -6px 0 rgba(0, 0, 0, .18), inset 0 4px 8px rgba(255, 255, 255, .35), 0 8px 18px rgba(0, 0, 0, .4);
  position: relative
}

.die.win::after {
  content: "";
  position: absolute;
  inset: -5px;
  border-radius: 20px;
  border: 3px solid var(--gold);
  box-shadow: 0 0 18px var(--gold)
}

.result {
  min-height: 22px;
  margin: 6px 0 8px;
  font-weight: 600;
  font-size: 15px;
  text-align: center
}

.result .chip {
  padding: 2px 8px;
  border-radius: 8px;
  color: #1a1030;
  font-weight: 800;
  margin: 0 2px
}

.result .gain {
  color: var(--c-green);
  font-weight: 800
}

.result .loss {
  color: var(--muted)
}

.roll-btn {
  font-family: var(--font-sign);
  font-size: 20px;
  letter-spacing: 1px;
  color: #3a2600;
  background: linear-gradient(180deg, var(--gold-soft), var(--gold));
  border: none;
  border-radius: 12px;
  padding: 11px 40px;
  cursor: pointer;
  box-shadow: 0 7px 0 #b9860f, 0 10px 20px rgba(0, 0, 0, .4);
  transition: transform .08s ease, box-shadow .08s ease;
  margin-bottom: 7px
}

.roll-btn:active {
  transform: translateY(4px);
  box-shadow: 0 3px 0 #b9860f
}

.roll-btn:disabled {
  filter: grayscale(.4) brightness(.85);
  cursor: default
}

/* ---------- bets ---------- */
.bet-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px
}

.bet {
  position: relative;
  border: 2px solid transparent;
  border-radius: 11px;
  padding: 9px 6px 8px;
  background: var(--panel-2);
  cursor: pointer;
  text-align: center;
  transition: transform .08s ease, border-color .15s ease;
  user-select: none
}

.bet:hover {
  transform: translateY(-2px)
}

.bet.active {
  border-color: var(--gold)
}

.bet.hot {
  border-color: var(--c-orange);
  box-shadow: 0 0 14px rgba(255, 140, 26, .45)
}

.bet .hotbadge {
  position: absolute;
  top: -9px;
  right: -6px;
  font-size: 15px;
  line-height: 1;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, .5));
  animation: hotpulse 1.2s ease-in-out infinite
}

@keyframes hotpulse {

  0%,
  100% {
    transform: scale(1)
  }

  50% {
    transform: scale(1.2)
  }
}

.bet .swatch {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  margin: 0 auto 5px;
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, .2), inset 0 2px 5px rgba(255, 255, 255, .35)
}

.bet .cname {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .5px
}

.bet .stake {
  font-size: 16px;
  font-weight: 800;
  margin-top: 1px;
  min-height: 20px
}

.bet .stake.empty {
  color: var(--line)
}

/* ---------- wheel of fortune ---------- */
.wheel-overlay {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(10, 6, 24, .72);
  z-index: 50;
  padding: 16px
}

.wheel-overlay.show {
  display: flex;
  animation: wheelfade .2s ease
}

@keyframes wheelfade {
  from {
    opacity: 0
  }

  to {
    opacity: 1
  }
}

.wheel-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 18px 20px 20px;
  box-shadow: var(--shadow);
  text-align: center;
  max-width: 92vw
}

.wheel-title {
  font-family: var(--font-sign);
  font-size: 22px;
  color: var(--gold-soft);
  margin-bottom: 12px;
  min-height: 26px
}

.wheel-spin {
  position: relative;
  width: 260px;
  max-width: 76vw;
  margin: 0 auto
}

.wheel-spin canvas {
  width: 100%;
  height: auto;
  display: block
}

.wheel-pointer {
  position: absolute;
  top: -3px;
  left: 50%;
  transform: translateX(-50%);
  width: 0;
  height: 0;
  border-left: 10px solid transparent;
  border-right: 10px solid transparent;
  border-top: 16px solid var(--gold);
  z-index: 2;
  filter: drop-shadow(0 2px 3px rgba(0, 0, 0, .5))
}

.wheel-sub {
  margin-top: 12px;
  color: var(--muted);
  font-size: 13px;
  min-height: 18px
}

/* ---------- notes / how-it-works overlay ---------- */
.notes-overlay {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(10, 6, 24, .72);
  z-index: 55;
  padding: 16px
}

.notes-overlay.show {
  display: flex;
  animation: wheelfade .2s ease
}

.notes-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  width: 460px;
  max-width: 94vw;
  max-height: 88vh;
  display: flex;
  flex-direction: column
}

.notes-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  font-family: var(--font-sign);
  font-size: 18px;
  color: var(--gold-soft)
}

.notes-close {
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--ink);
  width: 30px;
  height: 30px;
  border-radius: 999px;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  font-family: var(--font)
}

.notes-close:hover {
  border-color: var(--gold);
  color: var(--gold-soft)
}

.notes-body {
  overflow: auto;
  padding: 6px 18px 16px
}

.note {
  padding: 12px 0;
  border-bottom: 1px solid rgba(255, 255, 255, .05)
}

.note:last-child {
  border-bottom: 0
}

.note h3 {
  margin: 0 0 4px;
  font-size: 14px;
  color: var(--ink)
}

.note p {
  margin: 0;
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--muted)
}

.note b {
  color: var(--gold-soft);
  font-weight: 700
}

/* pills are clickable → open the stat legend */
.pill[data-legend] {
  cursor: pointer
}

.pill[data-legend]:hover {
  border-color: var(--gold)
}

/* ---------- stat legend modal (reuses .notes-overlay shell) ---------- */
.legend-row {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid rgba(255, 255, 255, .05)
}

.legend-row:last-child {
  border-bottom: 0
}

.legend-row img {
  flex: none;
  margin-top: 2px
}

.legend-row h3 {
  margin: 0 0 4px;
  font-size: 14px;
  color: var(--ink)
}

.legend-row p {
  margin: 0;
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--muted)
}

.legend-row b {
  color: var(--gold-soft);
  font-weight: 700
}

/* ---------- settings modal (reuses .notes-overlay shell) ---------- */
.set-row {
  padding: 14px 0;
  border-bottom: 1px solid rgba(255, 255, 255, .05)
}

.set-row:last-child {
  border-bottom: 0
}

.set-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 14px;
  font-weight: 700;
  color: var(--ink);
  margin-bottom: 8px
}

.set-label b {
  color: var(--gold-soft);
  font-variant-numeric: tabular-nums
}

.set-hint {
  margin: 8px 0 0;
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--muted)
}

.set-hint b {
  color: var(--gold-soft);
  font-weight: 700
}

.set-range {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--gold) 0%, var(--gold-soft) 100%);
  background-color: var(--panel-2);
  outline: none;
  cursor: pointer;
  margin: 2px 0
}

.set-range::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--ink);
  border: 2px solid var(--gold);
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(0, 0, 0, .45)
}

.set-range::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--ink);
  border: 2px solid var(--gold);
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(0, 0, 0, .45)
}

.set-range:focus-visible {
  outline: 2px solid var(--gold-soft);
  outline-offset: 3px
}

.set-danger {
  margin-top: 10px;
  background: var(--panel-2);
  border: 1px solid rgba(244, 69, 59, .5);
  color: #ff9d96;
  border-radius: 12px;
  padding: 9px 14px;
  font-family: var(--font);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer
}

.set-danger:hover {
  border-color: var(--c-red);
  color: #ffd2ce
}

.set-danger.solid {
  background: var(--c-red);
  border-color: var(--c-red);
  color: #fff
}

.set-danger.solid:hover {
  filter: brightness(1.1);
  color: #fff
}

.set-confirm {
  margin-top: 10px;
  padding: 12px;
  border: 1px solid rgba(244, 69, 59, .35);
  border-radius: 12px;
  background: rgba(244, 69, 59, .08)
}

.set-confirm[hidden] {
  display: none
}

.set-confirm .set-hint {
  margin-top: 0
}

.set-confirm-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap
}

/* ---------- broke / game-over modal ---------- */
.broke-overlay {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(10, 6, 24, .82);
  z-index: 60;
  padding: 16px
}

.broke-overlay.show {
  display: flex;
  animation: wheelfade .2s ease
}

.broke-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  width: 360px;
  max-width: 94vw;
  padding: 22px 22px 18px;
  text-align: center
}

.broke-title {
  font-family: var(--font-sign);
  font-size: 22px;
  color: var(--gold-soft);
  margin-bottom: 8px
}

.broke-msg {
  margin: 0 0 16px;
  font-size: 13px;
  line-height: 1.5;
  color: var(--muted)
}

.broke-msg b {
  color: var(--gold-soft)
}

.broke-card .prestige-btn {
  margin-bottom: 8px
}

.broke-dismiss {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 12px;
  cursor: pointer;
  font-family: var(--font);
  text-decoration: underline;
  padding: 4px
}

.broke-dismiss:hover {
  color: var(--ink)
}

.chips {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 12px;
  align-items: center
}

.chip-btn {
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--ink);
  border-radius: 9px;
  padding: 7px 12px;
  font-weight: 700;
  cursor: pointer;
  font-family: var(--font);
  font-size: 13px;
  transition: border-color .12s ease
}

.chip-btn.active {
  border-color: var(--gold);
  color: var(--gold-soft)
}

.chip-btn.ghost {
  color: var(--muted)
}

.chips .lbl {
  font-size: 12px;
  color: var(--muted)
}

.row2 {
  display: flex;
  gap: 6px;
  margin-top: 6px
}

.row2 .chip-btn {
  flex: 1;
  text-align: center
}

.hint {
  font-size: 11px;
  color: var(--muted);
  margin-top: 10px;
  line-height: 1.5
}

/* ---------- shop ---------- */
.upg {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 8px 10px;
  border-radius: 10px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  margin-bottom: 7px;
  cursor: pointer;
  transition: border-color .12s ease, transform .08s ease
}

.upg:hover:not(.locked) {
  transform: translateY(-1px);
  border-color: rgba(255, 203, 61, .4)
}

.upg.locked {
  opacity: .55;
  cursor: default
}

.upg .ic {
  font-size: 18px;
  width: 22px;
  text-align: center
}

.upg .body {
  flex: 1;
  min-width: 0
}

.upg .name {
  font-weight: 700;
  font-size: 13px;
  display: flex;
  gap: 6px;
  align-items: center
}

.upg .lvl {
  font-size: 10px;
  color: var(--muted);
  font-weight: 600
}

.upg .desc {
  font-size: 11px;
  color: var(--muted);
  margin-top: 1px;
  line-height: 1.3
}

.upg .cost {
  font-weight: 800;
  color: var(--gold-soft);
  white-space: nowrap;
  font-size: 13px
}

.upg .cost.cant {
  color: var(--muted)
}

.prestige {
  margin-top: 10px;
  border-top: 1px dashed var(--line);
  padding-top: 10px
}

.prestige-top {
  display: flex;
  align-items: center;
  justify-content: space-between
}

.prestige-top span:first-child {
  font-size: 11px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 700
}

.prestige .big {
  font-family: var(--font-sign);
  font-size: 20px;
  color: var(--gold-soft)
}

.prestige p {
  font-size: 11px;
  color: var(--muted);
  line-height: 1.45;
  margin: 6px 0 8px
}

.prestige-btn {
  font-family: var(--font);
  font-weight: 800;
  font-size: 14px;
  background: linear-gradient(180deg, #ff7ab0, #e83f8a);
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 9px;
  cursor: pointer;
  width: 100%;
  box-shadow: 0 5px 0 #a92765;
  transition: transform .08s ease, box-shadow .08s ease
}

.prestige-btn:active:not(:disabled) {
  transform: translateY(3px);
  box-shadow: 0 2px 0 #a92765
}

.prestige-btn:disabled {
  filter: grayscale(.5) brightness(.8);
  cursor: default;
  box-shadow: 0 5px 0 #55405f
}

/* ---------- stats panel ---------- */
.stats-wrap {
  display: grid;
  grid-template-columns: 1fr 250px;
  /* Constrain the row to the panel height so a tall right column can't stretch the
     row (and the chart with it) past the panel — which clipped the chart's x-labels. */
  grid-template-rows: minmax(0, 1fr);
  gap: 12px;
  flex: 1;
  min-height: 0
}

.chart-box {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0
}

/* right column: scroll internally if it's taller than the panel, rather than
   pushing the grid row (and the chart) beyond the visible area */
.stats-wrap > div:nth-child(2) {
  min-height: 0;
  overflow: auto
}

.chart-box .cap {
  font-size: 11px;
  color: var(--muted);
  margin-bottom: 6px;
  display: flex;
  justify-content: space-between
}

.chart-canvas-wrap {
  position: relative;
  flex: 1;
  width: 100%;
  min-height: 120px
}

/* Absolutely-positioned canvas: its backing-store size can't feed back into
   layout, so the chart height stays stable (no more creeping/clipping). */
#balChart {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block
}

.cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px
}

.card {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px
}

.card .ck {
  font-size: 10px;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--muted)
}

.card .cv {
  font-size: 22px;
  font-weight: 800;
  margin-top: 3px
}

.card.win .cv {
  color: var(--c-green)
}

.card.loss .cv {
  color: var(--c-red)
}

.card.streak .cv {
  color: var(--gold-soft)
}

.ministats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 10px
}

.ministats>div {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px 12px;
  display: flex;
  flex-direction: column;
  min-width: 0
}

.ministats .wide {
  grid-column: 1/-1
}

.ministats span {
  font-size: 10px;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--muted)
}

.ministats b {
  font-size: 18px;
  margin-top: 2px;
  font-variant-numeric: tabular-nums
}

/* clickable mini stat card (opens the achievements modal) */
.ministats .clickable {
  cursor: pointer;
  transition: border-color .15s ease
}

.ministats .clickable:hover,
.ministats .clickable:focus-visible {
  border-color: var(--gold);
  outline: none
}

.ministats .clickable b {
  color: var(--gold-soft)
}

/* achievements modal grid (rendered into the notes-overlay body) */
#achCountModal {
  color: var(--gold-soft);
  font-size: 14px;
  font-variant-numeric: tabular-nums
}

#achGrid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 8px
}

.ach {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 8px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px
}

.ach .ic {
  font-size: 18px;
  line-height: 1.2;
  flex: none
}

.ach .body {
  min-width: 0
}

.ach .name {
  font-size: 12px;
  font-weight: 700;
  color: var(--ink)
}

.ach .desc {
  font-size: 10px;
  color: var(--muted);
  line-height: 1.35;
  overflow-wrap: anywhere
}

.ach:not(.locked) {
  border-color: rgba(255, 203, 61, .4)
}

.ach:not(.locked) .name {
  color: var(--gold-soft)
}

.ach.locked {
  opacity: .5
}

/* ---------- mobile tabs (hidden on desktop) ---------- */
.tabs {
  display: none;
  grid-area: tabs;
  gap: 6px
}

.tab {
  flex: 1;
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--muted);
  border-radius: 10px;
  padding: 9px;
  font-weight: 700;
  font-size: 13px;
  cursor: pointer;
  font-family: var(--font)
}

.tab.active {
  border-color: var(--gold);
  color: var(--gold-soft)
}

/* ---------- responsive: portrait / narrow ---------- */
@media (max-width:960px) {
  body {
    overflow: auto
  }

  .app {
    height: auto;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    padding: 8px 10px 16px
  }

  header {
    flex-wrap: wrap
  }

  .brand {
    order: 0
  }

  .actions {
    order: 1;
    margin-left: auto
  }

  .pills {
    order: 2;
    flex-basis: 100%;
    margin-left: 0
  }

  .hero {
    min-height: 220px
  }

  #diceStage {
    min-height: 170px
  }

  /* One line, always: a second line grows the hero and shoves the tabs/panels below it
     down mid-roll. Scale with the viewport instead of wrapping, and pin the payout
     (always the last span of the result HTML) to the front so the chips are what clip
     if a 6-color sweep still overruns. `safe center` falls back to start-aligned when
     it does, so the payout can't be pushed off the left edge. */
  .result {
    display: flex;
    align-items: center;
    justify-content: center;
    justify-content: safe center;
    /* progressive: older engines keep the line above */
    flex-wrap: nowrap;
    gap: .25em;
    height: 22px;
    /* the height it already occupies when it fits */
    font-size: clamp(10px, 3.4vw, 15px);
    line-height: 1;
    white-space: nowrap;
    overflow: hidden
  }

  .result>span:last-child {
    order: -1
    /* the +amount / message leads the line */
  }

  .result .chip {
    padding: .12em .45em;
    margin: 0;
    border-radius: .5em;
    flex: none
    /* chips clip as whole units, never squeeze their text */
  }

  .tabs {
    display: flex
  }

  .panel {
    display: none
  }

  .panel.active {
    display: block;
    flex-grow: 1;
    height: 0;
    overflow: auto;
  }

  .panel[data-panel=stats] {
    overflow: auto
  }

  .stats-wrap {
    grid-template-columns: 1fr;
    height: auto
  }

  .chart-canvas-wrap {
    min-height: 170px
  }
}

@media (min-width:961px) {
  .panel {
    display: block !important
  }

  /* stats becomes a flex column on desktop only (beats the block!important above) so the
     chart fills the space under the heading and its x-labels aren't clipped. Kept out of the
     base rule so the mobile tab-switcher can still hide it with .panel { display:none }. */
  .panel[data-panel=stats] {
    display: flex !important;
    flex-direction: column;
  }
}
