/* ==========================================================================
   Riftbound Probability Calculator
   Design System: Vercel Light (default) + Linear Dark (toggle)
   Sourced from popular-web-designs (vercel.md & linear.app.md)
   ========================================================================== */

:root {
  /* Vercel Light Tokens */
  --bg: #ffffff;
  --bg-subtle: #fafafa;
  --bg-elevated: #ffffff;
  --bg-hover: #f5f5f5;
  --bg-active: #ebebeb;

  --text: #171717;
  --text-secondary: #4d4d4d;
  --text-muted: #666666;
  --text-faint: #808080;

  --cta-bg: #171717;
  --cta-text: #ffffff;
  --cta-hover: #2e2e2e;

  --accent: #0070f3;
  --accent-soft: #ebf5ff;
  --accent-text: #0068d6;
  --accent-bar: rgba(0, 112, 243, 0.22);
  --accent-bar-strong: rgba(0, 112, 243, 0.55);

  --danger: #e5484d;
  --danger-soft: rgba(229, 72, 77, 0.08);
  --ok: #12a150;
  --ok-soft: rgba(18, 161, 80, 0.1);

  --focus-color: hsla(212, 100%, 48%, 1);
  --focus-ring: 0 0 0 2px var(--focus-color);

  /* Vercel Shadow-as-Border System */
  --ring: 0 0 0 1px rgba(0, 0, 0, 0.08);
  --ring-strong: 0 0 0 1px rgba(0, 0, 0, 0.16);
  --ring-light: 0 0 0 1px rgb(235, 235, 235);
  --card-shadow:
    0 0 0 1px rgba(0, 0, 0, 0.08),
    0 2px 2px rgba(0, 0, 0, 0.04),
    0 8px 8px -8px rgba(0, 0, 0, 0.04),
    inset 0 0 0 1px #fafafa;
  --popover-shadow:
    0 0 0 1px rgba(0, 0, 0, 0.08),
    0 8px 24px rgba(0, 0, 0, 0.10);
  --divider: rgba(0, 0, 0, 0.07);
  --sticky-shadow: 4px 0 8px -4px rgba(0, 0, 0, 0.08);

  --row-base-bg: #f4f9ff;
  --row-mull-bg: #fafafa;
  --cell-high: rgba(0, 112, 243, 0.08);
  --cell-mid: rgba(0, 112, 243, 0.035);

  --font-sans: 'Geist', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Noto Sans TC', sans-serif;
  --font-mono: 'Geist Mono', ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  --font-features: "liga" 1;
  --weight-body: 400;
  --weight-ui: 500;
  --weight-head: 600;

  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 8px;
  --radius-pill: 9999px;
}

/* Linear Dark Tokens */
[data-theme="dark"] {
  --bg: #08090a;
  --bg-subtle: #0f1011;
  --bg-elevated: #141517;
  --bg-hover: rgba(255, 255, 255, 0.05);
  --bg-active: rgba(255, 255, 255, 0.08);

  --text: #f7f8f8;
  --text-secondary: #d0d6e0;
  --text-muted: #8a8f98;
  --text-faint: #62666d;

  --cta-bg: #5e6ad2;
  --cta-text: #ffffff;
  --cta-hover: #7170ff;

  --accent: #7170ff;
  --accent-soft: rgba(94, 106, 210, 0.16);
  --accent-text: #a5b4fc;
  --accent-bar: rgba(113, 112, 255, 0.25);
  --accent-bar-strong: rgba(113, 112, 255, 0.65);

  --danger: #f87171;
  --danger-soft: rgba(248, 113, 113, 0.12);
  --ok: #10b981;
  --ok-soft: rgba(16, 185, 129, 0.14);

  --focus-color: #7170ff;
  --focus-ring: 0 0 0 2px rgba(113, 112, 255, 0.7);

  /* Linear Luminance & Translucent White Border System */
  --ring: 0 0 0 1px rgba(255, 255, 255, 0.08);
  --ring-strong: 0 0 0 1px rgba(255, 255, 255, 0.16);
  --ring-light: 0 0 0 1px rgba(255, 255, 255, 0.05);
  --card-shadow:
    0 0 0 1px rgba(255, 255, 255, 0.08),
    0 2px 4px rgba(0, 0, 0, 0.35);
  --popover-shadow:
    0 0 0 1px rgba(255, 255, 255, 0.1),
    0 12px 32px rgba(0, 0, 0, 0.6);
  --divider: rgba(255, 255, 255, 0.06);
  --sticky-shadow: 4px 0 12px -4px rgba(0, 0, 0, 0.6);

  --row-base-bg: rgba(94, 106, 210, 0.12);
  --row-mull-bg: rgba(255, 255, 255, 0.015);
  --cell-high: rgba(113, 112, 255, 0.14);
  --cell-mid: rgba(113, 112, 255, 0.055);

  --font-sans: 'Inter', 'Geist', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Noto Sans TC', sans-serif;
  --font-mono: 'JetBrains Mono', 'Geist Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  --font-features: "cv01" 1, "ss03" 1, "liga" 1;
  --weight-ui: 500;
  --weight-head: 600;
}

