:root {
  color-scheme: light;
  --bg: #eef2ec;
  --bg-raised: #fbfcf8;
  --surface: #ffffff;
  --surface-muted: #f4f6f0;
  --surface-strong: #e6ece2;
  --ink: #18201c;
  --text: #253029;
  --muted: #687267;
  --line: #d5ddd0;
  --line-strong: #b9c7b2;
  --primary: #247a4d;
  --primary-strong: #165a37;
  --primary-soft: #e1f1e8;
  --accent: #2d6f88;
  --accent-soft: #e1edf1;
  --warning-soft: #fbefd8;
  --danger: #b42318;
  --danger-soft: #fbe7e4;
  --shadow: 0 1px 2px rgba(24, 32, 28, 0.06), 0 22px 56px rgba(24, 32, 28, 0.12);
  --shadow-soft: 0 1px 2px rgba(24, 32, 28, 0.05), 0 10px 24px rgba(24, 32, 28, 0.06);
  --shadow-panel: 0 1px 0 rgba(255, 255, 255, 0.9) inset, 0 18px 42px rgba(23, 34, 27, 0.1);
  --radius: 8px;
  --transition-fast: 160ms ease;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: #111811;
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  min-height: 100vh;
  margin: 0;
  background: #111811;
}

button,
input,
textarea,
select {
  font: inherit;
  letter-spacing: 0;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
}

::selection {
  background: rgba(36, 122, 77, 0.18);
  color: var(--ink);
}

.workspace {
  min-height: 100dvh;
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr);
  background: #111811;
}

.side-panel {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  gap: 20px;
  border-right: 1px solid #293029;
  padding: 18px 14px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.035) 0%, transparent 34%),
    linear-gradient(180deg, #121a14 0%, #151e17 52%, #101711 100%);
  color: #f7faf5;
  box-shadow: inset -1px 0 rgba(255, 255, 255, 0.045);
}

.brand-block {
  min-height: 58px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px;
}

.brand-symbol {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: var(--radius);
  background: #e8f4eb;
  color: var(--primary-strong);
  font-size: 24px;
  font-weight: 850;
  line-height: 1;
  box-shadow: 0 10px 22px rgba(6, 12, 8, 0.28);
}

.brand-block h1,
.brand-block p,
.catalog-strip h3,
.catalog-strip p,
.panel-heading h3,
.tool-titlebar h3,
.top-bar h2,
.top-bar p {
  margin: 0;
}

.brand-block h1 {
  color: #ffffff;
  font-size: 18px;
  line-height: 1.2;
}

.brand-block p {
  margin-top: 3px;
  color: #aeb9ae;
  font-size: 12px;
  font-weight: 700;
}

.collection-list,
.tool-list {
  display: grid;
  gap: 8px;
}

.collection-button,
.tool-row {
  min-width: 0;
  min-height: 56px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  color: inherit;
  text-decoration: none;
  text-align: left;
  transition:
    background var(--transition-fast),
    border-color var(--transition-fast),
    box-shadow var(--transition-fast),
    transform var(--transition-fast);
}

.collection-button {
  color: #d9e2d7;
}

.collection-button:hover {
  border-color: rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.06);
}

.collection-button.is-active {
  border-color: rgba(159, 210, 173, 0.45);
  background: #243126;
  color: #ffffff;
  box-shadow: inset 3px 0 0 #78bd86;
}

.collection-mark {
  width: 34px;
  height: 34px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.08);
  color: #c5d2c3;
  font-size: 15px;
  font-weight: 800;
}

.collection-button.is-active .collection-mark {
  background: #daf0df;
  color: var(--primary-strong);
}

.collection-button strong,
.collection-button small,
.tool-row strong,
.tool-row small {
  display: block;
}

.collection-button strong,
.tool-row strong {
  font-size: 15px;
  line-height: 1.25;
}

.collection-button small,
.tool-row small {
  margin-top: 3px;
  color: inherit;
  font-size: 12px;
  line-height: 1.35;
  opacity: 0.72;
}

