:root {
  --bg: #0f1115;
  --bg2: #1a1e27;
  --card: #232833;
  --text: #f2f4f8;
  --muted: #9aa3b2;
  --accent: #c45c26;
  --accent2: #2d8a4e;
  --border: #2e3545;
  --danger: #c44;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}
[data-theme="light"] {
  --bg: #f4f5f7;
  --bg2: #ffffff;
  --card: #ffffff;
  --text: #1a1e27;
  --muted: #5c6575;
  --border: #d8dde6;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; padding: 0;
  background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  min-height: 100%;
  min-height: 100dvh;
}
body {
  padding:
    calc(12px + var(--safe-top))
    calc(12px + var(--safe-right))
    calc(72px + var(--safe-bottom))
    calc(12px + var(--safe-left));
}
h1 {
  font-size: 1.05rem; font-weight: 700; margin: 0 0 4px;
  letter-spacing: -0.01em;
}
.subtitle { color: var(--muted); font-size: 0.75rem; margin: 0 0 12px; }
header {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 8px;
}
.icon-btn {
  background: var(--card); border: 1px solid var(--border); color: var(--text);
  border-radius: 12px; width: 44px; height: 44px; font-size: 1.2rem;
  display: grid; place-items: center;
}
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0;
  display: grid; grid-template-columns: repeat(5, 1fr);
  gap: 2px; background: var(--bg2); border-top: 1px solid var(--border);
  padding: 6px calc(8px + var(--safe-right)) calc(6px + var(--safe-bottom)) calc(8px + var(--safe-left));
  z-index: 20;
}
.tabs button {
  background: transparent; border: 0; color: var(--muted);
  padding: 8px 2px; font-size: 0.7rem; border-radius: 10px;
}
.tabs button.active { color: var(--accent); background: color-mix(in srgb, var(--accent) 15%, transparent); font-weight: 600; }
.panel { display: none; }
.panel.active { display: block; }
.stage-wrap {
  background: var(--card); border: 1px solid var(--border); border-radius: 16px;
  overflow: hidden; margin-bottom: 12px; position: relative;
  height: 220px;
}
#stage {
  width: 100%; height: 100%; display: block; touch-action: none;
}
.results {
  min-height: 72px; padding: 10px 12px; background: var(--bg2);
  border: 1px solid var(--border); border-radius: 14px; margin-bottom: 12px;
}
.results .rolling { color: var(--muted); font-style: italic; }
.results .total { font-size: 1.8rem; font-weight: 800; letter-spacing: -0.02em; }
.results .detail { color: var(--muted); font-size: 0.85rem; margin-top: 4px; word-break: break-word; }
.results .notes { color: var(--accent2); font-size: 0.8rem; margin-top: 4px; }
.results .error { color: var(--danger); }
.row { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; align-items: center; }
.die-btn, .btn {
  background: var(--accent); color: white; border: 0; border-radius: 12px;
  padding: 12px 14px; font-weight: 700; font-size: 0.95rem;
  min-height: 44px;
}
.die-btn.secondary, .btn.secondary { background: var(--card); color: var(--text); border: 1px solid var(--border); }
.die-btn:disabled, .btn:disabled { opacity: 0.4; }
label.field {
  display: flex; flex-direction: column; gap: 4px; font-size: 0.75rem; color: var(--muted);
}
input, select {
  background: var(--bg2); color: var(--text); border: 1px solid var(--border);
  border-radius: 10px; padding: 10px 12px; font-size: 1rem; min-height: 44px;
}
input[type="number"] { width: 72px; }
input[type="text"] { flex: 1; min-width: 140px; }
.card {
  background: var(--card); border: 1px solid var(--border); border-radius: 14px;
  padding: 12px; margin-bottom: 10px;
}
.card h2 { margin: 0 0 8px; font-size: 0.95rem; }
.switch-row {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 10px 0; border-bottom: 1px solid var(--border);
}
.switch-row:last-child { border-bottom: 0; }
.switch-row .help { color: var(--muted); font-size: 0.72rem; margin-top: 2px; }
.switch {
  position: relative; width: 48px; height: 28px; flex-shrink: 0;
}
.switch input { opacity: 0; width: 0; height: 0; }
.switch span {
  position: absolute; inset: 0; background: #555; border-radius: 999px; transition: .2s;
}
.switch span::before {
  content: ""; position: absolute; width: 22px; height: 22px; left: 3px; top: 3px;
  background: white; border-radius: 50%; transition: .2s;
}
.switch input:checked + span { background: var(--accent2); }
.switch input:checked + span::before { transform: translateX(20px); }
.history-item, .fav-item {
  display: flex; justify-content: space-between; gap: 8px; align-items: center;
  padding: 10px 0; border-bottom: 1px solid var(--border); font-size: 0.9rem;
}
.history-item .meta, .fav-item .meta { color: var(--muted); font-size: 0.75rem; }
.pill {
  display: inline-block; padding: 2px 8px; border-radius: 999px;
  background: color-mix(in srgb, var(--accent) 20%, transparent); color: var(--accent);
  font-size: 0.7rem; font-weight: 600;
}
.kept { font-weight: 700; }
.dropped { opacity: 0.45; text-decoration: line-through; }
.chip-row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.chip {
  background: var(--bg2); border: 1px solid var(--border); border-radius: 999px;
  padding: 6px 10px; font-size: 0.8rem;
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
