:root {
  color-scheme: dark;
  --page: #111413;
  --panel: #191d1b;
  --panel-raised: #202522;
  --border: #303632;
  --border-soft: #272c29;
  --text: #f2f5f2;
  --muted: #949d97;
  --faint: #68716b;
  --accent: #9ce38d;
  --accent-strong: #b7f0aa;
  --accent-ink: #142111;
  --danger: #ff9a8f;
  --warning: #efc36b;
  --radius: 12px;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
}

body {
  margin: 0;
  background:
    radial-gradient(circle at 15% -10%, rgba(101, 151, 93, .11), transparent 30rem),
    var(--page);
  color: var(--text);
  font: 14px/1.45 Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button, select, textarea { font: inherit; }

button, select { color: inherit; }

.app-shell {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100vh;
  height: 100dvh;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex: 0 0 62px;
  padding: 0 18px;
  border-bottom: 1px solid var(--border);
  background: rgba(17, 20, 19, .94);
}

.brand { display: flex; align-items: center; gap: 12px; }
.brand h1 { margin: 0; font-size: 16px; font-weight: 660; letter-spacing: -.01em; }
.brand p { margin: 1px 0 0; color: var(--muted); font-size: 12px; }

.brand-mark {
  position: relative;
  display: grid;
  grid-template-columns: repeat(2, 8px);
  grid-template-rows: repeat(2, 8px);
  gap: 3px;
  width: 31px;
  height: 31px;
  padding: 4px;
  border: 1px solid #50604f;
  border-radius: 9px;
  background: #222a21;
}
.brand-mark span { border-radius: 2px; background: var(--accent); opacity: .94; }
.brand-mark span:nth-child(2) { opacity: .55; }
.brand-mark span:nth-child(3) { grid-column: 1 / 3; width: 13px; }

.api-link { color: var(--muted); font-size: 12px; text-decoration: none; }
.api-link:hover { color: var(--text); }

.workspace {
  display: grid;
  grid-template-columns: minmax(280px, var(--editor-size, 44%)) 7px minmax(360px, 1fr);
  flex: 1;
  min-height: 0;
  overflow: hidden;
  background: var(--panel);
}

.panel { min-width: 0; min-height: 0; }
.editor-panel { display: flex; flex-direction: column; }
.preview-panel { display: grid; grid-template-rows: auto minmax(0, 1fr) auto auto; }

.splitter {
  position: relative;
  z-index: 2;
  width: 7px;
  cursor: col-resize;
  touch-action: none;
  background: var(--border-soft);
  transition: background-color 120ms ease;
}
.splitter::before {
  content: "";
  position: absolute;
  inset: 0 -4px;
}
.splitter span {
  position: absolute;
  top: 50%;
  left: 2px;
  width: 3px;
  height: 34px;
  border-radius: 999px;
  background: #505852;
  transform: translateY(-50%);
}
.splitter:hover, .splitter:focus-visible, .splitter.dragging { background: rgba(156, 227, 141, .42); outline: none; }
.splitter:hover span, .splitter:focus-visible span, .splitter.dragging span { background: var(--accent); }
body.resizing { cursor: col-resize; user-select: none; }

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 52px;
  padding: 9px 13px;
  border-bottom: 1px solid var(--border-soft);
  background: rgba(31, 36, 33, .86);
}

.panel-title { display: flex; align-items: center; gap: 8px; font-size: 12px; font-weight: 620; }
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 3px rgba(156, 227, 141, .09); }
.shortcut { color: var(--faint); font: 11px ui-monospace, SFMono-Regular, Menlo, monospace; }

#source {
  flex: 1;
  width: 100%;
  min-height: 0;
  resize: none;
  border: 0;
  outline: 0;
  padding: 22px 24px;
  background: #171a19;
  color: #dfe8e0;
  caret-color: var(--accent);
  font: 13px/1.75 "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  tab-size: 2;
}
#source::selection { background: rgba(156, 227, 141, .2); }

.editor-footer, .preview-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 34px;
  padding: 0 13px;
  border-top: 1px solid var(--border-soft);
  color: var(--faint);
  font-size: 11px;
  background: #181c1a;
}