.side-summary {
  margin-top: auto;
  border: 1px solid rgba(255, 255, 255, 0.11);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  background: rgba(255, 255, 255, 0.05);
}

.side-summary span {
  color: #b8c2b7;
  font-size: 12px;
  font-weight: 700;
}

.side-summary strong {
  color: #ffffff;
  font-size: 22px;
  font-variant-numeric: tabular-nums;
}

.main-panel {
  position: relative;
  isolation: isolate;
  min-width: 0;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  gap: 18px;
  padding: 22px;
  overflow: hidden;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.72) 0%, rgba(244, 247, 240, 0.92) 34%, rgba(235, 240, 232, 0.98) 100%),
    linear-gradient(135deg, rgba(36, 122, 77, 0.11) 0%, rgba(36, 122, 77, 0.04) 26%, transparent 27%),
    linear-gradient(25deg, transparent 0%, transparent 58%, rgba(45, 111, 136, 0.08) 59%, rgba(45, 111, 136, 0.03) 100%),
    repeating-linear-gradient(90deg, rgba(24, 32, 28, 0.035) 0 1px, transparent 1px 72px),
    repeating-linear-gradient(180deg, rgba(24, 32, 28, 0.028) 0 1px, transparent 1px 72px),
    var(--bg);
}

.main-panel::before {
  content: '';
  position: absolute;
  z-index: 0;
  inset: 0;
  background:
    linear-gradient(100deg, rgba(17, 24, 20, 0.08) 0%, transparent 19%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.74) 0%, transparent 240px);
  clip-path: polygon(0 0, 100% 0, 100% 176px, 0 300px);
  pointer-events: none;
}

.main-panel > * {
  position: relative;
  z-index: 1;
}

.top-bar,
.catalog-strip,
.tool-list-panel,
.tool-surface {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.88);
  box-shadow: var(--shadow-soft);
  backdrop-filter: blur(14px);
}

.top-bar {
  min-height: 86px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 18px 20px;
  border-color: rgba(255, 255, 255, 0.78);
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.96) 0%, rgba(249, 252, 247, 0.94) 54%, rgba(232, 243, 235, 0.94) 100%);
  box-shadow: var(--shadow-panel);
}

.top-bar h2 {
  color: var(--ink);
  font-size: 32px;
  line-height: 1.12;
}

.top-bar p:not(.eyebrow) {
  margin-top: 6px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--primary);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.runtime-stack {
  min-width: 144px;
  border: 1px solid rgba(22, 90, 55, 0.12);
  border-radius: var(--radius);
  display: grid;
  gap: 5px;
  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.7);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.9);
}

.runtime-stack span,
.runtime-stack strong {
  display: block;
  line-height: 1.2;
}

.runtime-stack span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.runtime-stack strong {
  color: var(--ink);
  font-size: 15px;
}

.catalog-strip {
  min-height: 78px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 16px 18px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.9) 0%, rgba(248, 250, 245, 0.88) 100%);
}

.catalog-strip h3 {
  color: var(--ink);
  font-size: 20px;
  line-height: 1.25;
}

.catalog-strip p:not(.eyebrow) {
  margin-top: 4px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
}

.tool-count {
  width: 70px;
  height: 54px;
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  display: grid;
  place-items: center;
  background: var(--warning-soft);
  color: #614715;
}

.tool-count strong,
.tool-count span {
  display: block;
  line-height: 1;
}

.tool-count strong {
  font-size: 20px;
  font-variant-numeric: tabular-nums;
}

.tool-count span {
  margin-top: -3px;
  font-size: 11px;
  font-weight: 800;
}

