/* ---------- BASE ---------- */
* { box-sizing: border-box; margin: 0; }

:root {
  --ink: #1e2430;
  --muted: #667085;
  --line: #e4e7ec;
  --accent: #4f46e5;
  --accent-soft: #eef2ff;
  --bad: #b42318;
  --mono: ui-monospace, "SF Mono", Consolas, monospace;
}

body {
  min-height: 100vh;
  background: #f6f7fb;
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

.top { max-width: 1200px; margin: 0 auto; padding: 28px 16px 8px; }
.top h1 { font-size: clamp(24px, 4vw, 34px); letter-spacing: -.5px; }
.top p { color: var(--muted); margin-top: 6px; }

.layout {
  max-width: 1200px;
  margin: 0 auto;
  padding: 16px;
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr) 240px;
  grid-template-areas:
    "controls examples examples"
    "controls preview item"
    "controls code item";
  grid-template-rows: auto auto 1fr;
  gap: 16px;
  align-items: start;
}
.examples { grid-area: examples; }
.controls { grid-area: controls; }
.preview { grid-area: preview; }
.item-panel { grid-area: item; }
.code { grid-area: code; }

.panel { background: #fff; border: 1px solid var(--line); border-radius: 16px; padding: 18px; }
.panel h2 { font: 700 16px var(--mono); margin-bottom: 12px; color: var(--accent); }
/* ---------- END BASE ---------- */

/* ---------- CONTROLS ---------- */
.group { margin-bottom: 14px; }
.group-name { display: block; font: 600 13px var(--mono); margin-bottom: 6px; }
.opts { display: flex; flex-wrap: wrap; gap: 5px; }
.opt {
  padding: 5px 9px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: inherit;
  font: 12px var(--mono);
  cursor: pointer;
  transition: background .15s, border-color .15s;
}
.opt:hover { border-color: #a5b4fc; }
.opt[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }
.opt:focus-visible, .tool:focus-visible, .copy:focus-visible, .item:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.ctl { display: block; margin-bottom: 14px; font: 600 13px var(--mono); }
.ctl > span { display: flex; margin-bottom: 6px; }
.ctl output { margin-left: auto; color: var(--accent); }
.ctl input[type="range"] { width: 100%; accent-color: var(--accent); }
.ctl input[type="text"], .ctl textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  font: 13px/1.5 var(--mono);
  resize: vertical;
}
.ctl input[type="text"]:focus, .ctl textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(79, 70, 229, .15); }
.ctl .bad { border-color: var(--bad); }
.invalid { margin: -6px 0 14px; color: var(--bad); font-size: 13px; }
/* ---------- END CONTROLS ---------- */

/* ---------- PREVIEW ---------- */
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 12px; }
.tool {
  padding: 7px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: inherit;
  font: 600 13px system-ui, sans-serif;
  cursor: pointer;
}
.tool:hover { background: #f2f4f7; }
.show-lines { margin-left: auto; display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); cursor: pointer; }
.show-lines input { accent-color: var(--accent); }

/* The padding leaves room for the line numbers, which sit outside the grid. */
.stage {
  padding: 26px 14px 14px 26px;
  border-radius: 12px;
  background: repeating-linear-gradient(45deg, #fafbff 0 10px, #f3f4fd 10px 20px);
  overflow-x: auto;
}
.grid {
  position: relative; /* the line markers are placed against the grid */
  min-height: 320px;
  /* display: grid and the rest are set by script.js */
}
.item {
  min-width: 0;
  min-height: 46px;
  padding: 10px;
  border: 0;
  border-radius: 10px;
  color: #fff;
  font: 800 16px system-ui, sans-serif;
  cursor: pointer;
  box-shadow: 0 6px 16px rgba(30, 36, 48, .15);
  overflow: hidden;
  text-overflow: ellipsis;
}
.item.selected { box-shadow: 0 0 0 3px #fff, 0 0 0 6px var(--ink); }

/* An absolutely positioned grid child takes its size from the grid area it is
   placed in, and it does not take up a cell. That gives us one marker per track
   that follows the real tracks, whatever the alignment or gap. */
.line { position: absolute; inset: 0; pointer-events: none; z-index: 1; }
.line::before {
  content: attr(data-n);
  position: absolute;
  font: 700 12px var(--mono);
  color: #b42318;
}
.line.col { border-left: 2px dashed rgba(180, 35, 24, .55); }
.line.col.last { border-left: 0; border-right: 2px dashed rgba(180, 35, 24, .55); }
.line.col::before { top: -20px; left: -6px; }
.line.col.last::before { left: auto; right: -6px; }
.line.row { border-top: 2px dashed rgba(180, 35, 24, .55); }
.line.row.last { border-top: 0; border-bottom: 2px dashed rgba(180, 35, 24, .55); }
.line.row::before { left: -18px; top: -8px; }
.line.row.last::before { top: auto; bottom: -8px; }
/* ---------- END PREVIEW ---------- */

/* ---------- CODE ---------- */
.code-head { display: flex; justify-content: space-between; align-items: center; }
.code-head h2 { margin: 0; }
.copy {
  padding: 6px 12px;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font: 600 13px system-ui, sans-serif;
  cursor: pointer;
}
.code pre {
  margin-top: 12px;
  padding: 14px 16px;
  border-radius: 10px;
  background: #111827;
  color: #e5e7eb;
  font: 13.5px/1.6 var(--mono);
  overflow-x: auto;
}
.css .sel { color: #f9a8d4; }
.css .k { color: #93c5fd; }
.css .v { color: #fcd34d; }
/* ---------- END CODE ---------- */

/* ---------- SMALL SCREENS ---------- */
@media (max-width: 1000px) {
  .layout {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: "examples" "preview" "item" "controls" "code";
    grid-template-rows: none;
  }
  .grid { min-height: 260px; }
}
@media (prefers-reduced-motion: reduce) {
  .opt { transition: none; }
}
/* ---------- END SMALL SCREENS ---------- */
