:root {
  color-scheme: dark;
  --bg: #0d1113;
  --surface: #15191d;
  --surface-2: #1b2127;
  --surface-3: #222a31;
  --line: #303a43;
  --line-soft: #242b32;
  --text: #edf2f7;
  --muted: #9ba8b5;
  --accent: #49a6df;
  --accent-strong: #66c2ff;
  --success: #72d68a;
  --warn: #f2c166;
  --danger: #ff7a7a;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.28);
}

* {
  box-sizing: border-box;
}

html {
  min-width: 0;
}

body {
  margin: 0;
  min-width: 0;
  min-height: 100vh;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, sans-serif;
}

button,
select,
textarea {
  font: inherit;
}

a,
button {
  touch-action: manipulation;
}

a {
  color: var(--text);
  text-decoration: none;
}

a:hover,
a:focus-visible {
  color: var(--accent-strong);
}

button,
select {
  min-height: 40px;
}

button {
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
  border-radius: 6px;
  padding: 9px 12px;
}

button:hover,
button:focus-visible,
select:focus-visible,
textarea:focus-visible,
a:focus-visible {
  border-color: var(--accent);
  outline: 2px solid rgba(73, 166, 223, 0.28);
  outline-offset: 2px;
}

button.primary {
  min-width: 112px;
  border-color: #55baf3;
  background: #176c9e;
  font-weight: 700;
}

button.primary:hover,
button.primary:focus-visible {
  background: #1b7db8;
}

button:disabled {
  cursor: wait;
  opacity: 0.68;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  min-height: 82px;
  padding: 16px clamp(16px, 4vw, 36px);
  border-bottom: 1px solid var(--line-soft);
  background: #11161a;
}

.brand-block {
  min-width: 0;
}

.eyebrow,
.section-kicker {
  margin: 0 0 5px;
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 4px;
  font-size: clamp(21px, 2.3vw, 30px);
  line-height: 1.15;
}

h2 {
  margin-bottom: 0;
  font-size: 18px;
  line-height: 1.25;
}

h3 {
  margin-bottom: 12px;
  color: var(--muted);
  font-size: 13px;
  letter-spacing: 0;
  text-transform: uppercase;
}

p {
  color: var(--muted);
  line-height: 1.5;
}

.tagline {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.header-tools {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 10px;
}

.status-panel {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  white-space: nowrap;
}

.status-dot {
  width: 10px;
  height: 10px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--warn);
  box-shadow: 0 0 0 4px rgba(242, 193, 102, 0.12);
}

.status-dot.pending {
  animation: statusPulse 1200ms ease-in-out infinite;
}

.status-dot.ready {
  background: var(--success);
  box-shadow: 0 0 0 4px rgba(114, 214, 138, 0.12);
}

.status-dot.error {
  background: var(--danger);
  box-shadow: 0 0 0 4px rgba(255, 122, 122, 0.12);
}

.quick-links {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  color: var(--muted);
  font-size: 14px;
}

.quick-links a,
.link-button {
  min-height: 34px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  padding: 6px 8px;
}

.quick-links a:hover,
.quick-links a:focus-visible,
.link-button:hover,
.link-button:focus-visible {
  color: var(--text);
}

.page-shell {
  width: min(1500px, 100%);
  margin: 0 auto;
  padding: clamp(14px, 2.4vw, 28px);
}

.workbench {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(300px, 0.92fr);
  gap: 18px;
  align-items: stretch;
}

.workspace,
.toolbox,
.history-wrap {
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--line-soft);
  border-radius: 8px;
}

.workspace {
  padding: clamp(16px, 2.5vw, 26px);
  box-shadow: var(--shadow);
}

.workspace-head,
.toolbox-head,
.actionbar,
.output-header,
.tabs {
  display: flex;
  align-items: center;
  gap: 10px;
}

.workspace-head {
  justify-content: space-between;
  margin-bottom: 16px;
}