.content-grid {
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(230px, 310px) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.tool-list-panel {
  min-width: 0;
  padding: 12px;
  background: rgba(255, 255, 255, 0.78);
}

.panel-heading {
  min-height: 42px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 4px 10px;
}

.panel-heading h3,
.tool-titlebar h3 {
  color: var(--ink);
  font-size: 17px;
  line-height: 1.25;
}

.panel-heading span {
  min-width: 28px;
  height: 26px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 12px;
  font-weight: 850;
}

.tool-row {
  color: var(--text);
}

.tool-row:hover {
  border-color: var(--line-strong);
  background: var(--surface-muted);
}

.tool-row.is-active {
  border-color: rgba(36, 122, 77, 0.42);
  background: var(--primary-soft);
  box-shadow: inset 3px 0 0 var(--primary);
}

.tool-glyph {
  width: 44px;
  height: 44px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-raised);
  color: var(--primary-strong);
  font-size: 12px;
  font-weight: 850;
}

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

.tool-row-arrow {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 24px;
  line-height: 1;
}

.tool-surface {
  min-width: 0;
  min-height: 620px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: var(--shadow);
}

.tool-titlebar {
  min-height: 78px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.96) 0%, rgba(247, 250, 244, 0.94) 100%);
}

.tool-meta {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.meta-pill {
  min-height: 28px;
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 10px;
  background: var(--surface);
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
  line-height: 1;
}

.tool-mount {
  padding: 20px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.78) 0%, rgba(255, 255, 255, 0.96) 100%);
}

.decoder-layout,
.regex-tester-layout,
.regex-railroad-layout,
.video-player-layout,
.video-source-layout,
.screen-recorder-layout,
.image-gen-layout {
  display: grid;
  gap: 16px;
}

.field-block {
  min-width: 0;
  display: grid;
  gap: 8px;
}

.field-block > span {
  color: var(--ink);
  font-size: 13px;
  font-weight: 800;
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.94);
  color: var(--ink);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.8) inset;
  transition:
    border-color var(--transition-fast),
    box-shadow var(--transition-fast),
    background var(--transition-fast);
}

input,
select {
  min-height: 48px;
  padding: 0 13px;
}

textarea {
  min-height: 174px;
  resize: vertical;
  padding: 13px;
  line-height: 1.6;
}

textarea[readonly] {
  background: var(--surface-muted);
}

textarea::placeholder,
input::placeholder {
  color: #98a093;
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(36, 122, 77, 0.14);
  outline: none;
}

.collection-button:focus-visible,
.tool-row:focus-visible,
.primary-action:focus-visible,
.secondary-action:focus-visible,
.flag-toggle:focus-visible,
.image-gen-mode-btn:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible {
  outline: 3px solid rgba(45, 111, 136, 0.28);
  outline-offset: 2px;
}

.action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.primary-action,
.secondary-action {
  min-height: 44px;
  border-radius: var(--radius);
  padding: 0 16px;
  font-weight: 800;
  transition:
    background var(--transition-fast),
    border-color var(--transition-fast),
    box-shadow var(--transition-fast),
    color var(--transition-fast),
    transform 100ms ease;
}

.primary-action {
  border: 1px solid var(--primary);
  background: var(--primary);
  color: #ffffff;
}

.primary-action:hover {
  border-color: var(--primary-strong);
  background: var(--primary-strong);
  box-shadow: 0 8px 18px rgba(36, 122, 77, 0.2);
}

.secondary-action {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.86);
  color: var(--text);
}

.secondary-action:hover {
  border-color: var(--line-strong);
  background: var(--surface-muted);
}

.primary-action:active,
.secondary-action:active,
.image-gen-mode-btn:active,
.flag-toggle:active {
  transform: scale(0.97);
}

.primary-action:disabled,
.secondary-action:disabled {
  opacity: 0.48;
  transform: none;
  box-shadow: none;
}

.status-line {
  min-height: 24px;
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
}

.status-line[data-tone='ok'] {
  color: var(--primary-strong);
}

.status-line[data-tone='error'] {
  color: var(--danger);
}

.metric-grid,
.result-panel {
  display: grid;
  gap: 10px;
}

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

.metric-tile,
.result-panel > div {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  background: rgba(244, 246, 240, 0.82);
}

