:root {
  color-scheme: light;
  --lab-bg: #f4f4f3;
  --lab-surface: #ffffff;
  --lab-surface-muted: #f8f7f6;
  --lab-surface-strong: #ecebea;
  --lab-text: #27231f;
  --lab-muted: #746c65;
  --lab-faint: #978f87;
  --lab-border: #ddd9d5;
  --lab-border-strong: #bdb7b1;
  --lab-primary: #b65742;
  --lab-primary-hover: #9f4837;
  --lab-primary-soft: #f7e7e1;
  --lab-success: #2f7d68;
  --lab-success-hover: #286b5a;
  --lab-success-soft: #e4f0eb;
  --lab-danger: #b23b32;
  --lab-danger-soft: #fbe8e6;
  --lab-focus: rgba(182, 87, 66, 0.24);
  --lab-upload: #414543;
  --lab-upload-hover: #303432;
  --lab-preview: #eaeae8;
  --lab-switch-off: #c7c5c2;
  --lab-code-bg: #292521;
  --lab-code-text: #f8f3ee;
  --lab-overlay: rgba(255, 255, 255, 0.94);
  --lab-toast-bg: #2c2824;
  --lab-toast-text: #fffaf6;
  --lab-toast-border: #423c36;
  --lab-shadow: 0 1px 2px rgba(63, 47, 37, 0.06), 0 8px 24px rgba(63, 47, 37, 0.035);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
  font-synthesis: none;
  line-height: 1.5;
}

html[data-theme="dark"] {
  color-scheme: dark;
  --lab-bg: #171817;
  --lab-surface: #202220;
  --lab-surface-muted: #272925;
  --lab-surface-strong: #30322e;
  --lab-text: #f1f2ee;
  --lab-muted: #b4b7b0;
  --lab-faint: #858982;
  --lab-border: #3b3e39;
  --lab-border-strong: #60655d;
  --lab-primary: #b65440;
  --lab-primary-hover: #a34837;
  --lab-primary-soft: #452b25;
  --lab-success: #2f8069;
  --lab-success-hover: #276e5b;
  --lab-success-soft: #213b33;
  --lab-danger: #ffb3a8;
  --lab-danger-soft: #3a211e;
  --lab-focus: rgba(218, 119, 95, 0.34);
  --lab-upload: #434945;
  --lab-upload-hover: #505852;
  --lab-preview: #181b19;
  --lab-switch-off: #5d625d;
  --lab-code-bg: #0f1110;
  --lab-code-text: #f2f3ef;
  --lab-overlay: rgba(32, 34, 32, 0.95);
  --lab-toast-bg: #f2f3ef;
  --lab-toast-text: #20231f;
  --lab-toast-border: #d8dcd5;
  --lab-shadow: 0 1px 2px rgba(0, 0, 0, 0.34), 0 10px 28px rgba(0, 0, 0, 0.12);
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--lab-bg);
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
  background: var(--lab-bg) !important;
  color: var(--lab-text) !important;
  -webkit-font-smoothing: antialiased;
  transition: background-color 180ms ease, color 180ms ease;
}

button,
input,
select,
textarea {
  font: inherit;
}

