:root {
  --bg-app: #0c0d0f;
  --bg-surface: #17181b;
  --bg-surface-raised: #1c1e22;
  --bg-editor: #0a0b0d;
  --bg-input: #131417;

  --border: #2a2c31;
  --border-strong: #3a3c43;

  --text-primary: #e7e8eb;
  --text-secondary: #9a9ca6;
  --text-tertiary: #6b6d77;

  --accent: #5b9fdd;
  --accent-hover: #6fadE3;
  --accent-active: #4c8bc9;
  --accent-soft: rgba(91, 159, 221, 0.12);
  --accent-border: rgba(91, 159, 221, 0.35);

  --success: #4fae7c;
  --warning: #d3a054;
  --danger: #dc6f68;

  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 8px;

  --font-ui: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
  --font-mono: 'JetBrains Mono', 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
}

body {
  background-color: var(--bg-app);
  color: var(--text-primary);
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 1.5;
  padding: 24px;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 {
  margin: 0;
  font-weight: 600;
}

button {
  font-family: inherit;
}

/* ---------- Layout shell ---------- */

.app {
  max-width: 1400px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ---------- Header ---------- */

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

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

.brand-mark {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: var(--radius-md);
  background: var(--accent-soft);
  border: 1px solid var(--accent-border);
  color: var(--accent);
  font-weight: 600;
  font-size: 15px;
  flex-shrink: 0;
}

.brand-title {
  font-size: 16px;
  color: var(--text-primary);
  letter-spacing: -0.01em;
}

.brand-subtitle {
  font-size: 12.5px;
  color: var(--text-secondary);
  margin-top: 2px;
}

.header-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
  color: var(--text-tertiary);
  white-space: nowrap;
}

.meta-sep {
  color: var(--border-strong);
}

/* ---------- Stats bar ---------- */

.stats-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.stat-item {
  flex: 1 1 140px;
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 10px 18px;
  border-right: 1px solid var(--border);
}

.stat-item:last-child {
  border-right: none;
}

.stat-value {
  font-family: var(--font-mono);
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
}

.stat-label {
  font-size: 12px;
  color: var(--text-tertiary);
}

/* ---------- Workspace grid ---------- */

.workspace {
  display: grid;
  grid-template-columns: 1.1fr 300px 1.1fr;
  gap: 16px;
  align-items: start;
}

.editor-panel,
.settings-panel {
  display: flex;
  flex-direction: column;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.panel-head {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-surface-raised);
}

.panel-head h2 {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-secondary);
}

.editor-wrap {
  flex: 1 1 auto;
  display: flex;
  background: var(--bg-editor);
  min-height: 420px;
}

textarea {
  width: 100%;
  height: 100%;
  min-height: 420px;
  background: transparent;
  border: none;
  resize: none;
  outline: none;
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 12.5px;
  line-height: 1.6;
  padding: 14px 16px;
  tab-size: 4;
}

textarea::placeholder {
  color: var(--text-tertiary);
}

textarea[readonly] {
  color: #b9c9db;
}

/* ---------- Settings panel ---------- */

.settings-panel {
  min-width: 0;
}

.settings-scroll {
  padding: 14px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 18px;
  max-height: 70vh;
}

.settings-group-title {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 10px;
}

.option-row {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  padding: 7px 0;
  cursor: pointer;
}

.option-row input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  width: 15px;
  height: 15px;
  margin-top: 2px;
  flex-shrink: 0;
  border: 1px solid var(--border-strong);
  border-radius: 3px;
  background: var(--bg-input);
  cursor: pointer;
  position: relative;
  transition: background-color 0.1s ease, border-color 0.1s ease;
}

.option-row input[type="checkbox"]:checked {
  background: var(--accent);
  border-color: var(--accent);
}

.option-row input[type="checkbox"]:checked::after {
  content: "";
  position: absolute;
  left: 4px;
  top: 1px;
  width: 4px;
  height: 8px;
  border: solid #0c1116;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

.option-row input[type="checkbox"]:focus-visible {
  outline: 2px solid var(--accent-border);
  outline-offset: 2px;
}

.option-text {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.option-title {
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-primary);
}

.option-desc {
  font-size: 11.5px;
  color: var(--text-tertiary);
  line-height: 1.35;
}

.select-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 12px;
}