.workspace-hint {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.command-label {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

textarea {
  width: 100%;
  min-height: clamp(220px, 32vh, 360px);
  resize: vertical;
  color: var(--text);
  background: #090c0f;
  border: 1px solid #3a4650;
  border-radius: 8px;
  padding: 16px;
  font-family: Consolas, "Courier New", monospace;
  font-size: 16px;
  line-height: 1.55;
}

.input-frame {
  position: relative;
}

.autocomplete-list {
  position: absolute;
  z-index: 30;
  top: calc(100% + 8px);
  right: 0;
  left: 0;
  max-height: min(270px, 40vh);
  overflow: auto;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #11171c;
  box-shadow: var(--shadow);
}

.autocomplete-list button,
.search-results button {
  display: grid;
  width: 100%;
  min-height: 52px;
  gap: 3px;
  border-color: transparent;
  background: transparent;
  text-align: left;
}

.autocomplete-list button:hover,
.autocomplete-list button:focus-visible,
.autocomplete-list button.active,
.search-results button:hover,
.search-results button:focus-visible {
  border-color: rgba(73, 166, 223, 0.44);
  background: rgba(73, 166, 223, 0.1);
}

.autocomplete-list span,
.search-results span {
  font-weight: 700;
}

.autocomplete-list code,
.search-results code,
.example-list code,
.history-command {
  color: #d8edf9;
  font-family: Consolas, "Courier New", monospace;
  font-size: 12px;
}

.autocomplete-list small,
.search-results small {
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
}

.actionbar {
  position: relative;
  margin: 14px 0 18px;
  flex-wrap: wrap;
}

.menu-wrap {
  position: relative;
}

.more-menu {
  position: absolute;
  z-index: 20;
  top: calc(100% + 8px);
  right: 0;
  min-width: 180px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  box-shadow: var(--shadow);
}

.more-menu button {
  width: 100%;
  border-color: transparent;
  background: transparent;
  text-align: left;
}

.output-wrap {
  min-height: 260px;
  overflow: hidden;
  background: #101418;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
}

.graph-panel {
  margin-top: 14px;
  overflow: hidden;
  background: #101418;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
}

.graph-panel canvas {
  display: block;
  width: 100%;
  min-height: 260px;
  max-height: 52vh;
  aspect-ratio: 16 / 9;
  background: #0f1418;
}

.graph-controls {
  display: grid;
  grid-template-columns: repeat(5, minmax(72px, max-content)) repeat(3, minmax(96px, 1fr)) minmax(100px, max-content) repeat(3, minmax(96px, 1fr));
  gap: 8px;
  align-items: end;
  padding: 12px;
  border-top: 1px solid var(--line-soft);
  background: #13191e;
}

.graph-controls button {
  min-height: 34px;
  padding: 7px 10px;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  background: #1b232a;
  color: var(--text);
  font-weight: 700;
  cursor: pointer;
}

.graph-controls button:hover,
.graph-controls button.active {
  border-color: rgba(102, 194, 255, 0.66);
  background: rgba(102, 194, 255, 0.16);
}

.graph-controls label {
  display: grid;
  gap: 4px;
  min-width: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.graph-controls input[type="number"] {
  width: 100%;
  min-width: 0;
  height: 34px;
  padding: 6px 8px;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  background: #0f1418;
  color: var(--text);
}

.graph-controls input:disabled {
  opacity: 0.52;
}

.graph-check {
  display: flex !important;
  align-items: center;
  grid-auto-flow: column;
  justify-content: start;
  min-height: 34px;
}

.txt-panel {
  margin-top: 14px;
  overflow: hidden;
  background: #101418;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
}

.txt-drop-zone {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  padding: 12px;
  border-bottom: 1px solid var(--line-soft);
  background: #13191e;
}

.txt-drop-zone.drag-over {
  border-color: rgba(102, 194, 255, 0.66);
  background: rgba(102, 194, 255, 0.1);
}

.txt-drop-zone button {
  min-height: 34px;
  padding: 7px 10px;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  background: #1b232a;
  color: var(--text);
  font-weight: 700;
}

.txt-drop-zone button.primary {
  border-color: #55baf3;
  background: #176c9e;
}

.txt-preview,
.txt-results {
  min-height: 120px;
  max-height: 260px;
  border-bottom: 1px solid var(--line-soft);
  font-size: 13px;
}

.txt-results {
  min-height: 170px;
  border-bottom: 0;
}

.output-header {
  justify-content: space-between;
  min-height: 42px;
  padding: 9px 14px;
  border-bottom: 1px solid var(--line-soft);
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

pre {
  margin: 0;
  min-height: 216px;
  max-height: 46vh;
  overflow: auto;
  padding: 16px;
  white-space: pre-wrap;
  word-break: normal;
  overflow-wrap: normal;
  color: #f2f7fb;
  font-family: Consolas, "Courier New", monospace;
  font-size: 15px;
  line-height: 1.55;
}

.example-shelf {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--line-soft);
}

.example-shelf.is-quiet {
  opacity: 0.72;
}

.example-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.example-head small {
  color: var(--muted);
  font-size: 11px;
  font-weight: 500;
}

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

.example-list button {
  display: grid;
  min-height: 58px;
  align-content: center;
  gap: 4px;
  text-align: left;
}

.example-list span {
  font-size: 13px;
  font-weight: 700;
}

.toolbox {
  align-self: start;
  padding: 14px;
}

.toolbox-head {
  justify-content: space-between;
  margin-bottom: 12px;
}

.toolbox-head h2 {
  font-size: 16px;
}

.search-label {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.command-search {
  width: 100%;
  min-height: 40px;
  margin-bottom: 10px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #101418;
  color: var(--text);
}

.search-results {
  max-height: 330px;
  overflow: auto;
  margin-bottom: 12px;
  padding: 6px;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  background: #12171c;
}

.search-empty {
  margin: 0;
  padding: 8px 10px;
  color: var(--muted);
  font-size: 13px;
}

.tabs {
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.tab {
  min-height: 34px;
  padding: 7px 9px;
  color: var(--muted);
  font-size: 13px;
}

.tab.active {
  border-color: var(--accent);
  background: rgba(73, 166, 223, 0.12);
  color: #d9f1ff;
}

.panel {
  display: none;
  padding: 2px 0 0;
}

.panel.active {
  display: block;
}

.panel h2 {
  margin-bottom: 8px;
  font-size: 16px;
}

.panel p {
  margin-bottom: 12px;
  font-size: 13px;
}

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

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

.template-grid button {
  min-height: 42px;
  padding: 8px 9px;
  text-align: left;
}

.template-grid button span,
.template-grid button small {
  display: block;
}

.template-grid button small {
  margin-top: 4px;
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
}

.history-wrap {
  margin-top: 18px;
  overflow: hidden;
}

#historyList {
  min-height: 88px;
  max-height: 190px;
  overflow: auto;
  margin: 0;
  padding: 10px 14px 14px;
  list-style: none;
}

#historyList li {
  margin: 0;
  color: var(--muted);
  font-family: Consolas, "Courier New", monospace;
}

#historyList li:hover {
  color: var(--text);
}

.history-empty {
  padding: 8px 0;
}

.history-entry {
  display: grid;
  grid-template-columns: 58px minmax(180px, 1fr) minmax(220px, 1.3fr) auto;
  gap: 10px;
  align-items: start;
  padding: 10px 0;
  border-top: 1px solid var(--line-soft);
}

.history-entry:first-child {
  border-top: 0;
}

.history-time {
  color: var(--muted);
  font-size: 12px;
}

.history-command {
  min-width: 0;
  overflow: auto;
  white-space: nowrap;
}

.history-result {
  min-height: 0;
  max-height: 74px;
  padding: 0;
  color: var(--muted);
  font-size: 12px;
}

.history-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
}

.history-actions button {
  min-height: 32px;
  padding: 5px 8px;
  font-size: 12px;
}

select {
  width: 100%;
  margin-top: 6px;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 7px 8px;
}

.switch {
  display: flex;
  align-items: center;
  gap: 8px;
}

.settings-backdrop {
  position: fixed;
  z-index: 40;
  inset: 0;
  background: rgba(3, 6, 8, 0.62);
}

.settings-drawer {
  position: fixed;
  z-index: 50;
  top: 0;
  right: 0;
  width: min(390px, 100%);
  height: 100vh;
  overflow-y: auto;
  padding: 18px;
  background: var(--surface);
  border-left: 1px solid var(--line);
  box-shadow: var(--shadow);
  transform: translateX(100%);
  transition: transform 160ms ease;
}

.settings-drawer.open {
  transform: translateX(0);
}

.settings-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
}

