:root {
  --bg: #f4f0e8;
  --panel: #fffaf2;
  --ink: #20180f;
  --muted: #6d6053;
  --accent: #0f766e;
  --accent-soft: #ccece7;
  --error: #c32621;
  --error-soft: #fee6e4;
  --ok: #115e2f;
  --ok-soft: #d8f7e0;
  --border: #ddceb9;
  --shadow: 0 14px 32px rgba(42, 23, 7, 0.08);
  --font-ui: "Trebuchet MS", "Segoe UI", "Gill Sans", sans-serif;
  --font-code: "Cascadia Mono", "SFMono-Regular", "Consolas", "Liberation Mono", monospace;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  padding: 1rem;
  color: var(--ink);
  background: radial-gradient(circle at 12% 18%, #fff8e2 0%, transparent 30%),
    radial-gradient(circle at 86% 14%, #d6f4ef 0%, transparent 35%),
    linear-gradient(140deg, #f0e8db 0%, #f9f5ef 48%, #e7f5f2 100%);
  font-family: var(--font-ui);
  position: relative;
}

.bg-orb {
  position: fixed;
  width: 28rem;
  height: 28rem;
  border-radius: 999px;
  pointer-events: none;
  mix-blend-mode: multiply;
  filter: blur(38px);
  opacity: 0.3;
  z-index: -1;
}

.bg-orb-a {
  top: -10rem;
  right: -8rem;
  background: #f7cbb2;
}

.bg-orb-b {
  bottom: -12rem;
  left: -10rem;
  background: #b3e8de;
}

.topbar {
  border: 1px solid var(--border);
  border-radius: 1rem;
  padding: 1rem;
  background: linear-gradient(120deg, rgba(255, 250, 242, 0.95), rgba(246, 255, 253, 0.95));
  box-shadow: var(--shadow);
  backdrop-filter: blur(2px);
}

.brand h1 {
  margin: 0;
  font-size: clamp(1.3rem, 3vw, 1.9rem);
}

.brand-eyebrow {
  margin: 0;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--muted);
  font-size: 0.72rem;
}

.controls-grid {
  margin-top: 1rem;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr));
  gap: 0.75rem;
}

.control {
  display: grid;
  gap: 0.25rem;
  font-size: 0.92rem;
}

.control > span {
  font-weight: 700;
}

.control input,
.control select,
.control output {
  border: 1px solid var(--border);
  border-radius: 0.6rem;
  min-height: 2.4rem;
  padding: 0.5rem 0.65rem;
  font: inherit;
  color: inherit;
  background: #fff;
}

.control output {
  display: block;
  font-family: var(--font-code);
  font-size: 0.84rem;
  line-height: 1.45;
}

.checkbox-control {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  align-self: end;
  min-height: 2.4rem;
}

.checkbox-control input {
  min-height: auto;
  width: 1rem;
  height: 1rem;
}

.hint {
  color: var(--muted);
  font-size: 0.8rem;
  min-height: 1.1rem;
}

.layout {
  margin-top: 1rem;
  display: grid;
  gap: 1rem;
  grid-template-columns: 1fr;
}

.panel {
  border: 1px solid var(--border);
  border-radius: 1rem;
  background: var(--panel);
  box-shadow: var(--shadow);
  padding: 0.9rem;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.panel-head h2 {
  margin: 0;
  font-size: 1.05rem;
}

.status-group,
.meta-row {
  display: flex;
  gap: 0.45rem;
  flex-wrap: wrap;
}

.badge {
  border-radius: 999px;
  padding: 0.2rem 0.55rem;
  font-size: 0.78rem;
  font-weight: 700;
  border: 1px solid #b9d7d2;
  background: #edf8f6;
  color: #145952;
}

.badge.subtle {
  background: #efe8db;
  border-color: #dcccb3;
  color: #705c41;
}

.badge.success {
  background: var(--ok-soft);
  border-color: #a7d8b7;
  color: var(--ok);
}

.editor-wrap {
  position: relative;
  margin-top: 0.75rem;
  border: 1px solid var(--border);
  border-radius: 0.85rem;
  overflow: hidden;
  background: #fffcf7;
  min-height: 14rem;
}

#editorHighlight,
#expressionInput {
  margin: 0;
  width: 100%;
  min-height: 14rem;
  padding: 0.9rem;
  border: none;
  resize: vertical;
  font-family: var(--font-code);
  font-size: 0.96rem;
  line-height: 1.55;
  white-space: pre-wrap;
  overflow-wrap: break-word;
  tab-size: 2;
}