/* Base Reset */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

[hidden] {
  display: none !important;
}

html {
  -webkit-text-size-adjust: 100%;
  background: var(--bg);
}

body {
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-weight: var(--weight-body);
  font-feature-settings: var(--font-features);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

button, input, select {
  font: inherit;
  color: inherit;
  border: none;
  background: none;
  outline: none;
  touch-action: manipulation;
}

button {
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
input:focus-visible,
select:focus-visible {
  box-shadow: var(--focus-ring);
}

.mono {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1, "liga" 1;
}

/* Sticky Top Header */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: color-mix(in srgb, var(--bg) 90%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  box-shadow: 0 1px 0 0 var(--divider);
}

.topbar-inner {
  max-width: 1040px;
  margin: 0 auto;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: var(--radius-md);
  background: var(--cta-bg);
  color: var(--cta-text);
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: var(--weight-head);
  letter-spacing: -0.02em;
}

.brand-title {
  font-size: 15px;
  font-weight: var(--weight-head);
  letter-spacing: -0.03em;
  color: var(--text);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  height: 32px;
  padding: 0 10px;
  border-radius: var(--radius-md);
  font-size: 13px;
  font-weight: var(--weight-ui);
  background: var(--bg-elevated);
  color: var(--text);
  box-shadow: var(--ring);
  transition: background 120ms ease, box-shadow 120ms ease, color 120ms ease;
  white-space: nowrap;
}

.btn:hover {
  background: var(--bg-hover);
  box-shadow: var(--ring-strong);
}

.btn:active {
  background: var(--bg-active);
}

.btn-primary {
  background: var(--cta-bg);
  color: var(--cta-text);
  box-shadow: none;
}

.btn-primary:hover {
  background: var(--cta-hover);
  box-shadow: none;
}

.btn-ghost {
  background: transparent;
  box-shadow: none;
  color: var(--text-muted);
}

.btn-ghost:hover {
  background: var(--bg-hover);
  color: var(--text);
  box-shadow: none;
}

.btn-danger {
  color: var(--danger);
}

.btn-danger:hover {
  background: var(--danger-soft);
  color: var(--danger);
  box-shadow: none;
}

.btn-icon {
  width: 32px;
  padding: 0;
}

.btn-sm {
  height: 28px;
  padding: 0 8px;
  font-size: 12px;
}

.btn svg {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
}

/* Preset Trigger */
.preset-wrap {
  position: relative;
}

.preset-trigger {
  max-width: 170px;
  justify-content: space-between;
  padding: 0 8px 0 10px;
}

.preset-trigger-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.preset-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  flex-shrink: 0;
}

/* Popover */
.popover {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: 300px;
  max-width: calc(100vw - 24px);
  background: var(--bg-elevated);
  border-radius: var(--radius-lg);
  box-shadow: var(--popover-shadow);
  padding: 12px;
  z-index: 60;
  display: none;
}

.popover.open {
  display: block;
}

.popover-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.popover-title {
  font-size: 12px;
  font-weight: var(--weight-head);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-family: var(--font-mono);
}

.save-row {
  display: flex;
  gap: 6px;
  margin-bottom: 10px;
}

.text-input {
  flex: 1;
  min-width: 0;
  height: 34px;
  padding: 0 10px;
  border-radius: var(--radius-md);
  background: var(--bg-subtle);
  box-shadow: var(--ring);
  color: var(--text);
  font-size: 14px;
}

.text-input::placeholder {
  color: var(--text-faint);
}

.save-actions {
  display: flex;
  gap: 6px;
  margin-bottom: 10px;
}

.save-actions .btn {
  flex: 1;
}

.preset-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 240px;
  overflow-y: auto;
  padding-top: 8px;
  border-top: 1px solid var(--divider);
}

.preset-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  border-radius: var(--radius-md);
  transition: background 100ms ease;
}

.preset-item:hover {
  background: var(--bg-hover);
}

.preset-item.active {
  background: var(--accent-soft);
}

.preset-item-main {
  flex: 1;
  min-width: 0;
  text-align: left;
}

