/* Yahtzee / Kniffel — TagWhy edition
   Tokens, reset, body, Inter font, .chip, focus-visible, touch-action,
   .visually-hidden, and reduced-motion come from /assets/base.css. */

:root {
  --good: #27d17a;
  --error: #ff5d5d;
}

/* ============================================================
   TOP BAR (grid, matches Tally / Minesweeper / Hearts)
   ============================================================ */

.top {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  padding: 0.4rem 0.75rem 0.5rem;
  position: sticky;
  top: 0;
  z-index: 10;
}

.top-side {
  display: flex;
  align-items: center;
  gap: 8px;
}
.top-side-left  { justify-content: flex-start; flex-wrap: wrap; }
.top-side-right { justify-content: flex-end;   flex-wrap: wrap; }

.top-center { text-align: center; }
.top-center h1 {
  margin: 0 0 2px;
  font-size: clamp(1.4rem, 3vw, 2.1rem);
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.muted {
  margin: 0;
  color: var(--muted);
  font-size: 0.72rem;
}


/* ============================================================
   BUTTONS (pill style, matches site)
   ============================================================ */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  border-radius: 999px;
  border: 1px solid transparent;
  padding: 0.4rem 0.9rem;
  font-size: 0.78rem;
  font-weight: 500;
  cursor: pointer;
  background: transparent;
  color: var(--text);
  white-space: nowrap;
  transition: background 0.15s ease, border-color 0.15s ease,
              transform 0.08s ease, box-shadow 0.1s ease;
}

.btn.ghost {
  border-color: rgba(255, 255, 255, 0.18);
  background: rgba(6, 11, 26, 0.9);
}
.btn.ghost:hover:not(:disabled) {
  background: rgba(40, 50, 70, 0.8);
  transform: translateY(-1px);
}

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #0b0b18;
  font-weight: 600;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.12),
              0 10px 24px rgba(0, 0, 0, 0.7);
}
.btn.primary:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.12),
              0 14px 32px rgba(0, 0, 0, 0.85);
}

.btn:disabled { opacity: 0.4; cursor: default; pointer-events: none; }

/* Muted state for sound button */
.icon-btn.muted { opacity: 0.45; }

