:root {
  --ink: #f4efe6;
  --dim: rgba(244, 239, 230, 0.62);
  --faint: rgba(244, 239, 230, 0.16);
  --amber: #ffb547;
  --coral: #ff5a4d;
  --panel: rgba(10, 14, 26, 0.72);
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, ui-serif, serif;
  --sans: "Avenir Next", Avenir, "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }
:root { color-scheme: dark; }

/* slim, dark scrollbars inside the panels */
.tally ol, .card, .gacha-box { scrollbar-width: thin; scrollbar-color: rgba(244, 239, 230, 0.22) transparent; }
.tally ol::-webkit-scrollbar, .card::-webkit-scrollbar, .gacha-box::-webkit-scrollbar { width: 6px; }
.tally ol::-webkit-scrollbar-track, .card::-webkit-scrollbar-track, .gacha-box::-webkit-scrollbar-track { background: transparent; }
.tally ol::-webkit-scrollbar-thumb, .card::-webkit-scrollbar-thumb, .gacha-box::-webkit-scrollbar-thumb {
  background: rgba(244, 239, 230, 0.22);
  border-radius: 3px;
}

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: radial-gradient(120% 90% at 50% 40%, #0b1226 0%, #05070f 60%, #020308 100%);
  color: var(--ink);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
}

#scene {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: grab;
}
#scene.aiming { cursor: grabbing; }

.brand {
  position: fixed;
  top: 26px;
  left: 30px;
  max-width: 300px;
  pointer-events: none;
}
.brand h1 {
  margin: 0;
  font: italic 600 44px/1 var(--serif);
  letter-spacing: -0.01em;
}
.brand p {
  margin: 10px 0 0;
  font-size: 14px;
  line-height: 1.45;
  color: var(--dim);
}

.card, .tally {
  position: fixed;
  background: var(--panel);
  border: 1px solid var(--faint);
  border-radius: 16px;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

.card {
  left: 30px;
  bottom: 64px;
  width: 330px;
  padding: 20px 22px 18px;
  animation: rise 0.45s cubic-bezier(0.2, 0.9, 0.3, 1.2);
}
.card[hidden], .tally[hidden] { display: none; }
@keyframes rise {
  from { opacity: 0; transform: translateY(14px) scale(0.97); }
  to { opacity: 1; transform: none; }
}
.card-top { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.card-kicker {
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--amber);
}
.card-title {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 8px 0 14px;
  font: 600 30px/1.1 var(--serif);
}
.card-sub { margin: -8px 0 14px; font-size: 14px; color: var(--dim); }
.card-sub[hidden] { display: none; }
.card-title .flag { font-size: 38px; line-height: 1; }
.odds-bar {
  height: 6px;
  border-radius: 3px;
  background: var(--faint);
  overflow: hidden;
}
.odds-bar i {
  display: block;
  height: 100%;
  min-width: 3px;
  border-radius: 3px;
  background: linear-gradient(90deg, var(--coral), var(--amber));
  transition: width 0.5s ease;
}
.odds-text { margin-top: 8px; font-size: 14px; color: var(--dim); }
.odds-text b { color: var(--ink); font-weight: 600; }
.stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px 16px;
  margin: 16px 0 0;
  padding-top: 14px;
  border-top: 1px solid var(--faint);
}
.stats dt {
  font-size: 10.5px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--dim);
}
.stats dd { margin: 3px 0 0; font-size: 14.5px; font-variant-numeric: tabular-nums; }
.stats a { color: var(--amber); text-decoration: none; border-bottom: 1px dotted currentColor; }

