:root {
  color-scheme: light;
  --bg: #f7f8f5;
  --surface: #ffffff;
  --surface-alt: #f0f4f1;
  --surface-strong: #e5ece7;
  --ink: #17201c;
  --muted: #66716a;
  --soft: #879189;
  --line: #d9e0da;
  --line-strong: #b9c4bd;
  --accent: #087f73;
  --accent-strong: #055e56;
  --accent-soft: #dcefeb;
  --amber: #b36b08;
  --amber-soft: #f5ead7;
  --danger: #b13b2f;
  --danger-soft: #f7dfdc;
  --terminal: #111714;
  --terminal-line: #26342f;
  --terminal-ink: #eaf4ef;
  --terminal-muted: #98aaa1;
  --shadow: 0 18px 50px rgba(26, 36, 31, 0.08);
  --radius: 6px;
  --font-ui: "Aptos", "Hiragino Sans", "Yu Gothic UI", "Yu Gothic", sans-serif;
  --font-mono: "SFMono-Regular", "Cascadia Code", "Roboto Mono", "Noto Sans Mono", monospace;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111512;
  --surface: #171d19;
  --surface-alt: #1d2520;
  --surface-strong: #253029;
  --ink: #edf4ef;
  --muted: #9ba8a1;
  --soft: #7f8d85;
  --line: #303b34;
  --line-strong: #455348;
  --accent: #55c8b9;
  --accent-strong: #7fd9ce;
  --accent-soft: #173c38;
  --amber: #f0b454;
  --amber-soft: #3a2b16;
  --danger: #ef8177;
  --danger-soft: #3c1f1c;
  --terminal: #090d0b;
  --terminal-line: #203028;
  --terminal-ink: #f2fbf6;
  --terminal-muted: #96aaa0;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.24);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background:
    linear-gradient(135deg, rgba(8, 127, 115, 0.06), transparent 30%),
    linear-gradient(315deg, rgba(179, 107, 8, 0.07), transparent 34%),
    var(--bg);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 14px;
}

button,
input {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

button:focus-visible,
input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.app-shell {
  min-height: 100vh;
  padding: 18px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  max-width: 1480px;
  margin: 0 auto 14px;
  padding: 12px 14px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

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

.brand-mark {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius);
  background: var(--terminal);
  color: var(--terminal-ink);
  font-family: var(--font-mono);
  font-size: 15px;
  font-weight: 700;
  box-shadow: inset 0 0 0 1px var(--terminal-line);
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 17px;
  line-height: 1.1;
  font-weight: 760;
}

h2 {
  font-size: 13px;
  line-height: 1.2;
  font-weight: 760;
}

.brand p,
.panel-header p,
.preview-meta,
.inspector-meta,
.hint {
  color: var(--muted);
}

.brand p {
  margin-top: 3px;
  font-size: 12px;
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 8px;
}

.segmented {
  display: inline-flex;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-alt);
}

.segment-button,
.tool-button,
.primary-button,
.ghost-button,
.preset-button,
.move-button,
.remove-button {
  min-height: 34px;
  border-radius: var(--radius);
  color: var(--ink);
  transition:
    background 140ms ease,
    color 140ms ease,
    border-color 140ms ease,
    transform 140ms ease;
}

.segment-button {
  padding: 0 10px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 680;
}

.segment-button.is-active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}

.tool-button,
.primary-button {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 0 12px;
  font-size: 12px;
  font-weight: 720;
}

.tool-button {
  border: 1px solid var(--line);
  background: var(--surface);
}

.primary-button {
  background: var(--accent);
  color: #ffffff;
}

.primary-button:hover,
.preset-button:hover,
.tool-button:hover,
.ghost-button:hover,
.move-button:hover,
.remove-button:hover {
  transform: translateY(-1px);
}