.metric-tile span,
.result-panel span,
.screen-result-summary span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.metric-tile strong,
.result-panel strong,
.screen-result-summary strong {
  display: block;
  margin-top: 6px;
  overflow-wrap: anywhere;
  color: var(--ink);
  font-size: 14px;
  line-height: 1.45;
}

.metric-tile strong,
.screen-result-summary strong {
  font-variant-numeric: tabular-nums;
}

/* Regex Tester */

.regex-input-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

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

.flag-toggle {
  min-width: 44px;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  display: grid;
  place-items: center;
  background: var(--surface);
  color: var(--muted);
  font-family: ui-monospace, "Cascadia Code", "SFMono-Regular", monospace;
  font-size: 14px;
  font-weight: 850;
  transition:
    background var(--transition-fast),
    border-color var(--transition-fast),
    color var(--transition-fast),
    transform 100ms ease;
}

.flag-toggle:hover {
  border-color: var(--line-strong);
  background: var(--surface-muted);
}

.flag-toggle[aria-pressed='true'] {
  border-color: rgba(36, 122, 77, 0.42);
  background: var(--primary-soft);
  color: var(--primary-strong);
}

.match-highlight-area,
.railroad-diagram-area,
.railroad-breakdown-area,
.debug-log,
.image-gen-chat-messages {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.8) inset;
}

.match-highlight-area {
  min-height: 110px;
  padding: 14px;
  color: var(--text);
  font-size: 14px;
  line-height: 1.7;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.match-highlight-area mark {
  border-radius: 4px;
  padding: 1px 3px;
  background: #ffe68a;
  color: inherit;
}

.match-group-list {
  display: grid;
  gap: 10px;
}

.match-group-item {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  background: rgba(244, 246, 240, 0.84);
}

.match-group-item strong {
  color: var(--primary-strong);
  font-size: 13px;
}

.match-group-item code,
.group-tag code {
  border-radius: 5px;
  padding: 2px 6px;
  background: #e5e9df;
  color: var(--ink);
  font-family: ui-monospace, "Cascadia Code", "SFMono-Regular", monospace;
  font-size: 13px;
}

.group-details {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

.group-tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 13px;
}

.group-label {
  color: var(--muted);
  font-weight: 700;
}

.debug-log {
  max-height: 180px;
  margin: 0;
  overflow: auto;
  padding: 12px;
  color: #344036;
  font-family: ui-monospace, "Cascadia Code", "SFMono-Regular", monospace;
  font-size: 12px;
  line-height: 1.55;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.debug-log[hidden] {
  display: none;
}

/* Video */

.video-frame {
  overflow: hidden;
  border: 1px solid #242a24;
  border-radius: var(--radius);
  background: #101410;
  aspect-ratio: 16 / 9;
}

.video-frame video {
  width: 100%;
  height: 100%;
  display: block;
  background: #101410;
}

.source-panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: var(--shadow-soft);
}

.source-panel-heading {
  min-height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  padding: 0 14px;
  background: linear-gradient(180deg, rgba(249, 251, 246, 0.94) 0%, rgba(238, 243, 235, 0.9) 100%);
}

.source-panel-heading h4 {
  margin: 0;
  color: var(--ink);
  font-size: 15px;
  line-height: 1.3;
}

.source-panel-heading span {
  min-width: 32px;
  height: 28px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary-strong);
  font-size: 13px;
  font-weight: 850;
}

.source-list {
  display: grid;
}

.source-row {
  width: 100%;
  min-height: 68px;
  border: 0;
  border-bottom: 1px solid var(--line);
  display: grid;
  grid-template-columns: 80px 58px minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 12px 14px;
  background: rgba(255, 255, 255, 0.82);
  color: var(--text);
  text-align: left;
  transition: background var(--transition-fast);
}

.source-row:last-child {
  border-bottom: 0;
}

.source-row:hover {
  background: var(--surface-muted);
}

.source-row:focus-visible {
  outline: 3px solid rgba(45, 111, 136, 0.28);
  outline-offset: -3px;
}

