:root {
  color-scheme: light dark;
  --bg: #ffffff;
  --fg: #1e1f22;
  /* A light-gray elevated panel in light mode (mirrors Discord's own light
     theme secondary background), and the existing dark panel in dark mode
     -- --fg already flips alongside it, so card text just works in both. */
  --card-bg: #f2f3f5;
  --border: #d4d6da;
  --accent: #802932;
  --accent-2: #283593;
  --accent-text: #ffffff;
  --error: #d83c3e;
  --mono-font: Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #313338;
    --fg: #f2f3f5;
    --card-bg: #202225;
    --border: #1e1f22;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 8px;
  font-family: -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 13px;
  background: var(--bg);
  color: var(--fg);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

h1 {
  font-size: 15px;
  margin: 0;
}

.bottom-row {
  align-items: flex-start;
}

.bottom-row details {
  flex: 1;
  min-width: 0;
  min-height: 30px;
}

.reset-btn {
  flex: 0 0 auto;
  font-size: 11px;
  padding: 4px 8px;
  white-space: nowrap;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
}

.reset-btn:hover {
  border-color: var(--accent);
  filter: brightness(1.1);
}

h2 {
  font-size: 13px;
  margin: 0 0 6px 0;
}

.status {
  margin: 2px 0 0 0;
  min-height: 14px;
  font-size: 12px;
  color: var(--fg);
  opacity: 0.75;
}

.status.error {
  color: var(--error);
  opacity: 1;
}

details {
  border: 1px solid var(--border);
  border-radius: 0;
  padding: 4px 8px;
}

summary {
  cursor: pointer;
  font-weight: 600;
}

.card {
  border: 1px solid var(--border);
  border-radius: 0;
  padding: 8px;
  background: var(--card-bg);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin: 6px 0;
}

.field label {
  font-size: 11px;
  opacity: 0.8;
}

input,
select {
  border: 1px solid var(--border);
  border-radius: 0;
  padding: 4px 6px;
  background: var(--bg);
  color: var(--fg);
  width: 100%;
}

.row {
  display: flex;
  gap: 8px;
}

.row .field {
  flex: 1;
  min-width: 0;
}

.checkbox-group {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.checkbox-group .checkbox-field {
  margin: 0;
}

.checkbox-field {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  margin: 6px 0;
  cursor: pointer;
}

#accent-color-setting,
#accent-color-2-setting {
  height: 28px;
}

.reset-colors-btn {
  flex: 0 0 auto;
  align-self: flex-end;
  height: 28px;
  margin: 6px 0;
  padding: 0 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  white-space: nowrap;
}

.settings-links-row {
  align-items: center;
  justify-content: space-between;
}

.settings-links {
  display: flex;
  gap: 8px;
  font-size: 12px;
}

.settings-links a {
  display: inline-block;
  background: var(--accent-2);
  color: #ffffff;
  border: 1px solid var(--accent-2);
  padding: 4px 8px;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
}

.settings-links a:hover {
  filter: brightness(1.1);
}

.checkbox-field input {
  width: auto;
  accent-color: var(--accent-2);
}

.d20-controls-row {
  align-items: flex-end;
  flex-wrap: wrap;
}

.stat-group {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.stat-group label {
  font-size: 11px;
  opacity: 0.8;
}

.modifier-control {
  display: flex;
  align-items: center;
  gap: 4px;
}

.tally-control {
  display: flex;
  align-items: flex-start;
  gap: 4px;
}

.tally-field-stack {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

/* Field (26) + gap (2) + minus (12) = 40 -- matches .tally-btn's height, so
   the field's top and the minus button's bottom both line up with it. */
.tally-field-stack .stack-btn-minus {
  width: 40px;
}

.step-btn {
  width: 26px;
  height: 40px;
  padding: 0;
  font-size: 16px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.dice-stepper {
  display: flex;
  align-items: center;
  gap: 4px;
}

.stepper-stack {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.stack-btn {
  width: 26px;
  padding: 0;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.stack-btn-plus {
  height: 26px;
  font-size: 16px;
}

.stack-btn-minus {
  height: 12px;
  font-size: 9px;
}

.modifier-input {
  width: 40px;
  height: 40px;
  padding: 0;
  text-align: center;
  font-size: 15px;
  font-weight: 600;
  font-family: var(--mono-font);
}

.dice-input {
  width: 54px;
  font-size: 13px;
  font-family: var(--mono-font);
}

/* Width/font/etc. come from .modifier-input (shared class, in markup) --
   height is shortened so field + gap + minus button == .tally-btn's height,
   lining up the field's top and the minus button's bottom with it. */
.tally-input {
  height: 26px;
  /* The custom hex "Add" button already increments, and the new minus
     button below decrements -- the native spinner is redundant. */
  appearance: textfield;
  -moz-appearance: textfield;
}

.tally-input::-webkit-inner-spin-button,
.tally-input::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.tally-btn {
  width: 40px;
  height: 40px;
  padding: 0;
  font-size: 20px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.tally-icon {
  width: 26px;
  height: 26px;
  color: var(--fg);
}

.tally-btn:hover .tally-icon {
  color: var(--accent-2);
}

.xdx-controls-row {
  align-items: flex-end;
  flex-wrap: wrap;
}

.keep-crit-row {
  align-items: center;
  justify-content: space-between;
  margin: 6px 0;
}

.keep-field {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.keep-field label {
  font-size: 11px;
  opacity: 0.8;
}

.keep-toggle {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 0;
  overflow: hidden;
}

.keep-btn {
  border: none;
  border-radius: 0;
  padding: 4px 8px;
  font-size: 11px;
  background: transparent;
}

.keep-btn:not(:last-child) {
  border-right: 1px solid var(--border);
}

.keep-btn.active {
  background: var(--accent);
  color: var(--accent-text);
}

.quick-die-btn {
  flex: 0 0 auto;
  white-space: nowrap;
}

.saved-roll-row {
  align-items: center;
  margin: 6px 0;
}

.saved-rolls-select {
  flex: 1;
  min-width: 0;
}

.delete-roll-btn {
  flex: 0 0 auto;
  width: 32px;
  padding: 4px;
  line-height: 1;
}

.save-roll-row {
  align-items: stretch;
}

.save-roll-btn {
  flex: 0 0 auto;
  white-space: nowrap;
}

.save-roll-row .btn-primary {
  flex: 1;
  width: auto;
}

button {
  border: 1px solid var(--border);
  border-radius: 0;
  padding: 5px 9px;
  background: transparent;
  color: var(--fg);
  cursor: pointer;
  font-weight: 600;
}

button:hover {
  border-color: var(--accent-2);
}

.btn-primary {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--accent-text);
  padding: 8px 14px;
  font-size: 14px;
  width: 100%;
}

.btn-primary:hover {
  border-color: var(--accent);
  filter: brightness(1.1);
}

button:disabled {
  opacity: 0.5;
  cursor: default;
}

input:disabled {
  opacity: 0.5;
  cursor: default;
}

#clear-saved-rolls-btn,
.confirm-danger-btn {
  font-size: 11px;
  padding: 4px 8px;
}

.confirm-danger-btn,
.confirm-danger-btn:hover {
  border-color: var(--accent);
}

.clear-rolls-row {
  margin-top: 2px;
}

.roll-history {
  list-style: none;
  margin: 0;
  padding: 0;
  /* Fixed (not max-) height -- keeps the card at a constant size regardless
     of entry count, so the rest of the layout never shifts and leaves
     blank space at the bottom of the extension when history is short. */
  height: 240px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.roll-history:empty::before {
  content: "No rolls yet.";
  opacity: 0.6;
  font-size: 12px;
}

.roll-history li {
  font-size: 12px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 6px;
}

.roll-history li:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.roll-time {
  opacity: 0.6;
  font-size: 11px;
  font-weight: 400;
}

.roll-text {
  white-space: pre-wrap;
  margin-top: 2px;
}

.roll-title-line {
  font-size: 16px;
  font-weight: 600;
  margin-top: 2px;
}

.roll-total-line {
  display: block;
  width: fit-content;
  font-size: 16px;
  text-transform: uppercase;
  border: 1px solid var(--accent-2);
  padding: 2px 4px;
  margin-top: 2px;
}

.roll-overkill-line {
  display: block;
  width: fit-content;
  font-size: 16px;
  text-transform: uppercase;
  border: 1px solid var(--accent);
  padding: 2px 4px;
  margin-top: 2px;
}

.roll-uppercase-line {
  text-transform: uppercase;
}

.dice-faces {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
  margin: 2px 0;
}

.hide-dice-icons .dice-faces {
  display: none;
}

.dice-face-icon {
  width: 36px;
  height: 36px;
}

/* Must stay last: relies on cascade order (not just specificity) to beat
   other single-class rules like .checkbox-field's `display: flex`. */
.hidden {
  display: none;
}