.preview-toolbar { gap: 12px; }
.actions { display: flex; align-items: center; gap: 7px; }
.select-control { display: flex; align-items: center; gap: 5px; color: var(--faint); font-size: 10px; text-transform: uppercase; letter-spacing: .05em; }
select {
  height: 31px;
  border: 1px solid var(--border);
  border-radius: 7px;
  outline: none;
  padding: 0 24px 0 8px;
  background: #171b19;
  color: #cbd1cd;
  font-size: 11px;
  text-transform: none;
  letter-spacing: 0;
}
select:focus-visible, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.icon-button, .primary-button {
  height: 31px;
  border: 1px solid var(--border);
  border-radius: 7px;
  cursor: pointer;
}
.icon-button { width: 32px; background: #171b19; color: var(--muted); }
.icon-button:hover:not(:disabled), .icon-button.active { border-color: #576257; color: var(--text); background: #252c27; }
.icon-button:disabled { cursor: default; opacity: .36; }
.primary-button { display: flex; align-items: center; gap: 7px; padding: 0 13px; border-color: #a3e594; background: var(--accent); color: var(--accent-ink); font-size: 12px; font-weight: 700; }
.primary-button:hover:not(:disabled) { background: var(--accent-strong); }
.primary-button:disabled { cursor: wait; opacity: .65; }
.render-icon { font-size: 9px; }
.primary-button.loading .render-icon { animation: pulse .8s ease-in-out infinite alternate; }

.state-badge { padding: 2px 7px; border-radius: 999px; background: #2b332d; color: var(--muted); font-size: 10px; font-weight: 550; }
.state-badge.stale { color: var(--warning); background: rgba(239, 195, 107, .1); }
.state-badge.error { color: var(--danger); background: rgba(255, 154, 143, .1); }
.state-badge.rendered { color: var(--accent); background: rgba(156, 227, 141, .1); }

.preview-canvas {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 0;
  overflow: auto;
  padding: 42px;
  background-color: #e9ebe8;
  background-image:
    linear-gradient(45deg, rgba(40, 50, 44, .04) 25%, transparent 25%),
    linear-gradient(-45deg, rgba(40, 50, 44, .04) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, rgba(40, 50, 44, .04) 75%),
    linear-gradient(-45deg, transparent 75%, rgba(40, 50, 44, .04) 75%);
  background-size: 20px 20px;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0;
}
.preview-canvas.dark-canvas { background-color: #202522; background-image: none; }
.preview-canvas img { display: block; max-width: none; height: auto; filter: drop-shadow(0 12px 22px rgba(15, 21, 17, .13)); }
.preview-canvas.fit-mode img { max-width: 100%; max-height: 100%; object-fit: contain; }

.empty-state { display: flex; flex-direction: column; align-items: center; gap: 5px; color: #6b736e; }
.empty-state strong { color: #3e4641; font-size: 13px; }
.empty-state span { font-size: 11px; }
.empty-glyph { display: flex; align-items: center; gap: 7px; height: 34px; margin-bottom: 4px; }
.empty-glyph span { display: block; width: 18px; height: 18px; border: 1px solid #9ca59f; border-radius: 5px; }
.empty-glyph span:nth-child(2) { position: relative; width: 27px; height: 1px; border: 0; border-top: 1px solid #9ca59f; border-radius: 0; }
.empty-glyph span:nth-child(2)::after { content: ""; position: absolute; right: -1px; top: -4px; width: 6px; height: 6px; border-top: 1px solid #9ca59f; border-right: 1px solid #9ca59f; transform: rotate(45deg); }

.message.error { color: var(--danger); }
.image-summary { font-variant-numeric: tabular-nums; }
.diagnostics { max-height: 180px; overflow: auto; border-top: 1px solid var(--border-soft); background: #1b1d1c; }
.diagnostic { display: grid; grid-template-columns: auto 1fr; gap: 9px; padding: 10px 13px; border-bottom: 1px solid var(--border-soft); font-size: 12px; }
.diagnostic:last-child { border-bottom: 0; }
.diagnostic-position { color: var(--danger); font: 11px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; }
.diagnostic-message { color: #d6dcd7; }
.diagnostic-hint { display: block; margin-top: 2px; color: var(--muted); }

.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

@keyframes pulse { to { transform: scale(.72); opacity: .45; } }

@media (max-width: 900px) {
  .app-header { flex-basis: 56px; padding: 0 12px; }
  .workspace { grid-template-columns: 1fr; grid-template-rows: minmax(0, var(--editor-size, 44%)) 7px minmax(0, 1fr); }
  .splitter { width: auto; height: 7px; cursor: row-resize; }
  .splitter::before { inset: -4px 0; }
  .splitter span { top: 2px; left: 50%; width: 34px; height: 3px; transform: translateX(-50%); }
  body.resizing { cursor: row-resize; }
  .preview-toolbar { align-items: flex-start; flex-direction: column; }
  .actions { width: 100%; flex-wrap: wrap; }
  .primary-button { margin-left: auto; }
}

@media (max-width: 560px) {
  .app-header { padding-inline: 4px; }
  .shortcut, .select-control > span { display: none; }
  .preview-canvas { padding: 20px; }
  #source { padding: 17px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}