.workspace {
  display: grid;
  grid-template-columns: minmax(260px, 320px) minmax(420px, 1fr) minmax(320px, 390px);
  gap: 14px;
  max-width: 1480px;
  margin: 0 auto;
  min-height: calc(100vh - 96px);
}

.panel,
.stage {
  min-width: 0;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.item-panel,
.inspector-panel {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

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

.panel-header p {
  margin-top: 4px;
  font-size: 12px;
}

.search-field {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 12px;
  padding: 0 10px;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-alt);
  color: var(--soft);
}

.search-field input {
  width: 100%;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
  font-size: 13px;
}

.item-list,
.order-list {
  overflow: auto;
}

.item-list {
  padding: 0 8px 12px;
}

.item-row {
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr) 26px;
  gap: 8px;
  align-items: start;
  width: 100%;
  padding: 9px 8px;
  border-radius: var(--radius);
  color: var(--ink);
}

.item-row:hover,
.item-row.is-focused {
  background: var(--surface-alt);
}

.check {
  display: grid;
  place-items: center;
  width: 18px;
  height: 18px;
  margin-top: 1px;
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  color: transparent;
  font-size: 12px;
  font-weight: 800;
}

.item-row.is-selected .check {
  border-color: var(--accent);
  background: var(--accent);
  color: #ffffff;
}

.item-main {
  min-width: 0;
  text-align: left;
}

.key-label,
.order-key,
.inspector-key {
  font-family: var(--font-mono);
  letter-spacing: 0;
}

.key-label {
  display: block;
  overflow: hidden;
  color: var(--ink);
  font-size: 12px;
  font-weight: 720;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.item-desc {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.info-dot {
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 999px;
  background: var(--surface-strong);
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.stage {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.preview-band,
.order-panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.preview-band {
  padding: 14px;
}

.preview-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
  font-size: 12px;
  font-weight: 720;
}

.switch {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  user-select: none;
}

.switch input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.switch-ui {
  position: relative;
  width: 36px;
  height: 20px;
  border-radius: 999px;
  background: var(--surface-strong);
  border: 1px solid var(--line-strong);
}

.switch-ui::after {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--surface);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.24);
  content: "";
  transition: transform 160ms ease;
}

.switch input:checked + .switch-ui {
  background: var(--accent);
  border-color: var(--accent);
}

.switch input:checked + .switch-ui::after {
  transform: translateX(16px);
}

.terminal-preview {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 76px;
  padding: 14px;
  overflow: hidden;
  border-radius: var(--radius);
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.03), transparent),
    var(--terminal);
  border: 1px solid var(--terminal-line);
  color: var(--terminal-ink);
  font-family: var(--font-mono);
  font-size: 12px;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.02);
}

.preview-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  max-width: 170px;
  height: 28px;
  padding: 0 9px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--terminal-ink);
  white-space: nowrap;
}

.preview-chip.is-muted {
  color: var(--terminal-muted);
}

.preview-chip.use-color[data-tone="model"] {
  color: #90d7ff;
}

.preview-chip.use-color[data-tone="path"] {
  color: #b8e986;
}

.preview-chip.use-color[data-tone="git"] {
  color: #ffd37e;
}

.preview-chip.use-color[data-tone="state"] {
  color: #ff9d8a;
}

.preview-chip.use-color[data-tone="usage"] {
  color: #bfa7ff;
}

.preview-chip.use-color[data-tone="meta"] {
  color: #89eadf;
}

.preview-chip span:last-child {
  overflow: hidden;
  text-overflow: ellipsis;
}

.preset-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.preset-button,
.ghost-button {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  font-size: 12px;
  font-weight: 720;
}

.preset-button {
  padding: 0 13px;
}

.ghost-button {
  padding: 0 10px;
}