/* Mode toggle pill */
.mode-toggle {
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(6, 11, 26, 0.9);
  border-radius: 999px;
  padding: 3px 6px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.mode-pill {
  padding: 3px 10px;
  font-size: 0.78rem;
  font-weight: 500;
  border-radius: 999px;
  background: transparent;
  border: none;
  color: var(--muted);
  cursor: pointer;
  transition: 0.15s ease;
}

.mode-pill.active {
  background: var(--accent);
  color: #0b0b18;
  font-weight: 600;
}

.mode-pill:not(.active):hover {
  background: rgba(40, 50, 70, 0.8);
  color: var(--text);
}

/* ============================================================
   APP WRAPPER
   ============================================================ */

.app {
  max-width: 920px;
  margin: 0 auto;
  padding: 0 18px 40px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

@media (max-width: 480px) { .app { padding: 0 10px 28px; } }

/* ============================================================
   MAIN LAYOUT
   ============================================================ */

.layout {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

@media (min-width: 960px) {
  .layout {
    display: grid;
    grid-template-columns: 1fr 1.15fr;
    gap: 14px;
  }
}

/* ============================================================
   CARD
   ============================================================ */

.card {
  background: linear-gradient(160deg, #141826, #101321);
  border: 1px solid rgba(255, 255, 255, 0.06);
  padding: 16px;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-soft);
}

/* ============================================================
   TURN BANNER
   ============================================================ */

.turn-banner {
  text-align: center;
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  display: inline-block;
  margin-bottom: 4px;
  transition: background 0.3s ease, color 0.3s ease, box-shadow 0.3s ease;
}

.turn-banner.your-turn {
  background: var(--accent);
  color: #0b0b18;
  box-shadow: 0 0 16px rgba(138, 124, 255, 0.5);
}

.turn-banner.bot-turn {
  background: rgba(255, 255, 255, 0.08);
  color: var(--muted);
  animation: bot-turn-pulse 1.5s ease-in-out infinite;
}

.turn-banner.p1-turn {
  background: var(--accent);
  color: #0b0b18;
  box-shadow: 0 0 16px rgba(138, 124, 255, 0.5);
}

.turn-banner.p2-turn {
  background: #ff7aa8;
  color: #0b0b18;
  box-shadow: 0 0 16px rgba(255, 122, 168, 0.5);
}

@keyframes bot-turn-pulse {
  0%, 100% { opacity: 0.6; }
  50%      { opacity: 1; }
}

/* ============================================================
   DICE PANEL
   ============================================================ */

.dice-panel {
  display: flex;
  flex-direction: column;
  gap: 10px;
  transition: border-color 0.3s ease, box-shadow 0.3s ease;
  min-height: 420px;
}

.dice-panel.card { padding-top: 16px; padding-bottom: 12px; }

@media (min-width: 960px) {
  .dice-panel { min-height: 560px; }
}

.dice-panel.glow-you {
  border-color: rgba(138, 124, 255, 0.3);
  box-shadow: var(--shadow-soft), 0 0 20px rgba(138, 124, 255, 0.12);
}

.dice-panel.glow-bot {
  border-color: rgba(255, 255, 255, 0.08);
}

.dice-panel.glow-p2 {
  border-color: rgba(255, 122, 168, 0.3);
  box-shadow: var(--shadow-soft), 0 0 20px rgba(255, 122, 168, 0.12);
}

.dice-header {
  text-align: center;
  margin-bottom: 4px;
}

.dice-header .controls {
  margin-top: 8px;
  margin-bottom: 8px;
  display: flex;
  justify-content: center;
}

/* Roll button */
#roll-btn {
  padding: 0.55rem 2rem;
  font-size: 0.88rem;
  font-weight: 600;
  text-align: center;
  display: inline-flex;
  justify-content: center;
  margin: 0 auto;
  transition: transform 0.14s ease, box-shadow 0.14s ease, background 0.14s ease;
}

/* Dice area: positioning context for felt + shelf + dice */
.dice-area {
  position: relative;
  margin-top: 4px;
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: visible;
}

/* Casino felt table */
.felt {
  position: relative;
  border-radius: var(--radius-lg);
  min-height: 280px;
  flex: 1;
  background:
    radial-gradient(ellipse 120% 80% at 50% 40%, rgba(40, 140, 70, 0.25), transparent 70%),
    linear-gradient(160deg, #1a6b3a, #145a2e 40%, #0f4a24 100%);
  border: 5px solid #1a3d28;
  box-shadow:
    inset 0 2px 12px rgba(0, 0, 0, 0.5),
    inset 0 0 40px rgba(0, 0, 0, 0.15),
    0 4px 20px rgba(0, 0, 0, 0.5);
}

/* Felt texture overlay */
.felt::before {
  content: "";
  position: absolute;
  inset: 0;
  background: url("data:image/svg+xml,%3Csvg width='6' height='6' xmlns='http://www.w3.org/2000/svg'%3E%3Crect width='1' height='1' fill='rgba(255,255,255,0.02)'/%3E%3C/svg%3E") repeat;
  border-radius: inherit;
  pointer-events: none;
}

/* Felt wear marks — subtle darker patches like a used casino table */
.felt::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  background:
    radial-gradient(ellipse 35% 25% at 30% 55%, rgba(0,0,0,0.12), transparent 70%),
    radial-gradient(ellipse 25% 30% at 70% 40%, rgba(0,0,0,0.09), transparent 65%),
    radial-gradient(ellipse 40% 20% at 50% 75%, rgba(0,0,0,0.08), transparent 60%),
    radial-gradient(ellipse 18% 22% at 20% 30%, rgba(0,0,0,0.06), transparent 55%),
    radial-gradient(ellipse 22% 18% at 80% 70%, rgba(0,0,0,0.07), transparent 55%),
    radial-gradient(ellipse 50% 50% at 50% 50%, rgba(0,0,0,0.04), transparent 80%);
}

/* Held-dice cabinet */
.shelf {
  display: flex;
  justify-content: center;
  gap: 10px;
  padding: 10px 18px;
  margin-top: 8px;
  background:
    linear-gradient(180deg, rgba(20, 15, 40, 0.7), rgba(10, 8, 25, 0.85));
  border: 1px solid rgba(138, 124, 255, 0.1);
  border-radius: 14px;
  min-height: 56px;
  align-items: center;
  flex-shrink: 0;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.04),
    inset 0 -2px 8px rgba(0, 0, 0, 0.3),
    0 2px 8px rgba(0, 0, 0, 0.3);
}

.shelf-slot {
  width: calc(var(--die-size, 62px) + 6px);
  height: calc(var(--die-size, 62px) + 6px);
  border-radius: 12px;
  border: 1.5px dashed rgba(138, 124, 255, 0.18);
  background: rgba(138, 124, 255, 0.03);
  flex-shrink: 0;
  transition: border-color 0.2s ease, background 0.2s ease;
}

.shelf-slot:hover {
  border-color: rgba(138, 124, 255, 0.3);
  background: rgba(138, 124, 255, 0.06);
}

/* Die container — absolutely positioned on the felt */
.die {
  --die-size: 62px;
  position: absolute;
  width: var(--die-size);
  height: var(--die-size);
  border: none;
  background: #d8d3c3;
  border-radius: 10px;
  cursor: pointer;
  z-index: 2;
  perspective: 260px;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  -webkit-tap-highlight-color: transparent;
  padding: 0;
}

/* Shadow on the felt beneath each die */
.die::before {
  content: '';
  position: absolute;
  inset: 4px;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.35);
  filter: blur(8px);
  transform: translate(2px, 4px);
  z-index: -1;
  pointer-events: none;
}

