/* ── Design tokens ─────────────────────────────────────────────────────────── */
:root {
  --bg:          #0F172A;
  --surface:     #1E293B;
  --surface-2:   #263448;
  --text:        #F8FAFC;
  --text-muted:  #94A3B8;
  --text-subtle: #64748B;
  --accent:      #6366F1;
  --accent-soft: rgba(99, 102, 241, 0.18);
  --accent-mid:  rgba(99, 102, 241, 0.35);
  --gold:        #F59E0B;
  --held-bg:     #EEF2FF;
  --held-border: #6366F1;
  --dice-face:   #FFFFFF;
  --dice-pip:    #1E293B;
  --font:        'Outfit', system-ui, sans-serif;
  --radius:      16px;
  --radius-sm:   10px;
  --shadow:      0 10px 25px -5px rgba(0, 0, 0, 0.4);
  --tray-gap:    10px;
}

/* ── Reset ─────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

html {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

body {
  height: 100dvh;
  display: flex;
  justify-content: center;
}

/* ── Shell ─────────────────────────────────────────────────────────────────── */
.app {
  width: 100%;
  max-width: 480px;
  height: 100%;
  display: flex;
  flex-direction: column;
  padding: 16px;
}

.app-header {
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid rgba(255,255,255,0.05);
}

.logo {
  font-size: 20px;
  font-weight: 800;
  letter-spacing: -0.5px;
  background: linear-gradient(135deg, #FFF, var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.header-actions {
  display: flex;
  gap: 8px;
}

.btn-icon {
  background: transparent;
  border: none;
  font-size: 22px;
  cursor: pointer;
  padding: 4px;
  filter: grayscale(1);
  opacity: 0.7;
  transition: 0.2s;
}

.btn-icon:hover {
  filter: grayscale(0);
  opacity: 1;
}

/* ── Screens ────────────────────────────────────────────────────────────────── */
.game-screen, .result-screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-top: 24px;
  gap: 0;
}

.date-display {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 2.5px;
  color: var(--text-subtle);
  margin-bottom: 16px;
  font-weight: 600;
}

/* ── Hold Tray Section ──────────────────────────────────────────────────────── */
.hold-section {
  width: 100%;
  margin-bottom: 20px;
}

.hold-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
  padding: 0 2px;
}

.hold-section-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 2px;
  color: var(--text-subtle);
}

.hold-hint {
  font-size: 11px;
  font-weight: 600;
  color: var(--accent);
  display: flex;
  align-items: center;
  gap: 5px;
  opacity: 0;
  transform: translateY(2px);
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.hold-hint.visible {
  opacity: 1;
  transform: translateY(0);
}

.hold-hint::before {
  content: '👆';
  font-size: 13px;
}

/* ── Hold Tray ──────────────────────────────────────────────────────────────── */
.hold-tray {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: var(--tray-gap);
  width: 100%;
}

.tray-slot {
  aspect-ratio: 1;
  background: rgba(255,255,255,0.03);
  border: 1.5px dashed rgba(255,255,255,0.12);
  border-radius: var(--radius-sm);
  cursor: pointer;
  position: relative;
  transition: transform 0.2s cubic-bezier(.2,.8,.3,1.2), box-shadow 0.2s ease, border-color 0.2s ease, background 0.2s ease;
  background-size: 100% 100%;
  background-repeat: no-repeat;
  -webkit-tap-highlight-color: transparent;
}

.tray-slot:not(.has-value):hover {
  border-color: rgba(255,255,255,0.2);
  background: rgba(255,255,255,0.05);
}

.tray-slot.has-value {
  background-color: white;
  border: 1.5px solid rgba(203, 213, 225, 0.6);
  box-shadow: 0 2px 0 #B0BEC5, 0 4px 10px rgba(0,0,0,0.2);
}

.tray-slot.has-value:hover {
  transform: translateY(-1px);
  box-shadow: 0 3px 0 #B0BEC5, 0 6px 14px rgba(0,0,0,0.25);
}

/* ── HELD STATE: clearly selected ─────────────────────────────────────────── */
.tray-slot.held {
  border: 2px solid var(--accent);
  background-color: var(--held-bg);
  box-shadow:
    0 0 0 3px var(--accent-soft),
    0 2px 0 #5557CC,
    0 6px 16px rgba(99, 102, 241, 0.25);
  transform: scale(1.06) translateY(-3px);
  animation: holdPulse 2s ease-in-out infinite;
}

@keyframes holdPulse {
  0%, 100% {
    box-shadow:
      0 0 0 3px rgba(99,102,241,0.15),
      0 2px 0 #5557CC,
      0 6px 16px rgba(99,102,241,0.2);
  }
  50% {
    box-shadow:
      0 0 0 5px rgba(99,102,241,0.25),
      0 2px 0 #5557CC,
      0 8px 22px rgba(99,102,241,0.35);
  }
}

/* Stats modal — rich content, allow scroll if needed */
.stats-modal-content {
  max-height: 88vh;
  overflow-y: auto;
}

.stats-modal-content .modal-header h2 {
  font-size: 20px;
  letter-spacing: 0;
  font-weight: 800;
  color: var(--text);
}

/* ── Stats Modal ─────────────────────────────────────────────────────────────────── */

/* HELD badge — pill on top of the die slot */
.tray-slot.held::before {
  content: '🔒 SEGURO';
  position: absolute;
  top: -22px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--accent);
  color: white;
  font-size: 8px;
  font-weight: 800;
  font-family: var(--font);
  letter-spacing: 0.08em;
  padding: 2px 6px;
  border-radius: 100px;
  white-space: nowrap;
  pointer-events: none;
  z-index: 10;
  animation: badgePop 0.2s cubic-bezier(.2,.8,.3,1.5) both;
}