.preset-item-name {
  font-size: 13px;
  font-weight: var(--weight-ui);
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.preset-item-meta {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.preset-empty {
  padding: 14px 8px;
  text-align: center;
  font-size: 12px;
  color: var(--text-faint);
}

/* URL Load Banner */
.url-banner {
  max-width: 1040px;
  margin: 10px auto 0;
  padding: 0 16px;
  display: none;
}

.url-banner.show {
  display: block;
}

.url-banner-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 12px;
  border-radius: var(--radius-lg);
  background: var(--accent-soft);
  color: var(--accent-text);
  font-size: 12px;
  font-weight: var(--weight-ui);
}

/* Main Container */
.container {
  max-width: 1040px;
  margin: 0 auto;
  padding: 16px 16px 40px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* Card (Vercel Shadow-as-Border / Linear Translucent Surface) */
.card {
  background: var(--bg-elevated);
  border-radius: var(--radius-lg);
  box-shadow: var(--card-shadow);
  padding: 14px;
}

[data-theme="dark"] .card {
  background: rgba(255, 255, 255, 0.025);
}

.section-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 6px 8px;
  margin-bottom: 12px;
}

.section-title-group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 8px;
  min-width: 0;
}

.section-label {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: var(--weight-ui);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.pill {
  display: inline-flex;
  align-items: center;
  height: 22px;
  padding: 0 8px;
  border-radius: var(--radius-pill);
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: var(--weight-ui);
  background: var(--bg-subtle);
  color: var(--text-secondary);
  box-shadow: var(--ring-light);
  white-space: nowrap;
}

.pill-accent {
  background: var(--accent-soft);
  color: var(--accent-text);
  box-shadow: none;
}

.pill-danger {
  background: var(--danger-soft);
  color: var(--danger);
  box-shadow: none;
}

/* Round Control */
.turn-control {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.turn-label {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: var(--weight-ui);
  letter-spacing: 0.03em;
  color: var(--text-muted);
  white-space: nowrap;
}

/* Stepper */
.stepper {
  display: inline-flex;
  align-items: center;
  border-radius: var(--radius-md);
  background: var(--bg-elevated);
  box-shadow: var(--ring);
  overflow: hidden;
}

.stepper-btn {
  width: 30px;
  height: 30px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-size: 15px;
  color: var(--text-secondary);
  transition: background 100ms ease, color 100ms ease;
}

.stepper-btn:hover:not(:disabled) {
  background: var(--bg-hover);
  color: var(--text);
}

.stepper-btn:active:not(:disabled) {
  background: var(--bg-active);
}

.stepper-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.stepper-input {
  width: 36px;
  height: 30px;
  text-align: center;
  font-family: var(--font-mono);
  font-size: 14px;
  font-weight: var(--weight-head);
  color: var(--text);
  font-variant-numeric: tabular-nums;
  -moz-appearance: textfield;
}

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

/* Domain Target Cards Row */
.domain-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.group-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 6px 5px 8px;
  border-radius: var(--radius-md);
  background: var(--bg-subtle);
  box-shadow: var(--ring);
}

.group-name-input {
  width: 34px;
  height: 28px;
  padding: 0 4px;
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: var(--weight-head);
  text-align: center;
  color: var(--text);
  background: transparent;
  transition: background 100ms ease, box-shadow 100ms ease;
}

.group-name-input:hover {
  background: var(--bg-hover);
}

.group-name-input:focus {
  background: var(--bg-elevated);
  box-shadow: var(--focus-ring);
  width: 58px;
}

.group-del {
  width: 24px;
  height: 24px;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-faint);
  font-size: 14px;
  line-height: 1;
}

.group-del:hover {
  background: var(--danger-soft);
  color: var(--danger);
}

.add-group-btn {
  height: 40px;
  padding: 0 12px;
  border-radius: var(--radius-md);
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: var(--weight-ui);
  color: var(--text);
  background: var(--bg-elevated);
  box-shadow: var(--ring-strong);
  transition: background 100ms ease, box-shadow 100ms ease;
}

.add-group-btn:hover {
  background: var(--bg-hover);
  box-shadow: 0 0 0 1px var(--accent);
}

/* Selectors Grid */
.selectors-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
  gap: 10px;
}

.selector-card {
  border-radius: var(--radius-lg);
  background: var(--bg-subtle);
  box-shadow: var(--ring);
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  transition: box-shadow 160ms ease;
}

.selector-card.just-added {
  box-shadow: 0 0 0 2px var(--accent);
}

