:root {
  --bg:           #F2F4F7; /* Neutral light grey-blue */
  --surface:      #ffffff;
  --surface-alt:  #F8F9FB;

  --accent:       #4f7ef7; /* Solid Blue */
  --accent-dark:  #3A5BB2;
  --blue:         #B5E3FF;
  --blue-dark:    #80CFFF;
  --green:        #B2F0C1;
  --green-dark:   #88E09E;
  --yellow:       #FFEA7D;
  --yellow-dark:  #EBCB4D;
  --purple:       #E0D6FF;
  --purple-dark:  #B9A6FF;
  --orange:       #FFD1A9;

  --text-dark:    #2D3748;
  --text-mid:     #4A5568;
  --text-muted:   #A0AEC0;
  --text-white:   #ffffff;

  --border:       #E2E8F0;
  --stroke:       #4A5568;

  --radius-sm:    10px;
  --radius-md:    16px;
  --radius-lg:    22px;
  --radius-xl:    28px;
  --radius-full:  999px;

  --transition:   0.15s ease;
  --font:         'Nunito', sans-serif;
}

/* ── Reset ─────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  min-height: 100vh;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text-dark);
  -webkit-font-smoothing: antialiased;
}


/* ── App Shell ─────────────────────────────────────────────── */
#app {
  min-height: 100vh;
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 20px 20px;
  display: flex;
  flex-direction: column;
}

#sticky-top {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--bg);
  padding-top: 24px;
  padding-bottom: 20px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

#dice-tray {
  display: flex;
  justify-content: center;
  gap: 16px;
  margin: 30px 0;
  flex-wrap: wrap;
  perspective: 1000px;
}

.die.rolling-a { animation: roll-bounce 0.22s ease-out; }
.die.rolling-b { animation: roll-bounce-low 0.26s ease-out; }
.die.rolling-c { animation: roll-bounce-high 0.3s ease-out; }

@keyframes rollBounceA {
  0%, 100% { transform: translateY(0); }
  25%      { transform: translateY(-20px); }
  50%      { transform: translateY(0); }
  75%      { transform: translateY(-8px); }
}
@keyframes rollBounceB {
  0%, 100% { transform: translateY(0); }
  35%      { transform: translateY(-30px); }
  65%      { transform: translateY(0); }
  85%      { transform: translateY(-12px); }
}
@keyframes rollBounceC {
  0%, 100% { transform: translateY(0); }
  20%      { transform: translateY(-15px); }
  45%      { transform: translateY(0); }
  75%      { transform: translateY(-6px); }
}

/* ── Buttons ────────────────────────────────────────────────── */
#header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-shrink: 0;
}

#header h1 {
  font-size: 2.2rem;
  font-weight: 900;
  color: var(--accent);
  letter-spacing: -0.03em;
  display: flex;
  align-items: center;
  gap: 10px;
}
#header h1::before {
  content: '🎲';
  font-size: 2.2rem;
}

#header-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

#score-bubble {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--accent);
  border-radius: var(--radius-full);
  padding: 6px 6px 6px 20px;
}
#score-bubble .label {
  font-size: 0.8rem;
  font-weight: 800;
  color: #fff;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
#score-bubble .value {
  font-size: 1.1rem;
  font-weight: 900;
  color: var(--accent-dark);
  background: #fff;
  border-radius: var(--radius-full);
  min-width: 56px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}


/* ── Game Area ─────────────────────────────────────────────── */
#game-area {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Scorecard area - side by side on desktop */
#scorecard-area {
  display: flex;
  flex-direction: row;
  gap: 20px;
  align-items: stretch;
}

/* ── Score Column Cards ─────────────────────────────────────── */
.score-col-card {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.score-col-card.card {
  height: 100%;
}

/* ── Card base ─────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border-radius: var(--radius-xl);
  border: 4px solid var(--border);
  padding: 24px 30px;
}

.card-title {
  font-size: 0.85rem;
  font-weight: 800;
  color: var(--text-mid);
  text-transform: uppercase;
  letter-spacing: 0.15em;
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.card-title::before {
  content: '';
  display: inline-block;
  width: 12px;
  height: 12px;
  background: var(--pink);
  border-radius: 3px;
}

/* ── Dice Panel ────────────────────────────────────────────── */
#dice-card { 
  order: 0; 
}

#dice-tray {
  display: flex;
  justify-content: center;
  gap: 14px;
  flex-wrap: nowrap;
  margin-bottom: 26px;
  padding: 4px 0;
}