.source-row strong,
.source-row small {
  display: block;
}

.source-row strong {
  overflow-wrap: anywhere;
  color: var(--ink);
  font-size: 13px;
  line-height: 1.45;
}

.source-row small {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.source-actions {
  display: flex;
  gap: 8px;
}

.source-action {
  min-height: 36px;
  padding: 0 12px;
  font-size: 13px;
}

.source-kind {
  min-height: 34px;
  display: grid;
  place-items: center;
  border-radius: var(--radius);
  background: var(--primary-soft);
  color: var(--primary-strong);
  font-size: 12px;
  font-weight: 850;
}

.source-thumb {
  width: 80px;
  height: 45px;
  border-radius: 6px;
  overflow: hidden;
  display: grid;
  place-items: center;
  background: var(--surface-muted);
}

.source-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.source-thumb-loading {
  width: 16px;
  height: 16px;
  border: 2px solid var(--line);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: thumb-spin 0.7s linear infinite;
}

@keyframes thumb-spin {
  to {
    transform: rotate(360deg);
  }
}

.source-thumb-invalid {
  color: var(--danger);
  font-size: 11px;
  font-weight: 700;
}

.source-thumb-valid {
  color: var(--primary);
  font-size: 11px;
  font-weight: 700;
}

.empty-line {
  margin: 0;
  padding: 18px 14px;
  color: var(--muted);
  font-size: 14px;
}

/* Regex Railroad */

.railroad-split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.railroad-diagram-area {
  min-height: 140px;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 16px;
}

.railroad-diagram-area:empty,
.railroad-breakdown-area:empty {
  display: grid;
  place-items: center;
}

.railroad-diagram-area:empty::after {
  content: '输入正则表达式后将显示铁路图';
  color: var(--muted);
  font-size: 14px;
}

.railroad-breakdown-area {
  min-height: 140px;
  max-height: 420px;
  overflow-y: auto;
  padding: 12px;
}

.railroad-breakdown-area:empty::after {
  content: '输入正则表达式后将显示结构解析';
  color: var(--muted);
  font-size: 14px;
}

.breakdown-tree {
  display: grid;
  gap: 4px;
}

.breakdown-node {
  min-height: 28px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  line-height: 1.4;
}

.breakdown-badge {
  min-width: 36px;
  height: 22px;
  flex: 0 0 auto;
  border-radius: 5px;
  display: inline-grid;
  place-items: center;
  padding: 0 6px;
  background: var(--primary-soft);
  color: var(--primary-strong);
  font-size: 11px;
  font-weight: 850;
}

.breakdown-label {
  color: var(--ink);
  font-family: ui-monospace, "Cascadia Code", "SFMono-Regular", monospace;
  font-weight: 700;
}

.breakdown-desc {
  color: var(--muted);
  font-size: 12px;
}

.railroad-diagram-area svg {
  display: block;
  margin: 0 auto;
}

.railroad-diagram-area svg path {
  stroke: var(--ink);
  stroke-width: 2;
  fill: none;
}

.railroad-diagram-area svg rect {
  stroke: var(--line-strong);
  stroke-width: 2;
  fill: var(--primary-soft);
  rx: 4;
}

.railroad-diagram-area svg text {
  fill: var(--ink);
  font-family: ui-monospace, "Cascadia Code", "SFMono-Regular", monospace;
  font-size: 13px;
}

/* Screen Recorder */

.screen-recorder-steps {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.screen-step {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  display: grid;
  grid-template-columns: 32px minmax(0, 1fr);
  gap: 8px 10px;
  align-items: center;
  padding: 12px;
  background: rgba(244, 246, 240, 0.86);
}

.screen-step span {
  grid-row: span 2;
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  font-size: 13px;
  font-weight: 850;
}

.screen-step strong,
.screen-step small {
  min-width: 0;
  display: block;
}

.screen-step strong {
  color: var(--ink);
  font-size: 14px;
  line-height: 1.25;
}

.screen-step small {
  overflow-wrap: anywhere;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.25;
}

.screen-step.is-active {
  border-color: rgba(36, 122, 77, 0.38);
  background: var(--primary-soft);
}

.screen-step.is-active span,
.screen-step.is-complete span {
  background: var(--primary);
  color: #ffffff;
}

.screen-recorder-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.screen-recorder-frame {
  position: relative;
  overflow: hidden;
  border: 1px solid #242a24;
  border-radius: var(--radius);
  background: #101410;
  aspect-ratio: 16 / 9;
}

.screen-recorder-frame video,
.screen-recorder-frame canvas {
  width: 100%;
  height: 100%;
  display: block;
  background: #101410;
}

.screen-recorder-frame [hidden] {
  display: none;
}

.screen-frame-badge,
.screen-recording-indicator {
  position: absolute;
  z-index: 6;
  min-height: 32px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border-radius: 999px;
  padding: 0 12px;
  background: rgba(16, 20, 16, 0.86);
  color: #ffffff;
  font-size: 13px;
  font-weight: 850;
  line-height: 1;
  pointer-events: none;
}

.screen-frame-badge {
  top: 12px;
  left: 12px;
}

.screen-recording-indicator {
  top: 12px;
  right: 12px;
}

.screen-recording-indicator span {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: #ef4444;
  box-shadow: 0 0 0 4px rgba(239, 68, 68, 0.22);
}

.screen-recording-indicator strong {
  font-variant-numeric: tabular-nums;
}

.screen-crop-layer {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.28);
  cursor: crosshair;
  touch-action: none;
}

.screen-crop-selection {
  position: absolute;
  border: 2px solid #8bd59b;
  border-radius: 4px;
  background: rgba(139, 213, 155, 0.12);
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.36);
  pointer-events: none;
}

