:root {
  --bg-1: #0b1320;
  --bg-2: #17253a;
  --panel: #111d2e;
  --panel-soft: #1b2d46;
  --ink: #e8f0ff;
  --ink-soft: #aac1e6;
  --accent: #ff875f;
  --accent-2: #5eead4;
  --ok: #85efac;
  --line: rgba(255, 255, 255, 0.12);
  --ring: rgba(94, 234, 212, 0.45);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Space Grotesk", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(1200px 700px at -10% -20%, #1d3353 0%, transparent 60%),
    radial-gradient(800px 600px at 110% 10%, rgba(255, 135, 95, 0.25) 0%, transparent 60%),
    linear-gradient(145deg, var(--bg-1), var(--bg-2));
}

.app-shell {
  width: min(1240px, calc(100vw - 2rem));
  margin: 1rem auto;
  border: 1px solid var(--line);
  border-radius: 20px;
  backdrop-filter: blur(8px);
  background: rgba(8, 14, 24, 0.78);
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.35);
  overflow: hidden;
}

.app-header {
  display: flex;
  gap: 0.75rem;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.2rem;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(90deg, rgba(255, 135, 95, 0.15), rgba(94, 234, 212, 0.1));
}

.app-header h1 {
  margin: 0;
  font-size: clamp(1.05rem, 2.3vw, 1.35rem);
  letter-spacing: 0.02em;
}

.eyebrow,
.subtitle,
.meta,
.shortcut-note {
  margin: 0;
  color: var(--ink-soft);
}

.eyebrow {
  font-size: 0.75rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.subtitle {
  font-size: 0.9rem;
}

.meta {
  margin-top: 0.3rem;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.76rem;
}

.meta.saved {
  color: var(--ok);
}

.header-actions {
  display: flex;
  gap: 0.55rem;
  flex-wrap: wrap;
}

.toolbar {
  display: flex;
  gap: 0.55rem;
  flex-wrap: wrap;
  align-items: stretch;
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--line);
}

.tool-section {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 0.5rem;
  padding: 0.5rem;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.02);
}

.tool-title {
  margin: 0;
  width: 100%;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.68rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-soft);
  opacity: 0.95;
}

.toggle-wrap {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.8rem;
  color: var(--ink-soft);
  margin-right: 0.2rem;
}

.toggle-wrap input {
  accent-color: var(--accent-2);
}

.field {
  display: grid;
  gap: 0.2rem;
  color: var(--ink-soft);
  font-size: 0.74rem;
}

.field select,
.field input,
.group button,
.btn {
  font-family: inherit;
  color: var(--ink);
  background: var(--panel-soft);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 10px;
  padding: 0.5rem 0.9rem;
  font-size: 0.84rem;
  font-weight: 500;
  cursor: pointer;
  transition: transform 160ms ease, border-color 160ms ease, background 160ms ease;
}

.toolbar .group button,
.toolbar > .btn {
  min-width: 86px;
}

.btn {
  border-radius: 999px;
}

.btn:hover,
.group button:hover,
.field select:hover,
.field input:hover {
  transform: translateY(-1px);
  border-color: var(--accent-2);
}

.size-custom {
  min-width: 220px;
}

.size-row {
  display: grid;
  grid-template-columns: 74px 64px auto;
  gap: 0.35rem;
}

#custom-size-value {
  width: 100%;
}

.btn-danger {
  color: #1f130f;
  background: linear-gradient(90deg, var(--accent), #ffab75);
  border-color: transparent;
  font-weight: 700;
}

.group {
  display: flex;
  gap: 0.4rem;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 0.18rem;
  background: rgba(255, 255, 255, 0.03);
}

.image-tools {
  flex-wrap: wrap;
  align-items: end;
  gap: 0.5rem;
}

.table-section {
  width: 100%;
}

.table-section > summary {
  cursor: pointer;
  list-style: none;
}

.table-section > summary::-webkit-details-marker {
  display: none;
}

.table-section > summary::after {
  content: " (expand)";
  font-size: 0.66rem;
  opacity: 0.75;
}

.table-section[open] > summary::after {
  content: " (collapse)";
}

.table-tools {
  flex-wrap: wrap;
  align-items: end;
  gap: 0.5rem;
}

#table-rows,
#table-cols,
#table-border-width,
#table-cell-padding {
  width: 78px;
}

.field.compact {
  min-width: 78px;
}

.field.compact span {
  font-size: 0.68rem;
}

.image-css-value {
  width: 130px;
}

.image-tools input:invalid {
  border-color: #f87171;
}

.image-advanced {
  width: 100%;
  min-width: 0;
}

.image-advanced > summary {
  padding: 0.4rem;
  cursor: pointer;
  color: var(--ink-soft);
  font-size: 0.8rem;
}

.image-advanced > .group {
  margin-top: 0.4rem;
}

#image-padding,
#image-radius {
  width: 74px;
}

.group button.is-active {
  background: rgba(94, 234, 212, 0.16);
  border-color: var(--accent-2);
}

.color-field input {
  width: 3rem;
  height: 2.4rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  cursor: pointer;
}

.color-none-btn {
  font-family: inherit;
  color: var(--ink);
  background: var(--panel-soft);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  padding: 0.35rem 0.5rem;
  font-size: 0.72rem;
  cursor: pointer;
}

.color-none-btn:hover {
  border-color: var(--accent-2);
}

.workspace {
  display: grid;
  grid-template-columns: 1.1fr 1fr;
  height: min(68vh, 760px);
  max-height: 68vh;
}

.panel {
  min-width: 0;
  display: grid;
  grid-template-rows: auto 1fr;
  min-height: 0;
}

.panel + .panel {
  border-left: 1px solid var(--line);
}

.panel > h2 {
  margin: 0;
  padding: 0.55rem 0.85rem;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.77rem;
  letter-spacing: 0.08em;
  color: var(--ink-soft);
  background: rgba(255, 255, 255, 0.03);
  border-bottom: 1px solid var(--line);
}

.editor-frame {
  display: block;
  width: 100%;
  border: 0;
  min-height: 0;
  height: 100%;
  max-height: 100%;
  overflow: auto;
  outline: none;
  background: white;
}

.editor-frame:focus {
  box-shadow: inset 0 0 0 2px var(--ring);
}

.output {
  margin: 0;
  min-height: 0;
  height: 100%;
  max-height: 100%;
  overflow: auto;
  padding: 1rem;
  background: #0f1a2a;
  color: #c8d9f8;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.84rem;
  line-height: 1.5;
}

.source-editor {
  border: 0;
  resize: none;
  width: 100%;
  height: 100%;
  max-height: 100%;
  outline: none;
  white-space: pre-wrap;
  word-break: break-word;
}

.source-editor.no-wrap {
  white-space: pre;
  word-break: normal;
}

.shortcut-note {
  padding: 0.65rem 1rem 0.9rem;
  border-top: 1px solid var(--line);
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.76rem;
}

:focus-visible {
  outline: 2px solid var(--ring);
  outline-offset: 2px;
}

@media (max-width: 980px) {
  .app-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .workspace {
    grid-template-columns: 1fr;
    height: auto;
    max-height: none;
  }

  .panel {
    min-height: 38vh;
    max-height: 44vh;
  }

  .panel + .panel {
    border-left: 0;
    border-top: 1px solid var(--line);
  }
}
