:root {
  --bg-primary: #0a0a0f;
  --bg-secondary: #14141f;
  --bg-tertiary: #1e1e2e;
  --text-primary: #ffffff;
  --text-secondary: #a0a0b0;
  --text-muted: #606070;
  --accent: #00d4ff;
  --accent-secondary: #00ff88;
  --danger: #ff4466;
  --focus-ring: #00d4ff;
  --focus-glow: rgba(0, 212, 255, 0.4);
  --radius-md: 12px;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
html, body {
  width: 600px; height: 600px; overflow: hidden;
  background: #000;
  color: var(--text-primary);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  -webkit-font-smoothing: antialiased;
}
#app { width: 100%; height: 100%; position: relative; }
.screen { width: 100%; height: 100%; position: absolute; top: 0; left: 0; display: flex; flex-direction: column; }
.screen.hidden { display: none; }
.focusable { transition: all 0.15s ease; border: 2px solid transparent; cursor: pointer; outline: none; }
.focusable:focus { border-color: var(--focus-ring); box-shadow: 0 0 20px var(--focus-glow); }
.hidden { display: none !important; }

/* ===== Topbar ===== */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 18px; gap: 12px; min-height: 64px;
  background: var(--bg-primary);
  border-bottom: 1px solid #20202c;
}
.brand { font-size: 22px; font-weight: 700; letter-spacing: 0.5px; display: flex; align-items: center; gap: 8px; }
.logo { font-size: 26px; }
.iconbtn {
  background: var(--bg-tertiary); color: var(--text-primary);
  border-radius: var(--radius-md); padding: 0 18px; height: 48px; min-width: 88px;
  font-size: 16px; font-weight: 600;
  display: flex; align-items: center; justify-content: center;
}
.iconbtn.danger { color: var(--danger); }

/* ===== Result ===== */
.result {
  flex: 1; min-height: 0; overflow: hidden;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 12px 18px; gap: 10px;
}
.dice-grid {
  display: flex; flex-wrap: wrap; gap: 10px;
  justify-content: center; align-items: center;
  max-height: 162px;
}
.die {
  width: 70px; height: 70px; border-radius: 14px;
  background: linear-gradient(145deg, #242438, #15151e);
  border: 1px solid #2c2c3c;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.06), 0 4px 10px rgba(0,0,0,0.45);
  display: flex; align-items: center; justify-content: center;
  position: relative;
}
.die .num { font-size: 30px; font-weight: 800; color: var(--accent); }
.die .pips {
  width: 100%; height: 100%; padding: 12px;
  display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr);
}
.die .cell { display: flex; align-items: center; justify-content: center; }
.die .cell.on::after {
  content: ''; width: 12px; height: 12px; border-radius: 50%;
  background: var(--accent); box-shadow: 0 0 6px var(--focus-glow);
}

/* compact faces when many dice */
.dice-grid.compact .die { width: 52px; height: 52px; border-radius: 11px; }
.dice-grid.compact .die .num { font-size: 22px; }
.dice-grid.compact .die .pips { padding: 8px; }
.dice-grid.compact .die .cell.on::after { width: 9px; height: 9px; }

.die.rolling { animation: shake 0.18s ease-in-out infinite; }
.die.pop { animation: pop 0.32s cubic-bezier(.2, 1.4, .4, 1); }
@keyframes shake {
  0% { transform: translateY(0) rotate(0); }
  25% { transform: translateY(-3px) rotate(-5deg); }
  75% { transform: translateY(3px) rotate(5deg); }
  100% { transform: translateY(0) rotate(0); }
}
@keyframes pop { 0% { transform: scale(0.6); } 100% { transform: scale(1); } }

.total-wrap { text-align: center; }
.total-label { font-size: 12px; letter-spacing: 3px; color: var(--text-muted); font-weight: 700; }
.total {
  font-size: 62px; font-weight: 800; line-height: 1;
  color: var(--text-primary); text-shadow: 0 0 24px rgba(0, 212, 255, 0.25);
}
.breakdown {
  font-size: 14px; color: var(--text-secondary); margin-top: 6px;
  max-width: 540px; line-height: 1.4;
}
.breakdown .cfg { color: var(--accent-secondary); font-weight: 700; margin-right: 8px; }

/* ===== Controls ===== */
.controls { padding: 4px 22px; display: flex; flex-direction: column; gap: 8px; }
.control-row { display: flex; align-items: center; justify-content: space-between; }
.control-label { font-size: 17px; font-weight: 600; color: var(--text-secondary); }
.stepper { display: flex; align-items: center; gap: 10px; }
.step {
  width: 60px; height: 50px; border-radius: var(--radius-md);
  background: var(--bg-tertiary); color: var(--text-primary);
  font-size: 28px; font-weight: 700; line-height: 1;
  display: flex; align-items: center; justify-content: center;
}
.step-value { min-width: 92px; text-align: center; font-size: 24px; font-weight: 700; }

/* ===== Action bar ===== */
.actionbar { padding: 12px 22px 18px; }
.roll-btn {
  width: 100%; height: 84px; border-radius: 18px;
  background: linear-gradient(135deg, var(--accent), #0099cc);
  color: #04141a; font-size: 30px; font-weight: 800; letter-spacing: 2px;
  display: flex; align-items: center; justify-content: center;
}
.roll-btn:focus { border-color: #ffffff; box-shadow: 0 0 26px rgba(0, 212, 255, 0.7); }
.roll-btn.busy { opacity: 0.65; }

/* ===== History ===== */
.history-list {
  flex: 1; min-height: 0; overflow-y: auto;
  padding: 12px 16px; display: flex; flex-direction: column; gap: 10px;
}
.history-list::-webkit-scrollbar { width: 6px; }
.history-list::-webkit-scrollbar-thumb { background: #2c2c3c; border-radius: 3px; }
.history-row {
  background: var(--bg-secondary); border-radius: var(--radius-md);
  padding: 12px 16px; min-height: 64px; width: 100%; text-align: left;
  display: flex; align-items: center; gap: 14px;
}
.hr-badge {
  background: var(--bg-tertiary); color: var(--accent-secondary);
  border-radius: 8px; padding: 6px 10px; min-width: 74px; text-align: center;
  font-weight: 800; font-size: 16px;
}
.hr-mid { flex: 1; min-width: 0; }
.hr-vals, .hr-time { display: block; }
.hr-vals { color: var(--text-secondary); font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hr-time { color: var(--text-muted); font-size: 12px; margin-top: 2px; }
.hr-total { font-size: 30px; font-weight: 800; color: var(--text-primary); }
.empty-state {
  flex: 1; display: flex; align-items: center; justify-content: center;
  color: var(--text-muted); font-size: 20px;
}