.screen-crop-selection span {
  position: absolute;
  right: -2px;
  bottom: calc(100% + 6px);
  min-height: 24px;
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 0 8px;
  background: var(--primary);
  color: #ffffff;
  font-size: 12px;
  font-weight: 850;
  line-height: 1;
  white-space: nowrap;
}

.screen-result-panel {
  display: grid;
  gap: 12px;
}

.screen-result-panel[hidden] {
  display: none;
}

.screen-result-summary {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr)) auto;
  gap: 12px;
  align-items: center;
  padding: 12px;
  background: rgba(244, 246, 240, 0.86);
}

.screen-result-summary strong {
  font-size: 16px;
}

/* Image Generator */

.image-gen-config-panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background:
    linear-gradient(180deg, rgba(249, 251, 246, 0.92) 0%, rgba(239, 244, 235, 0.88) 100%);
  box-shadow: var(--shadow-soft);
}

.image-gen-config-panel summary {
  padding: 12px 14px;
  color: var(--ink);
  font-size: 14px;
  font-weight: 800;
  cursor: pointer;
}

.image-gen-config-panel[open] summary {
  border-bottom: 1px solid var(--line);
}

.image-gen-config {
  display: grid;
  gap: 12px;
  padding: 14px;
}

.image-gen-hint {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.image-gen-mode-row {
  display: flex;
  gap: 4px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 4px;
  background: rgba(233, 239, 229, 0.86);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.7) inset;
}

.image-gen-mode-btn {
  flex: 1;
  min-height: 40px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  font-weight: 800;
  transition:
    background var(--transition-fast),
    color var(--transition-fast),
    transform 100ms ease;
}

.image-gen-mode-btn:hover {
  color: var(--ink);
}

.image-gen-mode-btn.is-active {
  background: rgba(255, 255, 255, 0.96);
  color: var(--ink);
  box-shadow: var(--shadow-soft);
}

.image-gen-panel {
  display: grid;
  gap: 14px;
}

.image-gen-panel[hidden] {
  display: none;
}