/* ── Die ───────────────────────────────────────────────────── */
.die {
  width: 78px;
  height: 78px;
  background: var(--surface);
  border: 4px solid var(--stroke);
  border-radius: var(--radius-md);
  cursor: pointer;
  display: grid;
  align-items: center;
  justify-items: center;
  position: relative;
  transition: transform var(--transition), filter var(--transition);
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

/* Colors by Die Value (Accessibility) */
.die.face-1 { background: var(--blue); }
.die.face-2 { background: var(--purple); }
.die.face-3 { background: var(--yellow); }
.die.face-4 { background: var(--green); }
.die.face-5 { background: var(--orange); }
.die.face-6 { background: #FFC0C0; }

.die:hover:not(.disabled) {
  transform: translateY(-5px) rotate(3deg);
  filter: brightness(1.05);
}
.die:active:not(.disabled) { transform: scale(0.92); }

.die.held {
  border-color: var(--stroke);
  transform: translateY(-6px);
}
.die.held::after {
  content: '✓ HOLD';
  position: absolute;
  top: -24px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.7rem;
  font-weight: 900;
  color: var(--accent-dark);
  white-space: nowrap;
  letter-spacing: 0.05em;
}

/* Die face dot grid */
.die-face {
  display: grid;
  width: 54px;
  height: 54px;
  padding: 8px;
  gap: 4px;
  grid-template-columns: 1fr 1fr 1fr;
  grid-template-rows: 1fr 1fr 1fr;
}

.dot {
  background: var(--stroke);
  border-radius: 50%;
  width: 100%;
  height: 100% !important;
}

/* ── Roll Section ──────────────────────────────────────────── */
#roll-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

#btn-roll {
  padding: 18px 50px;
  font-family: var(--font);
  font-size: 1.2rem;
  font-weight: 900;
  color: var(--text-white);
  background: var(--accent);
  border: none;
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: transform var(--transition);
  letter-spacing: 0.03em;
  -webkit-tap-highlight-color: transparent;
  min-width: 240px;
}
#btn-roll:hover:not(:disabled) {
  transform: translateY(-2px);
}
#btn-roll:active:not(:disabled) {
  transform: translateY(2px);
}
#btn-roll:disabled {
  background: var(--text-muted);
  cursor: not-allowed;
  opacity: 0.5;
}

#rolls-indicator {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-top: 8px;
}
.roll-pip {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--border);
  transition: background 0.3s ease, transform 0.3s ease;
}
.roll-pip.active {
  background: var(--accent);
  transform: scale(1.2);
}
#rolls-label {
  font-size: 0.9rem;
  font-weight: 800;
  color: var(--text-mid);
  margin-left: 6px;
}

/* ── Scorecard Inner Containers ─────────────────────────────── */
#scorecard-upper,
#scorecard-lower {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 10px;
  height: 100%;
}

/* ── Score Row ─────────────────────────────────────────────── */
.score-row {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: transform var(--transition), background var(--transition), border-color var(--transition);
  border: 2px solid var(--border);
  background: var(--surface-alt);
  min-height: 54px;
  -webkit-tap-highlight-color: transparent;
  flex-shrink: 0;
}

.score-row:hover:not(.used):not(.inactive) {
  background: #fff;
  border-color: var(--accent);
  transform: translateY(-2px);
}

.score-row.potential {
  background: #fff;
}
.score-row.potential .score-value {
  background: var(--blue);
  color: var(--text-dark);
}

.score-row.used {
  cursor: default;
}
.score-row.used .score-name { opacity: 0.6; }
.score-row.used .score-value {
  background: var(--stroke);
  color: #fff;
}

.score-row.inactive { cursor: default; opacity: 0.5; }

.score-icon {
  font-size: 1.8rem;
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent !important;
  border: none !important;
}

/* Clear specific colors for icons as they should be plain now */
.score-icon { background: none !important; border-color: transparent !important; }

.score-name {
  flex: 1;
  font-size: 0.95rem;
  font-weight: 800;
  color: var(--text-dark);
  line-height: 1.1;
  text-align: left;
}
.score-name small {
  display: block;
  font-weight: 600;
  color: var(--text-muted);
  font-style: italic;
}

.score-value {
  font-size: 1rem;
  font-weight: 900;
  min-width: 56px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--blue);
  border-radius: var(--radius-full);
  color: var(--text-dark);
}

.score-row.used .score-icon::after {
  content: ' ✓';
  font-size: 0.7rem;
  color: var(--green);
}

/* ── Bonus Progress Bar ─────────────────────────────────────── */
#bonus-bar-wrap {
  grid-column: 1 / -1;
  padding: 10px 16px;
  border-radius: var(--radius-md);
  background: var(--surface-alt);
  border: 2px solid var(--border);
  margin-top: 8px;
  min-height: 60px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  flex-shrink: 0;
}
#bonus-bar-label {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 4px;
}
#bonus-bar-desc {
  font-size: 0.75rem;
  font-weight: 800;
  color: var(--text-mid);
}
#bonus-bar-need {
  font-size: 0.75rem;
  font-weight: 900;
  color: var(--text-dark);
}
#bonus-bar-track {
  height: 8px;
  background: var(--border);
  border-radius: 99px;
  overflow: hidden;
}
#bonus-bar-fill {
  height: 100%;
  border-radius: 99px;
  background: var(--accent);
  transition: width 0.5s ease;
  width: 0%;
}
#bonus-bar-fill.complete { background: var(--green-dark); }

