/* Gridcalc: framed-sheet app style (tinted L-frame, white sheet inset 8px, no shadows at rest). */
:root {
  --ground: #f5f8f9;
  --surface: #ffffff;
  --raised: #f2f5f7;
  --active: #e6ebee;
  --border: #e5e9ec;
  --rule: #eef1f3;
  --control: #c9ced3;
  --text: #131416;
  --muted: #5b6063;
  --accent: #1b6c80;
  --accent-soft: rgba(27, 108, 128, 0.14);
  --accent-line: rgba(27, 108, 128, 0.55);
  --radius-card: 8px;
  --radius-control: 6px;
  --radius-sheet: 16px;
  --gap: 24px;
  --pad: 24px;
  --control-height: 32px;
  --fs-title: 22px;
  --fs-section: 16px;
  --fs-body: 14px;
  --fs-small: 12px;
  --code: "IBM Plex Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--ground);
  color: var(--text);
  font: 400 var(--fs-body)/1.45 "IBM Plex Sans", system-ui, sans-serif;
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; color: inherit; }
h1, h2 { margin: 0; }
[hidden] { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.skip { position: absolute; left: 8px; top: -60px; z-index: 10; padding: 8px 12px; background: var(--text); color: #fff; border-radius: var(--radius-control); }
.skip:focus { top: 8px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- shell ---------- */
.app {
  display: grid;
  grid-template-columns: 392px minmax(0, 1fr);
  grid-template-rows: 48px minmax(0, 1fr);
  height: 100dvh;
}
.top {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 8px 0 20px;
}
.brand { display: flex; align-items: center; gap: 8px; min-width: 0; }
.mark { width: 20px; height: 20px; fill: var(--accent); flex: none; }
.name { font-weight: 600; font-size: 15px; }
.by { color: var(--muted); font-size: var(--fs-small); white-space: nowrap; }
.top-actions { display: flex; gap: 8px; }

.panel { overflow-y: auto; padding: 4px 20px 32px; }
.group { padding: 16px 0 20px; }
.group + .group { border-top: 1px solid var(--border); }
.group h2 { font-size: var(--fs-section); font-weight: 600; margin-bottom: 12px; }

.sheet {
  margin: 0 8px 8px 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sheet);
  overflow-y: auto;
  padding: 8px var(--pad) var(--pad);
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.sheet:focus { outline: none; }

/* ---------- controls ---------- */
.btn {
  height: var(--control-height);
  padding: 0 12px;
  border-radius: var(--radius-control);
  border: 1px solid var(--control);
  background: var(--surface);
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 0.15s ease-out, transform 0.1s ease-out;
}
.btn:hover { background: var(--raised); }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--text); border-color: var(--text); color: #fff; }
.btn-primary:hover { background: #2b2d30; }
.btn-quiet { border-color: transparent; background: transparent; color: var(--accent); padding: 0 4px; margin-top: 8px; }
.btn-quiet:hover { background: transparent; text-decoration: underline; text-underline-offset: 3px; }

.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; min-width: 0; }
.label { font-size: var(--fs-small); color: var(--muted); }
input[type="number"], input[type="text"], select {
  height: var(--control-height);
  width: 100%;
  min-width: 0;
  padding: 0 8px;
  border: 1px solid var(--control);
  border-radius: var(--radius-control);
  background: var(--surface);
}
input:disabled { color: var(--muted); background: var(--raised); }
select {
  appearance: none;
  padding-right: 32px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M3 4.5 6 7.5 9 4.5' fill='none' stroke='%235b6063' stroke-width='1.5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  cursor: pointer;
}
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.row3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
.check { display: flex; align-items: center; gap: 8px; min-height: 32px; margin-bottom: 4px; cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--accent); margin: 0; }
.hint { margin: 4px 0 8px; color: var(--muted); font-size: var(--fs-small); }

.seg { display: flex; padding: 2px; gap: 2px; background: var(--raised); border-radius: var(--radius-control); margin-bottom: 12px; }
.seg button {
  flex: 1;
  min-height: 28px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--muted);
  font-weight: 500;
  cursor: pointer;
  padding: 0 8px;
  white-space: nowrap;
  transition: background-color 0.15s ease-out, color 0.15s ease-out;
}
.seg button:hover { color: var(--text); }
.seg button[aria-checked="true"] { background: var(--surface); color: var(--text); outline: 1px solid var(--border); }
.seg-wide { max-width: 520px; }

