:root {
  color-scheme: light;
  --bg: #f5f7fa;
  --panel: #ffffff;
  --ink: #18202a;
  --muted: #687383;
  --line: #d9e2ec;
  --soft-line: #e9eef4;
  --accent: #d9480f;
  --accent-ink: #ffffff;
  --accent-hover: #bf3e0c;
  --blue: #2563eb;
  --teal: #0f766e;
  --danger: #b42318;
  --shadow: 0 18px 50px rgba(26, 37, 55, 0.12);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

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

body {
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

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

button,
a {
  -webkit-tap-highlight-color: transparent;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(290px, 370px) minmax(0, 1fr);
  min-height: 100vh;
}

.app-shell > * {
  min-width: 0;
}

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

.controls {
  display: flex;
  flex-direction: column;
  gap: 22px;
  min-width: 0;
  padding: 28px;
}

.brand-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

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

.brand > div {
  min-width: 0;
}

.brand-mark {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: var(--radius);
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 12px;
  font-weight: 850;
  box-shadow: inset 0 -8px 20px rgba(0, 0, 0, 0.12);
}

.home-link,
.primary-action,
.secondary-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 13px;
  font-weight: 760;
  text-decoration: none;
  transition: border-color 0.18s ease, color 0.18s ease, background 0.18s ease, transform 0.18s ease;
}

.home-link,
.secondary-action {
  border: 1px solid var(--line);
  background: #ffffff;
  color: var(--muted);
}

.home-link {
  flex: 0 0 auto;
  min-width: 68px;
  min-height: 36px;
  height: 36px;
  padding: 0 12px;
  white-space: nowrap;
}

.primary-action {
  width: 100%;
  border: 0;
  background: var(--accent);
  color: var(--accent-ink);
}

.secondary-action {
  width: 100%;
  padding: 0 12px;
}

.home-link:hover,
.home-link:focus-visible,
.secondary-action:hover:not(:disabled),
.secondary-action:focus-visible:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent);
  outline: none;
}

.primary-action:hover:not(:disabled),
.primary-action:focus-visible {
  background: var(--accent-hover);
  outline: none;
  transform: translateY(-1px);
}

.secondary-action:hover:not(:disabled) {
  transform: translateY(-1px);
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 20px;
  line-height: 1.15;
  word-break: keep-all;
}

h2 {
  font-size: 19px;
  line-height: 1.2;
}

.brand p,
.toolbar p,
.status,
.field,
.metric-card span,
.preview-actions span,
.console-heading span,
.console-empty {
  color: var(--muted);
}

.input-panel,
.control-group,
.file-actions {
  display: grid;
  gap: 12px;
}

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

.check-row {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  font-weight: 680;
}

.check-row input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.field {
  display: grid;
  gap: 8px;
  min-width: 0;
  font-size: 13px;
  font-weight: 680;
}

.field > span {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

select {
  width: 100%;
  min-width: 0;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #ffffff;
  color: var(--ink);
  padding: 0 12px;
  outline: none;
}

select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(217, 72, 15, 0.14);
}

.compact-field {
  max-width: 190px;
}

.status {
  min-height: 44px;
  font-size: 13px;
}

.status.is-error {
  color: var(--danger);
}

.copyright {
  margin-top: auto;
  color: var(--muted);
  font-size: 12px;
}

.workspace {
  display: grid;
  align-content: start;
  gap: 22px;
  min-width: 0;
  padding: 28px;
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-width: 0;
}

.toolbar > div {
  min-width: 0;
}

.toolbar-action {
  width: auto;
  min-width: 118px;
  height: 40px;
  flex: 0 0 auto;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}

.metric-card,
.editor-panel,
.preview-panel,
.console-panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.metric-card {
  display: grid;
  gap: 4px;
  min-width: 0;
  padding: 16px;
}

.metric-card strong {
  min-width: 0;
  font-size: 24px;
  line-height: 1.1;
  overflow-wrap: anywhere;
}

.workspace-grid {
  display: grid;
  grid-template-columns: minmax(320px, 0.95fr) minmax(420px, 1.25fr);
  gap: 18px;
  min-width: 0;
}