.selector-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.selector-title-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.selector-idx {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: var(--weight-ui);
  color: var(--text-faint);
  flex-shrink: 0;
}

.selector-code {
  font-family: var(--font-mono);
  font-size: 14px;
  font-weight: var(--weight-head);
  letter-spacing: -0.02em;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.given-badge {
  display: inline-flex;
  align-items: center;
  height: 20px;
  padding: 0 6px;
  border-radius: var(--radius-pill);
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: var(--weight-ui);
  background: var(--bg-elevated);
  color: var(--text-secondary);
  box-shadow: var(--ring);
  white-space: nowrap;
  flex-shrink: 0;
}

.given-section {
  padding-top: 8px;
  border-top: 1px dashed var(--divider);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.given-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.given-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 6px 2px 0;
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: var(--weight-ui);
  color: var(--text-muted);
  transition: color 100ms ease;
}

.given-toggle:hover {
  color: var(--text);
}

.given-toggle.has-given {
  color: var(--text);
}

.given-summary {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--accent-text);
}

.given-toggle:not(.has-given) .given-summary {
  color: var(--text-faint);
}

.th-given {
  display: block;
  font-size: 10px;
  font-weight: var(--weight-ui);
  color: var(--accent-text);
  line-height: 1.2;
  margin-top: 2px;
}

.selector-right {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.selector-preview {
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: var(--weight-head);
  color: var(--accent-text);
  background: var(--accent-soft);
  padding: 2px 7px;
  border-radius: var(--radius-pill);
  margin-right: 2px;
}

.cond-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.cond-tile {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 5px 4px 8px;
  border-radius: var(--radius-md);
  background: var(--bg-elevated);
  box-shadow: var(--ring);
  transition: box-shadow 100ms ease, opacity 120ms ease;
}

.cond-tile.is-any {
  opacity: 0.62;
}

.cond-tile.is-any:hover {
  opacity: 0.9;
}

.cond-tile.is-active {
  box-shadow: 0 0 0 1px var(--accent);
}

.cond-tile.is-over {
  box-shadow: 0 0 0 1px var(--danger);
}

.cond-tile.is-over .cond-val {
  color: var(--danger);
}

.cond-label {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: var(--weight-head);
  color: var(--text);
  min-width: 14px;
}

.op-btn {
  min-width: 28px;
  height: 26px;
  padding: 0 5px;
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: var(--weight-head);
  background: var(--bg-subtle);
  color: var(--text-muted);
  box-shadow: var(--ring-light);
  transition: background 100ms ease, color 100ms ease;
}

.cond-tile.is-active .op-btn {
  background: var(--accent-soft);
  color: var(--accent-text);
  box-shadow: none;
}

.cond-tile .stepper {
  box-shadow: none;
  background: transparent;
}

.cond-tile .stepper-btn {
  width: 26px;
  height: 26px;
  border-radius: var(--radius-sm);
  font-size: 14px;
}

.cond-val {
  min-width: 20px;
  text-align: center;
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: var(--weight-head);
  color: var(--text);
}

.legend-inline {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-faint);
}

/* Probability Matrix Table */
.table-card {
  padding: 0;
  overflow: hidden;
}

.table-head-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 14px 10px;
  border-bottom: 1px solid var(--divider);
}

.table-scroll {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

table.prob-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-variant-numeric: tabular-nums;
}

.prob-table th,
.prob-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--divider);
  white-space: nowrap;
}

.prob-table tbody tr:last-child td {
  border-bottom: none;
}

.prob-table thead th {
  background: var(--bg-subtle);
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: var(--weight-head);
  color: var(--text-secondary);
  text-align: right;
  vertical-align: bottom;
}

.prob-table thead th:first-child {
  text-align: left;
  position: sticky;
  left: 0;
  z-index: 3;
  box-shadow: var(--sticky-shadow);
  min-width: 116px;
}

.th-idx {
  display: block;
  font-size: 10px;
  font-weight: var(--weight-ui);
  color: var(--text-faint);
  line-height: 1.1;
  margin-bottom: 2px;
}

.th-expr {
  color: var(--text);
  font-size: 13px;
}

/* Sticky Draw Column */
.prob-table tbody td:first-child {
  position: sticky;
  left: 0;
  z-index: 2;
  background: var(--bg-elevated);
  box-shadow: var(--sticky-shadow);
  text-align: left;
}

[data-theme="dark"] .prob-table tbody td:first-child {
  background: #0f1011;
}

.prob-table tbody tr.row-mull td {
  background: var(--row-mull-bg);
}

.prob-table tbody tr.row-mull td:first-child {
  background: var(--bg-subtle);
}