.die.tossing::before {
  /* Larger, softer shadow when dice are "in the air" */
  inset: 0;
  filter: blur(14px);
  transform: translate(4px, 8px);
  opacity: 0.5;
}

.die:active:not(.tossing) {
  transform: translate(-50%, -50%) scale(0.92);
}

/* 3D Cube */
.die-cube {
  width: 100%;
  height: 100%;
  position: relative;
  transform-style: preserve-3d;
}

/* Each face of the cube */
.die-face-el {
  position: absolute;
  width: 100%;
  height: 100%;
  border-radius: 10px;
  background: linear-gradient(145deg, #f8f8f0, #e4dfcf);
  backface-visibility: hidden;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  padding: 20%;
  /* No box-shadow — prevents white rays leaking through cube edges */
}

/* Face positions on the cube */
.face-1 { transform: translateZ(calc(var(--die-size) / 2)); }
.face-2 { transform: rotateX(-90deg) translateZ(calc(var(--die-size) / 2)); }
.face-3 { transform: rotateY(90deg) translateZ(calc(var(--die-size) / 2)); }
.face-4 { transform: rotateY(-90deg) translateZ(calc(var(--die-size) / 2)); }
.face-5 { transform: rotateX(90deg) translateZ(calc(var(--die-size) / 2)); }
.face-6 { transform: rotateY(180deg) translateZ(calc(var(--die-size) / 2)); }

/* Pip dots */
.pip {
  width: 100%;
  aspect-ratio: 1;
  max-width: 11px;
  max-height: 11px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #333, #111);
  align-self: center;
  justify-self: center;
  box-shadow: inset 0 1px 1px rgba(0,0,0,0.4);
}

/* Held dice: purple faces + lighter pips */
.die.held .die-face-el {
  background: linear-gradient(145deg, #c8bdff, #9a8cef);
}

/* Held die background matches held face color */
.die.held {
  background: #8a7cdd;
  filter: drop-shadow(0 0 10px rgba(138, 124, 255, 0.7));
}

.die.held .pip {
  background: radial-gradient(circle at 35% 35%, #3d2a7a, #1e1245);
}

@media (max-width: 480px) {
  .felt { min-height: 260px; }
  .die { --die-size: 48px; }
  .die-face-el { padding: 18%; border-radius: 8px; }
  .die { border-radius: 8px; }
  .pip { max-width: 8px; max-height: 8px; }
  .shelf { gap: 6px; padding: 8px 10px; min-height: 46px; }
  .shelf-slot { width: calc(var(--die-size, 48px) + 4px); height: calc(var(--die-size, 48px) + 4px); }
}

/* ============================================================
   3D DICE TOSS (JS-driven via Web Animations API)
   ============================================================ */

/* Tossing state: disable clicks while dice are mid-air */
.die.tossing {
  pointer-events: none;
}

/* Charging effects */
@keyframes roll-charge-pulse {
  0%   { box-shadow: 0 0 0 rgba(138, 124, 255, 0); transform: scale(1); }
  40%  { box-shadow: 0 0 18px rgba(138, 124, 255, 0.8), 0 0 40px rgba(138, 124, 255, 0.5); transform: scale(1.06); }
  100% { box-shadow: 0 0 0 rgba(138, 124, 255, 0); transform: scale(1); }
}

#roll-btn.charging {
  background: radial-gradient(circle at 30% 20%, #c3d0ff, var(--accent));
  animation: roll-charge-pulse 0.7s ease-in-out infinite;
  position: relative;
  overflow: hidden;
}

/* Charge fill bar inside roll button */
#roll-btn .charge-bar {
  position: absolute;
  left: 0;
  bottom: 0;
  height: 3px;
  background: linear-gradient(90deg, #fff, #ffd166, #ff6b6b);
  border-radius: 0 0 999px 999px;
  width: 0%;
  transition: width 0.05s linear;
  pointer-events: none;
}

.die.charging-die {
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s ease;
}

/* ============================================================
   SCORE PANEL
   ============================================================ */

.score-panel h2 {
  margin: 0 0 2px;
  font-size: 0.92rem;
  font-weight: 700;
}

.score-panel .score-header { margin-bottom: 6px; }


/* Player column headers */
.player-header th {
  font-size: 0.68rem;
  font-weight: 500;
  color: var(--muted);
  text-align: center;
  padding-bottom: 6px;
}

.player-header th:first-child { text-align: left; }

.player-col {
  min-width: 42px;
  transition: color 0.2s ease, text-shadow 0.2s ease;
}

.player-col.active-col {
  color: var(--accent);
  font-weight: 600;
  text-shadow: 0 0 10px rgba(138, 124, 255, 0.5);
}

/* Score table */
.score-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.74rem;
}

.score-table th,
.score-table td { padding: 4px 2px; }

.score-table th { text-align: left; font-weight: 500; }
.score-table td { text-align: center; width: 42px; }

.section-label th {
  padding-top: 8px;
  padding-bottom: 4px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-size: 0.65rem;
  border-bottom: 1px solid var(--line);
}

.category {
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
  cursor: pointer;
  transition: background 0.12s ease;
}

.category:hover { background: rgba(255, 255, 255, 0.06); }

/* Per-cell used styling (unified table — each player's cell dims independently) */
.score-cell.used-cell { opacity: 0.5; }
.score-cell.last-scored {
  opacity: 1;
  color: var(--accent);
  text-shadow: 0 0 8px rgba(138, 124, 255, 0.6);
  transition: color 0.3s ease, text-shadow 0.3s ease;
}

.subtotal td,
.subtotal th {
  border-top: 1px solid var(--line);
  padding-top: 5px;
  font-weight: 500;
  font-size: 0.68rem;
  color: var(--muted);
}

.grand-total td,
.grand-total th {
  border-top: 1px solid var(--line);
  padding-top: 6px;
  font-weight: 700;
  font-size: 0.8rem;
}

.score-cell { font-variant-numeric: tabular-nums; }

.score-cell.preview {
  color: var(--accent);
  text-shadow: 0 0 10px rgba(138, 124, 255, 0.8);
}

/* ============================================================
   BOT TURN INDICATOR
   ============================================================ */

#roll-btn:disabled {
  transition: none;
}

/* ============================================================
   UTIL
   ============================================================ */

.hidden { display: none !important; }

/* ============================================================
   WINNER OVERLAY
   ============================================================ */

.winner-overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(3, 4, 10, 0.88);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  z-index: 999;
}