.image-gen-options {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.image-gen-token-row,
.image-gen-chat-input-row {
  display: flex;
  gap: 8px;
}

.image-gen-token-row input,
.image-gen-chat-input-row textarea {
  min-width: 0;
  flex: 1;
}

.image-gen-icon-btn {
  min-width: 48px;
  min-height: 48px;
  padding: 0 12px;
}

.image-gen-result {
  display: grid;
  gap: 12px;
}

.image-gen-preview {
  overflow: hidden;
  border: 1px solid #242a24;
  border-radius: var(--radius);
  background:
    linear-gradient(135deg, rgba(36, 122, 77, 0.1), transparent 36%),
    #101410;
  box-shadow: 0 18px 38px rgba(16, 20, 16, 0.16);
}

.image-gen-preview img {
  width: 100%;
  display: block;
}

.image-gen-chat-messages {
  min-height: 220px;
  max-height: 480px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 14px;
}

.image-gen-chat-bubble {
  max-width: 85%;
  border-radius: var(--radius);
  padding: 10px 14px;
  font-size: 14px;
  line-height: 1.55;
}

.image-gen-chat-bubble.is-user {
  align-self: flex-end;
  background: var(--primary-soft);
  color: var(--ink);
}

.image-gen-chat-bubble.is-assistant {
  align-self: flex-start;
  border: 1px solid var(--line);
  background: rgba(244, 246, 240, 0.9);
  color: var(--text);
}

.image-gen-chat-bubble p {
  margin: 0 0 8px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.image-gen-chat-bubble p:last-child {
  margin-bottom: 0;
}

.image-gen-chat-img {
  display: grid;
  gap: 8px;
}

.image-gen-chat-img img {
  width: 100%;
  border-radius: 6px;
  display: block;
}

.image-gen-chat-dl {
  min-height: 32px;
  justify-self: start;
  padding: 0 10px;
  font-size: 12px;
}

.image-gen-ref-preview {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  justify-self: start;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 6px;
  background: rgba(244, 246, 240, 0.9);
}

.image-gen-ref-preview img {
  max-width: 120px;
  max-height: 80px;
  border-radius: 6px;
  object-fit: cover;
}

.image-gen-chat-input-row {
  align-items: flex-end;
}

.image-gen-chat-input-row textarea {
  min-height: 64px;
}

.image-gen-chat-input-row .primary-action {
  min-width: 72px;
  align-self: stretch;
}

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

@media (max-width: 1060px) {
  .workspace {
    grid-template-columns: 220px minmax(0, 1fr);
  }

  .content-grid {
    grid-template-columns: 1fr;
  }

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

@media (max-width: 820px) {
  .workspace {
    grid-template-columns: 1fr;
  }

  .side-panel {
    min-height: auto;
    border-right: 0;
    border-bottom: 1px solid #293029;
  }

  .collection-list {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .side-summary {
    display: none;
  }

  .main-panel {
    padding: 16px;
  }

  .top-bar,
  .catalog-strip,
  .tool-titlebar {
    align-items: flex-start;
    flex-direction: column;
  }

  .runtime-stack {
    width: 100%;
  }

  .tool-meta {
    justify-content: flex-start;
  }

  .metric-grid,
  .railroad-split,
  .screen-recorder-steps,
  .screen-result-summary,
  .image-gen-options {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 560px) {
  .collection-list,
  .tool-list {
    grid-template-columns: 1fr;
  }

  .main-panel,
  .tool-mount {
    padding: 14px;
  }

  .top-bar,
  .catalog-strip,
  .tool-list-panel,
  .tool-titlebar {
    padding: 14px;
  }

  .tool-count {
    display: none;
  }

  .regex-input-row,
  .image-gen-chat-input-row {
    flex-wrap: wrap;
  }

  .regex-input-row input,
  .image-gen-chat-input-row textarea {
    flex-basis: 100%;
  }

  .source-row {
    grid-template-columns: 60px 48px minmax(0, 1fr);
  }

  .top-bar h2 {
    font-size: 26px;
  }

  .source-thumb {
    width: 60px;
    height: 34px;
  }

  .source-actions {
    grid-column: 2 / -1;
  }
}