.editor-panel,
.result-column {
  min-width: 0;
}

.editor-panel {
  display: grid;
  overflow: hidden;
}

.output-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 14px;
  border-bottom: 1px solid var(--soft-line);
}

.tab-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #ffffff;
  color: var(--muted);
  cursor: pointer;
  padding: 0 12px;
  font-size: 13px;
  font-weight: 760;
}

.tab-button:hover,
.tab-button:focus-visible {
  border-color: var(--accent);
  color: var(--accent);
  outline: none;
}

.tab-button.is-active {
  border-color: var(--accent);
  background: #fff4ed;
  color: var(--accent);
}

.editor-pane {
  display: grid;
  min-width: 0;
}

.editor-pane[hidden] {
  display: none;
}

textarea {
  width: 100%;
  min-width: 0;
  min-height: 540px;
  resize: vertical;
  border: 0;
  border-bottom: 1px solid var(--soft-line);
  background: #fbfcfe;
  color: var(--ink);
  padding: 16px;
  outline: none;
  font: 13px/1.55 ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  tab-size: 2;
}

textarea:focus {
  box-shadow: inset 0 0 0 3px rgba(217, 72, 15, 0.16);
}

.preview-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px;
}

.preview-actions span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
}

.preview-actions .secondary-action {
  width: auto;
  min-width: 104px;
}

.result-column {
  display: grid;
  gap: 18px;
}

.preview-panel {
  overflow: hidden;
}

.preview-canvas {
  display: flex;
  justify-content: center;
  min-height: 510px;
  overflow: auto;
  background:
    linear-gradient(45deg, rgba(104, 115, 131, 0.06) 25%, transparent 25%),
    linear-gradient(-45deg, rgba(104, 115, 131, 0.06) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, rgba(104, 115, 131, 0.06) 75%),
    linear-gradient(-45deg, transparent 75%, rgba(104, 115, 131, 0.06) 75%);
  background-color: #eef2f6;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0;
  background-size: 20px 20px;
  padding: 18px;
}

#previewFrame {
  width: 100%;
  min-width: 0;
  height: 540px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #ffffff;
  box-shadow: 0 14px 32px rgba(26, 37, 55, 0.12);
}

.preview-canvas[data-width="390"] #previewFrame {
  flex: 0 0 390px;
  width: 390px;
}

.preview-canvas[data-width="768"] #previewFrame {
  flex: 0 0 768px;
  width: 768px;
}

.preview-canvas[data-width="1024"] #previewFrame {
  flex: 0 0 1024px;
  width: 1024px;
}

.console-panel {
  display: grid;
  overflow: hidden;
}

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

.console-heading strong,
.console-heading span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.console-output {
  display: grid;
  align-content: start;
  min-height: 160px;
  max-height: 240px;
  overflow: auto;
  background: #fbfcfe;
  font: 13px/1.55 ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

.console-empty {
  padding: 16px;
}

.console-row {
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr);
  gap: 12px;
  min-width: 0;
  padding: 9px 14px;
  border-bottom: 1px solid var(--soft-line);
}

.console-row strong {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

.console-row span {
  min-width: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.console-row.is-error strong,
.console-row.is-error span {
  color: var(--danger);
}

.console-row.is-warn strong {
  color: #9a6700;
}

.console-row.is-info strong {
  color: var(--blue);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

@media (max-width: 1180px) {
  .workspace-grid {
    grid-template-columns: 1fr;
  }

  textarea {
    min-height: 420px;
  }
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

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

  .controls,
  .workspace {
    padding: 22px;
  }

  .copyright {
    margin-top: 0;
  }
}

@media (max-width: 640px) {
  .brand-row,
  .toolbar,
  .preview-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .home-link,
  .toolbar-action,
  .preview-actions .secondary-action {
    width: 100%;
  }

  .action-grid,
  .metric-grid {
    grid-template-columns: 1fr;
  }

  .preview-canvas {
    justify-content: flex-start;
    min-height: 420px;
    padding: 12px;
  }

  #previewFrame {
    height: 430px;
  }

  textarea {
    min-height: 320px;
  }
}
