@import url("https://fonts.googleapis.com/css2?family=Fraunces:opsz,wght@9..144,500;9..144,700&family=Outfit:wght@400;500;600;700&display=swap");

:root {
  --felt: #167a45;
  --felt-deep: #0c3d24;
  --felt-mid: #1e8f52;
  --navy: #12203a;
  --navy-2: #1a2d52;
  --gold: #e8b84a;
  --gold-2: #fff0b0;
  --gold-3: #c9922a;
  --ivory: #fff8e7;
  --ivory-2: #f3e6c4;
  --ink: #12203a;
  --muted: #5c6b7a;
  --red: #e23b3b;
  --blue: #2b7de0;
  --green: #2ebd5a;
  --yellow: #f5c62e;
  --purple: #9b4fd8;
  --ribbon: #1e5bb8;
  --rouge: #c62828;
  --line: rgba(18, 32, 58, 0.1);
  --shadow: 0 24px 60px rgba(6, 20, 12, 0.4);
  --radius: 18px;
  font-family: Outfit, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  background: var(--felt-deep);
  color: var(--ivory);
  min-height: 100dvh;
}
.page-bg {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    url("../img/superium-hero.jpg") center 42% / cover no-repeat;
}
.page-bg::after {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(180deg, rgba(8, 28, 18, 0.42), rgba(10, 24, 40, 0.58));
}
html.is-home .page-bg { opacity: 0; }

button, input { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }

.app {
  position: relative;
  z-index: 1;
  max-width: 1280px;
  margin: 0 auto;
  padding: 20px 16px 40px;
}
.app.is-home {
  max-width: none;
  margin: 0;
  padding: 0;
}

/* ——— Home ——— */
.home {
  position: relative;
  min-height: 100dvh;
  overflow: hidden;
  background: var(--felt-deep);
}
.hero {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center 46%;
  display: block;
}
.home-bar {
  position: absolute;
  left: max(20px, env(safe-area-inset-left));
  top: 50%;
  transform: translateY(-50%);
  z-index: 2;
  padding: 16px;
  border-radius: 18px;
  background: rgba(8, 28, 18, 0.42);
  border: 1px solid rgba(232, 184, 74, 0.28);
  backdrop-filter: blur(8px);
}
.home-actions {
  display: grid;
  gap: 10px;
  width: min(260px, 72vw);
}
.home-actions .btn {
  width: 100%;
}
.btn {
  border: 0;
  border-radius: 999px;
  padding: 14px 22px;
  background: var(--ivory);
  color: var(--navy);
  font-weight: 600;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}
.btn:hover { transform: translateY(-1px); box-shadow: 0 8px 20px rgba(0,0,0,.25); }
.btn.primary {
  background: linear-gradient(180deg, var(--gold-2), var(--gold) 55%, var(--gold-3));
  color: #2a1c0d;
  box-shadow: 0 6px 0 #8a5a10;
}
.btn.primary:hover { box-shadow: 0 7px 0 #8a5a10, 0 10px 22px rgba(0,0,0,.25); }
.btn.ghost {
  background: rgba(18, 32, 58, 0.28);
  color: var(--gold-2);
  border: 1px solid rgba(232, 184, 74, 0.45);
}
.btn.danger { background: var(--red); color: #fff; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; box-shadow: none; }
.btn.small { padding: 8px 14px; font-size: 14px; box-shadow: none; }

/* ——— Setup ——— */
.panel {
  width: min(560px, 100%);
  margin: 48px auto;
  background: linear-gradient(180deg, rgba(18, 32, 58, 0.78), rgba(12, 61, 36, 0.8));
  border: 1px solid rgba(232, 184, 74, 0.4);
  border-radius: var(--radius);
  padding: 28px;
  box-shadow: var(--shadow);
}
.panel h2 {
  font-family: Fraunces, Georgia, serif;
  margin: 0 0 8px;
  color: var(--gold-2);
}
.hint { color: var(--ivory-2); opacity: 0.85; margin: 0 0 22px; font-size: 14px; }
.field { display: grid; gap: 6px; margin-bottom: 14px; text-align: left; }
.field label { font-size: 13px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--gold); }
.field input, .field select {
  background: var(--navy);
  border: 1px solid rgba(232, 184, 74, 0.28);
  color: var(--ivory);
  border-radius: 12px;
  padding: 12px 14px;
}
.row-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 18px; }