@keyframes badgePop {
  from { transform: translateX(-50%) scale(0.5); opacity: 0; }
  to   { transform: translateX(-50%) scale(1); opacity: 1; }
}

/* Pips in tray slots */
.tray-slot[data-value="1"] { background-image: radial-gradient(circle at 50% 50%, var(--dice-pip) 14%, transparent 15%); }
.tray-slot[data-value="2"] { background-image: radial-gradient(circle at 28% 28%, var(--dice-pip) 14%, transparent 15%), radial-gradient(circle at 72% 72%, var(--dice-pip) 14%, transparent 15%); }
.tray-slot[data-value="3"] { background-image: radial-gradient(circle at 28% 28%, var(--dice-pip) 14%, transparent 15%), radial-gradient(circle at 50% 50%, var(--dice-pip) 14%, transparent 15%), radial-gradient(circle at 72% 72%, var(--dice-pip) 14%, transparent 15%); }
.tray-slot[data-value="4"] { background-image: radial-gradient(circle at 28% 28%, var(--dice-pip) 14%, transparent 15%), radial-gradient(circle at 72% 28%, var(--dice-pip) 14%, transparent 15%), radial-gradient(circle at 28% 72%, var(--dice-pip) 14%, transparent 15%), radial-gradient(circle at 72% 72%, var(--dice-pip) 14%, transparent 15%); }
.tray-slot[data-value="5"] { background-image: radial-gradient(circle at 28% 28%, var(--dice-pip) 14%, transparent 15%), radial-gradient(circle at 72% 28%, var(--dice-pip) 14%, transparent 15%), radial-gradient(circle at 28% 72%, var(--dice-pip) 14%, transparent 15%), radial-gradient(circle at 72% 72%, var(--dice-pip) 14%, transparent 15%), radial-gradient(circle at 50% 50%, var(--dice-pip) 14%, transparent 15%); }
.tray-slot[data-value="6"] { background-image: radial-gradient(circle at 28% 28%, var(--dice-pip) 14%, transparent 15%), radial-gradient(circle at 72% 28%, var(--dice-pip) 14%, transparent 15%), radial-gradient(circle at 28% 50%, var(--dice-pip) 14%, transparent 15%), radial-gradient(circle at 72% 50%, var(--dice-pip) 14%, transparent 15%), radial-gradient(circle at 28% 72%, var(--dice-pip) 14%, transparent 15%), radial-gradient(circle at 72% 72%, var(--dice-pip) 14%, transparent 15%); }

/* ── Status ─────────────────────────────────────────────────────────────────── */
.game-status {
  text-align: center;
  margin-bottom: 24px;
  padding: 16px 20px;
  background: rgba(255,255,255,0.03);
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: var(--radius);
  width: 100%;
}

.hand-name {
  font-size: clamp(20px, 6vw, 28px);
  font-weight: 800;
  margin-bottom: 4px;
  letter-spacing: -0.5px;
}

.rolls-left {
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 500;
}

/* ── Actions ────────────────────────────────────────────────────────────────── */
.game-actions {
  width: 100%;
  margin-top: auto;
  padding-bottom: env(safe-area-inset-bottom, 24px);
  padding-bottom: max(env(safe-area-inset-bottom, 0px), 24px);
}

.btn {
  width: 100%;
  height: 54px;
  border: none;
  border-radius: var(--radius);
  font-family: inherit;
  font-size: clamp(15px, 4vw, 18px);
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.2s ease, filter 0.2s ease, box-shadow 0.2s ease;
  letter-spacing: 0.05em;
}

