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

/* The same four colours browser DevTools use for the box model */
:root {
  --margin: #f9cc9d;
  --border: #e8a33d;
  --padding: #c3d08b;
  --content: #8cb6c0;
  --ink: #1e2430;
  --muted: #667085;
  --line: #e4e7ec;
  --accent: #4f46e5;
}

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

.top { max-width: 1100px; 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: 1100px;
  margin: 0 auto;
  padding: 16px;
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  gap: 16px;
}
.panel {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 20px;
  box-shadow: 0 1px 2px rgba(16, 24, 40, .04);
}
.dot { display: inline-block; width: 12px; height: 12px; border-radius: 3px; vertical-align: -1px; margin-right: 6px; }
.dot.m { background: var(--margin); }
.dot.b { background: var(--border); }
.dot.p { background: var(--padding); }
.dot.c { background: var(--content); }
/* ---------- END BASE ---------- */

/* ---------- CONTROLS ---------- */
.controls { grid-row: span 2; align-self: start; display: flex; flex-direction: column; gap: 18px; }
.ctl { display: block; font-size: 14px; }
.ctl > span { display: flex; align-items: center; margin-bottom: 8px; font-family: ui-monospace, Consolas, monospace; }
.ctl output { margin-left: auto; font-weight: 700; color: var(--accent); }
.ctl input[type="range"] { width: 100%; accent-color: var(--accent); }
.ctl select {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  font: inherit;
}
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.switch { display: flex; align-items: center; gap: 10px; font: 14px ui-monospace, Consolas, monospace; cursor: pointer; }
.switch input { position: absolute; opacity: 0; }
.track {
  position: relative;
  flex: none;
  width: 42px;
  height: 24px;
  border-radius: 12px;
  background: #d0d5dd;
  transition: background .2s;
}
.track::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .25);
  transition: transform .2s;
}
.switch input:checked + .track { background: var(--accent); }
.switch input:checked + .track::after { transform: translateX(18px); }
.switch input:focus-visible + .track { outline: 3px solid var(--accent); outline-offset: 2px; }

.reset {
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  font: 600 14px system-ui, sans-serif;
  cursor: pointer;
}
.reset:hover { background: #f2f4f7; }
/* ---------- END CONTROLS ---------- */

/* ---------- STAGE ---------- */
.legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: 13px; color: var(--muted); margin-bottom: 14px; }

.stage {
  display: grid;
  place-items: center;
  min-height: 360px;
  overflow: auto;
  border-radius: 12px;
  /* a light grid so you can see sizes change */
  background:
    linear-gradient(#eef0f6 1px, transparent 1px) 0 0 / 20px 20px,
    linear-gradient(90deg, #eef0f6 1px, transparent 1px) 0 0 / 20px 20px,
    #fbfcfe;
}

/* flow-root makes the wrapper contain the box's margin, so its orange
   background paints exactly the margin area */
.margin-view { display: flow-root; background: var(--margin); }

.box {
  /* script.js sets these variables from the sliders */
  width: var(--w);
  margin: var(--m);
  padding: var(--p);
  border: var(--b) var(--style) var(--border);
  border-radius: var(--r);
  box-sizing: var(--sizing);
  background: var(--padding);          /* shows through the padding */
  transition: all .25s ease;
}
.content {
  min-height: 70px;
  display: grid;
  place-items: center;
  background: var(--content);
  border-radius: max(0px, calc(var(--r) - var(--b) - var(--p)));
  font: 600 14px ui-monospace, Consolas, monospace;
  color: #12323b;
  transition: border-radius .25s ease;
}

.maths { margin-top: 16px; font: 14px/1.6 ui-monospace, Consolas, monospace; }
.sum b { padding: 1px 5px; border-radius: 4px; }
.sum .m { background: var(--margin); }
.sum .b { background: var(--border); }
.sum .p { background: var(--padding); }
.sum .c { background: var(--content); }
.measured { color: var(--muted); }
/* ---------- END STAGE ---------- */

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

/* ---------- SMALL SCREENS ---------- */
@media (max-width: 760px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .controls { grid-row: auto; }
  .stage { min-height: 300px; }
}
@media (prefers-reduced-motion: reduce) {
  .box, .content, .track, .track::after { transition: none; }
}
/* ---------- END SMALL SCREENS ---------- */