/* ——— Game chrome ——— */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}
.brand-mini {
  font-family: Fraunces, Georgia, serif;
  letter-spacing: 0.16em;
  font-size: 20px;
  font-weight: 700;
  background: linear-gradient(180deg, #fff6c8, var(--gold));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 1px 0 #7a4e12);
}
.match-pills { display: flex; gap: 8px; flex-wrap: wrap; }
.pill {
  border: 1px solid rgba(232, 184, 74, 0.35);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 13px;
  color: var(--ivory-2);
  background: rgba(18, 32, 58, 0.35);
}
.pill.lead {
  border-color: var(--gold);
  color: #2a1c0d;
  background: linear-gradient(180deg, var(--gold-2), var(--gold));
  font-weight: 700;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 380px;
  gap: 18px;
  align-items: start;
}

/* ——— Scorecard ——— */
.sheet-wrap {
  background: var(--ivory);
  color: var(--ink);
  border-radius: 16px;
  box-shadow: var(--shadow);
  overflow: hidden;
  border: 2px solid rgba(232, 184, 74, 0.55);
}
.sheet-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 14px 16px 10px;
  background: linear-gradient(180deg, var(--navy-2), var(--navy));
  color: var(--gold-2);
}
.sheet-head h2 {
  font-family: Fraunces, Georgia, serif;
  margin: 0;
  letter-spacing: 0.12em;
  font-size: 22px;
  background: linear-gradient(180deg, #fff6c8, var(--gold));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.manche-tabs { display: flex; gap: 6px; }
.manche-tabs button {
  border: 0;
  background: transparent;
  padding: 6px 10px;
  border-radius: 8px;
  color: rgba(255, 248, 231, 0.55);
}
.manche-tabs button.on {
  background: var(--gold);
  color: #2a1c0d;
  font-weight: 700;
}
.sheet {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}
.sheet th, .sheet td {
  padding: 5px 6px;
  border-bottom: 1px solid var(--line);
  text-align: center;
}
.sheet th {
  font-size: 11px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ribbon);
  font-weight: 700;
}
.sheet td.lab {
  text-align: left;
  padding-left: 14px;
  font-size: 13px;
  white-space: nowrap;
}
.sheet tr.section td { background: #dceeff; font-weight: 700; font-size: 12px; color: var(--navy); }
.sheet tr.total td {
  background: linear-gradient(180deg, var(--navy-2), var(--navy));
  color: var(--gold-2);
  font-weight: 700;
}
.sheet tr.bonus td { background: #ffe7a3; }
.cell {
  min-width: 42px;
  height: 28px;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 0;
  color: inherit;
  padding: 0 4px;
}
.cell.open { background: rgba(46, 189, 90, 0.18); cursor: pointer; }
.cell.open:hover { background: rgba(232, 184, 74, 0.45); }
.cell.preview { background: var(--navy); color: var(--gold-2); font-weight: 700; }
.cell.preview.zero { color: #ffb4b4; }
.cell.mine { outline: 2px solid var(--purple); }
.cell.scored { font-weight: 600; }
.cell.zero { color: var(--muted); }
.turn-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--gold);
  margin-right: 4px;
  vertical-align: middle;
}

/* ——— Table ——— */
.table {
  background:
    radial-gradient(circle at 50% 18%, var(--felt-mid), var(--felt) 42%, var(--felt-deep));
  border-radius: 16px;
  padding: 18px 16px 16px;
  box-shadow: var(--shadow), inset 0 0 0 3px rgba(232, 184, 74, 0.35);
  position: sticky;
  top: 12px;
}
.turn-line {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  color: var(--ivory);
}
.turn-line strong {
  font-family: Fraunces, Georgia, serif;
  font-size: 22px;
  color: var(--gold-2);
}
.dice-sum {
  background: rgba(18, 32, 58, 0.4);
  border: 1px solid rgba(232, 184, 74, 0.35);
  border-radius: 12px;
  padding: 10px 12px 8px;
  margin: 0 0 14px;
  text-align: center;
  color: var(--ivory);
}
.dice-sum-main {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
}
.dice-sum-label {
  font-size: 12px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--gold-2);
}
.dice-sum-value {
  font-family: Fraunces, Georgia, serif;
  font-size: 34px;
  line-height: 1;
  color: var(--gold-2);
  font-variant-numeric: tabular-nums;
}
.dice-sum-add {
  margin-top: 4px;
  font-variant-numeric: tabular-nums;
  font-size: 14px;
  color: var(--ivory-2);
}
.dice-sum-hint {
  margin-top: 4px;
  font-size: 11px;
  color: #d5ecdf;
  opacity: 0.85;
}
.dice-sum.is-empty { opacity: 0.55; }
.dice-sum.is-empty .dice-sum-value { font-size: 22px; }
.dice-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  min-height: 86px;
  margin: 10px 0 16px;
}
.die {
  width: 58px;
  height: 58px;
  border-radius: 12px;
  background: var(--red);
  color: #fff;
  border: 0;
  box-shadow: 0 8px 16px rgba(0,0,0,.28), inset 0 1px 0 rgba(255,255,255,.45);
  position: relative;
  padding: 0;
}
.die[data-face="1"] { background: linear-gradient(160deg, #ff6b6b, var(--red)); }
.die[data-face="2"] { background: linear-gradient(160deg, #5aa4ff, var(--blue)); }
.die[data-face="3"] { background: linear-gradient(160deg, #5be087, var(--green)); }
.die[data-face="4"] { background: linear-gradient(160deg, #ffe56a, var(--yellow)); }
.die[data-face="5"] { background: linear-gradient(160deg, #c07bff, var(--purple)); }
.die[data-face="6"] { background: linear-gradient(160deg, var(--gold-2), var(--gold-3)); }
.die.held {
  transform: translateY(-10px);
  box-shadow: 0 14px 22px rgba(0,0,0,.32), 0 0 0 3px var(--gold-2);
}
.keep-tag {
  position: absolute;
  left: 50%;
  bottom: -7px;
  transform: translateX(-50%);
  background: var(--gold);
  color: #2a1c0d;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  border-radius: 999px;
  padding: 1px 6px;
  pointer-events: none;
}
.die.rolling { animation: tumble 0.18s linear infinite; }
@keyframes tumble {
  50% { transform: rotate(12deg) scale(0.96); }
}
.bonus-flash {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  pointer-events: none;
  animation: bonus-veil 1.7s ease forwards;
}
.bonus-flash-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  transform: scale(0.4) rotate(-8deg);
  animation: bonus-pop 1.7s cubic-bezier(0.18, 1.4, 0.32, 1) forwards;
  filter: drop-shadow(0 12px 28px rgba(0, 0, 0, 0.45));
}
.bonus-flash-title {
  font-family: Fraunces, Georgia, serif;
  font-size: clamp(42px, 9vw, 84px);
  font-weight: 700;
  letter-spacing: 0.08em;
  line-height: 0.9;
  background: linear-gradient(180deg, #fffbe6, var(--gold-2) 40%, var(--gold) 70%, var(--gold-3));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow: none;
  -webkit-text-stroke: 1px rgba(122, 78, 18, 0.25);
}
.bonus-flash-n {
  font-family: Fraunces, Georgia, serif;
  font-size: clamp(56px, 12vw, 110px);
  font-weight: 700;
  line-height: 0.9;
  color: var(--gold-2);
  text-shadow:
    0 0 24px rgba(232, 184, 74, 0.85),
    0 4px 0 #8a5a10;
}
@keyframes bonus-pop {
  0% { transform: scale(0.35) rotate(-10deg); opacity: 0; }
  18% { transform: scale(1.18) rotate(3deg); opacity: 1; }
  32% { transform: scale(0.96) rotate(-2deg); }
  48% { transform: scale(1.06) rotate(1deg); }
  78% { transform: scale(1) rotate(0deg); opacity: 1; }
  100% { transform: scale(0.86) translateY(-28px); opacity: 0; }
}
@keyframes bonus-veil {
  0%, 70% { background: rgba(8, 28, 18, 0.12); }
  100% { background: transparent; }
}
.superium-fw {
  position: fixed;
  inset: 0;
  z-index: 50;
  pointer-events: none;
}
.superium-fw-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}
.superium-fw-title {
  position: absolute;
  left: 50%;
  top: 42%;
  transform: translate(-50%, -50%);
  font-family: Fraunces, Georgia, serif;
  font-size: clamp(48px, 11vw, 104px);
  font-weight: 700;
  letter-spacing: 0.1em;
  background: linear-gradient(180deg, #fffbe6, #ffe56a 40%, var(--gold) 70%, var(--gold-3));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 6px 18px rgba(0, 0, 0, 0.45));
  animation: bonus-pop 2.6s cubic-bezier(0.18, 1.4, 0.32, 1) forwards;
  white-space: nowrap;
}
.pips {
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  padding: 8px;
}
.pip {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 0 rgba(0,0,0,.2);
  justify-self: center;
  align-self: center;
  opacity: 0;
}
.die[data-face="4"] .pip,
.die[data-face="6"] .pip { background: #1a1408; }
.die[data-face="1"] .pip:nth-child(5) { opacity: 1; }
.die[data-face="2"] .pip:nth-child(1),
.die[data-face="2"] .pip:nth-child(9) { opacity: 1; }
.die[data-face="3"] .pip:nth-child(1),
.die[data-face="3"] .pip:nth-child(5),
.die[data-face="3"] .pip:nth-child(9) { opacity: 1; }
.die[data-face="4"] .pip:nth-child(1),
.die[data-face="4"] .pip:nth-child(3),
.die[data-face="4"] .pip:nth-child(7),
.die[data-face="4"] .pip:nth-child(9) { opacity: 1; }
.die[data-face="5"] .pip:nth-child(1),
.die[data-face="5"] .pip:nth-child(3),
.die[data-face="5"] .pip:nth-child(5),
.die[data-face="5"] .pip:nth-child(7),
.die[data-face="5"] .pip:nth-child(9) { opacity: 1; }
.die[data-face="6"] .pip:nth-child(1),
.die[data-face="6"] .pip:nth-child(3),
.die[data-face="6"] .pip:nth-child(4),
.die[data-face="6"] .pip:nth-child(6),
.die[data-face="6"] .pip:nth-child(7),
.die[data-face="6"] .pip:nth-child(9) { opacity: 1; }

.table-actions { display: grid; gap: 8px; }
.help {
  margin-top: 12px;
  font-size: 13px;
  color: var(--ivory);
  min-height: 36px;
}
.last-play {
  margin-top: 8px;
  font-size: 12px;
  color: var(--ivory-2);
  opacity: 0.9;
}

/* ——— Modals / rules / winner ——— */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(8, 22, 16, 0.78);
  display: grid;
  place-items: center;
  padding: 20px;
  z-index: 20;
}
.modal {
  width: min(720px, 100%);
  max-height: min(86dvh, 900px);
  overflow: auto;
  background: linear-gradient(180deg, var(--navy), var(--felt-deep));
  border: 1px solid rgba(232, 184, 74, 0.45);
  border-radius: 18px;
  padding: 24px;
  box-shadow: var(--shadow);
}
.modal h2 {
  font-family: Fraunces, Georgia, serif;
  margin-top: 0;
  color: var(--gold-2);
}
.rules dt { color: var(--gold); font-weight: 600; margin-top: 12px; }
.rules dd { margin: 4px 0 0; color: var(--ivory-2); }
.winner { text-align: center; }
.winner .score {
  font-family: Fraunces, Georgia, serif;
  font-size: 42px;
  color: var(--gold-2);
  margin: 8px 0 18px;
}
.fanfare-overlay {
  background:
    radial-gradient(circle at 50% 30%, rgba(232, 184, 74, 0.28), transparent 42%),
    rgba(6, 16, 12, 0.82);
}
.modal.fanfare {
  position: relative;
  overflow: hidden;
  border: 2px solid rgba(232, 184, 74, 0.65);
  padding: 32px 24px 28px;
  animation: fanfare-in 0.45s cubic-bezier(0.18, 1.3, 0.32, 1);
}
.modal.fanfare.match {
  box-shadow: 0 0 0 4px rgba(232, 184, 74, 0.2), var(--shadow);
}
.fanfare h2 {
  font-size: clamp(28px, 5vw, 44px);
  margin: 6px 0 16px;
  background: linear-gradient(180deg, #fffbe6, var(--gold-2) 45%, var(--gold));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.fanfare-kicker {
  margin: 0;
  font-family: Fraunces, Georgia, serif;
  font-size: clamp(40px, 8vw, 72px);
  letter-spacing: 0.14em;
  line-height: 0.9;
  background: linear-gradient(180deg, #fffbe6, var(--gold));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  animation: bonus-pop 1.4s cubic-bezier(0.18, 1.4, 0.32, 1) 1;
}
.fanfare-board {
  display: grid;
  gap: 8px;
  margin: 0 auto 16px;
  width: min(360px, 100%);
  font-size: 22px;
}
.fanfare-board.small { font-size: 16px; margin-bottom: 18px; }
.fanfare-line {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 8px 14px;
  border-radius: 12px;
  background: rgba(255, 248, 231, 0.08);
  color: var(--ivory);
}
.fanfare-line strong { color: var(--gold-2); }
.fanfare-manches { margin-bottom: 18px; color: var(--ivory-2); font-size: 13px; }
.fanfare-manche { margin: 4px 0; }
.fanfare-burst {
  position: absolute;
  inset: -20%;
  background:
    radial-gradient(circle at 20% 30%, rgba(226, 59, 59, 0.25), transparent 18%),
    radial-gradient(circle at 80% 25%, rgba(43, 125, 224, 0.25), transparent 18%),
    radial-gradient(circle at 50% 80%, rgba(155, 79, 216, 0.22), transparent 20%),
    radial-gradient(circle at 70% 70%, rgba(245, 198, 46, 0.22), transparent 16%);
  pointer-events: none;
  animation: fanfare-glow 2.4s ease-in-out infinite alternate;
}
@keyframes fanfare-in {
  from { transform: scale(0.86) translateY(16px); opacity: 0; }
  to { transform: none; opacity: 1; }
}
@keyframes fanfare-glow {
  from { opacity: 0.55; transform: scale(1); }
  to { opacity: 1; transform: scale(1.06); }
}

.keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 12px;
}
.keypad button {
  background: var(--navy-2);
  color: var(--ivory);
  border: 1px solid rgba(232, 184, 74, 0.25);
  border-radius: 10px;
  padding: 12px;
}

@media (max-width: 980px) {
  .layout { grid-template-columns: 1fr; }
  .table { position: static; }
  .sheet td.lab { padding-left: 8px; font-size: 12px; }
  .cell { min-width: 34px; }
}
@media (max-width: 640px) {
  .app { padding: 12px 10px 28px; }
  .die { width: 46px; height: 46px; }
  .home-bar {
    top: auto;
    bottom: max(16px, env(safe-area-inset-bottom));
    transform: none;
  }
  .hero { object-position: 62% 46%; }
  .sheet th, .sheet td { padding: 4px 3px; }
}