button,
a,
input,
select,
textarea {
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
[tabindex]:focus-visible {
  outline: 3px solid var(--lab-focus) !important;
  outline-offset: 2px;
}

button {
  min-height: 40px;
  border: 0 !important;
  border-radius: 6px !important;
  padding: 9px 13px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  background: var(--lab-primary) !important;
  color: #fff !important;
  box-shadow: none !important;
  font-weight: 650;
  line-height: 1.2;
  letter-spacing: 0;
  cursor: pointer;
  transition: background-color 150ms ease, border-color 150ms ease, color 150ms ease, opacity 150ms ease !important;
}

button:hover {
  background: var(--lab-primary-hover) !important;
  transform: none !important;
}

button:active {
  transform: none !important;
}

button:disabled {
  cursor: not-allowed !important;
  border-color: var(--lab-border) !important;
  background: var(--lab-surface-strong) !important;
  color: var(--lab-faint) !important;
  opacity: 0.72 !important;
  transform: none !important;
}

button svg,
a svg {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.sr-only {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

.app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Homepage */
.home-page {
  background: var(--lab-bg);
}

.home-main {
  width: min(920px, calc(100% - 40px));
  margin: 0 auto;
  padding: 56px 0 72px;
}

.home-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 28px;
}

.home-brand h1 {
  margin: 0;
  color: var(--lab-text);
  font-size: clamp(30px, 4vw, 44px);
  font-weight: 760;
  line-height: 1.08;
  letter-spacing: 0;
}

.home-brand p {
  margin: 9px 0 0;
  color: var(--lab-muted);
  font-size: 14px;
}

.lab-count {
  color: var(--lab-muted);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.home-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.theme-toggle {
  width: 36px !important;
  min-width: 36px !important;
  height: 36px !important;
  min-height: 36px !important;
  flex: 0 0 36px !important;
  padding: 0 !important;
  border: 1px solid var(--lab-border) !important;
  background: var(--lab-surface) !important;
  color: var(--lab-muted) !important;
}

.theme-toggle:hover {
  border-color: var(--lab-border-strong) !important;
  background: var(--lab-surface-muted) !important;
  color: var(--lab-text) !important;
}

.lab-header-inner > .theme-toggle {
  margin-left: auto;
}

.home-toolbar {
  display: grid;
  grid-template-columns: minmax(240px, 1fr) auto;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.domain-filter {
  min-height: 40px;
  display: inline-grid;
  grid-auto-flow: column;
  grid-auto-columns: max-content;
  align-items: center;
  gap: 2px;
  padding: 3px;
  border: 1px solid var(--lab-border);
  border-radius: 7px;
  background: var(--lab-surface-strong);
}

.domain-filter button {
  min-width: 48px;
  min-height: 32px;
  padding: 6px 10px;
  background: transparent !important;
  color: var(--lab-muted) !important;
  font-size: 12px;
}

.domain-filter button:hover {
  background: var(--lab-surface) !important;
  color: var(--lab-text) !important;
}

.domain-filter button[aria-pressed="true"] {
  background: var(--lab-surface) !important;
  color: var(--lab-primary-hover) !important;
  box-shadow: var(--lab-shadow) !important;
}

.search-field {
  min-height: 44px;
  flex: 1;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 10px 0 13px;
  border: 1px solid var(--lab-border);
  border-radius: 7px;
  background: var(--lab-surface);
  box-shadow: var(--lab-shadow);
  transition: border-color 150ms ease, box-shadow 150ms ease;
}

.search-field:focus-within {
  border-color: var(--lab-primary);
  box-shadow: 0 0 0 3px var(--lab-focus);
}

.search-field > svg {
  width: 18px;
  height: 18px;
  flex: none;
  color: var(--lab-muted);
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
}

.search-field input {
  min-width: 0;
  width: 100%;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--lab-text);
  font-size: 15px;
}

.search-field input::placeholder {
  color: var(--lab-faint);
}

.search-clear {
  width: 32px;
  min-width: 32px;
  min-height: 32px;
  height: 32px;
  padding: 0;
  background: transparent !important;
  color: var(--lab-muted) !important;
}

.search-clear:hover {
  background: var(--lab-surface-strong) !important;
  color: var(--lab-text) !important;
}

.project-list {
  display: grid;
  gap: 8px;
}

.project {
  min-height: 76px;
  display: grid;
  grid-template-columns: 54px minmax(0, 1fr) auto 24px;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  border: 1px solid var(--lab-border) !important;
  border-radius: 7px !important;
  background: var(--lab-surface) !important;
  color: var(--lab-text) !important;
  box-shadow: var(--lab-shadow) !important;
  text-decoration: none;
  transition: border-color 150ms ease, background-color 150ms ease !important;
}

.project:hover {
  border-color: color-mix(in srgb, var(--lab-primary) 34%, var(--lab-border)) !important;
  background: var(--lab-surface-muted) !important;
}

.project-index {
  color: var(--lab-primary);
  font-size: 13px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.project-body {
  min-width: 0;
}

.project-title {
  display: block;
  margin-bottom: 3px;
  overflow: hidden;
  color: var(--lab-text);
  font-size: 15px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.project-description {
  display: block;
  overflow: hidden;
  color: var(--lab-muted) !important;
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.project-domain {
  padding: 4px 8px;
  border-radius: 4px;
  background: var(--lab-surface-strong);
  color: var(--lab-muted);
  font-size: 12px;
  white-space: nowrap;
}

.project[data-domain="image"] .project-domain {
  background: var(--lab-primary-soft);
  color: var(--lab-primary-hover);
}

.project[data-domain="text"] .project-domain {
  background: var(--lab-success-soft);
  color: var(--lab-success);
}

.project-arrow {
  width: 18px;
  height: 18px;
  color: var(--lab-faint);
}

.empty-state {
  display: none;
  min-height: 120px;
  place-items: center;
  border: 1px dashed var(--lab-border-strong);
  border-radius: 7px;
  background: var(--lab-surface-muted);
  color: var(--lab-muted);
  font-size: 14px;
}

.project-list.is-empty .empty-state {
  display: grid;
}

.project[hidden] {
  display: none;
}

/* Shared Lab shell */
.lab-header,
body > .app > header {
  display: block !important;
  padding: 0 !important;
  border-bottom: 1px solid var(--lab-border) !important;
  background: var(--lab-surface) !important;
  box-shadow: none !important;
  backdrop-filter: none !important;
}

.lab-header-inner,
body > .app > header > .title-area {
  width: min(1120px, calc(100% - 40px));
  min-height: 72px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 12px;
}

.title-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.title-area h1,
.lab-title h1,
header h1 {
  margin: 0;
  color: var(--lab-text) !important;
  font-size: 19px !important;
  font-weight: 740;
  line-height: 1.25;
  letter-spacing: 0;
}

.title-area p,
.lab-title p,
header p {
  margin: 3px 0 0 !important;
  color: var(--lab-muted) !important;
  font-size: 12px !important;
}

.home-link {
  width: 36px !important;
  min-width: 36px !important;
  height: 36px !important;
  min-height: 36px !important;
  padding: 0 !important;
  display: inline-flex !important;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--lab-border) !important;
  border-radius: 6px !important;
  background: var(--lab-surface) !important;
  color: var(--lab-text) !important;
  box-shadow: none !important;
  text-decoration: none;
}

.home-link:hover {
  border-color: var(--lab-border-strong) !important;
  background: var(--lab-surface-muted) !important;
}

.home-link svg {
  width: 17px !important;
  height: 17px !important;
}

.lab-main,
body > .app > main {
  width: 100%;
  flex: 1;
  display: block !important;
  padding: 24px 20px 40px !important;
}

.stage {
  width: min(1120px, 100%) !important;
  margin: 0 auto;
  display: flex !important;
  flex-direction: column;
  gap: 14px !important;
}

.lab-toolbar,
.mode-row {
  min-height: 44px;
  display: flex !important;
  align-items: center !important;
  justify-content: space-between !important;
  gap: 10px;
  flex-wrap: wrap;
}

.mode-left {
  min-width: 0;
  display: flex !important;
  align-items: center;
  justify-content: flex-start !important;
  gap: 10px;
  flex-wrap: wrap;
}

.mode-switch {
  --mode-segment-width: 60px;
  position: relative !important;
  width: calc(var(--mode-segment-width) * 2 + 8px);
  min-width: calc(var(--mode-segment-width) * 2 + 8px);
  height: 44px;
  min-height: 44px;
  display: inline-grid !important;
  grid-template-columns: repeat(2, var(--mode-segment-width));
  align-items: center;
  gap: 0 !important;
  padding: 3px !important;
  flex: none;
  overflow: hidden;
  border: 1px solid var(--lab-border) !important;
  border-radius: 7px !important;
  background: var(--lab-surface-strong) !important;
  box-shadow: none !important;
}

.mode-switch::before {
  content: "";
  position: absolute;
  top: 3px;
  bottom: 3px;
  left: 3px;
  width: var(--mode-segment-width);
  border: 1px solid var(--lab-border);
  border-radius: 5px;
  background: var(--lab-surface);
  box-shadow: var(--lab-shadow);
  transition: transform 180ms ease;
}

.app.is-decrypt .mode-switch::before {
  transform: translateX(var(--mode-segment-width));
}

.mode-switch button {
  position: relative;
  z-index: 1;
  width: var(--mode-segment-width) !important;
  min-width: var(--mode-segment-width) !important;
  height: 36px !important;
  min-height: 36px !important;
  padding: 0 12px !important;
  background: transparent !important;
  color: var(--lab-muted) !important;
  font-size: 13px;
  line-height: 1 !important;
}

.mode-switch button:hover,
.mode-switch button.is-active {
  background: transparent !important;
  color: var(--lab-text) !important;
}

.segmented-control {
  --segment-width: 58px;
  height: 44px;
  min-height: 44px;
  display: inline-grid;
  grid-template-columns: repeat(2, var(--segment-width));
  align-items: center;
  gap: 2px;
  padding: 3px;
  flex: none;
  border: 1px solid var(--lab-border);
  border-radius: 7px;
  background: var(--lab-surface-strong);
}

.segmented-control button {
  width: var(--segment-width) !important;
  min-width: var(--segment-width) !important;
  height: 36px !important;
  min-height: 36px !important;
  padding: 0 10px !important;
  background: transparent !important;
  color: var(--lab-muted) !important;
  font-size: 13px;
}

.segmented-control button:hover {
  background: color-mix(in srgb, var(--lab-surface) 58%, transparent) !important;
  color: var(--lab-text) !important;
}

.segmented-control button.is-active {
  border: 1px solid var(--lab-border) !important;
  background: var(--lab-surface) !important;
  color: var(--lab-text) !important;
  box-shadow: var(--lab-shadow) !important;
}

.password-box,
.control,
.readonly-info,
.card-control,
.switch-card {
  min-height: 40px;
  display: flex !important;
  align-items: center;
  gap: 9px;
  border: 1px solid var(--lab-border) !important;
  border-radius: 6px !important;
  background: var(--lab-surface) !important;
  color: var(--lab-text) !important;
  box-shadow: none !important;
  font-size: 13px;
  font-weight: 600;
}

.control,
.readonly-info {
  padding: 6px 8px 6px 11px !important;
}

.password-box {
  height: 44px;
  min-height: 44px;
  padding: 3px 4px 3px 11px !important;
}

.password-box label,
.control > span,
.readonly-info > span {
  color: var(--lab-muted);
  font-weight: 550;
}

.password-box input {
  width: 94px !important;
  min-width: 0;
  border: 0 !important;
  outline: 0 !important;
  background: transparent !important;
  color: var(--lab-text) !important;
  font-weight: 550 !important;
}

.password-box input::placeholder {
  color: var(--lab-faint);
}

.random-password-btn,
.icon-button,
.twist-lock,
.parameter-toggle {
  width: 36px !important;
  min-width: 36px !important;
  height: 36px !important;
  min-height: 36px !important;
  padding: 0 !important;
  flex: 0 0 36px !important;
  background: transparent !important;
  color: var(--lab-muted) !important;
}

.random-password-btn:hover,
.icon-button:hover,
.twist-lock:hover,
.parameter-toggle:hover {
  background: var(--lab-surface-strong) !important;
  color: var(--lab-text) !important;
}

.upload-btn {
  background: var(--lab-upload) !important;
}

.upload-btn:hover {
  background: var(--lab-upload-hover) !important;
}

.secondary-btn {
  min-height: 44px;
  border: 1px solid var(--lab-border) !important;
  background: var(--lab-surface) !important;
  color: var(--lab-text) !important;
}

.secondary-btn:hover {
  border-color: var(--lab-border-strong) !important;
  background: var(--lab-surface-muted) !important;
}

.export-btn {
  flex: none !important;
  width: auto !important;
  background: var(--lab-success) !important;
}

.export-btn:hover {
  background: var(--lab-success-hover) !important;
}

.clear-btn {
  background: transparent !important;
  color: var(--lab-muted) !important;
}

.clear-btn:hover {
  background: var(--lab-surface-strong) !important;
  color: var(--lab-danger) !important;
}

.parameter-section {
  display: grid;
  grid-template-rows: 1fr;
  opacity: 1;
  transform: translateY(0);
  transition: grid-template-rows 220ms ease, opacity 170ms ease, transform 220ms ease;
}

.parameter-inner {
  min-height: 0;
  overflow: hidden;
  display: grid;
  gap: 10px;
}

.controls-panel {
  width: 100%;
  display: block !important;
}

.controls {
  width: 100%;
  display: grid !important;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  align-items: stretch;
  gap: 8px !important;
}

.card-control,
.switch-card {
  height: 48px;
  min-height: 48px;
  min-width: 0 !important;
  padding: 5px 10px !important;
  justify-content: space-between;
}

.card-control {
  grid-column: span 3;
}

.split-control,
.grid-control,
.grid-info {
  grid-column: span 2;
}

.controls > .control {
  grid-column: span 3;
  min-height: 48px;
}

.card-control > label {
  flex: none;
  white-space: nowrap;
}

.card-control input[type="range"],
.quality-control input[type="range"] {
  min-width: 72px;
  flex: 1;
  accent-color: var(--lab-primary);
}

.value-badge {
  min-width: 44px;
  padding: 3px 6px;
  border-radius: 4px !important;
  background: var(--lab-primary-soft) !important;
  color: var(--lab-primary-hover) !important;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  text-align: center;
}

.switch {
  position: relative;
  width: 42px !important;
  height: 24px !important;
  display: inline-block;
  flex: 0 0 42px;
}

.switch input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.knob {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background: var(--lab-switch-off) !important;
  cursor: pointer;
  transition: background-color 160ms ease;
}

.knob::before {
  content: "";
  position: absolute;
  width: 18px !important;
  height: 18px !important;
  top: 3px !important;
  left: 3px !important;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(17, 24, 39, 0.2);
  transition: transform 160ms ease;
}

.switch input:checked + .knob {
  background: var(--lab-primary) !important;
}

.switch input:checked + .knob::before {
  transform: translateX(18px) !important;
}

.switch input:focus-visible + .knob {
  outline: 3px solid var(--lab-focus);
  outline-offset: 2px;
}

.twist-lock[aria-pressed="true"] {
  background: var(--lab-primary-soft) !important;
  color: var(--lab-primary-hover) !important;
}

.twist-lock .icon-locked {
  display: none;
}

.twist-lock[aria-pressed="true"] .icon-unlocked {
  display: none;
}

.twist-lock[aria-pressed="true"] .icon-locked {
  display: block;
}

.encrypt-password-panel,
.decrypt-panel {
  align-items: center;
  gap: 8px;
}

.decrypt-panel {
  display: none;
}

.app.is-decrypt .encrypt-panel,
.app.is-decrypt .encrypt-password-panel {
  display: none !important;
}

.app.is-decrypt .decrypt-panel {
  display: flex !important;
}

.decrypt-parameters {
  display: none;
}

.app.is-decrypt .decrypt-parameters {
  display: block;
  animation: lab-enter 180ms ease both;
}

.decrypt-summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.decrypt-summary .readonly-info {
  min-width: 0;
  min-height: 48px;
  justify-content: space-between;
  padding: 7px 10px !important;
  background: var(--lab-surface-strong) !important;
}

.decrypt-summary .readonly-info strong {
  min-width: 0;
  overflow: hidden;
  color: var(--lab-text);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.decrypt-summary .decrypt-summary-empty {
  grid-column: 1 / -1;
  justify-content: flex-start;
}

.decrypt-parameter-note {
  min-height: 44px;
  padding: 8px 10px !important;
  background: var(--lab-surface-strong) !important;
  color: var(--lab-muted) !important;
  font-size: 12px;
}

.parameter-toggle {
  display: none !important;
  border: 1px solid var(--lab-border) !important;
  background: var(--lab-surface) !important;
}

.parameter-toggle svg {
  transition: transform 180ms ease;
}

.app.parameters-collapsed .parameter-toggle svg {
  transform: rotate(180deg);
}

.metadata-panel {
  display: none;
  width: 100%;
  padding: 10px !important;
  border: 1px solid var(--lab-border) !important;
  border-radius: 7px !important;
  background: var(--lab-surface-strong) !important;
  color: var(--lab-text) !important;
  box-shadow: none !important;
}

.metadata-panel.is-visible {
  display: grid;
  gap: 8px;
  animation: lab-enter 180ms ease both;
}

.metadata-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 6px;
}

.metadata-item {
  min-width: 0;
  padding: 8px 9px;
  border: 0 !important;
  border-radius: 5px !important;
  background: var(--lab-surface) !important;
}

.metadata-item span {
  display: block;
  color: var(--lab-muted);
  font-size: 11px;
}

.metadata-item strong {
  display: block;
  margin-top: 2px;
  overflow-wrap: anywhere;
  font-size: 12px;
}

.metadata-raw {
  max-height: 160px;
  margin: 0;
  overflow: auto;
  padding: 10px;
  border-radius: 5px !important;
  background: var(--lab-code-bg) !important;
  color: var(--lab-code-text) !important;
  font: 12px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  white-space: pre-wrap;
}

.preview-card {
  position: relative;
  width: 100% !important;
  height: clamp(360px, 50vh, 560px);
  max-height: 560px;
  aspect-ratio: auto !important;
  display: grid !important;
  place-items: center;
  overflow: hidden;
  border: 1px solid var(--lab-border) !important;
  border-radius: 8px !important;
  background: var(--lab-preview) !important;
  box-shadow: none !important;
  cursor: pointer;
  isolation: isolate;
  transition: border-color 150ms ease, background-color 150ms ease !important;
}

.preview-card.is-dragging {
  border-color: var(--lab-primary) !important;
  background: var(--lab-primary-soft) !important;
}

.preview-card canvas,
.preview-card > img:not([hidden]) {
  width: 100% !important;
  height: 100% !important;
  display: none;
  object-fit: contain !important;
}

.preview-tools {
  position: absolute !important;
  top: 10px !important;
  right: 10px !important;
  z-index: 3;
  display: flex;
  align-items: center;
  gap: 6px !important;
}

.preview-tools button {
  min-height: 38px !important;
  padding: 8px 11px !important;
  flex: none !important;
  font-size: 12px;
  box-shadow: var(--lab-shadow) !important;
}

.preview-tools .icon-button,
.preview-tools .clear-btn {
  width: 38px !important;
  min-width: 38px !important;
  height: 38px !important;
  min-height: 38px !important;
  padding: 0 !important;
  border: 1px solid var(--lab-border) !important;
  background: var(--lab-overlay) !important;
}

.preview-card.is-empty .preview-tools button:not(.upload-btn) {
  display: none !important;
}

.placeholder {
  width: 100% !important;
  height: 100% !important;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 7px !important;
  padding: 64px 20px 24px !important;
  background: transparent !important;
  color: var(--lab-muted) !important;
  text-align: center;
}

.placeholder .icon {
  width: 44px !important;
  height: 44px !important;
  display: grid;
  place-items: center;
  border-radius: 6px !important;
  background: var(--lab-surface) !important;
  color: var(--lab-primary);
  box-shadow: var(--lab-shadow) !important;
}

.placeholder .icon svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.placeholder strong {
  color: var(--lab-text) !important;
  font-size: 15px !important;
}

.placeholder span {
  color: var(--lab-muted) !important;
  font-size: 12px !important;
}

.result-row,
.export-row {
  display: flex !important;
  align-items: center;
  justify-content: space-between !important;
  gap: 12px;
}

.result-row.is-empty {
  display: none !important;
}

.export-row {
  justify-content: flex-end !important;
}

.status-row,
.stats {
  min-width: 0;
  display: flex !important;
  align-items: stretch;
  justify-content: flex-start !important;
  gap: 7px !important;
  flex-wrap: wrap;
  color: var(--lab-muted) !important;
  font-size: 12px !important;
}

.pill,
.metric {
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 9px !important;
  border: 0 !important;
  border-radius: 5px !important;
  background: var(--lab-surface-strong) !important;
  color: var(--lab-muted) !important;
  box-shadow: none !important;
  white-space: nowrap;
}

.pill strong,
.metric strong {
  max-width: min(360px, 50vw);
  overflow: hidden;
  color: var(--lab-text);
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.hidden-file,
[hidden] {
  display: none !important;
}

/* Avatar generator */
.avatar-controls {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  align-items: stretch;
  gap: 8px;
}

.avatar-color-section {
  min-width: 0;
  display: grid;
  gap: 8px;
}

.avatar-settings-section {
  min-width: 0;
  display: grid;
}

.avatar-settings-section > .avatar-color-head {
  margin-bottom: 8px;
}

.avatar-settings-panel {
  display: grid;
  grid-template-rows: 0fr;
  opacity: 0;
  transform: translateY(-4px);
  transition: grid-template-rows 220ms ease, opacity 170ms ease, transform 220ms ease;
}

.app.avatar-settings-open .avatar-settings-panel {
  grid-template-rows: 1fr;
  opacity: 1;
  transform: translateY(0);
}

.avatar-settings-inner {
  min-height: 0;
  overflow: hidden;
}

.avatar-settings-grid {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  gap: 8px;
  padding-top: 8px;
}

.avatar-color-head {
  min-height: 38px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.avatar-color-head strong {
  color: var(--lab-text);
  font-size: 13px;
}

.avatar-color-advanced-btn {
  width: auto !important;
  min-height: 36px;
  padding: 7px 11px;
  font-size: 12px;
}

.avatar-disclosure-btn {
  gap: 5px;
}

.avatar-disclosure-btn svg {
  width: 14px;
  height: 14px;
  transition: transform 180ms ease;
}

.avatar-disclosure-btn[aria-expanded="true"] svg {
  transform: rotate(180deg);
}

.avatar-preset-area {
  min-width: 0;
}

.avatar-preset-grid {
  display: grid;
  grid-template-columns: repeat(9, minmax(0, 1fr));
  gap: 8px;
  animation: lab-enter 180ms ease both;
}

.avatar-preset {
  min-width: 0;
  min-height: 66px;
  align-items: stretch;
  flex-direction: column;
  gap: 6px;
  padding: 6px;
  border: 1px solid var(--lab-border) !important;
  background: var(--lab-surface) !important;
  color: var(--lab-muted) !important;
}

.avatar-preset:hover {
  border-color: var(--lab-border-strong) !important;
  background: var(--lab-surface-muted) !important;
  color: var(--lab-text) !important;
}

.avatar-preset.is-active {
  border-color: var(--lab-primary) !important;
  background: var(--lab-primary-soft) !important;
  color: var(--lab-text) !important;
}

.avatar-preset > span:last-child {
  min-width: 0;
  overflow: hidden;
  font-size: 12px;
  line-height: 1.2;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.avatar-preset-swatch {
  position: relative;
  width: 100%;
  height: 30px;
  flex: none;
  overflow: hidden;
  border: 1px solid color-mix(in srgb, var(--lab-border) 74%, transparent);
  border-radius: 4px;
  background: linear-gradient(var(--preset-angle), var(--preset-start), var(--preset-end));
}

.avatar-preset-swatch::after {
  position: absolute;
  right: 5px;
  bottom: 5px;
  width: 8px;
  height: 8px;
  border: 1px solid rgba(0, 0, 0, 0.24);
  border-radius: 50%;
  background: var(--preset-text);
  content: "";
}

.app.is-gradient .solid-preset-grid,
.app:not(.is-gradient) .gradient-preset-grid {
  display: none;
}

.avatar-color-advanced {
  display: none;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.app.is-color-advanced .avatar-preset-area {
  display: none;
}

.app.is-color-advanced .avatar-color-advanced {
  display: grid;
  animation: lab-enter 180ms ease both;
}

.app:not(.is-gradient) .avatar-color-advanced {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.avatar-span-2 {
  grid-column: span 2;
}

.avatar-span-3 {
  grid-column: span 3;
}

.avatar-span-4 {
  grid-column: 1 / -1;
}

.avatar-slider-control {
  width: auto !important;
  grid-column: span 2;
}

.avatar-slider-control input[type="range"] {
  min-width: 80px;
  flex: 1;
  accent-color: var(--lab-primary);
}

.avatar-text-control,
.avatar-color-control {
  min-width: 0;
  border: 1px solid var(--lab-border);
  border-radius: 6px;
  background: var(--lab-surface);
  color: var(--lab-text);
}

.avatar-text-control {
  min-height: 48px;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: start;
  gap: 10px;
  padding: 7px 10px;
}

.avatar-text-control label,
.avatar-color-control label,
.avatar-select-control label {
  color: var(--lab-muted);
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
}

.avatar-text-control > label {
  height: 32px;
  display: flex;
  align-items: center;
  line-height: 1;
}

.avatar-text-control textarea {
  width: 100%;
  min-width: 0;
  height: 32px;
  min-height: 32px;
  max-height: 180px;
  resize: vertical;
  border: 0;
  outline: 0;
  padding: 5px 0;
  background: transparent;
  color: var(--lab-text);
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.55;
}

.avatar-color-control {
  min-height: 48px;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 9px;
}

.avatar-color-control input[type="color"] {
  width: 32px;
  min-width: 32px;
  height: 32px;
  padding: 2px;
  border: 1px solid var(--lab-border);
  border-radius: 5px;
  background: var(--lab-surface-muted);
  cursor: pointer;
}

.avatar-color-control input[type="color"]::-webkit-color-swatch-wrapper {
  padding: 0;
}

.avatar-color-control input[type="color"]::-webkit-color-swatch {
  border: 0;
  border-radius: 3px;
}

.avatar-color-control > span {
  min-width: 0;
  margin-left: auto;
  overflow: hidden;
  color: var(--lab-muted);
  font: 11px/1.2 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.avatar-color-control.is-disabled {
  background: var(--lab-surface-strong);
}

.avatar-color-control.is-disabled input,
.avatar-color-control.is-disabled > span {
  opacity: 0.45;
}

.avatar-select-control {
  min-height: 48px;
  justify-content: space-between;
}

.avatar-select-control select {
  min-width: 120px;
  text-align: right;
}

.app.is-gradient .solid-only,
.app:not(.is-gradient) .gradient-only,
.app:not(.is-circle) .circle-only {
  display: none !important;
}

.avatar-preview-card {
  height: clamp(440px, 60vh, 660px);
  max-height: 660px;
  padding: 24px;
  cursor: zoom-in;
  background-color: var(--lab-preview) !important;
  background-image:
    linear-gradient(45deg, color-mix(in srgb, var(--lab-border) 38%, transparent) 25%, transparent 25%),
    linear-gradient(-45deg, color-mix(in srgb, var(--lab-border) 38%, transparent) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, color-mix(in srgb, var(--lab-border) 38%, transparent) 75%),
    linear-gradient(-45deg, transparent 75%, color-mix(in srgb, var(--lab-border) 38%, transparent) 75%);
  background-position: 0 0, 0 8px, 8px -8px, -8px 0;
  background-size: 16px 16px;
}

.avatar-preview-card canvas {
  width: min(100%, 600px, calc(clamp(440px, 60vh, 660px) - 50px)) !important;
  height: auto !important;
  aspect-ratio: 1;
  display: block !important;
  box-shadow: 0 8px 28px rgba(18, 20, 18, 0.14);
}

.avatar-result-row .status-row {
  flex: 1;
}

/* Compression */
.compression-controls {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) minmax(150px, 220px);
  gap: 8px;
}

.quality-control {
  min-height: 48px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border: 1px solid var(--lab-border);
  border-radius: 6px;
  background: var(--lab-surface);
  font-size: 13px;
  font-weight: 600;
}

.compression-controls > .control {
  min-height: 48px;
}

.control select,
.quality-control select {
  min-width: 90px;
  border: 0 !important;
  outline: 0;
  background: transparent !important;
  color: var(--lab-text) !important;
  cursor: pointer;
}

/* Text lab */
.text-stage {
  display: grid !important;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) !important;
  gap: 10px !important;
}

.text-panel {
  min-width: 0;
  min-height: 460px !important;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--lab-border) !important;
  border-radius: 7px !important;
  background: var(--lab-surface) !important;
  color: var(--lab-text) !important;
  box-shadow: none;
}

.panel-head {
  min-height: 48px !important;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 7px 8px 7px 13px !important;
  border-bottom: 1px solid var(--lab-border) !important;
  background: var(--lab-surface-muted) !important;
  color: var(--lab-muted) !important;
  font-size: 12px !important;
}

.panel-head strong {
  color: var(--lab-text) !important;
  font-size: 13px !important;
}

.panel-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: none;
}

.panel-actions button {
  min-height: 34px;
  height: 34px;
  padding: 7px 9px;
  font-size: 12px;
}

.panel-actions .icon-button {
  width: 34px !important;
  min-width: 34px !important;
  height: 34px !important;
  min-height: 34px !important;
  padding: 0 !important;
}

.panel-meta {
  margin-left: 6px;
  color: var(--lab-faint);
  font-variant-numeric: tabular-nums;
}

.text-panel textarea,
.text-panel .output {
  min-width: 0;
  flex: 1;
  width: 100%;
  margin: 0;
  overflow: auto;
  border: 0 !important;
  outline: 0;
  padding: 15px !important;
  resize: none;
  background: var(--lab-surface) !important;
  color: var(--lab-text) !important;
  caret-color: var(--lab-primary);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font: 14px/1.75 ui-monospace, SFMono-Regular, Menlo, Consolas, "Microsoft YaHei", monospace !important;
}

.text-panel textarea::placeholder {
  color: var(--lab-faint) !important;
}

.text-result-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.error {
  display: none;
  padding: 8px 10px;
  border: 1px solid color-mix(in srgb, var(--lab-danger) 36%, var(--lab-border));
  border-radius: 5px;
  background: var(--lab-danger-soft);
  color: var(--lab-danger);
  font-size: 12px;
}

.error.is-visible {
  display: block;
}

.lab-toast {
  position: fixed;
  left: 50%;
  bottom: max(20px, env(safe-area-inset-bottom));
  z-index: 10000;
  max-width: min(420px, calc(100% - 32px));
  padding: 10px 13px;
  border: 1px solid var(--lab-toast-border);
  border-radius: 6px;
  background: var(--lab-toast-bg);
  color: var(--lab-toast-text);
  box-shadow: 0 8px 24px rgba(63, 47, 37, 0.18);
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 8px);
  transition: opacity 160ms ease, transform 160ms ease;
}

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

.lab-toast[data-tone="error"] {
  border-color: #8f231c;
  background: #7a211b;
}

html[data-theme="dark"] .value-badge,
html[data-theme="dark"] .random-password-btn {
  color: #efa18e !important;
}

html[data-theme="dark"] .preview-card {
  background: var(--lab-preview) !important;
}

html[data-theme="dark"] .preview-tools .icon-button,
html[data-theme="dark"] .preview-tools .clear-btn {
  background: var(--lab-overlay) !important;
}

html[data-theme="dark"] .metadata-raw {
  background: var(--lab-code-bg) !important;
  color: var(--lab-code-text) !important;
}

html[data-theme="dark"] .error {
  border-color: #75413b;
  background: var(--lab-danger-soft);
  color: var(--lab-danger);
}

html[data-theme="dark"] .lab-toast {
  border-color: var(--lab-toast-border);
  background: var(--lab-toast-bg);
  color: var(--lab-toast-text);
}

html[data-theme="dark"] .lab-toast[data-tone="error"] {
  border-color: #ffb4ab;
  background: #5d2521;
  color: #fff;
}

html[data-theme="dark"] ::selection {
  background: #8f4939;
  color: #fff;
}

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

@media (max-width: 760px) {
  .home-main {
    width: min(100% - 24px, 920px);
    padding: 28px 0 40px;
  }

  .home-toolbar {
    grid-template-columns: minmax(0, 1fr);
    gap: 8px;
  }

  .domain-filter {
    max-width: 100%;
    justify-self: start;
    overflow-x: auto;
  }

  .home-header {
    align-items: flex-start;
    margin-bottom: 20px;
  }

  .home-actions {
    gap: 7px;
  }

  .home-brand h1 {
    font-size: 29px;
  }

  .project {
    grid-template-columns: 42px minmax(0, 1fr) 20px;
    gap: 10px;
    padding: 13px 12px;
  }

  .project-domain {
    display: none;
  }

  .lab-header-inner,
  body > .app > header > .title-area {
    width: calc(100% - 24px);
    min-height: 64px;
  }

  .title-area h1,
  .lab-title h1,
  header h1 {
    font-size: 17px !important;
  }

  .title-area p,
  .lab-title p,
  header p {
    margin-top: 2px !important;
    font-size: 11px !important;
  }

  .home-link,
  .theme-toggle {
    position: relative;
    width: 44px !important;
    min-width: 44px !important;
    height: 44px !important;
    min-height: 44px !important;
    border-color: transparent !important;
    background: transparent !important;
  }

  .home-link::before,
  .theme-toggle::before {
    content: "";
    position: absolute;
    inset: 5px;
    z-index: 0;
    border: 1px solid var(--lab-border);
    border-radius: 6px;
    background: var(--lab-surface);
  }

  .home-link:hover,
  .theme-toggle:hover {
    border-color: transparent !important;
    background: transparent !important;
  }

  .home-link:hover::before,
  .theme-toggle:hover::before {
    border-color: var(--lab-border-strong);
    background: var(--lab-surface-muted);
  }

  .home-link svg,
  .theme-toggle svg {
    position: relative;
    z-index: 1;
  }

  .lab-main,
  body > .app > main {
    padding: 14px 12px 28px !important;
  }

  .stage {
    gap: 10px !important;
  }

  .lab-toolbar,
  .mode-row {
    min-height: 40px;
  }

  .mode-left {
    max-width: calc(100% - 46px);
    gap: 7px;
  }

  .mode-switch {
    --mode-segment-width: 56px;
    width: calc(var(--mode-segment-width) * 2 + 8px);
    min-width: calc(var(--mode-segment-width) * 2 + 8px);
    height: 48px;
    min-height: 48px;
  }

  .mode-switch button {
    width: var(--mode-segment-width) !important;
    min-width: var(--mode-segment-width) !important;
    height: 40px !important;
    min-height: 40px !important;
    padding-inline: 9px !important;
  }

  .segmented-control {
    --segment-width: 54px;
    height: 48px;
    min-height: 48px;
  }

  .segmented-control button {
    height: 40px !important;
    min-height: 40px !important;
    padding-inline: 8px !important;
  }

  .password-box {
    min-width: 0 !important;
    height: 48px;
    min-height: 48px;
    padding: 3px 4px 3px 9px !important;
  }

  .lab-toolbar > .secondary-btn {
    min-height: 48px;
  }

  .password-box input {
    width: 66px !important;
  }

  .random-password-btn,
  .icon-button,
  .twist-lock,
  .parameter-toggle {
    width: 40px !important;
    min-width: 40px !important;
    height: 40px !important;
    min-height: 40px !important;
    flex-basis: 40px !important;
  }

  .parameter-toggle {
    display: inline-flex !important;
    margin-left: auto;
  }

  .app.parameters-collapsed .parameter-section {
    grid-template-rows: 0fr;
    opacity: 0;
    transform: translateY(-5px);
  }

  .controls {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .avatar-controls {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .avatar-preset-area {
    max-width: 100%;
    overflow-x: auto;
    padding-bottom: 4px;
    overscroll-behavior-x: contain;
    scroll-snap-type: x proximity;
    scrollbar-width: none;
  }

  .avatar-preset-area::-webkit-scrollbar {
    display: none;
  }

  .avatar-preset-grid {
    width: max-content;
    display: flex;
    grid-template-columns: none;
  }

  .avatar-preset {
    width: 112px;
    flex: 0 0 112px;
    scroll-snap-align: start;
  }

  .avatar-settings-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .avatar-color-advanced {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .avatar-color-advanced-btn {
    min-height: 40px;
  }

  .avatar-span-3,
  .avatar-span-4 {
    grid-column: 1 / -1;
  }

  .decrypt-summary {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .card-control {
    grid-column: 1 / -1;
  }

  .switch-card {
    width: auto !important;
    min-width: 0 !important;
  }

  .preview-card {
    height: auto;
    max-height: none;
    aspect-ratio: 4 / 5 !important;
  }

  .avatar-preview-card {
    height: auto;
    max-height: none;
    aspect-ratio: 1 !important;
    padding: 14px;
  }

  .avatar-preview-card canvas {
    width: 100% !important;
    height: auto !important;
  }

  .preview-tools {
    top: 8px !important;
    right: 8px !important;
  }

  .preview-tools button {
    min-height: 40px !important;
    padding: 8px 10px !important;
  }

  .preview-tools .icon-button,
  .preview-tools .clear-btn {
    width: 40px !important;
    min-width: 40px !important;
    height: 40px !important;
    min-height: 40px !important;
  }

  .result-row {
    align-items: flex-end;
  }

  .status-row,
  .stats {
    flex: 1;
  }

  .pill strong,
  .metric strong {
    max-width: 150px;
  }

  .compression-controls {
    grid-template-columns: 1fr;
  }

  .text-stage {
    grid-template-columns: minmax(0, 1fr) !important;
  }

  .text-panel {
    width: 100%;
    min-height: 300px !important;
  }

  .panel-actions button,
  .panel-actions .icon-button {
    min-height: 40px !important;
    height: 40px !important;
  }

  .panel-actions .icon-button {
    width: 40px !important;
    min-width: 40px !important;
  }
}

@media (max-width: 430px) {
  .title-area p,
  .lab-title p,
  header p {
    display: none;
  }

  .home-header {
    gap: 10px;
  }

  .lab-count {
    padding-top: 7px;
  }

  .mode-left {
    max-width: none;
  }

  .lab-toolbar,
  .mode-row {
    align-items: center !important;
  }

  .parameter-toggle {
    align-self: center;
  }

  .readonly-info.decrypt-parameter-note {
    display: none !important;
  }

  .preview-tools button:not(.icon-button):not(.clear-btn) {
    font-size: 12px;
  }

  .result-row {
    flex-wrap: wrap;
  }

  .result-row .export-btn {
    margin-left: auto;
  }
}

@media (min-width: 761px) {
  .parameter-section {
    grid-template-rows: 1fr !important;
    opacity: 1 !important;
    transform: none !important;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}

/* Coin toss */
.coin-page {
  overflow: hidden;
}

.coin-app {
  position: relative;
  width: 100%;
  min-height: 100vh;
  min-height: 100dvh;
  overflow: hidden;
  background: var(--lab-bg);
}

html[data-theme="dark"] .coin-app {
  background: var(--lab-bg);
}

.coin-nav {
  position: fixed;
  top: 20px;
  left: 20px;
  z-index: 4;
  display: flex;
  align-items: center;
  gap: 8px;
}

.coin-nav .home-link,
.coin-nav .theme-toggle {
  position: relative;
  width: 36px !important;
  min-width: 36px !important;
  height: 36px !important;
  min-height: 36px !important;
  flex: 0 0 36px !important;
  padding: 0 !important;
  display: inline-flex !important;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--lab-border) !important;
  background: color-mix(in srgb, var(--lab-surface) 90%, transparent) !important;
  backdrop-filter: blur(10px);
}

.coin-nav .home-link::before,
.coin-nav .theme-toggle::before {
  display: none !important;
}

.coin-nav .home-link svg,
.coin-nav .theme-toggle svg {
  position: static;
  z-index: auto;
  width: 17px !important;
  height: 17px !important;
}

.coin-settings-button,
.coin-history-button {
  position: fixed;
  right: 20px;
  z-index: 4;
  width: 36px !important;
  min-width: 36px !important;
  height: 36px !important;
  min-height: 36px !important;
  padding: 0 !important;
  border: 1px solid var(--lab-border) !important;
  background: color-mix(in srgb, var(--lab-surface) 90%, transparent) !important;
  color: var(--lab-muted) !important;
  backdrop-filter: blur(10px);
}

.coin-settings-button {
  top: 20px;
}

.coin-speed-button,
.coin-auto-button {
  position: fixed;
  top: 20px;
  z-index: 4;
  height: 36px !important;
  min-height: 36px !important;
  padding: 0 !important;
  border: 1px solid var(--lab-border) !important;
  background: color-mix(in srgb, var(--lab-surface) 90%, transparent) !important;
  color: var(--lab-muted) !important;
  font-size: 12px;
  font-weight: 750;
  letter-spacing: 0;
  backdrop-filter: blur(10px);
}

.coin-speed-button[hidden],
.coin-auto-button[hidden] {
  display: none !important;
}

.coin-speed-button {
  right: 64px;
  width: 42px !important;
  min-width: 42px !important;
}

.coin-auto-button {
  right: 114px;
  width: 48px !important;
  min-width: 48px !important;
  font-size: 11px;
}

.coin-speed-button:hover,
.coin-auto-button:hover {
  border-color: var(--lab-border-strong) !important;
  background: var(--lab-surface-strong) !important;
  color: var(--lab-text) !important;
}

.coin-speed-button[aria-pressed="true"] {
  border-color: color-mix(in srgb, var(--lab-primary) 58%, var(--lab-border)) !important;
  background: var(--lab-primary-soft) !important;
  color: var(--lab-primary) !important;
}

.coin-speed-button[aria-pressed="true"]:hover {
  border-color: var(--lab-primary) !important;
  background: color-mix(in srgb, var(--lab-primary-soft) 80%, var(--lab-surface)) !important;
}

.coin-auto-button[aria-pressed="true"] {
  border-color: color-mix(in srgb, var(--lab-success) 58%, var(--lab-border)) !important;
  background: var(--lab-success-soft) !important;
  color: var(--lab-success) !important;
}

.coin-auto-button[aria-pressed="true"]:hover {
  border-color: var(--lab-success) !important;
  background: color-mix(in srgb, var(--lab-success-soft) 80%, var(--lab-surface)) !important;
}

.coin-history-button {
  bottom: 20px;
}

.coin-settings-button:hover,
.coin-history-button:hover {
  border-color: var(--lab-border-strong) !important;
  background: var(--lab-surface-strong) !important;
  color: var(--lab-text) !important;
}

.coin-settings-button svg,
.coin-history-button svg {
  width: 17px;
  height: 17px;
}

.coin-settings-dialog {
  width: min(400px, calc(100vw - 32px));
  max-width: none;
  margin: auto;
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--lab-border);
  border-radius: 8px;
  background: var(--lab-surface);
  color: var(--lab-text);
  box-shadow: 0 18px 60px rgba(31, 25, 21, 0.2);
}

.coin-settings-dialog[open],
.coin-history-dialog[open] {
  animation: coin-dialog-in 180ms ease-out;
}

.coin-settings-dialog::backdrop,
.coin-history-dialog::backdrop {
  background: rgba(21, 19, 17, 0.42);
  backdrop-filter: blur(3px);
}

.coin-settings-form {
  display: grid;
}

.coin-settings-header {
  min-height: 56px;
  padding: 10px 12px 10px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--lab-border);
}

.coin-settings-header h2 {
  margin: 0;
  font-size: 17px;
  line-height: 1.25;
  letter-spacing: 0;
}

.coin-dialog-close {
  width: 32px !important;
  min-width: 32px !important;
  height: 32px !important;
  min-height: 32px !important;
  flex: 0 0 32px !important;
  padding: 0 !important;
}

.coin-dialog-close svg {
  width: 16px;
  height: 16px;
}

.coin-probability-fields {
  padding: 18px;
  display: grid;
  gap: 18px;
}

.coin-probability-control {
  display: grid;
  gap: 9px;
}

.coin-probability-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  color: var(--lab-text);
  font-size: 14px;
  font-weight: 650;
}

.coin-probability-number {
  height: 34px;
  padding: 0 9px;
  display: flex;
  align-items: center;
  gap: 3px;
  border: 1px solid var(--lab-border);
  border-radius: 6px;
  background: var(--lab-surface-muted);
  color: var(--lab-muted);
  font-size: 13px;
  font-weight: 550;
}

.coin-probability-number:focus-within {
  border-color: var(--lab-primary);
  box-shadow: 0 0 0 3px var(--lab-focus);
}

.coin-probability-number input {
  width: 42px;
  min-width: 0;
  padding: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--lab-text);
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.coin-probability-number input:focus-visible {
  outline: 0 !important;
}

.coin-probability-control > input[type="range"] {
  width: 100%;
  height: 20px;
  margin: 0;
  accent-color: var(--lab-primary);
  cursor: pointer;
}

.coin-probability-remainder {
  min-height: 44px;
  padding: 0 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border: 1px solid var(--lab-border);
  border-radius: 6px;
  background: var(--lab-surface-strong);
  color: var(--lab-muted);
  font-size: 14px;
  font-weight: 650;
}

.coin-probability-remainder output {
  color: var(--lab-text);
  font-variant-numeric: tabular-nums;
}

.coin-advanced-control {
  min-height: 48px;
  padding: 0 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border: 1px solid var(--lab-border);
  border-radius: 6px;
  background: var(--lab-surface-muted);
  color: var(--lab-text);
  font-size: 14px;
  font-weight: 650;
}

.coin-settings-actions {
  padding: 12px 18px 16px;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  border-top: 1px solid var(--lab-border);
}

.coin-settings-actions button {
  min-height: 38px;
}

.coin-history-dialog {
  width: min(620px, calc(100vw - 32px));
  max-width: none;
  max-height: calc(100vh - 32px);
  max-height: calc(100dvh - 32px);
  margin: auto;
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--lab-border);
  border-radius: 8px;
  background: var(--lab-surface);
  color: var(--lab-text);
  box-shadow: 0 18px 60px rgba(31, 25, 21, 0.2);
  --coin-history-heads: #c76550;
  --coin-history-tails: #3f8275;
  --coin-history-edge: #796aa2;
}

.coin-history-form {
  max-height: calc(100vh - 32px);
  max-height: calc(100dvh - 32px);
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
}

.coin-history-chart-section {
  padding: 16px 18px 14px;
  display: grid;
  gap: 10px;
  border-bottom: 1px solid var(--lab-border);
}

.coin-history-legend {
  min-height: 28px;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 18px;
}

.coin-history-legend-item {
  min-height: 28px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--lab-muted);
  font-size: 12px;
  cursor: pointer;
}

.coin-history-legend-item[hidden] {
  display: none;
}

.coin-history-legend-item:focus-within {
  border-radius: 4px;
  outline: 3px solid var(--lab-focus);
  outline-offset: 2px;
}

.coin-history-legend-item:has(input:not(:checked)) {
  opacity: 0.46;
}

.coin-history-swatch {
  width: 18px;
  height: 3px;
  border-radius: 2px;
  background: var(--coin-history-heads);
}

[data-history-series="tails"] .coin-history-swatch {
  background: var(--coin-history-tails);
}

[data-history-series="edge"] .coin-history-swatch {
  background: var(--coin-history-edge);
}

.coin-history-legend-item output {
  min-width: 38px;
  color: var(--lab-text);
  font-variant-numeric: tabular-nums;
  font-weight: 650;
}

.coin-history-chart-frame {
  position: relative;
  width: 100%;
  min-height: 150px;
  aspect-ratio: 640 / 210;
  overflow: hidden;
  border: 1px solid var(--lab-border);
  border-radius: 6px;
  background: var(--lab-surface-muted);
}

.coin-history-chart-frame svg {
  width: 100%;
  height: 100%;
  display: block;
}

.coin-history-grid-line {
  stroke: var(--lab-border);
  stroke-width: 1;
  vector-effect: non-scaling-stroke;
}

.coin-history-axis-label {
  fill: var(--lab-faint);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.coin-history-line {
  fill: none;
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
}

.coin-history-line-heads {
  stroke: var(--coin-history-heads);
}

.coin-history-line-tails {
  stroke: var(--coin-history-tails);
}

.coin-history-line-edge {
  stroke: var(--coin-history-edge);
}

.coin-history-endpoint-heads {
  fill: var(--coin-history-heads);
}

.coin-history-endpoint-tails {
  fill: var(--coin-history-tails);
}

.coin-history-endpoint-edge {
  fill: var(--coin-history-edge);
}

.coin-history-chart-empty {
  position: absolute;
  inset: 0;
  margin: 0;
  display: grid;
  place-items: center;
  color: var(--lab-faint);
  font-size: 13px;
  pointer-events: none;
}

.coin-history-chart-empty[hidden] {
  display: none;
}

.coin-history-records {
  min-height: 0;
  padding: 12px 18px 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

.coin-history-records-header {
  min-height: 34px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.coin-history-records-header h3 {
  margin: 0;
  font-size: 14px;
  letter-spacing: 0;
}

.coin-history-records-meta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
}

.coin-history-retention {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--lab-muted);
  font-size: 12px;
  font-weight: 600;
}

.coin-history-retention[hidden] {
  display: none;
}

.coin-history-retention select {
  width: 88px;
  height: 30px;
  padding: 0 8px;
  border: 1px solid var(--lab-border);
  border-radius: 5px;
  outline: 0;
  background: var(--lab-surface-muted);
  color: var(--lab-text);
  font: inherit;
  cursor: pointer;
}

.coin-history-retention select:focus-visible {
  border-color: var(--lab-primary);
  box-shadow: 0 0 0 3px var(--lab-focus);
}

.coin-history-records-meta output {
  color: var(--lab-faint);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.coin-history-list {
  min-height: 96px;
  max-height: 210px;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  list-style: none;
  border-top: 1px solid var(--lab-border);
  scrollbar-gutter: stable;
}

.coin-history-item {
  min-height: 40px;
  padding: 0 4px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid color-mix(in srgb, var(--lab-border) 70%, transparent);
}

.coin-history-outcome {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--lab-text);
  font-size: 13px;
  font-weight: 650;
}

.coin-history-outcome::before {
  width: 7px;
  height: 7px;
  flex: 0 0 7px;
  border-radius: 50%;
  background: var(--coin-history-heads);
  content: "";
}

.coin-history-outcome[data-side="tails"]::before {
  background: var(--coin-history-tails);
}

.coin-history-outcome[data-side="edge"]::before {
  background: var(--coin-history-edge);
}

.coin-history-item time {
  color: var(--lab-faint);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.coin-history-list-empty {
  min-height: 96px;
  display: grid;
  place-items: center;
  color: var(--lab-faint);
  font-size: 13px;
}

.coin-history-actions {
  justify-content: space-between;
}

.coin-history-clear svg {
  width: 16px;
  height: 16px;
}

.coin-history-clear:not(:disabled):hover {
  border-color: color-mix(in srgb, var(--lab-danger) 48%, var(--lab-border)) !important;
  color: var(--lab-danger) !important;
}

@keyframes coin-dialog-in {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.985);
  }

  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.coin-material-switch {
  height: 36px;
  padding: 3px;
  display: flex;
  align-items: center;
  gap: 2px;
  border: 1px solid var(--lab-border);
  border-radius: 6px;
  background: color-mix(in srgb, var(--lab-surface) 90%, transparent);
  backdrop-filter: blur(10px);
}

.coin-material-button {
  position: relative;
  width: 28px !important;
  min-width: 28px !important;
  height: 28px !important;
  min-height: 28px !important;
  padding: 0 !important;
  align-items: center;
  justify-content: center;
  border: 1px solid transparent !important;
  border-radius: 4px !important;
  background: transparent !important;
}

.coin-material-button::before {
  width: 15px;
  height: 15px;
  border: 1px solid rgba(39, 35, 31, 0.24);
  border-radius: 50%;
  box-shadow: inset 2px 2px 2px rgba(255, 255, 255, 0.5);
  content: "";
}

.coin-material-button[data-coin-material="gold"]::before {
  background: #d7a43b;
}

.coin-material-button[data-coin-material="silver"]::before {
  background: #b8c4d0;
}

.coin-material-button[data-coin-material="bronze"]::before {
  background: #b96d45;
}

.coin-material-button[aria-pressed="true"] {
  border-color: var(--lab-border-strong) !important;
  background: var(--lab-surface-strong) !important;
}

.coin-scene {
  position: relative;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  touch-action: manipulation;
}

.coin-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  cursor: default;
}

.coin-canvas.is-over-coin {
  cursor: pointer;
}

.coin-canvas.is-tossing {
  cursor: wait;
}

.coin-loading,
.coin-result {
  position: absolute;
  left: 50%;
  z-index: 2;
  transform: translateX(-50%);
  color: var(--lab-muted);
  text-align: center;
  pointer-events: none;
}

.coin-loading {
  top: 50%;
  font-size: 13px;
}

.coin-loading[data-tone="error"] {
  color: var(--lab-danger);
}

.coin-result {
  bottom: clamp(28px, 7vh, 72px);
  padding: 7px 13px;
  border: 1px solid color-mix(in srgb, var(--lab-border) 74%, transparent);
  border-radius: 6px;
  background: color-mix(in srgb, var(--lab-surface) 88%, transparent);
  color: var(--lab-text);
  box-shadow: var(--lab-shadow);
  font-size: 14px;
  font-weight: 700;
  opacity: 0;
  backdrop-filter: blur(10px);
  transition: opacity 180ms ease, transform 180ms ease;
}

.coin-result.is-visible {
  opacity: 1;
  transform: translate(-50%, -4px);
}

@media (max-width: 760px) {
  .coin-nav {
    top: 10px;
    left: 10px;
    gap: 6px;
  }

  .coin-settings-button {
    top: 10px;
    right: 10px;
  }

  .coin-speed-button {
    top: 10px;
    right: 52px;
    width: 36px !important;
    min-width: 36px !important;
    font-size: 11px;
  }

  .coin-auto-button {
    top: 10px;
    right: 94px;
    width: 42px !important;
    min-width: 42px !important;
    font-size: 10px;
  }

  .coin-history-button {
    right: 10px;
    bottom: 10px;
  }

  .coin-settings-dialog,
  .coin-history-dialog {
    width: calc(100vw - 24px);
  }

  .coin-history-dialog,
  .coin-history-form {
    max-height: calc(100dvh - 24px);
  }

  .coin-history-chart-section {
    padding: 14px;
  }

  .coin-history-records {
    padding-right: 14px;
    padding-left: 14px;
  }

  .coin-history-list {
    max-height: 190px;
  }

  .coin-result {
    bottom: 24px;
  }
}

@media (max-width: 360px) {
  .coin-nav {
    gap: 4px;
  }

  .coin-speed-button {
    right: 50px;
  }

  .coin-auto-button {
    right: 90px;
    width: 38px !important;
    min-width: 38px !important;
    font-size: 9px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .coin-settings-dialog[open],
  .coin-history-dialog[open] {
    animation: none;
  }
}

/* Wheel picker */
.wheel-page {
  overflow: hidden;
}

.wheel-app {
  position: relative;
  width: 100%;
  min-height: 100vh;
  min-height: 100dvh;
  overflow: hidden;
  background: var(--lab-bg);
}

.wheel-nav {
  position: fixed;
  top: 20px;
  left: 20px;
  z-index: 4;
  display: flex;
  align-items: center;
  gap: 8px;
}

.wheel-nav .home-link,
.wheel-nav .theme-toggle,
.wheel-settings-button {
  width: 36px !important;
  min-width: 36px !important;
  height: 36px !important;
  min-height: 36px !important;
  flex: 0 0 36px !important;
  padding: 0 !important;
  display: inline-flex !important;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--lab-border) !important;
  background: color-mix(in srgb, var(--lab-surface) 90%, transparent) !important;
  color: var(--lab-muted) !important;
  backdrop-filter: blur(10px);
}

.wheel-nav .home-link::before,
.wheel-nav .theme-toggle::before {
  display: none !important;
}

.wheel-nav .home-link svg,
.wheel-nav .theme-toggle svg,
.wheel-settings-button svg {
  position: static;
  z-index: auto;
  width: 17px !important;
  height: 17px !important;
}

.wheel-nav .home-link:hover,
.wheel-nav .theme-toggle:hover,
.wheel-settings-button:hover {
  border-color: var(--lab-border-strong) !important;
  background: var(--lab-surface-strong) !important;
  color: var(--lab-text) !important;
}

.wheel-settings-button {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 4;
}

.wheel-stage {
  position: relative;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  padding: 74px 16px 62px;
  display: grid;
  place-items: center;
  overflow: hidden;
}

.wheel-wrap {
  position: relative;
  width: min(560px, calc(100vw - 32px), calc(100dvh - 150px));
  aspect-ratio: 1;
  flex: 0 0 auto;
}

.wheel-pointer-preview {
  position: absolute;
  top: -45px;
  left: 50%;
  z-index: 4;
  width: min(240px, calc(100vw - 140px));
  min-height: 30px;
  padding: 5px 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  transform: translateX(-50%);
  border: 1px solid var(--lab-border);
  border-radius: 6px;
  background: color-mix(in srgb, var(--lab-surface) 94%, transparent);
  color: var(--lab-text);
  box-shadow: 0 5px 16px rgba(36, 27, 22, 0.12);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.4;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
  backdrop-filter: blur(10px);
  pointer-events: none;
}

.wheel-pointer {
  position: absolute;
  top: -4px;
  left: 50%;
  z-index: 3;
  width: 34px;
  height: 44px;
  transform: translateX(-50%);
  filter: drop-shadow(0 4px 5px rgba(68, 39, 29, 0.2));
  pointer-events: none;
}

.wheel-pointer::before {
  position: absolute;
  top: 0;
  left: 50%;
  width: 26px;
  height: 26px;
  transform: translateX(-50%);
  border: 3px solid color-mix(in srgb, var(--lab-primary-hover) 78%, #40251e);
  border-radius: 50%;
  background: var(--lab-primary);
  content: "";
}

.wheel-pointer::after {
  position: absolute;
  top: 19px;
  left: 50%;
  width: 0;
  height: 0;
  transform: translateX(-50%);
  border-right: 11px solid transparent;
  border-left: 11px solid transparent;
  border-top: 22px solid var(--lab-primary-hover);
  content: "";
}

.wheel-button,
.wheel-button:hover,
.wheel-button:active {
  position: absolute;
  inset: 0;
  width: 100% !important;
  min-width: 0 !important;
  height: 100% !important;
  min-height: 0 !important;
  padding: 0 !important;
  overflow: hidden;
  border: 0 !important;
  border-radius: 50% !important;
  outline-offset: 5px;
  background: transparent !important;
  color: inherit !important;
  cursor: pointer;
  touch-action: manipulation;
}

.wheel-button.is-spinning {
  cursor: wait;
}

.wheel-button canvas {
  width: 100%;
  height: 100%;
  display: block;
  border-radius: 50%;
  pointer-events: none;
  transform-origin: 50% 50%;
  will-change: transform;
}

.wheel-result {
  position: absolute;
  left: 50%;
  bottom: clamp(18px, 4vh, 38px);
  z-index: 2;
  max-width: min(520px, calc(100vw - 88px));
  padding: 7px 13px;
  overflow: hidden;
  transform: translateX(-50%);
  border: 1px solid color-mix(in srgb, var(--lab-border) 74%, transparent);
  border-radius: 6px;
  background: color-mix(in srgb, var(--lab-surface) 90%, transparent);
  color: var(--lab-text);
  box-shadow: var(--lab-shadow);
  font-size: 14px;
  font-weight: 700;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
  opacity: 0;
  backdrop-filter: blur(10px);
  transition: opacity 180ms ease, transform 180ms ease;
}

.wheel-result.is-visible {
  opacity: 1;
  transform: translate(-50%, -4px);
}

.wheel-settings-dialog {
  width: min(470px, calc(100vw - 32px));
  max-width: none;
  max-height: calc(100vh - 32px);
  max-height: calc(100dvh - 32px);
  margin: auto;
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--lab-border);
  border-radius: 8px;
  background: var(--lab-surface);
  color: var(--lab-text);
  box-shadow: 0 18px 60px rgba(31, 25, 21, 0.2);
}

.wheel-settings-dialog[open] {
  animation: wheel-dialog-in 180ms ease-out;
}

.wheel-settings-dialog::backdrop {
  background: rgba(21, 19, 17, 0.42);
  backdrop-filter: blur(3px);
}

.wheel-settings-form {
  max-height: calc(100vh - 32px);
  max-height: calc(100dvh - 32px);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
}

.wheel-settings-header {
  min-height: 56px;
  padding: 10px 12px 10px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--lab-border);
}

.wheel-settings-header h2 {
  margin: 0;
  font-size: 17px;
  line-height: 1.25;
  letter-spacing: 0;
}

.wheel-settings-header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.wheel-editor-toggle,
.wheel-dialog-close {
  width: 32px !important;
  min-width: 32px !important;
  height: 32px !important;
  min-height: 32px !important;
  flex: 0 0 32px !important;
  padding: 0 !important;
}

.wheel-editor-toggle svg,
.wheel-dialog-close svg {
  width: 16px;
  height: 16px;
}

.wheel-editor-toggle[aria-pressed="true"] {
  border-color: var(--lab-border-strong) !important;
  background: var(--lab-surface-muted) !important;
  color: var(--lab-text) !important;
}

.wheel-options-section[hidden],
.wheel-import-section[hidden] {
  display: none !important;
}

.wheel-options-section {
  min-height: 0;
  padding: 16px 18px 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

.wheel-options-toolbar {
  min-height: 48px;
  padding-bottom: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.wheel-options-toolbar h3 {
  margin: 0;
  color: var(--lab-text);
  font-size: 14px;
  letter-spacing: 0;
}

.wheel-options-toolbar output {
  display: block;
  margin-top: 2px;
  color: var(--lab-faint);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.wheel-options-toolbar button {
  min-height: 36px;
  white-space: nowrap;
}

.wheel-options-toolbar button svg {
  width: 16px;
  height: 16px;
}

.wheel-option-list {
  min-height: 98px;
  max-height: min(52vh, 460px);
  overflow-y: auto;
  border-top: 1px solid var(--lab-border);
  scrollbar-gutter: stable;
}

.wheel-option-row {
  min-height: 54px;
  display: grid;
  grid-template-columns: 32px minmax(0, 1fr) 34px;
  align-items: center;
  gap: 8px;
  border-bottom: 1px solid color-mix(in srgb, var(--lab-border) 72%, transparent);
}

.wheel-option-number {
  color: var(--lab-faint);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  text-align: center;
}

.wheel-option-row input {
  width: 100%;
  min-width: 0;
  height: 38px;
  padding: 0 10px;
  border: 1px solid var(--lab-border);
  border-radius: 6px;
  outline: 0;
  background: var(--lab-surface-muted);
  color: var(--lab-text);
}

.wheel-option-row input:focus {
  border-color: var(--lab-primary);
  box-shadow: 0 0 0 3px var(--lab-focus);
}

.wheel-option-remove {
  width: 32px !important;
  min-width: 32px !important;
  height: 32px !important;
  min-height: 32px !important;
  padding: 0 !important;
  border: 1px solid transparent !important;
  background: transparent !important;
  color: var(--lab-faint) !important;
}

.wheel-option-remove:not(:disabled):hover {
  border-color: color-mix(in srgb, var(--lab-danger) 42%, var(--lab-border)) !important;
  background: var(--lab-danger-soft) !important;
  color: var(--lab-danger) !important;
}

.wheel-option-remove svg {
  width: 15px;
  height: 15px;
}

.wheel-import-section {
  min-height: 0;
  padding: 16px 18px 0;
  display: grid;
  grid-template-rows: auto minmax(190px, 1fr) auto;
  gap: 12px;
}

.wheel-import-toolbar {
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.wheel-import-toolbar h3,
.wheel-preset-section h4 {
  margin: 0;
  color: var(--lab-text);
  font-size: 14px;
  letter-spacing: 0;
}

.wheel-import-toolbar output {
  display: block;
  margin-top: 2px;
  color: var(--lab-faint);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.wheel-import-section textarea {
  width: 100%;
  min-height: 190px;
  max-height: min(42dvh, 430px);
  padding: 11px 12px;
  resize: vertical;
  border: 1px solid var(--lab-border);
  border-radius: 6px;
  outline: 0;
  background: var(--lab-surface-muted);
  color: var(--lab-text);
  font: 500 14px/1.65 Inter, "Microsoft YaHei", sans-serif;
}

.wheel-import-section textarea::placeholder {
  color: var(--lab-faint);
}

.wheel-import-section textarea:focus {
  border-color: var(--lab-primary);
  box-shadow: 0 0 0 3px var(--lab-focus);
}

.wheel-preset-section {
  padding-bottom: 16px;
  display: grid;
  gap: 8px;
}

.wheel-preset-section h4 {
  font-size: 12px;
}

.wheel-preset-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.wheel-preset-button {
  width: 100% !important;
  min-width: 0 !important;
  min-height: 58px !important;
  padding: 8px 10px !important;
  display: flex !important;
  flex-direction: column;
  align-items: flex-start !important;
  justify-content: center;
  gap: 2px !important;
  text-align: left;
}

.wheel-preset-button strong {
  color: var(--lab-text);
  font-size: 13px;
}

.wheel-preset-button span {
  max-width: 100%;
  overflow: hidden;
  color: var(--lab-faint);
  font-size: 11px;
  font-weight: 550;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.wheel-settings-actions {
  padding: 12px 18px 16px;
  display: flex;
  justify-content: space-between;
  gap: 8px;
  border-top: 1px solid var(--lab-border);
}

.wheel-settings-actions button {
  min-height: 38px;
}

@keyframes wheel-dialog-in {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.985);
  }

  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@media (max-width: 760px) {
  .wheel-nav {
    top: 10px;
    left: 10px;
    gap: 6px;
  }

  .wheel-settings-button {
    top: 10px;
    right: 10px;
  }

  .wheel-stage {
    padding: 64px 12px 58px;
  }

  .wheel-wrap {
    width: min(540px, calc(100vw - 28px), calc(100dvh - 138px));
  }

  .wheel-pointer {
    width: 30px;
    height: 39px;
  }

  .wheel-pointer::before {
    width: 23px;
    height: 23px;
  }

  .wheel-pointer::after {
    top: 17px;
    border-right-width: 10px;
    border-left-width: 10px;
    border-top-width: 20px;
  }

  .wheel-settings-dialog {
    width: calc(100vw - 24px);
    max-height: calc(100dvh - 24px);
  }

  .wheel-settings-form {
    max-height: calc(100dvh - 24px);
  }

  .wheel-options-section,
  .wheel-import-section {
    padding-right: 14px;
    padding-left: 14px;
  }

  .wheel-option-list {
    max-height: 56dvh;
  }

  .wheel-settings-actions {
    padding-right: 14px;
    padding-left: 14px;
  }

  .wheel-import-section {
    grid-template-rows: auto minmax(170px, 1fr) auto;
  }

  .wheel-import-section textarea {
    min-height: 170px;
    max-height: 38dvh;
  }
}

@media (max-width: 360px) {
  .wheel-options-toolbar {
    gap: 8px;
  }

  .wheel-options-toolbar button {
    width: 36px !important;
    min-width: 36px !important;
    padding: 0 !important;
  }

  .wheel-options-toolbar button span {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important;
    white-space: nowrap !important;
  }

  .wheel-option-row {
    grid-template-columns: 28px minmax(0, 1fr) 32px;
    gap: 6px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .wheel-settings-dialog[open] {
    animation: none;
  }
}