/* ── Section Totals ─────────────────────────────────────────── */
.total-row {
  grid-column: 1 / -1;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 16px;
  font-size: 1rem;
  font-weight: 900;
  color: var(--text-dark);
  background: var(--blue);
  border-radius: var(--radius-md);
  margin-top: 8px;
  min-height: 60px;
  flex-shrink: 0;
}

.total-row .total-val {
  color: var(--text-dark);
  font-size: 1.1rem;
  font-weight: 900;
  background: #fff;
  padding: 0 14px;
  min-width: 56px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-full);
}

/* ── End Game Modal ────────────────────────────────────────── */
#modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(26, 31, 54, 0.5);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  padding: 20px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}
#modal-overlay.open {
  opacity: 1;
  pointer-events: all;
}

#modal-box {
  background: var(--surface);
  border-radius: var(--radius-xl);
  border: 2px solid var(--border);
  padding: 40px;
  max-width: 440px;
  width: 100%;
  text-align: center;
  transform: scale(0.9);
  transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
#modal-overlay.open #modal-box { transform: scale(1); }

.modal-emoji { font-size: 3.5rem; margin-bottom: 12px; }
.modal-title {
  font-size: 2rem;
  font-weight: 900;
  color: var(--text-dark);
  margin-bottom: 8px;
}
.modal-subtitle {
  font-size: 1rem;
  color: var(--text-muted);
  margin-bottom: 24px;
}
.modal-score {
  font-size: 3.5rem;
  font-weight: 900;
  color: var(--accent);
  line-height: 1;
  margin-bottom: 24px;
}
.modal-score-label {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  margin-bottom: 32px;
}

#btn-play-again {
  width: 100%;
  padding: 16px;
  font-family: var(--font);
  font-size: 1.2rem;
  font-weight: 900;
  color: white;
  background: var(--accent);
  border: none;
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: transform var(--transition);
}
#btn-play-again:hover { transform: translateY(-2px); }
#btn-play-again:active {
  transform: translateY(2px);
}

/* ── Toast ─────────────────────────────────────────────────── */
#toast-container {
  position: fixed;
  top: 40px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: center;
  pointer-events: none;
}
.toast {
  padding: 14px 32px;
  background: var(--stroke);
  color: white;
  border-radius: var(--radius-full);
  font-size: 1rem;
  font-weight: 800;
  box-shadow: 0 6px 0 rgba(0,0,0,0.2);
  animation: toastIn 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275), toastOut 0.4s ease 2.3s forwards;
  white-space: nowrap;
}
@keyframes toastIn  { from { opacity: 0; transform: translateY(-20px); } to { opacity: 1; transform: translateY(0); } }
@keyframes toastOut { to   { opacity: 0; transform: translateY(-20px); } }

/* ── Score Pop Animation ────────────────────────────────────── */
.score-pop {
  position: fixed;
  pointer-events: none;
  font-family: var(--font);
  font-size: 1.8rem;
  font-weight: 900;
  color: var(--blue);
  animation: scorePop 1.2s ease-out forwards;
  z-index: 300;
}
@keyframes scorePop {
  0%   { transform: translateY(0) scale(1);      opacity: 1; }
  100% { transform: translateY(-80px) scale(1.2); opacity: 0; }
}

/* ── Yahtzee Celebration ────────────────────────────────────── */
.yahtzee-flash {
  animation: yahtzeeCelebrate 0.8s ease-out;
}
@keyframes yahtzeeCelebrate {
  0%   { transform: scale(1); }
  30%  { transform: scale(1.15); }
  60%  { transform: scale(0.97); }
  100% { transform: scale(1); }
}

/* ── Restart / New Game Button ──────────────────────────────── */
#btn-restart {
  padding: 10px 22px;
  font-family: var(--font);
  font-size: 0.9rem;
  font-weight: 900;
  color: var(--text-dark);
  background: var(--yellow);
  border: none;
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: transform var(--transition);
  letter-spacing: 0.05em;
}
#btn-restart:hover {
  transform: translateY(-2px);
}
#btn-restart:active {
  transform: translateY(2px);
}

/* ── Responsive ─────────────────────────────────────────────── */

/* Stack section cards vertically on medium screens */
@media (max-width: 1000px) {
  #scorecard-area {
    flex-direction: column;
  }

  .score-col-card.card {
    height: auto;
  }
}

/* Tighten layout and go single-column grid on small screens */
@media (max-width: 520px) {
  #app {
    padding: 0 12px 16px;
  }

  #sticky-top {
    padding-top: 16px;
    padding-bottom: 14px;
  }

  #header h1 {
    font-size: 1.6rem;
  }
  #header h1::before {
    font-size: 1.6rem;
  }

  .card {
    padding: 16px 14px;
  }

  .score-icon {
    width: 32px;
    height: 32px;
    font-size: 1.5rem;
  }

  .score-value {
    min-width: 48px;
    font-size: 0.9rem;
  }

  .score-name {
    font-size: 0.85rem;
  }
}
