/* Yahtzee — paper-and-ink dice game */

.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}
.page-head h1 {
  font-family: 'Fraunces', Georgia, serif;
  font-weight: 700;
  font-size: clamp(28px, 4.4vw, 40px);
  letter-spacing: -0.02em;
  margin: 0;
  line-height: 1.05;
}
.page-head .sub {
  color: var(--ink-soft);
  margin: 6px 0 0;
  font-size: 14px;
  min-height: 1.4em;
}
.head-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.player-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 6px 10px;
  font: 600 13px 'Inter', sans-serif;
  color: var(--ink-soft);
}
.player-toggle select {
  appearance: none;
  border: none;
  background: transparent;
  font: 600 14px 'Inter', sans-serif;
  color: var(--ink);
  padding: 4px 18px 4px 4px;
  cursor: pointer;
  background-image: linear-gradient(45deg, transparent 50%, var(--ink-soft) 50%),
                    linear-gradient(135deg, var(--ink-soft) 50%, transparent 50%);
  background-position: calc(100% - 9px) 55%, calc(100% - 5px) 55%;
  background-size: 4px 4px;
  background-repeat: no-repeat;
}
.player-toggle select:focus { outline: 2px solid var(--accent-soft); border-radius: 4px; }

.play {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
}

.board {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) minmax(280px, 1.1fr);
  gap: 22px;
  align-items: start;
}
@media (max-width: 820px) {
  .board { grid-template-columns: 1fr; }
}

/* Dice zone --------------------------------------------------- */
.dice-zone {
  background: linear-gradient(180deg, #fdf8eb 0%, #f6ecd1 100%);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 20px 18px;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.7);
}
.dice-row {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 10px;
  margin-bottom: 18px;
}
@media (max-width: 420px) {
  .dice-row { gap: 7px; }
}

.die {
  appearance: none;
  border: 2px solid var(--line-strong);
  background: #fbf6ea;
  border-radius: 14px;
  aspect-ratio: 1 / 1;
  padding: 12%;
  cursor: pointer;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  grid-template-rows: 1fr 1fr 1fr;
  gap: 4%;
  box-shadow: 0 2px 0 rgba(31,58,95,0.18), 0 6px 14px -8px rgba(31,58,95,0.4);
  transition: transform 160ms ease, background 160ms ease, border-color 160ms ease, box-shadow 160ms ease;
  position: relative;
}
.die:disabled { cursor: default; }
.die:not(:disabled):hover { transform: translateY(-2px); }
.die.is-held {
  background: var(--accent-soft);
  border-color: var(--accent);
  box-shadow: 0 2px 0 rgba(31,58,95,0.28), 0 8px 18px -6px rgba(31,58,95,0.45);
}
.die.is-held::after {
  content: 'HELD';
  position: absolute;
  bottom: -9px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--accent);
  color: var(--paper);
  font: 700 9px 'Inter', sans-serif;
  letter-spacing: 0.14em;
  padding: 2px 7px;
  border-radius: 999px;
}
.die.is-fresh { animation: dieDrop 220ms ease; }
.die.is-rolling { animation: dieShake 90ms linear infinite; }

@keyframes dieDrop {
  0%   { transform: translateY(-10px) rotate(-6deg); opacity: 0.4; }
  60%  { transform: translateY(2px) rotate(2deg); opacity: 1; }
  100% { transform: translateY(0) rotate(0); }
}
@keyframes dieShake {
  0%   { transform: translate(0,0) rotate(0); }
  25%  { transform: translate(-2px, 1px) rotate(-4deg); }
  50%  { transform: translate(2px, -1px) rotate(3deg); }
  75%  { transform: translate(-1px, -2px) rotate(-2deg); }
  100% { transform: translate(0,0) rotate(0); }
}

/* Pips — placed via grid cells */
.pip {
  background: var(--ink);
  border-radius: 50%;
  width: 100%;
  height: 100%;
  align-self: center;
  justify-self: center;
  box-shadow: inset 0 -1px 1px rgba(255,255,255,0.2);
}
.die .pip { display: none; } /* default — face classes reveal */

/* Grid positions:
   row 1: pos 1 (tl) 2 (tm) 3 (tr)
   row 2: pos 4 (ml) 5 (mm) 6 (mr)
   row 3: pos 7 (bl) 8 (bm) 9 (br) */
.die .pip.tl { grid-column: 1; grid-row: 1; }
.die .pip.tm { grid-column: 2; grid-row: 1; }
.die .pip.tr { grid-column: 3; grid-row: 1; }
.die .pip.ml { grid-column: 1; grid-row: 2; }
.die .pip.mm { grid-column: 2; grid-row: 2; }
.die .pip.mr { grid-column: 3; grid-row: 2; }
.die .pip.bl { grid-column: 1; grid-row: 3; }
.die .pip.bm { grid-column: 2; grid-row: 3; }
.die .pip.br { grid-column: 3; grid-row: 3; }

.die.face-1 .pip.mm,
.die.face-2 .pip.tl, .die.face-2 .pip.br,
.die.face-3 .pip.tl, .die.face-3 .pip.mm, .die.face-3 .pip.br,
.die.face-4 .pip.tl, .die.face-4 .pip.tr, .die.face-4 .pip.bl, .die.face-4 .pip.br,
.die.face-5 .pip.tl, .die.face-5 .pip.tr, .die.face-5 .pip.mm, .die.face-5 .pip.bl, .die.face-5 .pip.br,
.die.face-6 .pip.tl, .die.face-6 .pip.tr, .die.face-6 .pip.ml, .die.face-6 .pip.mr, .die.face-6 .pip.bl, .die.face-6 .pip.br {
  display: block;
}

