:root {
  --bg: #11130f;
  --panel: #171a15;
  --panel-2: #1e221c;
  --line: #32382d;
  --line-strong: #4b5543;
  --text: #e5e7dc;
  --muted: #9da491;
  --green: #69c27d;
  --cyan: #61c3cf;
  --gold: #d8b45d;
  --red: #e66a61;
  --input: #0c0e0b;
  --focus: rgba(97, 195, 207, 0.24);
  --shadow: rgba(0, 0, 0, 0.35);
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

button,
input,
select {
  font: inherit;
}

button {
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  border-radius: 6px;
  min-height: 34px;
  padding: 0 12px;
  cursor: pointer;
}

button:hover {
  border-color: var(--cyan);
  color: white;
}

button:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 2px;
  box-shadow: 0 0 0 4px var(--focus);
}

input,
select {
  border: 1px solid var(--line);
  background: var(--input);
  color: var(--text);
  border-radius: 6px;
  min-height: 34px;
  padding: 0 10px;
}

label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

#app-shell {
  height: 100%;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

#topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 14px;
  background: #151812;
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 180px;
}

.brand-mark {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  color: var(--gold);
  font-weight: 800;
  background: #222016;
}

h1 {
  margin: 0;
  font-size: 16px;
  line-height: 1.15;
  letter-spacing: 0;
}

#connection-label {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}

#connection-label.connected {
  color: var(--green);
}

#connection-label.error {
  color: var(--red);
}

.profile-form {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  min-width: 0;
}

.profile-form input {
  width: 160px;
}

.profile-form select {
  width: 128px;
}

#save-state {
  color: var(--muted);
  font-size: 12px;
  width: 64px;
  text-align: right;
}

#save-state.saving {
  color: var(--gold);
}

#save-state.error {
  color: var(--red);
}

#workspace {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 420px;
}

#terminal-pane {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  background: #090b08;
}

#terminal-output {
  min-height: 0;
  overflow: auto;
  padding: 12px 14px;
  font-family: "Cascadia Mono", "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 14px;
  line-height: 1.35;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.terminal-line {
  min-height: 18px;
}

.terminal-link {
  color: var(--cyan);
  text-decoration: underline;
  text-decoration-color: rgba(97, 195, 207, 0.45);
  text-underline-offset: 2px;
}

.terminal-link:hover {
  color: #9be7ef;
  text-decoration-color: currentColor;
}

.terminal-local {
  color: var(--gold);
}

.terminal-system {
  color: var(--cyan);
}

.terminal-error {
  color: var(--red);
}

.hl-cyan {
  color: #76d8e0;
}

.hl-green {
  color: #8dde9b;
}

.hl-gold {
  color: #f1cf73;
}

.hl-red {
  color: #ff8178;
}

#command-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 8px;
  padding: 10px;
  border-top: 1px solid var(--line);
  background: #12150f;
}

#command-input {
  min-width: 0;
}

#send-command {
  background: #244b35;
  border-color: #3b7352;
}

#connect-toggle {
  color: var(--cyan);
}

#connect-toggle.connected {
  color: var(--red);
}

#module-pane {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  border-left: 1px solid var(--line);
  background: var(--panel);
}

#module-tabs {
  display: flex;
  gap: 4px;
  padding: 8px;
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
}

#module-tabs button {
  flex: 0 0 auto;
  min-height: 30px;
  padding: 0 10px;
  color: var(--muted);
}

#module-tabs button.active {
  border-color: var(--gold);
  color: var(--gold);
  background: #242113;
}

.module-panel {
  min-height: 0;
  overflow: auto;
  display: none;
  padding: 12px;
}

.module-panel.active {
  display: block;
}

.module-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.module-head h2 {
  margin: 0;
  font-size: 15px;
  letter-spacing: 0;
}

.rows {
  display: grid;
  gap: 8px;
}

.editor-row {
  display: grid;
  gap: 8px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #141711;
}

.trigger-row {
  grid-template-columns: 28px minmax(0, 1fr) minmax(0, 1fr) 84px 34px;
}

.trigger-tester {
  display: grid;
  gap: 8px;
  margin-bottom: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.trigger-test-input {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.trigger-test-results {
  display: grid;
  gap: 6px;
}

.trigger-test-result {
  display: grid;
  gap: 4px;
  padding: 7px 8px;
  border-left: 3px solid var(--line);
  background: rgba(255, 255, 255, 0.02);
}

.trigger-test-result.matched {
  border-left-color: var(--green);
}

.trigger-test-result.error {
  border-left-color: var(--red);
}

.trigger-test-result.disabled {
  opacity: 0.62;
}

.trigger-test-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.trigger-test-title span {
  color: var(--muted);
  font-size: 12px;
}

.trigger-test-detail {
  color: var(--muted);
  font-size: 12px;
}

.trigger-test-detail code {
  color: var(--gold);
}

.trigger-test-detail.error {
  color: var(--red);
}

.alias-row {
  grid-template-columns: 28px minmax(0, 0.8fr) minmax(0, 1.2fr) 34px;
}

.variable-row {
  grid-template-columns: minmax(0, 0.8fr) minmax(0, 1.2fr) 34px;
}

.hotkey-row {
  grid-template-columns: 78px minmax(0, 1fr) 34px;
}

.editor-row input,
.editor-row select {
  width: 100%;
}

.editor-row input[type="checkbox"] {
  width: 18px;
  min-height: 18px;
  align-self: center;
  accent-color: var(--green);
}

.remove-btn {
  padding: 0;
  color: var(--red);
}

.empty-state {
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 12px;
}

.settings-grid {
  display: grid;
  gap: 10px;
}

.setting-line {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  padding: 8px 0;
}

.setting-line span:first-child {
  color: var(--muted);
}

@media (max-width: 980px) {
  body {
    overflow: auto;
  }

  #app-shell {
    min-height: 100%;
    height: auto;
  }

  #topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .profile-form {
    justify-content: stretch;
    flex-wrap: wrap;
  }

  .profile-form input {
    flex: 1 1 140px;
  }

  #workspace {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(60vh, 1fr) auto;
  }

  #module-pane {
    border-left: 0;
    border-top: 1px solid var(--line);
  }

  .trigger-row,
  .alias-row,
  .variable-row,
  .hotkey-row {
    grid-template-columns: 1fr;
  }

  .trigger-test-input {
    grid-template-columns: 1fr;
  }

  .editor-row input[type="checkbox"] {
    justify-self: start;
  }
}