.prob-table tbody tr.row-base td {
  background: var(--row-base-bg);
}

.prob-table tbody tr.row-base td:first-child {
  background: var(--row-base-bg);
  box-shadow: inset 3px 0 0 0 var(--accent), var(--sticky-shadow);
}

[data-theme="dark"] .prob-table tbody tr.row-base td:first-child {
  background: #14172a;
}

.draw-cell {
  display: flex;
  align-items: baseline;
  gap: 7px;
}

.draw-num {
  font-family: var(--font-mono);
  font-size: 15px;
  font-weight: var(--weight-head);
  color: var(--text);
  min-width: 22px;
}

.draw-tag {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: var(--weight-ui);
  color: var(--text-muted);
  padding: 1px 5px;
  border-radius: var(--radius-sm);
  background: var(--bg-hover);
}

.row-base .draw-tag {
  background: var(--accent-soft);
  color: var(--accent-text);
}

/* Probability Cells */
.prob-cell {
  text-align: right;
  font-family: var(--font-mono);
  font-size: 14px;
  font-weight: var(--weight-ui);
  color: var(--text);
  position: relative;
  min-width: 84px;
}

.prob-cell.lvl-high {
  font-weight: var(--weight-head);
}

.prob-cell.lvl-zero {
  color: var(--text-faint);
}

.prob-bar-track {
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: 3px;
  height: 2px;
  border-radius: 1px;
  background: transparent;
  overflow: hidden;
  pointer-events: none;
}

.prob-bar-fill {
  height: 100%;
  border-radius: 1px;
  background: var(--accent-bar);
  margin-left: auto;
}

.prob-cell.lvl-high .prob-bar-fill {
  background: var(--accent-bar-strong);
}

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: 20px;
  transform: translate(-50%, 16px);
  background: var(--cta-bg);
  color: var(--cta-text);
  padding: 8px 14px;
  border-radius: var(--radius-pill);
  font-size: 13px;
  font-weight: var(--weight-ui);
  box-shadow: var(--popover-shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity 150ms ease, transform 150ms ease;
  z-index: 100;
  white-space: nowrap;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* Precision Toggle */
.seg-toggle {
  display: inline-flex;
  padding: 2px;
  border-radius: var(--radius-md);
  background: var(--bg-subtle);
  box-shadow: var(--ring-light);
}

.seg-btn {
  height: 24px;
  padding: 0 7px;
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: var(--weight-ui);
  color: var(--text-muted);
}

.seg-btn.active {
  background: var(--bg-elevated);
  color: var(--text);
  box-shadow: var(--ring);
}

/* ==========================================================================
   Mobile Responsive Optimization (< 640px)
   ========================================================================== */
@media (max-width: 640px) {
  .topbar-inner {
    padding: 8px 12px;
  }

  .brand-title {
    font-size: 14px;
  }

  .preset-trigger {
    max-width: 126px;
  }

  .btn .btn-label-desktop {
    display: none;
  }

  .container {
    padding: 10px 10px 32px;
    gap: 10px;
  }

  .card {
    padding: 12px;
  }

  .table-card {
    padding: 0;
  }

  .table-head-bar {
    padding: 10px 12px 8px;
  }

  .turn-control .stepper-input {
    font-size: 16px; /* Prevent iOS Safari auto-zoom */
    width: 34px;
    height: 32px;
  }

  .turn-control .stepper-btn {
    width: 32px;
    height: 32px;
  }

  .group-chip {
    padding: 4px 5px 4px 7px;
  }

  .group-name-input {
    font-size: 16px; /* Prevent iOS auto-zoom */
    width: 32px;
  }

  .group-chip .stepper-input {
    font-size: 16px;
    width: 32px;
  }

  .text-input {
    font-size: 16px; /* Prevent iOS auto-zoom */
  }

  .selectors-list {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .cond-tile {
    padding: 5px 6px 5px 8px;
  }

  .op-btn {
    min-width: 30px;
    height: 30px;
  }

  .cond-tile .stepper-btn {
    width: 30px;
    height: 30px;
  }

  .prob-table th,
  .prob-table td {
    padding: 9px 10px;
  }

  .prob-table thead th:first-child {
    min-width: 102px;
  }

  .prob-cell {
    min-width: 78px;
    font-size: 13px;
  }

  .draw-num {
    font-size: 14px;
  }

  .popover {
    position: fixed;
    top: 56px;
    right: 10px;
    left: 10px;
    width: auto;
    max-width: none;
  }
}

@media (max-width: 380px) {
  .brand-title {
    display: none;
  }
}