/* breakpoint table */
.bp-row { display: grid; grid-template-columns: 1.25fr 1.1fr 0.75fr 0.85fr 0.85fr 1.1fr 24px; gap: 4px; align-items: center; margin-bottom: 4px; }
.bp-row input { padding: 0 5px; height: 30px; font-size: 13px; }
.bp-row input[type="number"] { text-align: right; }
.bp-head { font-size: var(--fs-small); color: var(--muted); margin-bottom: 6px; }
.x { width: 24px; height: 30px; border: 0; background: transparent; color: var(--muted); font-size: 18px; cursor: pointer; border-radius: 4px; }
.x:hover:not(:disabled) { color: var(--text); background: var(--raised); }
.x:disabled { opacity: 0.3; cursor: default; }

/* ---------- sheet: tabs and titles ---------- */
.tabs { display: flex; gap: 20px; border-bottom: 1px solid var(--rule); margin: 0 calc(var(--pad) * -1) 20px; padding: 0 var(--pad); }
.tabs button {
  height: 40px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-weight: 500;
  cursor: pointer;
  padding: 0 2px;
  margin-bottom: -1px;
  border-bottom: 2px solid transparent;
  transition: color 0.15s ease-out;
}
.tabs button:hover { color: var(--text); }
.tabs button[aria-selected="true"] { color: var(--text); font-weight: 600; border-bottom-color: var(--accent); }
.view { display: flex; flex-direction: column; min-width: 0; }
.title-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.title-row h1 { font-size: var(--fs-title); font-weight: 600; letter-spacing: -0.01em; }
.finding { margin: 6px 0 16px; color: var(--muted); max-width: 72ch; }
.width-field { display: flex; align-items: center; gap: 8px; }
.width-field input { width: 84px; text-align: right; }
.unit { color: var(--muted); font-size: var(--fs-small); }

/* ruler */
.ruler { position: relative; display: flex; gap: 2px; margin-bottom: 12px; }
.stop {
  flex-basis: 0;
  min-width: 44px;
  height: 44px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  padding: 0 8px;
  border: 0;
  border-radius: 4px;
  background: var(--raised);
  cursor: pointer;
  text-align: left;
  overflow: hidden;
  transition: background-color 0.15s ease-out;
}
.stop:hover { background: var(--active); }
.stop[aria-current="true"] { background: var(--accent-soft); }
.stop-name { font-weight: 600; font-size: 13px; line-height: 1.2; }
.stop-min { color: var(--muted); font-size: var(--fs-small); line-height: 1.2; }
.needle { position: absolute; top: -4px; bottom: -4px; width: 2px; margin-left: -1px; background: var(--accent); border-radius: 1px; pointer-events: none; }

/* stage and frame */
.stage { position: relative; background: var(--raised); border-radius: var(--radius-card); overflow: hidden; }
.frame { position: absolute; left: 0; top: 0; transform-origin: 0 0; background: var(--surface); outline: 1px solid var(--border); overflow: hidden; }
.demo { display: grid; align-content: start; }
.cols, .rows { position: absolute; inset: 0; pointer-events: none; }
.cols i { position: absolute; top: 0; bottom: 0; background: var(--accent-soft); }
.rows { fill: var(--accent-line); opacity: 0.5; }
.handle {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 24px;
  margin-left: 0;
  border: 0;
  background: transparent;
  cursor: ew-resize;
  touch-action: none;
  display: flex;
  align-items: center;
  justify-content: center;
}
.handle span { width: 6px; height: 48px; border-radius: 3px; background: var(--control); transition: background-color 0.15s ease-out; }
.handle:hover span, .handle:focus-visible span { background: var(--accent); }

