:root {
  --tw-bg: #090d16;
  --tw-surface: #101724;
  --tw-surface-2: #151e2e;
  --tw-surface-3: #0b111c;
  --tw-border: rgba(148, 163, 184, 0.18);
  --tw-border-strong: rgba(139, 92, 246, 0.48);
  --tw-text: #f8fafc;
  --tw-muted: #9aa8bb;
  --tw-accent: #8b5cf6;
  --tw-accent-2: #6d5dfc;
  --tw-success: #34d399;
  --tw-danger: #fb7185;
  --tw-warning: #fbbf24;
  --tw-radius: 15px;
  --tw-shadow: 0 22px 60px rgba(0, 0, 0, 0.26);
}

body.tw-body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  color: var(--tw-text);
  background:
    radial-gradient(circle at 10% -10%, rgba(109, 93, 252, 0.13), transparent 34rem),
    var(--tw-bg);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

.tw-body main { flex: 1; }
.tw-body button,
.tw-body input,
.tw-body select,
.tw-body textarea { font: inherit; }
.tw-body button { color: inherit; }
.tw-body * { box-sizing: border-box; }
.tw-body a { color: inherit; }

.tw-page {
  width: min(1180px, calc(100% - 36px));
  margin: 0 auto;
  padding: 34px 0 74px;
}

.tw-breadcrumb {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 20px;
  color: #a9b5c7;
  font-size: 0.86rem;
  font-weight: 700;
  text-decoration: none;
}
.tw-breadcrumb:hover { color: #fff; }

.tw-hero {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 26px;
  margin-bottom: 24px;
}
.tw-hero-copy { max-width: 760px; }
.tw-eyebrow {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  margin-bottom: 10px;
  padding: 0 10px;
  border: 1px solid rgba(167, 139, 250, 0.25);
  border-radius: 999px;
  background: rgba(139, 92, 246, 0.09);
  color: #c4b5fd;
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}
.tw-hero h1 {
  margin: 0 0 10px;
  font-size: clamp(2rem, 4vw, 3.35rem);
  line-height: 1.08;
  letter-spacing: -0.04em;
}
.tw-hero p {
  max-width: 700px;
  margin: 0;
  color: var(--tw-muted);
  font-size: 1rem;
  line-height: 1.65;
}
.tw-hero-badges { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }
.tw-badge {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 34px;
  padding: 0 11px;
  border: 1px solid var(--tw-border);
  border-radius: 999px;
  background: rgba(16, 23, 36, 0.78);
  color: #c7d0dc;
  font-size: 0.76rem;
  font-weight: 700;
  white-space: nowrap;
}
.tw-badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--tw-success); }

.tw-workspace {
  display: grid;
  grid-template-columns: minmax(290px, 0.76fr) minmax(0, 1.24fr);
  gap: 18px;
  align-items: start;
}
.tw-workspace--equal { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.tw-panel {
  min-width: 0;
  border: 1px solid var(--tw-border);
  border-radius: var(--tw-radius);
  background: rgba(16, 23, 36, 0.88);
  box-shadow: var(--tw-shadow);
  overflow: hidden;
}
.tw-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 17px 19px;
  border-bottom: 1px solid var(--tw-border);
  background: rgba(8, 13, 22, 0.45);
}
.tw-panel-header h2,
.tw-panel-header h3 { margin: 0; font-size: 1rem; letter-spacing: -0.015em; }
.tw-panel-header p { margin: 3px 0 0; color: var(--tw-muted); font-size: 0.76rem; }
.tw-panel-body { padding: 19px; }
.tw-panel-body--flush { padding: 0; }