.select-row:last-child {
  margin-bottom: 0;
}

.select-row label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
}

select {
  appearance: none;
  -webkit-appearance: none;
  background: var(--bg-input);
  border: 1px solid var(--border-strong);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 12px;
  padding: 7px 28px 7px 10px;
  border-radius: var(--radius-sm);
  outline: none;
  cursor: pointer;
  width: 100%;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6' fill='none'><path d='M1 1L5 5L9 1' stroke='%239a9ca6' stroke-width='1.4' stroke-linecap='round' stroke-linejoin='round'/></svg>");
  background-repeat: no-repeat;
  background-position: right 10px center;
}

select:hover {
  border-color: var(--text-tertiary);
}

select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

select option {
  background: var(--bg-surface);
  color: var(--text-primary);
}

/* ---------- Scrollbars ---------- */

.settings-scroll,
.terminal-body {
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}

.settings-scroll::-webkit-scrollbar,
.terminal-body::-webkit-scrollbar {
  width: 8px;
}

.settings-scroll::-webkit-scrollbar-track,
.terminal-body::-webkit-scrollbar-track {
  background: transparent;
}

.settings-scroll::-webkit-scrollbar-thumb,
.terminal-body::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 4px;
}

.settings-scroll::-webkit-scrollbar-thumb:hover,
.terminal-body::-webkit-scrollbar-thumb:hover {
  background: var(--text-tertiary);
}

/* ---------- Footer / buttons ---------- */

.panel-foot {
  padding: 12px 14px;
  border-top: 1px solid var(--border);
  background: var(--bg-surface-raised);
}

.btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 9px 14px;
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 0.12s ease, border-color 0.12s ease, opacity 0.12s ease;
}

.btn-primary {
  background: var(--accent);
  color: #0c1116;
  border-color: var(--accent);
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
}

.btn-primary:active:not(:disabled) {
  background: var(--accent-active);
}

.btn-primary:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.btn-secondary {
  background: transparent;
  color: var(--text-primary);
  border-color: var(--border-strong);
}

.btn-secondary:hover:not(:disabled) {
  border-color: var(--text-tertiary);
  background: var(--bg-input);
}

.btn-secondary:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-loader {
  width: 13px;
  height: 13px;
  border: 2px solid rgba(12, 17, 22, 0.3);
  border-top-color: #0c1116;
  border-radius: 50%;
  flex-shrink: 0;
  animation: spin 0.7s linear infinite;
}

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

.hidden {
  display: none !important;
}

/* ---------- Terminal ---------- */

.terminal {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.terminal-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-surface-raised);
}

.console-indicator {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-tertiary);
  flex-shrink: 0;
}

.status-green {
  background-color: var(--success);
}

.status-amber {
  background-color: var(--warning);
}

.status-red {
  background-color: var(--danger);
}

.terminal-title {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
}

.terminal-body {
  height: 150px;
  padding: 10px 16px;
  background: var(--bg-editor);
  font-family: var(--font-mono);
  font-size: 12px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.console-line {
  line-height: 1.5;
  color: var(--text-secondary);
  white-space: pre-wrap;
  word-break: break-word;
}

.line-system {
  color: var(--text-tertiary);
}

.line-success {
  color: var(--success);
}

.line-warning {
  color: var(--warning);
}

.line-error {
  color: var(--danger);
  background: rgba(220, 111, 104, 0.08);
  border-left: 2px solid var(--danger);
  padding-left: 8px;
  margin-left: -8px;
}

/* ---------- Responsive ---------- */

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

  .editor-wrap,
  textarea {
    min-height: 320px;
  }

  .settings-scroll {
    max-height: none;
  }
}

@media (max-width: 720px) {
  body {
    padding: 14px;
  }

  .app-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
  }

  .stat-item {
    flex: 1 1 45%;
  }

  .editor-wrap,
  textarea {
    min-height: 260px;
  }

  .terminal-body {
    height: 130px;
  }
}

@media (max-width: 420px) {
  .stat-item {
    flex: 1 1 100%;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  .stat-item:last-child {
    border-bottom: none;
  }
}