.order-panel {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.order-header {
  flex: 0 0 auto;
}

.order-list {
  padding: 10px;
}

.order-row {
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  min-height: 54px;
  margin-bottom: 8px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

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

.order-row[draggable="true"] {
  cursor: grab;
}

.order-row.is-dragging {
  opacity: 0.52;
}

.order-index {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: var(--radius);
  background: var(--surface-alt);
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 760;
}

.order-main {
  min-width: 0;
}

.order-key {
  display: block;
  overflow: hidden;
  font-size: 12px;
  font-weight: 760;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.order-example {
  display: block;
  margin-top: 4px;
  overflow: hidden;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.order-actions {
  display: inline-flex;
  gap: 4px;
}

.move-button,
.remove-button {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  min-height: 30px;
  border: 1px solid var(--line);
  background: var(--surface-alt);
  color: var(--muted);
  font-size: 13px;
  font-weight: 760;
}

.remove-button {
  color: var(--danger);
  background: var(--danger-soft);
  border-color: color-mix(in srgb, var(--danger) 28%, var(--line));
}

.inspector-panel {
  gap: 0;
}

.inspector-section {
  min-height: 316px;
  border-bottom: 1px solid var(--line);
}

.inspector-card {
  padding: 14px;
}

.inspector-key {
  display: inline-block;
  max-width: 100%;
  overflow: hidden;
  padding: 7px 9px;
  border-radius: var(--radius);
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 760;
  text-overflow: ellipsis;
}

.inspector-title {
  margin-top: 14px;
  font-size: 18px;
  line-height: 1.25;
  font-weight: 780;
}

.inspector-copy {
  margin-top: 10px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.7;
}

.inspector-meta {
  display: grid;
  gap: 8px;
  margin-top: 14px;
}

.meta-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 0;
  border-top: 1px solid var(--line);
  font-size: 12px;
}

.meta-row strong {
  color: var(--ink);
  font-family: var(--font-mono);
  font-weight: 720;
  text-align: right;
}

.toml-section {
  min-height: 0;
  display: flex;
  flex: 1;
  flex-direction: column;
}

.code-header {
  flex: 0 0 auto;
}

.code-block {
  flex: 1;
  min-height: 280px;
  margin: 0;
  padding: 14px;
  overflow: auto;
  background: var(--terminal);
  color: var(--terminal-ink);
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.65;
  white-space: pre;
}

.empty-state {
  padding: 20px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
  text-align: center;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 20;
  max-width: min(360px, calc(100vw - 36px));
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow);
  font-size: 13px;
  opacity: 0;
  transform: translateY(12px);
  transition:
    opacity 160ms ease,
    transform 160ms ease;
  pointer-events: none;
}

.toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 1160px) {
  .workspace {
    grid-template-columns: minmax(240px, 300px) minmax(360px, 1fr);
  }

  .inspector-panel {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.1fr);
  }

  .inspector-section {
    border-right: 1px solid var(--line);
    border-bottom: 0;
  }
}

@media (max-width: 760px) {
  .app-shell {
    padding: 10px;
  }

  .topbar,
  .workspace,
  .inspector-panel {
    display: flex;
    flex-direction: column;
  }

  .topbar {
    align-items: stretch;
  }

  .brand {
    min-width: 0;
  }

  .toolbar {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    justify-content: stretch;
  }

  .segmented {
    grid-column: 1 / -1;
    min-width: 0;
  }

  .tool-button,
  .primary-button {
    width: 100%;
    min-width: 0;
  }

  .primary-button {
    grid-column: 1 / -1;
  }

  .segment-button,
  .tool-button,
  .primary-button {
    justify-content: center;
  }

  .workspace {
    min-height: auto;
  }

  .stage {
    order: -1;
  }

  .terminal-preview {
    min-height: 68px;
    overflow-x: auto;
  }

  .preview-chip {
    flex: 0 0 auto;
    max-width: 145px;
  }

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

  .order-actions {
    grid-column: 2 / -1;
    justify-content: flex-start;
  }

  .inspector-section {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .code-block {
    min-height: 230px;
  }
}

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