#editorHighlight {
  position: absolute;
  inset: 0;
  color: transparent;
  overflow: hidden;
  pointer-events: none;
}

#expressionInput {
  position: relative;
  background: transparent;
  color: var(--ink);
}

.error-span {
  text-decoration-line: underline;
  text-decoration-style: wavy;
  text-decoration-color: var(--error);
  text-decoration-thickness: 1.5px;
  background: rgba(195, 38, 33, 0.08);
}

.error-caret {
  display: inline-block;
  width: 0;
  border-left: 2px solid var(--error);
  margin-left: -1px;
  height: 1.1em;
  vertical-align: text-bottom;
}

.state-block {
  margin-top: 0.75rem;
}

.primary-output {
  margin: 0;
  font-family: var(--font-code);
  font-size: clamp(1rem, 2.5vw, 1.2rem);
  line-height: 1.45;
  color: #113735;
}

.secondary-output {
  margin: 0.55rem 0 0;
  color: var(--muted);
}

.explain-panel {
  margin-top: 0.8rem;
  padding-top: 0.7rem;
  border-top: 1px dashed var(--border);
}

.explain-panel h3 {
  margin: 0;
  font-size: 0.92rem;
}

.explain-panel ul {
  margin: 0.45rem 0 0;
  padding-left: 1rem;
}

.error-message {
  all: unset;
  cursor: pointer;
  display: inline-block;
  font-weight: 700;
  color: var(--error);
  background: var(--error-soft);
  padding: 0.45rem 0.6rem;
  border-radius: 0.5rem;
  border: 1px solid #efbbb8;
}

.error-code,
.error-location {
  margin: 0.6rem 0 0;
}

.error-hints {
  margin: 0.6rem 0 0;
  padding-left: 1rem;
  color: #5e322e;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.chip-btn {
  border: 1px solid #b6dbd4;
  background: #f3fffd;
  border-radius: 999px;
  padding: 0.3rem 0.68rem;
  font: inherit;
  font-size: 0.84rem;
  cursor: pointer;
}

.examples-panel {
  margin-top: 1rem;
}

.examples-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(13rem, 1fr));
  gap: 0.75rem;
}

.example-group {
  border: 1px solid var(--border);
  border-radius: 0.8rem;
  padding: 0.65rem;
  background: #fff;
}

.example-group h3 {
  margin: 0 0 0.5rem;
  font-size: 0.9rem;
}

.example-item {
  width: 100%;
  text-align: left;
  border: 1px solid #d9c9b2;
  border-radius: 0.55rem;
  background: #fffbf5;
  margin: 0.35rem 0;
  padding: 0.42rem 0.5rem;
  font-family: var(--font-code);
  font-size: 0.8rem;
  cursor: pointer;
}

.developer-panel {
  margin-top: 1rem;
}

.developer-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr));
  gap: 0.7rem;
}

details {
  border: 1px solid var(--border);
  border-radius: 0.7rem;
  padding: 0.5rem;
  background: #fff;
}

summary {
  cursor: pointer;
  font-weight: 700;
}

pre {
  margin: 0.55rem 0 0;
  overflow: auto;
  font-family: var(--font-code);
  font-size: 0.76rem;
}

@media (min-width: 980px) {
  .layout {
    grid-template-columns: 1.08fr 0.92fr;
  }

  .editor-wrap,
  #editorHighlight,
  #expressionInput {
    min-height: 17rem;
  }
}
