:root {
  color-scheme: light;
  --bg: #f4f6f4;
  --surface: #ffffff;
  --surface-2: #eef3f1;
  --ink: #18201d;
  --muted: #61716b;
  --line: #d6dfda;
  --accent: #116b5b;
  --accent-2: #0f5c88;
  --warn: #a15c00;
  --danger: #a43b3b;
  --shadow: 0 12px 30px rgba(21, 39, 33, 0.08);
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111715;
  --surface: #1a2420;
  --surface-2: #24312c;
  --ink: #edf4f1;
  --muted: #adbbb6;
  --line: #364640;
  --accent: #31a58e;
  --accent-2: #4aa3d2;
  --warn: #d49a3d;
  --danger: #e07b7b;
  --shadow: 0 14px 34px rgba(0, 0, 0, 0.24);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
  letter-spacing: 0;
}

button,
input,
textarea,
select {
  font: inherit;
}

button {
  min-height: 40px;
  border: 0;
  border-radius: 8px;
  padding: 0 14px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  font-weight: 650;
}

button:hover {
  filter: brightness(0.96);
}

button:disabled {
   cursor: not-allowed;
  opacity: 0.55;
}

button.secondary,
.segmented button {
  background: var(--surface-2);
  color: var(--ink);
  border: 1px solid var(--line);
}

.icon-button {
  width: 40px;
  padding: 0;
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--line);
}

.icon-button.wide {
  width: 56px;
}

#app {
  width: min(1180px, 100%);
  margin: 0 auto;
  padding: 18px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 2px 16px;
}

.topbar h1 {
  margin: 0;
  font-size: clamp(24px, 4vw, 34px);
  line-height: 1.1;
}

.topbar p {
  margin: 6px 0 0;
  color: var(--muted);
}

.top-actions,
.button-row,
.primary-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}

.tabs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 14px;
}

.tab {
  background: var(--surface);
  color: var(--muted);
  border: 1px solid var(--line);
}

.tab.active {
  color: #fff;
  background: var(--accent-2);
  border-color: var(--accent-2);
}

.page {
  display: none;
}

.page.active {
  display: block;
}

.layout {
  display: grid;
  gap: 14px;
}

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

.layout.editor {
  grid-template-columns: minmax(330px, 0.95fr) minmax(330px, 1.05fr);
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 14px;
}

.section-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.section-title h2 {
  margin: 0;
  font-size: 18px;
}

.section-title span,
.hint {
  color: var(--muted);
  font-size: 13px;
}

.hint {
  margin-top: 12px;
  line-height: 1.5;
}

.kv,
.profile-card {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  gap: 8px 14px;
  margin-top: 14px;
  padding: 12px;
  border-radius: 8px;
  background: var(--surface-2);
  min-width: 0;
}

.kv span,
.profile-card span {
  color: var(--muted);
}

.kv strong,
.profile-card strong {
  min-width: 0;
  overflow-wrap: anywhere;
}

.form-grid,
.profile-strip {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  align-items: end;
}

.profile-strip {
  grid-template-columns: minmax(180px, 1fr) auto minmax(220px, 1fr);
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 620;
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  padding: 10px 11px;
  outline: none;
}

textarea {
  resize: vertical;
  min-height: 118px;
  line-height: 1.5;
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--accent-2);
  box-shadow: 0 0 0 3px rgba(15, 92, 136, 0.12);
}

.file-drop {
  margin-top: 12px;
  min-height: 54px;
  place-items: center;
  border: 1px dashed #9badb2;
  border-radius: 8px;
  background: var(--surface-2);
  cursor: pointer;
}

.file-drop input {
  display: none;
}

.inline-file {
  min-height: 40px;
  display: inline-grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--ink);
  padding: 0 14px;
  cursor: pointer;
}

.inline-file input {
  display: none;
}

.hidden {
  display: none !important;
}

.section-title.compact {
  margin-top: 14px;
  margin-bottom: 8px;
}

.section-title.compact h2 {
  font-size: 15px;
}

.mixed-tools,
.doodle-tools {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.mixed-list {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.mixed-item {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--ink);
  font-size: 13px;
}

.mixed-item span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mixed-item button {
  min-height: 30px;
  padding: 0 10px;
}

#doodleCanvas {
  display: block;
  width: 100%;
  max-width: 520px;
  aspect-ratio: 16 / 15;
  height: auto;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  touch-action: none;
  cursor: crosshair;
}

.mini-control {
  width: min(220px, 100%);
}

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

.preview-shell {
  height: min(62vh, 560px);
  min-height: 330px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(45deg, #eef1f0 25%, transparent 25%),
    linear-gradient(-45deg, #eef1f0 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #eef1f0 75%),
    linear-gradient(-45deg, transparent 75%, #eef1f0 75%);
  background-size: 20px 20px;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0;
  padding: 14px;
}

#previewCanvas {
  display: block;
  width: min(100%, 384px);
  height: auto;
  margin: 0 auto;
  background: #fff;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.12);
  image-rendering: auto;
}

.controls {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) auto auto minmax(260px, auto);
  align-items: center;
  gap: 14px;
}

.segmented {
  display: inline-grid;
  grid-template-columns: repeat(3, max-content);
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--line);
}

.segmented button {
  border: 0;
  border-radius: 0;
  min-width: 92px;
}

.segmented button.active {
  background: var(--accent-2);
  color: #fff;
}

.toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--ink);
}

.toggle input {
  width: 18px;
  height: 18px;
}

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

.log,
.history {
  min-height: 320px;
  max-height: 520px;
  overflow: auto;
  display: grid;
  align-content: start;
  gap: 8px;
}

.entry {
  padding: 10px;
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--ink);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.45;
}

.entry.warn {
  border-left: 4px solid var(--warn);
}

.entry.error {
  border-left: 4px solid var(--danger);
}

@media (max-width: 860px) {
  #app {
    padding: 12px;
  }

  .layout.two,
  .layout.editor,
  .form-grid,
  .profile-strip,
  .controls {
    grid-template-columns: 1fr;
  }

  .tabs {
    gap: 6px;
  }

  .tab {
    padding: 0 6px;
  }

  .segmented {
    grid-template-columns: 1fr;
    width: 100%;
  }

  .segmented button {
    width: 100%;
  }

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

  .preview-shell {
    min-height: 260px;
  }
}
