:root {
  color-scheme: dark;
  font-family: Inter, ui-rounded, "SF Pro Rounded", "SF Pro Display", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #0d0f14;
  color: #f7f7f8;
  --surface: #171a22;
  --surface-2: #202530;
  --border: #303746;
  --text-muted: #aeb6c5;
  --accent: #7c9cff;
  --success: #55d68b;
  --failure: #ff6b6b;
  --warning: #f5c451;
  --shadow: 0 14px 36px rgba(0, 0, 0, 0.28);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at top left, rgba(124, 156, 255, 0.18), transparent 34rem),
    linear-gradient(180deg, #11141b 0%, #0d0f14 100%);
}

button, input {
  font: inherit;
}

button {
  touch-action: manipulation;
}

.app-shell {
  width: min(760px, 100%);
  margin: 0 auto;
  padding: max(24px, env(safe-area-inset-top)) 16px max(34px, env(safe-area-inset-bottom));
}

.app-header,
.section-heading,
.bonus-row,
.recovery-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.app-header {
  margin-bottom: 18px;
}

h1, h2, p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(1.8rem, 6vw, 2.5rem);
  letter-spacing: -0.04em;
}

h2 {
  margin-bottom: 0;
  font-size: 1.15rem;
}

.eyebrow {
  margin-bottom: 5px;
  color: var(--accent);
  font-size: 0.73rem;
  font-weight: 800;
  letter-spacing: 0.14em;
}

.tracker-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-bottom: 12px;
}

.tracker-card,
.panel {
  border: 1px solid var(--border);
  background: rgba(23, 26, 34, 0.94);
  box-shadow: var(--shadow);
}

.tracker-card {
  border-radius: 20px;
  padding: 18px;
}

.active-card {
  background: linear-gradient(145deg, rgba(49, 76, 75, .92), rgba(23, 26, 34, .97));
}

.failed-card {
  background: linear-gradient(145deg, rgba(81, 43, 50, .92), rgba(23, 26, 34, .97));
}

.tracker-label,
.tracker-limit {
  display: block;
  color: var(--text-muted);
}

.tracker-label {
  font-weight: 700;
}

.tracker-value {
  display: inline-block;
  margin: 7px 6px 0 0;
  font-size: 3.1rem;
  line-height: 1;
}

.tracker-limit {
  display: inline;
  font-size: .9rem;
}

.panel {
  margin-top: 12px;
  padding: 18px;
  border-radius: 22px;
}

.status-pill {
  flex: 0 0 auto;
  padding: 7px 10px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-muted);
  font-size: .8rem;
  font-weight: 750;
}

.status-pill.warning {
  color: #17120a;
  background: var(--warning);
}

.segmented-control {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin: 18px 0;
}

.segmented-control button,
.stepper button {
  min-height: 52px;
  border: 1px solid var(--border);
  border-radius: 15px;
  background: var(--surface-2);
  color: #fff;
  font-weight: 800;
}

.segmented-control button.selected {
  border-color: transparent;
  background: var(--accent);
  color: #111827;
}

.segmented-control button:disabled {
  opacity: .3;
}

.bonus-row {
  padding: 14px 0 18px;
  border-top: 1px solid var(--border);
}

.bonus-row label {
  font-weight: 800;
}

.bonus-row p,
.recovery-panel p {
  margin: 4px 0 0;
  color: var(--text-muted);
  font-size: .88rem;
}

.stepper {
  display: grid;
  grid-template-columns: 48px 48px 48px;
  align-items: center;
  text-align: center;
}

.stepper button {
  min-height: 46px;
  font-size: 1.4rem;
}

.stepper output {
  font-size: 1.25rem;
  font-weight: 850;
}

.primary-button,
.secondary-button,
.danger-button {
  min-height: 52px;
  border-radius: 16px;
  padding: 0 18px;
  font-weight: 850;
}

.primary-button {
  width: 100%;
  border: 0;
  background: var(--accent);
  color: #111827;
}

.primary-button:disabled {
  opacity: .45;
}

.secondary-button {
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: #fff;
}

.secondary-button:disabled {
  opacity: .4;
}

.compact {
  min-height: 42px;
  padding: 0 14px;
}

.danger-button {
  border: 0;
  background: var(--failure);
  color: #230707;
}

.text-button {
  border: 0;
  background: transparent;
  color: var(--accent);
  font-weight: 800;
}

.hidden {
  display: none;
}

.roll-summary {
  margin: 14px 0;
  color: var(--text-muted);
  font-size: .9rem;
}

.dice-results {
  display: grid;
  gap: 12px;
  margin-bottom: 16px;
}

.die-card {
  display: grid;
  grid-template-columns: 72px 1fr;
  gap: 14px;
  align-items: center;
  padding: 13px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: #12151c;
}

.die-card.resolved-success {
  border-color: rgba(85, 214, 139, .7);
}

.die-card.resolved-failure {
  border-color: rgba(255, 107, 107, .7);
}

.die-face {
  display: grid;
  place-items: center;
  width: 68px;
  aspect-ratio: 1;
  border-radius: 17px;
  background: #f3f4f6;
  color: #111827;
  font-size: 2rem;
  font-weight: 900;
  box-shadow: inset 0 -4px 0 rgba(0,0,0,.14);
}

.die-info {
  min-width: 0;
}

.die-label {
  margin-bottom: 9px;
  font-weight: 800;
}

.die-label span {
  color: var(--text-muted);
  font-size: .82rem;
}

.outcome-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.outcome-buttons button {
  min-height: 44px;
  border-radius: 13px;
  font-weight: 850;
}

.success-button {
  border: 1px solid rgba(85, 214, 139, .7);
  background: rgba(85, 214, 139, .12);
  color: var(--success);
}

.failure-button {
  border: 1px solid rgba(255, 107, 107, .7);
  background: rgba(255, 107, 107, .12);
  color: var(--failure);
}

.success-button.selected {
  background: var(--success);
  color: #082216;
}

.failure-button.selected {
  background: var(--failure);
  color: #2a0808;
}

.recovery-panel {
  align-items: flex-end;
}

.recovery-panel > div {
  flex: 1;
}

.history-list {
  margin: 14px 0 0;
  padding: 0;
  list-style: none;
}

.history-list li {
  padding: 12px 0;
  border-top: 1px solid var(--border);
}

.history-list li:first-child {
  border-top: 0;
}

.history-line {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-weight: 750;
}

.history-details {
  margin-top: 4px;
  color: var(--text-muted);
  font-size: .83rem;
}

.empty-state {
  color: var(--text-muted);
}

dialog {
  width: min(420px, calc(100% - 32px));
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 22px;
  background: #171a22;
  color: #fff;
  box-shadow: var(--shadow);
}

dialog::backdrop {
  background: rgba(0,0,0,.68);
  backdrop-filter: blur(4px);
}

dialog p {
  color: var(--text-muted);
}

.dialog-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 20px;
}

@media (max-width: 520px) {
  .recovery-panel {
    align-items: stretch;
    flex-direction: column;
  }

  .recovery-panel .secondary-button {
    width: 100%;
  }

  .die-card {
    grid-template-columns: 62px 1fr;
  }

  .die-face {
    width: 60px;
  }
}