.tw-drop-zone {
  min-height: 178px;
  display: grid;
  place-items: center;
  padding: 24px;
  border: 1px dashed rgba(167, 139, 250, 0.42);
  border-radius: 13px;
  background: linear-gradient(145deg, rgba(139, 92, 246, 0.08), rgba(10, 16, 27, 0.42));
  text-align: center;
  cursor: pointer;
  transition: 0.18s ease;
}
.tw-drop-zone:hover,
.tw-drop-zone.is-dragging {
  border-color: rgba(196, 181, 253, 0.82);
  background: rgba(139, 92, 246, 0.13);
  transform: translateY(-1px);
}
.tw-drop-icon {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  margin: 0 auto 12px;
  border-radius: 13px;
  background: rgba(139, 92, 246, 0.15);
  color: #d8ccff;
  font-size: 1.3rem;
  font-weight: 800;
}
.tw-drop-zone strong { display: block; margin-bottom: 5px; }
.tw-drop-zone span { display: block; color: var(--tw-muted); font-size: 0.8rem; line-height: 1.5; }
.tw-file-input { position: absolute !important; width: 1px !important; height: 1px !important; opacity: 0 !important; pointer-events: none !important; }

.tw-fields { display: grid; gap: 14px; }
.tw-fields--two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.tw-fields--three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.tw-field { display: grid; gap: 7px; min-width: 0; }
.tw-field > label,
.tw-field > span { color: #dce3ed; font-size: 0.78rem; font-weight: 750; }
.tw-field small { color: #718096; font-size: 0.72rem; line-height: 1.4; }
.tw-input,
.tw-select,
.tw-textarea {
  width: 100%;
  border: 1px solid var(--tw-border);
  border-radius: 10px;
  outline: none;
  background: var(--tw-surface-3);
  color: var(--tw-text);
  transition: border-color 0.18s ease, box-shadow 0.18s ease;
}
.tw-input,
.tw-select { min-height: 43px; padding: 0 12px; }
.tw-textarea { min-height: 270px; padding: 13px; resize: vertical; font: 0.85rem/1.55 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.tw-input:focus,
.tw-select:focus,
.tw-textarea:focus { border-color: rgba(139, 92, 246, 0.72); box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.12); }
.tw-range-row { display: grid; grid-template-columns: minmax(0, 1fr) 62px; gap: 10px; align-items: center; }
.tw-range { width: 100%; accent-color: var(--tw-accent); }
.tw-range-value { min-height: 36px; display: grid; place-items: center; border: 1px solid var(--tw-border); border-radius: 9px; background: var(--tw-surface-3); color: #ddd6fe; font-size: 0.76rem; font-weight: 800; }
.tw-check-row { display: flex; flex-wrap: wrap; gap: 9px; }
.tw-check {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0 11px;
  border: 1px solid var(--tw-border);
  border-radius: 10px;
  background: var(--tw-surface-3);
  color: #c7d0dc;
  font-size: 0.78rem;
  cursor: pointer;
}
.tw-check input { accent-color: var(--tw-accent); }

.tw-divider { height: 1px; margin: 18px 0; background: var(--tw-border); }
.tw-actions { display: flex; flex-wrap: wrap; gap: 9px; margin-top: 18px; }
.tw-button {
  min-height: 43px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 15px;
  border: 1px solid var(--tw-border);
  border-radius: 10px;
  background: var(--tw-surface-2);
  color: #e7eaf0;
  font-size: 0.82rem;
  font-weight: 760;
  cursor: pointer;
  text-decoration: none;
  transition: 0.18s ease;
}
.tw-button:hover:not(:disabled) { transform: translateY(-1px); border-color: rgba(167, 139, 250, 0.48); background: #1a2537; }
.tw-button:disabled { opacity: 0.46; cursor: not-allowed; }
.tw-button--primary { border-color: transparent; background: linear-gradient(135deg, var(--tw-accent), var(--tw-accent-2)); color: #fff; box-shadow: 0 11px 28px rgba(109, 93, 252, 0.22); }
.tw-button--success { border-color: rgba(52, 211, 153, 0.32); background: rgba(52, 211, 153, 0.1); color: #a7f3d0; }
.tw-button--danger { border-color: rgba(251, 113, 133, 0.3); background: rgba(251, 113, 133, 0.08); color: #fecdd3; }
.tw-button--ghost { background: transparent; }

.tw-status {
  min-height: 46px;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-top: 15px;
  padding: 12px 13px;
  border: 1px solid var(--tw-border);
  border-radius: 10px;
  background: rgba(8, 13, 22, 0.55);
  color: #aeb9c8;
  font-size: 0.78rem;
  line-height: 1.5;
}
.tw-status::before { content: "i"; width: 20px; height: 20px; display: grid; place-items: center; flex: 0 0 auto; border-radius: 50%; background: rgba(139, 92, 246, 0.17); color: #ddd6fe; font-weight: 850; }
.tw-status.is-success { border-color: rgba(52, 211, 153, 0.28); color: #a7f3d0; }
.tw-status.is-success::before { content: "✓"; background: rgba(52, 211, 153, 0.13); color: #6ee7b7; }
.tw-status.is-error { border-color: rgba(251, 113, 133, 0.32); color: #fecdd3; }
.tw-status.is-error::before { content: "!"; background: rgba(251, 113, 133, 0.12); color: #fda4af; }

.tw-preview-shell {
  min-height: 420px;
  display: grid;
  place-items: center;
  position: relative;
  padding: 18px;
  overflow: auto;
  background:
    linear-gradient(45deg, rgba(148,163,184,.055) 25%, transparent 25%),
    linear-gradient(-45deg, rgba(148,163,184,.055) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, rgba(148,163,184,.055) 75%),
    linear-gradient(-45deg, transparent 75%, rgba(148,163,184,.055) 75%),
    #080d15;
  background-size: 22px 22px;
  background-position: 0 0, 0 11px, 11px -11px, -11px 0;
}
.tw-preview-empty { max-width: 360px; text-align: center; color: #77869a; }
.tw-preview-empty strong { display: block; margin-bottom: 5px; color: #b8c3d2; }
.tw-preview-image,
.tw-preview-canvas,
.tw-video { display: block; max-width: 100%; max-height: 68vh; border-radius: 9px; box-shadow: 0 16px 40px rgba(0,0,0,.3); }
.tw-preview-canvas { cursor: crosshair; touch-action: none; }
.tw-preview-stack { position: relative; display: inline-block; max-width: 100%; }
.tw-selection-help { position: absolute; left: 12px; bottom: 12px; max-width: calc(100% - 24px); padding: 8px 10px; border-radius: 8px; background: rgba(5, 9, 16, 0.78); color: #d4dbe5; font-size: 0.72rem; backdrop-filter: blur(8px); pointer-events: none; }

.tw-meta-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 9px; margin-top: 14px; }
.tw-meta-card { min-width: 0; padding: 11px; border: 1px solid var(--tw-border); border-radius: 10px; background: var(--tw-surface-3); }
.tw-meta-card span { display: block; color: #6f7e92; font-size: 0.66rem; font-weight: 800; letter-spacing: 0.07em; text-transform: uppercase; }
.tw-meta-card strong { display: block; margin-top: 4px; overflow: hidden; color: #dfe5ee; font-size: 0.8rem; text-overflow: ellipsis; white-space: nowrap; }

.tw-tabs { display: flex; gap: 7px; padding: 7px; border: 1px solid var(--tw-border); border-radius: 11px; background: var(--tw-surface-3); }
.tw-tab { flex: 1; min-height: 36px; border: 0; border-radius: 8px; background: transparent; color: #8795a8; font-size: 0.75rem; font-weight: 760; cursor: pointer; }
.tw-tab.is-active { background: rgba(139, 92, 246, 0.17); color: #ddd6fe; }

.tw-result-list { display: grid; gap: 9px; margin-top: 14px; }
.tw-result-item { display: grid; grid-template-columns: 28px minmax(0, 1fr); gap: 10px; padding: 12px; border: 1px solid var(--tw-border); border-radius: 10px; background: var(--tw-surface-3); }
.tw-result-item__icon { width: 28px; height: 28px; display: grid; place-items: center; border-radius: 8px; background: rgba(251, 191, 36, 0.11); color: #fde68a; font-size: 0.72rem; font-weight: 850; }
.tw-result-item--error .tw-result-item__icon { background: rgba(251, 113, 133, 0.12); color: #fda4af; }
.tw-result-item--success .tw-result-item__icon { background: rgba(52, 211, 153, 0.12); color: #6ee7b7; }
.tw-result-item strong { display: block; color: #e7ebf1; font-size: 0.8rem; }
.tw-result-item p { margin: 4px 0 0; color: #94a3b8; font-size: 0.74rem; line-height: 1.5; }
.tw-result-item code { color: #ddd6fe; }

.tw-toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 2000;
  max-width: min(360px, calc(100% - 36px));
  padding: 13px 15px;
  border: 1px solid rgba(52, 211, 153, 0.35);
  border-radius: 11px;
  background: rgba(8, 17, 21, 0.96);
  color: #b7f7dc;
  box-shadow: 0 18px 50px rgba(0,0,0,.35);
  font-size: 0.8rem;
  font-weight: 700;
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  transition: 0.2s ease;
}
.tw-toast.is-visible { opacity: 1; transform: translateY(0); }
.tw-toast.is-error { border-color: rgba(251, 113, 133, 0.38); background: rgba(28, 10, 16, 0.97); color: #fecdd3; }

.tw-code-summary { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.tw-summary-chip { min-height: 34px; display: inline-flex; align-items: center; gap: 7px; padding: 0 10px; border: 1px solid var(--tw-border); border-radius: 999px; background: var(--tw-surface-3); color: #aeb9c8; font-size: 0.72rem; font-weight: 700; }
.tw-summary-chip strong { color: #fff; }

.tw-hidden { display: none !important; }

@media (max-width: 920px) {
  .tw-workspace,
  .tw-workspace--equal { grid-template-columns: 1fr; }
  .tw-hero { align-items: flex-start; flex-direction: column; }
  .tw-hero-badges { justify-content: flex-start; }
  .tw-preview-shell { min-height: 340px; }
}

@media (max-width: 620px) {
  .tw-page { width: min(100% - 24px, 1180px); padding-top: 24px; }
  .tw-hero h1 { font-size: clamp(1.85rem, 10vw, 2.55rem); }
  .tw-fields--two,
  .tw-fields--three { grid-template-columns: 1fr; }
  .tw-panel-body { padding: 15px; }
  .tw-panel-header { padding: 14px 15px; }
  .tw-actions { display: grid; grid-template-columns: 1fr 1fr; }
  .tw-actions .tw-button--primary { grid-column: 1 / -1; }
  .tw-meta-grid { grid-template-columns: 1fr; }
  .tw-preview-shell { min-height: 280px; padding: 10px; }
}

@media (max-width: 410px) {
  .tw-actions { grid-template-columns: 1fr; }
  .tw-actions .tw-button--primary { grid-column: auto; }
}

/* Functional tools patch v3 */
.tw-inline-control {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 9px;
  align-items: stretch;
}
.tw-inline-control .tw-button { white-space: nowrap; }
.tw-button.is-working { cursor: progress; }
.tw-button.is-complete { border-color: rgba(52, 211, 153, 0.4); color: #a7f3d0; }
.tw-runtime-error {
  margin: 12px 0;
  padding: 12px 14px;
  border: 1px solid rgba(251, 113, 133, 0.4);
  border-radius: 10px;
  background: rgba(80, 12, 25, 0.2);
  color: #fecdd3;
  font-size: 0.8rem;
}
@media (max-width: 620px) {
  .tw-inline-control { grid-template-columns: 1fr; }
}
