[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0d1117;
  --surface: #161b22;
  --border: #30363d;
  --text: #e6edf3;
  --muted: #8b949e;
  --accent: #58a6ff;
  --accent-dim: #388bfd66;
  --success: #3fb950;
  --error: #f85149;
  --btn-hover: #21262d;
  --hist-hover: #1c2128;
  --primary-fg: #0d1117;
}

[data-theme="light"] {
  color-scheme: light;
  --bg: #f6f8fa;
  --surface: #ffffff;
  --border: #d0d7de;
  --text: #1f2328;
  --muted: #656d76;
  --accent: #0969da;
  --accent-dim: #0969da33;
  --success: #1a7f37;
  --error: #cf222e;
  --btn-hover: #eaeef2;
  --hist-hover: #eaeef2;
  --primary-fg: #ffffff;
}

:root {
  --font: "JetBrains Mono", "Fira Code", "SF Mono", Consolas, monospace;
  --font-ui: system-ui, -apple-system, "Segoe UI", sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
}

.app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.brand h1 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 650;
  letter-spacing: -0.02em;
}

.logo {
  color: var(--accent);
  font-size: 1.1rem;
}

.tagline {
  margin: 0;
  font-size: 0.8rem;
  color: var(--muted);
  width: 100%;
  margin-left: 0;
}

@media (min-width: 640px) {
  .tagline {
    width: auto;
    margin-left: 0.25rem;
  }
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

button {
  font-family: var(--font-ui);
  font-size: 0.85rem;
  padding: 0.45rem 0.9rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
}

button:hover {
  border-color: var(--muted);
  background: var(--btn-hover);
}

button.theme-toggle {
  min-width: 5.5rem;
}

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--primary-fg);
  font-weight: 600;
}

button.primary:hover {
  filter: brightness(1.08);
}

button.small {
  padding: 0.25rem 0.5rem;
  font-size: 0.75rem;
}

button.danger:hover {
  border-color: var(--error);
  color: var(--error);
}

.status {
  font-size: 0.8rem;
  color: var(--muted);
  margin-left: 0.25rem;
}

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

.status.busy {
  color: var(--accent);
}

.main {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: minmax(200px, 1fr) minmax(160px, 0.45fr);
  grid-template-areas:
    "editor output"
    "history history";
  gap: 1px;
  background: var(--border);
  min-height: 0;
}

@media (max-width: 960px) {
  .main {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(220px, 40vh) minmax(180px, 30vh) auto;
    grid-template-areas:
      "editor"
      "output"
      "history";
  }
}

.panel {
  background: var(--bg);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.editor-panel {
  grid-area: editor;
}

.output-panel {
  grid-area: output;
}

.history-panel {
  grid-area: history;
  max-height: 320px;
}

@media (max-width: 960px) {
  .history-panel {
    max-height: none;
  }
}

.panel-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.4rem 0.75rem;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.pkg-line {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.7rem;
  text-transform: none;
  letter-spacing: normal;
  font-weight: normal;
}

.pkg-line input {
  width: min(280px, 50vw);
  padding: 0.25rem 0.45rem;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-family: var(--font);
  font-size: 0.75rem;
}

.CodeMirror {
  height: 100% !important;
  font-family: var(--font);
  font-size: 13px;
  line-height: 1.45;
}

.editor-panel .CodeMirror-wrap {
  flex: 1;
  min-height: 200px;
}

.output {
  margin: 0;
  flex: 1;
  padding: 0.75rem 1rem;
  overflow: auto;
  font-family: var(--font);
  font-size: 12.5px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}

.output .err {
  color: var(--error);
}

.output .meta {
  color: var(--muted);
  font-style: italic;
}

.hint {
  margin: 0;
  padding: 0.5rem 0.75rem;
  font-size: 0.8rem;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
}

.history-list {
  list-style: none;
  margin: 0;
  padding: 0.35rem;
  overflow: auto;
  flex: 1;
}

.history-list li {
  margin-bottom: 0.35rem;
}

.history-list button.entry {
  width: 100%;
  text-align: left;
  padding: 0.5rem 0.65rem;
  border-radius: 6px;
  border: 1px solid transparent;
  background: var(--surface);
  color: var(--text);
  font-family: var(--font);
  font-size: 0.72rem;
  line-height: 1.35;
  cursor: pointer;
  display: block;
}

.history-list button.entry:hover {
  border-color: var(--accent-dim);
  background: var(--hist-hover);
}

.history-list .time {
  display: block;
  font-size: 0.65rem;
  color: var(--muted);
  margin-bottom: 0.2rem;
  font-family: var(--font-ui);
}

.history-list .preview {
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  white-space: pre-wrap;
  word-break: break-word;
}

.history-empty {
  padding: 1rem;
  color: var(--muted);
  font-size: 0.85rem;
  text-align: center;
}