.roll-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.roll-bar #btnRoll { min-width: 130px; }
.roll-bar #btnRoll:disabled {
  background: var(--bg-2);
  color: var(--muted);
  border-color: var(--line);
  cursor: not-allowed;
}
.rolls-left {
  font: 700 13px 'Inter', sans-serif;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 12px;
}
.hint {
  color: var(--muted);
  font-size: 12px;
  flex: 1 1 auto;
  min-width: 140px;
}

/* Scorecard --------------------------------------------------- */
.scorecard {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
}
.score-table {
  width: 100%;
  border-collapse: collapse;
  font: 500 13px 'Inter', sans-serif;
}
.score-table th, .score-table td {
  padding: 8px 12px;
  text-align: left;
  border-bottom: 1px solid var(--line);
}
.score-table thead th {
  background: var(--accent);
  color: var(--paper);
  font: 700 12px 'Inter', sans-serif;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  border-bottom: none;
}
.score-table th.p, .score-table td.p {
  text-align: center;
  width: 22%;
  font-variant-numeric: tabular-nums;
}
.score-table tr.section-head td {
  background: var(--bg-2);
  font: 700 11px 'Inter', sans-serif;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-soft);
  padding: 5px 12px;
}
.score-table tr.subtotal td,
.score-table tfoot td {
  background: #f7eed6;
  font-weight: 700;
}
.score-table tfoot td.total {
  font-family: 'Fraunces', Georgia, serif;
  font-weight: 800;
  font-size: 18px;
}

.score-cell {
  cursor: default;
  user-select: none;
  font-variant-numeric: tabular-nums;
  position: relative;
  min-width: 48px;
}
.score-cell.is-empty.is-active {
  cursor: pointer;
  color: var(--muted);
}
.score-cell.is-empty.is-active:hover {
  background: var(--accent-soft);
  color: var(--ink);
}
.score-cell.is-empty.is-active.preview {
  color: #a59572;
  font-style: italic;
}
.score-cell.is-empty.is-active.preview:hover { font-style: normal; color: var(--ink); }
.score-cell.is-filled {
  color: var(--ink);
  font-weight: 700;
}
/* Just-scored — quick flash on the newly scored cell */
@keyframes yz-score-in {
  0%   { background: rgba(213, 192, 125, 0.7); transform: scale(1); }
  50%  { background: rgba(213, 192, 125, 0.4); transform: scale(1.06); }
  100% { background: transparent; transform: scale(1); }
}
.score-cell.just-scored {
  animation: yz-score-in 700ms ease-out;
}

/* Total-row bump when total updates */
@keyframes yz-total-bump {
  0%   { transform: scale(1); }
  40%  { transform: scale(1.1); color: var(--accent); }
  100% { transform: scale(1); }
}
.grand-total.is-bumped {
  animation: yz-total-bump 380ms cubic-bezier(0.34, 1.56, 0.64, 1);
  display: inline-block;
}

@media (prefers-reduced-motion: reduce) {
  .score-cell.just-scored, .grand-total.is-bumped { animation: none; }
}
.score-cell.is-zero { color: var(--muted); }
.score-cell.is-turn { background: rgba(244, 227, 178, 0.45); }

.score-table tr.turn-row td.cat { font-weight: 700; }

/* Win overlay ------------------------------------------------- */
.win-overlay {
  position: fixed; inset: 0; background: rgba(28, 42, 58, 0.55);
  display: flex; align-items: center; justify-content: center; z-index: 50; padding: 20px;
}
.win-overlay[hidden] { display: none; }
.win-card {
  background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 28px 30px; text-align: center; box-shadow: var(--shadow-lift); max-width: 380px; width: 100%;
}
.win-card h2 {
  font-family: 'Fraunces', Georgia, serif;
  margin: 0 0 6px;
  font-size: 28px;
  letter-spacing: -0.02em;
}
.win-sub { color: var(--ink-soft); margin: 0 0 16px; font-size: 14px; }
.win-scores {
  display: flex; flex-direction: column; gap: 6px; margin-bottom: 18px;
  font-variant-numeric: tabular-nums;
}
.win-scores .row {
  display: flex; justify-content: space-between; align-items: baseline;
  padding: 8px 14px;
  background: var(--bg-2);
  border-radius: 8px;
}
.win-scores .row.winner {
  background: var(--accent-soft);
  border: 1px solid var(--accent);
}
.win-scores .row .label { font-weight: 600; }
.win-scores .row .value {
  font-family: 'Fraunces', Georgia, serif;
  font-weight: 700;
  font-size: 20px;
}
.win-actions { display: flex; justify-content: center; }

/* Aside info --------------------------------------------------- */
.aside-info { margin-top: 22px; }
.aside-info details {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 16px;
  box-shadow: var(--shadow);
}
.aside-info summary {
  cursor: pointer;
  font: 700 14px 'Inter', sans-serif;
  color: var(--ink);
}
.aside-info .help-body {
  margin-top: 10px;
  color: var(--ink-soft);
  font-size: 14px;
  line-height: 1.55;
}
.aside-info .help-body p { margin: 0 0 8px; }
.aside-info .help-body ul { margin: 0; padding-left: 18px; }
.aside-info .help-body li { margin: 4px 0; }