.btn-roll {
  background: linear-gradient(135deg, #6366F1, #818CF8);
  color: white;
  box-shadow: 0 4px 20px rgba(99,102,241,0.4), 0 1px 0 rgba(255,255,255,0.1) inset;
}

.btn-roll:hover:not([disabled]) {
  transform: translateY(-2px);
  box-shadow: 0 8px 28px rgba(99,102,241,0.5);
}

.btn-roll:active:not([disabled]) {
  transform: translateY(0);
  box-shadow: 0 2px 10px rgba(99,102,241,0.3);
}

.btn-roll[disabled] {
  opacity: 0.45;
  cursor: not-allowed;
}

/* ── Result Card ────────────────────────────────────────────────────────────── */
.result-card {
  background: var(--surface);
  width: 100%;
  border-radius: 24px;
  padding: 32px;
  text-align: center;
  box-shadow: var(--shadow);
  margin-bottom: 40px;
}

.result-header {
  font-size: 14px;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 16px;
}

.final-hand {
  font-size: 32px;
  font-weight: 800;
  color: var(--gold);
  margin-bottom: 8px;
}

.final-score {
  font-size: 64px;
  font-weight: 800;
  line-height: 1;
}

.result-label {
  color: var(--text-muted);
  margin-top: 4px;
}

.next-game {
  width: 100%;
  text-align: center;
  margin-top: auto;
  padding-bottom: 40px;
}

.countdown {
  font-size: 14px;
  color: var(--text-muted);
  margin-bottom: 16px;
}

.btn-share {
  background: #22C55E;
  color: white;
}

/* ── Modals ────────────────────────────────────────────────────────────────── */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(10px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: modalFadeIn 0.25s ease-out;
}

@keyframes modalFadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.modal-content {
  background: linear-gradient(145deg, #1E293B, #0F172A);
  width: 100%;
  max-width: 380px;
  border-radius: 24px;
  padding: 20px;
  border: 1px solid rgba(255,255,255,0.08);
  box-shadow: 0 25px 60px rgba(0,0,0,0.6);
  animation: modalSlideUp 0.3s ease-out;
  /* no scroll — content must fit */
  overflow: visible;
}

@keyframes modalSlideUp {
  from { transform: translateY(30px); opacity: 0; }
  to   { transform: translateY(0); opacity: 1; }
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}

.modal-header h2 {
  font-size: 18px;
  letter-spacing: 0.15em;
  color: var(--accent);
}

.btn-close {
  background: rgba(255,255,255,0.05);
  border: none;
  color: var(--text-muted);
  font-size: 24px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: 0.2s;
}

.btn-close:hover {
  background: rgba(255,255,255,0.1);
  color: var(--text);
}

/* ── Help Modal ─────────────────────────────────────────────────────────────── */

/* Override header h2 for help modal — friendlier, less uppercase */
.help-modal-content .modal-header h2 {
  font-size: 20px;
  letter-spacing: 0;
  font-weight: 800;
  color: var(--text);
}

.help-title {
  display: flex;
  align-items: center;
  gap: 10px;
}

.help-title-icon {
  font-size: 26px;
  line-height: 1;
}

.help-body {
  display: flex;
  flex-direction: column;
  gap: 0;
}

/* ── Steps ──────────────────────────────────────────────────────────────────── */
.help-steps {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
}

.help-step {
  display: flex;
  align-items: center;
  gap: 12px;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: 12px;
  padding: 10px 14px;
}

.step-num {
  flex-shrink: 0;
  width: 26px;
  height: 26px;
  background: var(--accent);
  color: white;
  font-size: 13px;
  font-weight: 800;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 6px rgba(99,102,241,0.4);
}

.step-text {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.step-text strong {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
}

.step-text span {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.3;
}

.step-text em {
  font-style: italic;
  color: var(--accent);
}

/* ── Divider ────────────────────────────────────────────────────────────────── */
.help-divider {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

.help-divider::before,
.help-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: rgba(255,255,255,0.08);
}

.help-divider span {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 2px;
  color: var(--text-subtle);
  white-space: nowrap;
}

/* ── Score rows ─────────────────────────────────────────────────────────────── */
.help-scores {
  display: flex;
  flex-direction: column;
  gap: 0;
  margin-bottom: 0;
}

.help-score-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-radius: 8px;
  transition: background 0.15s;
}

.help-score-row:hover {
  background: rgba(255,255,255,0.04);
}

.help-score-row.gold .hs-pts {
  background: rgba(245,158,11,0.15);
  color: var(--gold);
}

.hs-icon {
  font-size: 15px;
  flex-shrink: 0;
  width: 20px;
  text-align: center;
}

.hs-name {
  flex: 1;
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
}

.hs-name em {
  font-style: normal;
  font-weight: 400;
  color: var(--text-muted);
  font-size: 12px;
}

.hs-pts {
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
  padding: 2px 8px;
  border-radius: 100px;
  flex-shrink: 0;
  min-width: 30px;
  text-align: center;
}

.btn-modal-close {
  margin-top: 14px;
}


/* ── Stats Modal ────────────────────────────────────────────────────────────── */
.stats-body {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* Big 3 numbers on top */
.stats-top {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.stat-big {
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: 14px;
  padding: 14px 8px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.stat-big-val {
  font-size: 26px;
  font-weight: 800;
  line-height: 1;
  color: var(--text);
}

.stat-big-lbl {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-subtle);
  font-weight: 600;
}

.stat-big.accent .stat-big-val { color: var(--accent); }
.stat-big.gold   .stat-big-val { color: var(--gold); }

/* Sections with label */
.stats-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.stats-section-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 2px;
  color: var(--text-subtle);
}

/* Sparkline */
.spark-wrap {
  background: rgba(255,255,255,0.03);
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: 12px;
  padding: 12px 14px;
  min-height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.spark-svg {
  width: 100%;
  height: 36px;
  display: block;
  overflow: visible;
}

.spark-empty {
  font-size: 12px;
  color: var(--text-subtle);
  text-align: center;
}

/* Secondary meta row */
.stats-meta {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.stat-meta-item {
  background: rgba(255,255,255,0.03);
  border-radius: 10px;
  padding: 10px 6px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.stat-meta-val {
  font-size: 18px;
  font-weight: 800;
  color: var(--text);
  line-height: 1;
}

.stat-meta-lbl {
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-subtle);
}

/* Hand distribution */
.hand-dist {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.hand-dist-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.hand-dist-icon {
  font-size: 14px;
  flex-shrink: 0;
  width: 18px;
  text-align: center;
}

.hand-dist-name {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  min-width: 80px;
  flex-shrink: 0;
}

.hand-dist-bar-wrap {
  flex: 1;
  background: rgba(255,255,255,0.06);
  border-radius: 100px;
  height: 6px;
  overflow: hidden;
}

.hand-dist-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), #818CF8);
  border-radius: 100px;
  transition: width 0.6s ease;
  min-width: 4px;
}

.hand-dist-count {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  min-width: 18px;
  text-align: right;
}


/* ── Toast ──────────────────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 100px;
  left: 50%;
  transform: translateX(-50%);
  background: white;
  color: black;
  padding: 12px 24px;
  border-radius: 100px;
  font-weight: 600;
  font-size: 14px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.5);
  z-index: 2000;
  animation: toastIn 0.3s ease-out;
}

@keyframes toastIn {
  from { transform: translateX(-50%) translateY(20px); opacity: 0; }
  to   { transform: translateX(-50%) translateY(0); opacity: 1; }
}

/* ── Responsive — Mobile first ──────────────────────────────────────────────── */

/*
  Mobile layout: hold-section moves to the bottom, just above the roll button.
  game-screen is flex-column; use CSS order to reflow without touching the HTML.
  Default (desktop) order: table(0) → hold-section(0) → game-status(0) → game-actions(auto)
  Mobile order:            table(1) → game-status(2) → hold-section(3) → game-actions(4)
*/
@media (max-width: 480px) {
  .game-screen {
    padding-top: 16px;
  }

  /* Reorder: table → status → [flex space] → hold-section → button */
  .dice-table   { order: 1; }
  .game-status  { order: 2; margin-bottom: 0; }

  /* hold-section absorbs remaining space and anchors itself + button to the bottom */
  .hold-section {
    order: 3;
    margin-top: auto;   /* ← key: pushes this + everything below to bottom */
    margin-bottom: 10px;
  }

  /* button follows hold-section naturally — no auto margin needed */
  .game-actions {
    order: 4;
    margin-top: 0;
  }
}

/* Very small phones: tighten spacing */
@media (max-width: 360px) {
  .app {
    padding: 10px 12px;
  }
  .game-screen {
    padding-top: 10px;
  }
  .hold-section-label {
    font-size: 10px;
  }
  .tray-slot.held::before {
    font-size: 7px;
    top: -20px;
  }
  .game-status {
    padding: 10px 12px;
  }
  .hand-name {
    font-size: 18px;
  }
}

/* Tablets / larger screens: desktop order (no reflow needed, just more room) */
@media (min-width: 481px) {
  .app {
    max-width: 520px;
    padding: 20px 24px;
  }
  .game-screen {
    padding-top: 32px;
  }
  .hold-section {
    margin-bottom: 24px;
  }
  .tray-slot.held::before {
    font-size: 9px;
    top: -24px;
    padding: 3px 8px;
  }
  .game-status {
    margin-bottom: 28px;
  }
}

/* Desktop */
@media (min-width: 768px) {
  .app {
    max-width: 560px;
  }
  .hold-section {
    margin-bottom: 28px;
  }
  .btn {
    height: 58px;
  }
}
