/* Dice Simulator - tabletop dice roller. Dark by default; light-theme variables
   are retained for a future data-theme="light" toggle but the app ships dark-only. */

:root {
  --bg: #0b0f14;
  --surface: #131a24;
  --surface-2: #1b2431;
  --text: #eef2f7;
  --dim: #8a97a8;
  --border: rgba(255, 255, 255, 0.12);
  --accent: #6366f1;
  --accent-2: #818cf8;
  --accent-ink: #ffffff;
  --shadow: rgba(0, 0, 0, 0.4);
}
:root[data-theme="light"] {
  --bg: #eef1f7;
  --surface: #ffffff;
  --surface-2: #f2f4fa;
  --text: #10151c;
  --dim: #5a6675;
  --border: rgba(0, 0, 0, 0.1);
  --accent: #4f46e5;
  --accent-2: #6366f1;
  --shadow: rgba(31, 41, 84, 0.14);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
body { min-height: 100vh; min-height: 100dvh; }

.app {
  max-width: 560px;
  margin: 0 auto;
  padding: max(20px, env(safe-area-inset-top)) 18px calc(28px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.head { margin-bottom: 2px; }
h1 { font-size: 26px; letter-spacing: -0.02em; margin: 6px 0 4px; }
.tagline { color: var(--dim); margin: 0; font-size: 15px; }

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 14px 16px;
}
.panel-title {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--dim);
  margin: 0 0 10px;
  font-weight: 600;
}

/* --- Die picker --- */
.dice-picker {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}
.die-btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  border-radius: 12px;
  padding: 12px 4px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.08s ease, border-color 0.15s ease, background 0.15s ease;
}
.die-btn:active { transform: scale(0.95); }
.die-btn[aria-checked="true"] {
  border-color: var(--accent);
  background: linear-gradient(160deg, var(--accent-2), var(--accent));
  color: var(--accent-ink);
  box-shadow: 0 6px 16px -8px var(--accent);
}

/* --- Steppers --- */
.steppers {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.stepper-label {
  display: block;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--dim);
  font-weight: 600;
  margin-bottom: 8px;
}
.stepper-controls {
  display: flex;
  align-items: center;
  gap: 6px;
}
.step {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  width: 40px;
  height: 40px;
  border-radius: 11px;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  flex: 0 0 auto;
  transition: transform 0.08s ease, background 0.15s ease;
}
.step:active { transform: scale(0.92); }
.step:disabled { opacity: 0.35; cursor: default; }
.stepper-value {
  flex: 1 1 auto;
  text-align: center;
  font-size: 20px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.notation {
  margin: 12px 0 0;
  text-align: center;
  color: var(--accent-2);
  font-weight: 700;
  font-size: 17px;
  letter-spacing: 0.01em;
  font-variant-numeric: tabular-nums;
}

/* --- Stage / dice tray --- */
.stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  min-height: 150px;
  justify-content: center;
  padding: 8px 0;
}
.tray {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  align-items: center;
  min-height: 82px;
}

.die {
  --size: 74px;
  width: var(--size);
  height: var(--size);
  border-radius: 16px;
  background: linear-gradient(155deg, var(--accent-2), var(--accent));
  color: var(--accent-ink);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 30px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  box-shadow: 0 10px 22px -12px var(--accent), inset 0 1px 0 rgba(255, 255, 255, 0.25);
  will-change: transform;
  position: relative;
}
.die.small { --size: 56px; font-size: 22px; border-radius: 13px; }
.die.tiny { --size: 44px; font-size: 16px; border-radius: 11px; }

.die.rolling { animation: tumble 0.6s cubic-bezier(0.3, 0.7, 0.4, 1) both; }
.die.landed { animation: land 0.4s cubic-bezier(0.2, 1.4, 0.4, 1) both; }

@keyframes tumble {
  0%   { transform: translateY(0) rotate(0deg) scale(1); }
  25%  { transform: translateY(-26px) rotate(140deg) scale(1.06); }
  55%  { transform: translateY(4px) rotate(280deg) scale(0.96); }
  80%  { transform: translateY(-8px) rotate(360deg) scale(1.02); }
  100% { transform: translateY(0) rotate(360deg) scale(1); }
}
@keyframes land {
  0%   { transform: scale(1.18); }
  60%  { transform: scale(0.94); }
  100% { transform: scale(1); }
}

/* Pip faces for d6 */
.pips {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  gap: 6%;
  width: 62%;
  height: 62%;
}
.pip {
  border-radius: 50%;
  background: var(--accent-ink);
  align-self: center;
  justify-self: center;
  width: 74%;
  height: 74%;
  aspect-ratio: 1;
}

/* --- Total --- */
.total {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}
.total-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--dim);
  font-weight: 600;
}
.total-value {
  font-size: 46px;
  font-weight: 800;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}
.total-detail {
  color: var(--dim);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

/* --- Roll button --- */
.roll {
  appearance: none;
  border: none;
  width: 100%;
  padding: 18px;
  border-radius: 16px;
  background: linear-gradient(155deg, var(--accent-2), var(--accent));
  color: var(--accent-ink);
  font-size: 19px;
  font-weight: 800;
  letter-spacing: 0.02em;
  cursor: pointer;
  box-shadow: 0 12px 26px -12px var(--accent);
  transition: transform 0.08s ease, opacity 0.15s ease;
}
.roll:active { transform: scale(0.98); }
.roll:disabled { opacity: 0.6; cursor: default; }

/* --- History --- */
.history-head,
.setup-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.history-head .panel-title,
.setup-head .panel-title { margin: 0; }
.clear,
.reset {
  appearance: none;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--dim);
  border-radius: 10px;
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.clear:active,
.reset:active { transform: scale(0.96); }
.reset:disabled { opacity: 0.4; cursor: default; }

.history-list { list-style: none; margin: 0; padding: 0; }
.history-item {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 2px;
  border-top: 1px solid var(--border);
  animation: fadeIn 0.25s ease both;
}
.history-item:first-child { border-top: none; }
.hi-main { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.hi-notation { font-weight: 700; font-size: 15px; }
.hi-rolls {
  color: var(--dim);
  font-size: 12.5px;
  font-variant-numeric: tabular-nums;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.hi-total {
  font-size: 22px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  flex: 0 0 auto;
}
.history-empty { color: var(--dim); font-size: 14px; margin: 4px 0 0; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}

@media (prefers-reduced-motion: reduce) {
  .die.rolling, .die.landed, .history-item { animation: none; }
  .die-btn, .step, .roll, .clear, .reset { transition: none; }
}