.settings-group {
  padding: 16px 0;
  border-top: 1px solid var(--line-soft);
}

.settings-group label {
  display: block;
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 14px;
}

.settings-group .switch {
  color: var(--text);
}

@media (max-width: 1100px) {
  .workbench {
    grid-template-columns: minmax(0, 1.65fr) minmax(280px, 0.9fr);
  }

  .template-grid,
  .template-grid.compact {
    grid-template-columns: 1fr;
  }

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

  .history-entry {
    grid-template-columns: 48px minmax(0, 1fr);
  }

  .history-result,
  .history-actions {
    grid-column: 2;
  }

  .history-actions {
    justify-content: flex-start;
  }
}

@media (max-width: 920px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .header-tools {
    width: 100%;
    align-items: flex-start;
  }

  .status-panel {
    white-space: normal;
  }

  .quick-links {
    justify-content: flex-start;
    flex-wrap: wrap;
  }

  .page-shell {
    padding: 12px;
  }

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

  .toolbox {
    order: 2;
  }

  .autocomplete-list {
    max-height: min(240px, 46vh);
  }

  .graph-panel canvas {
    min-height: 230px;
    aspect-ratio: 4 / 3;
  }

  .txt-drop-zone button {
    flex: 1 1 150px;
  }
}

@media (max-width: 520px) {
  .topbar {
    padding: 14px;
  }

  .workspace {
    padding: 14px;
  }

  .workspace-head {
    align-items: flex-start;
    flex-direction: column;
    gap: 6px;
  }

  textarea {
    min-height: 210px;
    font-size: 15px;
  }

  .actionbar > button,
  .menu-wrap,
  .menu-wrap > button {
    width: 100%;
  }

  .more-menu {
    left: 0;
    right: 0;
  }

  .example-list {
    grid-template-columns: 1fr;
  }

  .graph-panel canvas {
    min-height: 220px;
  }

  .txt-drop-zone {
    display: grid;
    grid-template-columns: 1fr;
  }

  .history-entry {
    grid-template-columns: 1fr;
  }

  .history-time,
  .history-result,
  .history-actions {
    grid-column: auto;
  }
}

@media (prefers-reduced-motion: reduce) {
  .settings-drawer {
    transition: none;
  }

  .status-dot.pending {
    animation: none;
  }
}

@keyframes statusPulse {
  0%,
  100% {
    opacity: 0.72;
  }

  50% {
    opacity: 1;
  }
}