.tally {
  top: 26px;
  right: 30px;
  width: 250px;
  max-height: min(70vh, 560px);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
}
.tally-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font: 600 17px var(--serif);
}
.tally-head button {
  all: unset;
  cursor: pointer;
  font: 12px var(--sans);
  color: var(--dim);
}
.tally-head button:hover { color: var(--ink); }
.tally ol {
  list-style: none;
  margin: 10px 0 0;
  padding: 0;
  overflow-y: auto;
  font-size: 13.5px;
  padding-right: 10px; /* keeps the counts clear of the scrollbar */
  margin-right: -6px;
  min-height: 0;
}
.tally li {
  display: grid;
  grid-template-columns: 22px 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 4px 0;
}
.tally li span:nth-child(2) { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tally li b { font-weight: 600; color: var(--amber); font-variant-numeric: tabular-nums; }
.tally li.fresh { animation: flash 0.9s ease; }
@keyframes flash { from { background: rgba(255, 181, 71, 0.28); } to { background: transparent; } }

.hint {
  position: fixed;
  left: 50%;
  top: 30px;
  transform: translateX(-50%);
  padding: 8px 16px;
  border-radius: 999px;
  background: var(--panel);
  border: 1px solid var(--faint);
  font-size: 13.5px;
  color: var(--dim);
  white-space: nowrap;
  pointer-events: none;
  transition: opacity 0.5s;
}
.hint.gone { opacity: 0; }

.controls {
  position: fixed;
  right: 30px;
  bottom: 64px;
  display: flex;
  gap: 10px;
}
.controls button {
  font: 600 14px var(--sans);
  color: var(--ink);
  padding: 11px 18px;
  border-radius: 999px;
  border: 1px solid var(--faint);
  background: var(--panel);
  cursor: pointer;
  transition: transform 0.12s, background 0.2s;
}
.controls button:hover { background: rgba(40, 50, 80, 0.8); }
.controls button:active { transform: scale(0.96); }
.controls button:disabled { opacity: 0.45; cursor: default; }
.controls .primary {
  background: linear-gradient(135deg, var(--coral), #ff8a3d);
  border-color: transparent;
  color: #1a0b06;
}
.controls .primary:hover { background: linear-gradient(135deg, #ff6c60, #ff9a55); }
kbd {
  font: 11px var(--sans);
  padding: 2px 6px;
  margin-left: 6px;
  border-radius: 5px;
  background: rgba(0, 0, 0, 0.18);
}

.credit {
  position: fixed;
  left: 30px;
  right: 30px;
  bottom: 22px;
  font-size: 11.5px;
  color: rgba(244, 239, 230, 0.4);
}
.credit a { color: inherit; }

.loading {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  font: italic 22px var(--serif);
  color: var(--dim);
  background: #05070f;
  transition: opacity 0.6s;
}
.loading.done { opacity: 0; pointer-events: none; }

/* ── rarity colours ── */
[data-tier="N"] { --tier: #9aa3b2; }
[data-tier="R"] { --tier: #5fb0ff; }
[data-tier="SR"] { --tier: #b88cff; }
[data-tier="SSR"] { --tier: #ffc94a; }
[data-tier="UR"] { --tier: #ff7ad9; }
[data-tier="none"] { --tier: #6b7280; }

.card { border-color: color-mix(in srgb, var(--tier, #fff) 45%, transparent); max-height: calc(100vh - 150px); overflow-y: auto; }
.card[data-tier="SSR"], .card[data-tier="UR"] { box-shadow: 0 0 34px -6px color-mix(in srgb, var(--tier) 60%, transparent); }
.tier-badge {
  flex: none;
  font: 700 11.5px var(--sans);
  letter-spacing: 0.06em;
  padding: 3px 9px;
  border-radius: 999px;
  color: #10131c;
  background: var(--tier, #9aa3b2);
  cursor: help;
}
.card[data-tier="UR"] .tier-badge, .tile[data-tier="UR"] .tile-stars, .pull[data-tier="UR"] em {
  background: linear-gradient(90deg, #ff7ad9, #ffd36b, #6be3ff);
}
.tile[data-tier="UR"] .tile-stars, .pull[data-tier="UR"] em { -webkit-background-clip: text; background-clip: text; color: transparent; }
.card-spot { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--faint); font-size: 14px; color: var(--dim); }
.card-spot a { color: var(--amber); text-decoration: none; border-bottom: 1px dotted currentColor; }
.card-note { margin-top: 8px; font-size: 10.5px; color: rgba(244, 239, 230, 0.38); }

/* ── stats panel ── */
.tier-row { display: flex; gap: 5px; margin-top: 10px; }
.tier-row span {
  flex: 1;
  text-align: center;
  font: 700 10.5px var(--sans);
  padding: 4px 0;
  border-radius: 6px;
  color: var(--tier);
  border: 1px solid color-mix(in srgb, var(--tier) 35%, transparent);
  opacity: 0.45;
  white-space: nowrap;
}
.tier-row span.on { opacity: 1; background: color-mix(in srgb, var(--tier) 16%, transparent); }
.pull {
  all: unset;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 1px 8px;
  margin-top: 8px;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid color-mix(in srgb, var(--tier) 50%, transparent);
  background: color-mix(in srgb, var(--tier) 10%, transparent);
  cursor: pointer;
  box-sizing: border-box;
  width: 100%;
}
.pull[hidden] { display: none; }
.pull:hover { background: color-mix(in srgb, var(--tier) 20%, transparent); }
.pull small { grid-column: 1 / -1; font-size: 10px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--dim); }
.pull span { font: 600 14.5px var(--serif); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pull em { grid-column: 1 / -1; font: 12px var(--sans); font-style: normal; color: var(--tier); }
.avg-line { margin-top: 8px; font-size: 11.5px; line-height: 1.4; color: var(--dim); }
.avg-line:empty { display: none; }

/* ── 10× roll ── */
.gacha {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(3, 5, 12, 0.72);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  animation: fade 0.3s ease;
  z-index: 5;
}
.gacha[hidden] { display: none; }
@keyframes fade { from { opacity: 0; } }
.gacha-box {
  width: min(860px, 100%);
  max-height: 100%;
  overflow-y: auto;
  padding: 22px 24px 18px;
  border-radius: 20px;
  border: 1px solid var(--faint);
  background: rgba(12, 16, 30, 0.94);
  text-align: center;
}
.gacha-box h2 { margin: 0 0 16px; font: italic 600 28px var(--serif); }
.gacha-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; perspective: 900px; }
.tile {
  all: unset;
  box-sizing: border-box;
  cursor: pointer;
  aspect-ratio: 3 / 4;
  border-radius: 12px;
  position: relative;
  transform: rotateY(180deg);
  transition: transform 0.55s cubic-bezier(0.2, 0.8, 0.2, 1.1);
  background: repeating-linear-gradient(135deg, #171c30 0 10px, #1d2340 10px 20px);
  border: 1px solid var(--faint);
}
.tile.shown {
  transform: none;
  background: linear-gradient(170deg, color-mix(in srgb, var(--tier) 26%, #0d111f), #0d111f 70%);
  border-color: color-mix(in srgb, var(--tier) 70%, transparent);
}
.tile.best { box-shadow: 0 0 26px -2px var(--tier); animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 40px 2px var(--tier); } }
.tile:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
.tile-face {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 8px 6px;
  opacity: 0;
  transition: opacity 0.2s 0.22s;
}
.tile.shown .tile-face { opacity: 1; }
.tile-stars { font-size: 13px; letter-spacing: 1px; color: var(--tier); }
.tile-flag { font-size: 34px; line-height: 1.1; }
.tile-name { font: 600 14px/1.15 var(--serif); max-width: 100%; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.tile-sub { font-size: 11px; color: var(--dim); max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile-gdp { font-size: 11.5px; color: var(--tier); font-variant-numeric: tabular-nums; }
.gacha-summary { margin: 16px 0 14px; font-size: 14px; color: var(--ink); min-height: 1.4em; }
.gacha-actions { display: flex; justify-content: center; gap: 10px; }
.gacha-actions button, .controls button {
  font: 600 14px var(--sans);
  color: var(--ink);
  padding: 11px 18px;
  border-radius: 999px;
  border: 1px solid var(--faint);
  background: var(--panel);
  cursor: pointer;
}
.gacha-actions .primary { background: linear-gradient(135deg, var(--coral), #ff8a3d); border-color: transparent; color: #1a0b06; }
.gacha-note { margin: 14px 0 0; font-size: 11px; color: rgba(244, 239, 230, 0.4); }

.card-brief, .card-more { display: none; }

@media (max-width: 760px) {
  .brand { top: calc(12px + env(safe-area-inset-top)); left: 14px; max-width: 60vw; }
  .brand h1 { font-size: 28px; }
  .brand p { display: none; }
  .hint { top: auto; bottom: calc(150px + env(safe-area-inset-bottom)); font-size: 12px; max-width: 92vw; }
  .hint .wide { display: none; }

  /* stats: a chip that opens into the full panel */
  .tally { top: calc(10px + env(safe-area-inset-top)); right: 12px; width: auto; padding: 7px 12px; max-height: 70dvh; z-index: 3; }
  .tally-head { font-size: 14px; gap: 14px; }
  .tally-head span { cursor: pointer; }
  .tally-head span::after { content: " ▾"; font-size: 10px; color: var(--dim); }
  .tally > :not(.tally-head), .tally-head button { display: none; }
  .tally.open { left: 12px; padding: 12px 14px; }
  .tally.open > :not(.tally-head):not([hidden]) { display: revert; }
  .tally.open .pull:not([hidden]) { display: grid; }
  .tally.open .tier-row { display: flex; }
  .tally.open .tally-head button { display: revert; }
  .tally.open .tally-head span::after { content: " ▴"; }

  /* result card: a short sheet above the buttons, expandable */
  .card {
    left: 10px; right: 10px; top: auto; width: auto;
    bottom: calc(70px + env(safe-area-inset-bottom));
    padding: 12px 14px;
    max-height: 62dvh;
    z-index: 2;
  }
  .card-title { font-size: 21px; margin: 5px 0 6px; gap: 9px; }
  .card-title .flag { font-size: 26px; }
  .card-sub { margin: -2px 0 8px; font-size: 13px; }
  .odds-bar { display: none; }
  .odds-text { margin-top: 0; font-size: 13px; }
  .card-brief { display: block; margin-top: 4px; font-size: 13px; color: var(--ink); padding-right: 64px; }
  .card-more {
    all: unset;
    display: block;
    position: absolute;
    right: 12px; bottom: 10px;
    font: 600 12px var(--sans);
    color: var(--amber);
    padding: 6px 4px;
    cursor: pointer;
  }
  .card:not(.open) .stats, .card:not(.open) .card-spot, .card:not(.open) .card-note { display: none; }
  .card.open .card-brief { display: none; }
  .card.open { padding-bottom: 34px; }
  .stats { gap: 8px 12px; margin-top: 10px; padding-top: 10px; }
  .stats dd { font-size: 13.5px; }
  .card-spot { margin-top: 10px; padding-top: 9px; font-size: 13px; }

  /* buttons in the corners, the dart between them */
  .controls { left: 12px; right: 12px; bottom: calc(18px + env(safe-area-inset-bottom)); justify-content: space-between; flex-direction: row-reverse; }
  .controls button { padding: 11px 16px; font-size: 14px; }
  kbd { display: none; }

  .credit {
    left: 0; right: 0; bottom: 0;
    padding: 2px 10px calc(2px + env(safe-area-inset-bottom));
    font-size: 9px;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    text-align: center;
  }
  .credit.open { white-space: normal; background: rgba(5, 7, 15, 0.92); padding: 10px 12px; font-size: 11px; z-index: 4; text-align: left; }

  .gacha { padding: 10px; }
  .gacha-box { padding: 14px 12px; }
  .gacha-box h2 { font-size: 22px; margin-bottom: 10px; }
  .gacha-grid { grid-template-columns: repeat(2, 1fr); gap: 7px; }
  .tile { aspect-ratio: 5 / 3; }
  .tile-face { gap: 1px; padding: 5px 8px; }
  .tile-flag { font-size: 20px; line-height: 1.15; }
  .tile-name { font-size: 13px; line-height: 1.25; display: block; white-space: nowrap; }
  .tile-sub, .tile-gdp { font-size: 10.5px; }
  .tile-stars { font-size: 10px; }
  .gacha-summary { font-size: 12.5px; margin: 10px 0; }
  .gacha-note { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .card, .tally li.fresh { animation: none; }
}