.winner-overlay.hidden { display: none !important; }

.winner-modal {
  background: linear-gradient(160deg, #141826, #101321);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius-lg);
  padding: 32px 32px 28px;
  max-width: 380px;
  width: calc(100% - 40px);
  text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.7);
}

.winner-trophy {
  font-size: 42px;
  margin-bottom: 10px;
  line-height: 1;
}

.winner-modal h2 {
  margin: 0 0 6px;
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: 0.06em;
}

.winner-score {
  font-size: 2.4rem;
  font-weight: 800;
  color: var(--accent);
  margin: 12px 0 4px;
  line-height: 1;
  text-shadow: 0 0 20px rgba(138, 124, 255, 0.5);
}

.winner-text {
  margin: 0 0 4px;
  font-size: 0.85rem;
  color: var(--text);
}

.winner-details {
  margin: 0 0 20px;
  font-size: 0.78rem;
  color: var(--muted);
  line-height: 1.5;
}

#winner-close {
  width: 100%;
  justify-content: center;
}

/* ============================================================
   STATS OVERLAY
   ============================================================ */

.stats-overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(3, 4, 10, 0.88);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  z-index: 998;
}

.stats-overlay.hidden { display: none !important; }

.stats-modal {
  background: linear-gradient(160deg, #141826, #101321);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius-lg);
  padding: 28px 28px 24px;
  max-width: 380px;
  width: calc(100% - 40px);
  text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.7);
}

.stats-modal h2 {
  margin: 0 0 16px;
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: 0.06em;
}

.stats-body {
  text-align: left;
  font-size: 0.78rem;
  line-height: 1.8;
  color: var(--text);
}

.stats-body .stat-row {
  display: flex;
  justify-content: space-between;
  border-bottom: 1px solid rgba(255,255,255,0.04);
  padding: 4px 0;
}

.stats-body .stat-label { color: var(--muted); }
.stats-body .stat-value { font-weight: 600; font-variant-numeric: tabular-nums; }

.stats-body .stat-section {
  margin-top: 12px;
  padding-top: 8px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-size: 0.65rem;
  font-weight: 600;
  margin-bottom: 4px;
}

#stats-close {
  width: 100%;
  justify-content: center;
  margin-top: 18px;
}

#stats-reset {
  width: 100%;
  justify-content: center;
}