.blk { background: #e9edf0; border-radius: 6px; min-height: 48px; display: flex; align-items: flex-end; padding: 10px 12px; color: var(--muted); font-size: 13px; }
.blk.nav { min-height: 44px; background: #dfe5e9; }
.blk.media { min-height: 220px; background: #dde3e7; }
.blk.card { min-height: 140px; }
.blk.text { flex-direction: column; align-items: flex-start; justify-content: center; gap: 12px; background: transparent; padding: 12px 0; }
.line { display: block; height: 18px; border-radius: 4px; background: #cfd7dc; }
.line.l1 { width: 92%; height: 28px; background: #8d979e; }
.line.l2 { width: 74%; }
.line.l3 { width: 60%; }
.pill { display: block; width: 120px; height: 36px; border-radius: 6px; background: var(--text); margin-top: 8px; }

.facts { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 0 var(--gap); margin: 20px 0 0; }
.fact { padding-top: 10px; border-top: 1px solid var(--rule); }
.facts dt { color: var(--muted); font-size: var(--fs-small); }
.facts dd { margin: 2px 0 10px; font-weight: 500; }

/* spacing */
.scale { display: flex; flex-direction: column; }
.srow { display: grid; grid-template-columns: 72px minmax(120px, 1fr) 64px 72px minmax(120px, 1.2fr); gap: 16px; align-items: center; min-height: 44px; border-bottom: 1px solid var(--rule); }
.shead { min-height: 32px; color: var(--muted); font-size: var(--fs-small); }
.shead span:nth-child(n + 3) { text-align: right; }
.sname { font-weight: 600; }
.sbar i { display: block; height: 16px; border-radius: 3px; background: var(--accent); max-width: 100%; }
.num { text-align: right; }
.val { font-family: var(--code); font-size: 12.5px; color: var(--muted); overflow-wrap: anywhere; }

/* export */
.code {
  margin: 4px 0 0;
  padding: 16px;
  background: var(--raised);
  border-radius: var(--radius-card);
  overflow: auto;
  max-height: 62vh;
  font-family: var(--code);
  font-size: 12.5px;
  line-height: 1.55;
  tab-size: 2;
}

.foot { margin-top: auto; padding-top: 32px; color: var(--muted); font-size: var(--fs-small); }

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translate(-50%, 12px);
  opacity: 0;
  padding: 10px 14px;
  border-radius: var(--radius-control);
  background: var(--text);
  color: #fff;
  pointer-events: none;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.16); /* taste-skill-ignore: the toast floats over the page */
  transition: opacity 0.18s ease-out, transform 0.18s ease-out;
}
.toast.on { opacity: 1; transform: translate(-50%, 0); }

/* ---------- narrower screens ---------- */
@media (max-width: 1100px) {
  .app { grid-template-columns: 360px minmax(0, 1fr); }
  .panel { padding-inline: 16px; }
  .bp-row { gap: 3px; grid-template-columns: 1fr 1.2fr 0.75fr 0.85fr 0.85fr 1.2fr 22px; }
  .bp-row input { padding: 0 3px; }
}
@media (max-width: 860px) {
  .app { display: flex; flex-direction: column; height: auto; }
  .top { order: 0; }
  .sheet { order: 1; }
  .panel { order: 2; }
  .top { position: sticky; top: 0; z-index: 5; background: var(--ground); height: 56px; padding: 0 16px; }
  .top .by { display: none; }
  .top .btn { padding: 0 10px; }
  .panel { overflow: visible; padding: 0 16px 8px; }
  .sheet { margin: 0; border-radius: 0; border-width: 1px 0 0; overflow: visible; padding: 8px 16px 24px; }
  .tabs { margin: 0 -16px 16px; padding: 0 16px; position: sticky; top: 56px; background: var(--surface); z-index: 4; }
  .tabs button { height: 44px; }
  .btn { height: 44px; }
  .seg button { min-height: 40px; }
  input[type="number"], input[type="text"], select { height: 44px; font-size: 16px; }
  .bp-row input { height: 44px; padding: 0 3px; }
  .x { width: 28px; height: 44px; }
  .bp-row { grid-template-columns: 1fr 1.2fr 0.75fr 0.85fr 0.85fr 1.2fr 28px; gap: 3px; }
  .check { min-height: 44px; }
  .check input { width: 20px; height: 20px; }
  .title-row h1 { font-size: 20px; }
  .srow { grid-template-columns: 48px minmax(60px, 1fr) 44px 52px; gap: 10px; }
  .srow > :last-child { grid-column: 1 / -1; text-align: left; padding-bottom: 8px; margin-top: -6px; }
  .shead > :last-child { display: none; }
  .title-row .top-actions { width: 100%; }
  .title-row .top-actions .btn { flex: 1; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
