/* WrapRender POC: one stylesheet. Cues from Ray's generator: dark header, orange pills, white diagram card. */
:root {
  --orange: #ff6a00;
  --orange-dark: #e35d00;
  --orange-soft: #fff1e6;
  --red: #e00000;
  --pill: #ef8080;
  --dim: #8fbfe0;
  --ink: #16191d;
  --ink-2: #4a525b;
  --muted: #6b7480;
  --line: #dfe3e8;
  --bg: #f4f5f7;
  --card: #ffffff;
  --dark: #121212;
  --dark-2: #1e1f22;
  --ok: #138a4a;
  --warn: #a36100;
  --warn-bg: #fff6e5;
  --bad: #c0152f;
  --bad-bg: #fdecef;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Inter, Roboto, Helvetica, Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: var(--font); color: var(--ink); background: var(--bg); font-size: 15px; line-height: 1.45; -webkit-font-smoothing: antialiased; }
a { color: var(--orange-dark); }
h1 { font-size: 1.6rem; margin: .2rem 0 1rem; letter-spacing: -.01em; }
h2 { font-size: 1.2rem; margin: 0 0 .6rem; }
h3 { font-size: 1rem; margin: 0 0 .4rem; }
code, pre { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .86em; }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.ok { color: var(--ok); }
.warn { color: var(--warn); }
.bad { color: var(--bad); }
.break { word-break: break-all; }
.inline { display: inline; }

/* ------------------------------------------------ chrome */
.topbar { background: var(--dark); color: #fff; display: flex; align-items: center; justify-content: space-between; padding: .7rem 1.2rem; gap: 1rem; flex-wrap: wrap; }
.brand { color: #fff; text-decoration: none; font-weight: 700; display: flex; align-items: center; gap: .5rem; font-size: 1.05rem; }
.brand-mark { background: var(--orange); color: #fff; border-radius: 8px; padding: .15rem .4rem; font-size: .85rem; letter-spacing: .02em; }
.brand-tag { font-size: .7rem; border: 1px solid #555; border-radius: 99px; padding: .05rem .45rem; color: #bbb; font-weight: 600; }
.topnav { display: flex; gap: 1rem; align-items: center; flex-wrap: wrap; }
.topnav a, .topnav .linkish { color: #ddd; text-decoration: none; font-size: .92rem; }
.topnav a:hover, .topnav .linkish:hover { color: #fff; }
.project-bar { background: var(--dark-2); color: #fff; padding: .5rem 1.2rem .6rem; display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; }
.project-name a { color: #fff; font-weight: 700; text-decoration: none; }
.steps { display: flex; gap: .35rem; flex-wrap: wrap; }
.step-link { color: #cfd3d8; text-decoration: none; border-radius: 99px; padding: .3rem .75rem; font-size: .88rem; border: 1px solid #3a3c40; white-space: nowrap; }
.step-link:hover { border-color: #6a6d72; color: #fff; }
.step-link.active { background: var(--orange); border-color: var(--orange); color: #fff; font-weight: 600; }
.step-n { display: inline-block; min-width: 1.1em; font-weight: 700; }
.wrap { max-width: 1120px; margin: 1.4rem auto; padding: 0 16px; }
.wrap.wide { max-width: 1320px; }
.wrap.narrow { max-width: 460px; }
.foot { text-align: center; color: var(--muted); font-size: .8rem; padding: 2rem 1rem; }

/* ------------------------------------------------ cards, forms, buttons */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.1rem 1.2rem; margin-bottom: 1rem; border: 1px solid #eceef1; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; align-items: start; }
.index-grid { grid-template-columns: 1.6fr 1fr; }
.stack { display: grid; gap: .8rem; }
label { display: grid; gap: .3rem; font-weight: 600; font-size: .9rem; }
input[type=text], input[type=password], input[type=number], input:not([type]), select {
  font: inherit; padding: .55rem .7rem; border: 1px solid #cfd5dc; border-radius: 10px; background: #fff; color: var(--ink); min-width: 0;
}
input:focus-visible, select:focus-visible, button:focus-visible, a:focus-visible, [tabindex]:focus-visible { outline: 3px solid rgba(255, 106, 0, .45); outline-offset: 2px; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .35rem; font: inherit; font-weight: 600; font-size: .92rem; padding: .55rem 1rem; border-radius: 10px; border: 1px solid #cfd5dc; background: #fff; color: var(--ink); text-decoration: none; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: #9aa3ad; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--orange); border-color: var(--orange); color: #fff; }
.btn-primary:hover { background: var(--orange-dark); border-color: var(--orange-dark); }
.btn-danger { color: var(--bad); border-color: #f0b8c2; }
.btn-ghost { background: transparent; color: #eee; border-color: #4b4d52; }
.btn-ghost:hover { border-color: #888; color: #fff; }
.btn-outline { background: #fff; }
.btn-small { padding: .3rem .65rem; font-size: .84rem; border-radius: 8px; }
.btn.active { border-color: var(--orange); color: var(--orange-dark); background: var(--orange-soft); }
.linkish { background: none; border: 0; color: var(--orange-dark); cursor: pointer; font: inherit; padding: 0; }
.row-form { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.row-form input[type=text] { flex: 1 1 220px; }
.flashes { display: grid; gap: .5rem; margin-bottom: 1rem; }
.flash { padding: .65rem .9rem; border-radius: 10px; background: #e9f6ef; color: #0c5a31; border: 1px solid #bfe5cf; }
.flash-error { background: var(--bad-bg); color: var(--bad); border-color: #f4c3cc; }
.notice { background: var(--orange-soft); border-color: #ffd7ba; }
.notice-error { background: var(--bad-bg); border-color: #f4c3cc; }
.empty { color: var(--muted); }
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.table th { text-align: left; font-weight: 600; color: var(--ink-2); border-bottom: 1px solid var(--line); padding: .45rem .5rem; white-space: nowrap; }
.table td { border-bottom: 1px solid #f0f2f4; padding: .5rem; vertical-align: top; }
.table tr.revoked td { color: var(--muted); }
.chip { display: inline-block; border-radius: 99px; padding: .1rem .55rem; font-size: .78rem; font-weight: 600; background: #eef0f3; color: var(--ink-2); }
.chip-done { background: #e3f5ea; color: var(--ok); }
.chip-failed, .chip-canceled { background: var(--bad-bg); color: var(--bad); }
.chip-running { background: var(--orange-soft); color: var(--orange-dark); }
.chip-queued { background: #eef0f3; }
.copy-row { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.copy-row code { background: #f3f4f6; padding: .4rem .6rem; border-radius: 8px; word-break: break-all; }
pre.code { background: #16191d; color: #e8eaed; padding: .7rem .9rem; border-radius: 10px; overflow-x: auto; white-space: pre-wrap; word-break: break-all; }
.token-once { background: var(--warn-bg); border: 1px solid #f3d9a6; border-radius: 12px; padding: .8rem 1rem; margin-bottom: 1rem; display: grid; gap: .5rem; }
.title-row { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.rename summary { list-style: none; }
.rename summary::-webkit-details-marker { display: none; }
.rename[open] summary { margin-bottom: .5rem; }
.toggle { display: inline-flex; flex-direction: row; align-items: center; gap: .45rem; font-weight: 500; }
.progress { position: relative; height: 26px; background: #eef0f3; border-radius: 8px; overflow: hidden; margin: .5rem 0; }
.progress .bar { position: absolute; inset: 0 auto 0 0; background: linear-gradient(90deg, var(--orange), #ff9a4d); width: 0; transition: width .4s; }
.progress .label { position: relative; z-index: 1; font-size: .82rem; font-weight: 600; padding: 0 .6rem; line-height: 26px; }

/* ------------------------------------------------ projects */
.project-list { display: grid; gap: .6rem; }
.project-card { display: block; text-decoration: none; color: inherit; margin: 0; }
.project-card:hover { border-color: var(--orange); }
.pc-name { font-weight: 700; font-size: 1.05rem; }
.overview { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 1rem; }
.ov-step { display: flex; gap: .8rem; text-decoration: none; color: inherit; margin: 0; }
.ov-step:hover { border-color: var(--orange); }
.ov-step.disabled { opacity: .6; }
.ov-n { background: var(--orange); color: #fff; font-weight: 800; width: 2rem; height: 2rem; border-radius: 99px; display: grid; place-items: center; flex: none; }
.ov-body p { margin: .2rem 0; }
.login-card { margin-top: 2rem; }

/* ------------------------------------------------ measurement wizard */
.gen { display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(330px, 1fr); grid-template-areas: "head head" "diagram wizard" "checks wizard"; gap: 1rem; align-items: start; }
.gen-head { grid-area: head; background: var(--dark); color: #fff; border-radius: var(--radius); padding: 1rem 1.2rem; }
.gen-head h1 { color: #fff; font-size: 1.35rem; margin: 0 0 .7rem; }
.gen-controls { display: flex; gap: .8rem; align-items: center; flex-wrap: wrap; }
.gen-actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.seg { display: inline-flex; border: 1px solid #55575c; border-radius: 99px; padding: 3px; }
.seg-btn { font: inherit; font-weight: 700; color: #ddd; background: transparent; border: 0; border-radius: 99px; padding: .45rem 1rem; cursor: pointer; }
.seg-btn.active { background: var(--orange); color: #fff; }
.dark-select { background: #2a2b2f; color: #fff; border-color: #4b4d52; }
.save-status { margin-left: auto; font-size: .85rem; color: #9fe0bb; }
.save-status.pending { color: #ffd49e; }
.save-status.bad { color: #ff9aa9; }
.inline-confirm { margin-top: .8rem; background: #2a2b2f; border: 1px solid var(--orange); border-radius: 10px; padding: .6rem .8rem; display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
.diagram-card { grid-area: diagram; background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); border: 1px solid #eceef1; overflow: hidden; }
.diagram-scroll { overflow: auto; padding: .8rem; }
#diagram { width: 100%; height: auto; display: block; min-height: 220px; }
#diagram.stale { opacity: .45; }
#diagram .bleed { fill: none; stroke: #dde2e6; stroke-width: 4; stroke-linejoin: round; }
#diagram .piece { fill: var(--orange); stroke: #c94f00; stroke-width: .25; stroke-linejoin: round; }
#diagram .anchor { fill: var(--red); }
#diagram .anchor-label { font-size: 1.8px; fill: var(--red); font-weight: 700; }
#diagram .dim line { stroke: var(--dim); stroke-width: .3; }
#diagram .dim .ext { stroke-dasharray: .8 .6; stroke-width: .2; }
#diagram .dpill { cursor: pointer; }
#diagram .dpill rect { fill: var(--pill); }
#diagram .dpill text { font-size: 3px; fill: #fff; font-weight: 700; font-family: var(--font); }
#diagram .dim.invalid .dpill rect { fill: #fff; stroke: var(--red); stroke-width: .4; }
#diagram .dim.invalid .dpill text { fill: var(--red); }
#diagram .dim.active line { stroke: var(--red); stroke-width: .6; }
#diagram .dim.active .ext { stroke-width: .35; }
#diagram .dim.active .dpill rect { fill: var(--red); }
#diagram .dpill:hover rect { filter: brightness(.9); }
.diagram-foot { display: flex; align-items: center; gap: .8rem; padding: .6rem 1rem; border-top: 1px solid var(--line); background: #fafbfc; flex-wrap: wrap; }
.diagram-foot label { display: flex; font-weight: 500; }
.diagram-foot input[type=range] { accent-color: var(--orange); width: 180px; }
.wizard-card { grid-area: wizard; background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); border: 1px solid #eceef1; padding: 1rem 1.1rem; position: sticky; top: .8rem; }
.step-head { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: .8rem; text-align: center; }
.round-btn { width: 52px; height: 52px; border-radius: 99px; border: 0; background: var(--orange); color: #fff; font-size: 1.9rem; line-height: 1; cursor: pointer; box-shadow: 0 2px 6px rgba(255, 106, 0, .35); }
.round-btn:disabled { background: #e6e8eb; color: #9aa1a9; box-shadow: none; cursor: default; }
.step-kicker { color: var(--orange); font-weight: 800; letter-spacing: .12em; font-size: .82rem; }
.step-title h2 { margin: .15rem 0 0; font-size: 1.15rem; }
.confirmed-count { text-align: center; color: var(--ink-2); margin: .7rem 0; }
.step-preset { display: grid; gap: .3rem; margin-bottom: .8rem; }
.step-preset select { background: #eef0f3; border-color: #e3e6ea; border-radius: 99px; font-size: 1rem; padding: .55rem .9rem; }
.letters { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem .7rem; }
.letter-row { display: grid; grid-template-columns: 2.6rem auto 1fr 2.6rem; align-items: center; gap: .35rem; position: relative; border-radius: 12px; padding: 3px; border: 2px solid transparent; }
.letter-row.active { border-color: var(--red); background: #fff5f5; }
.letter-row .pill { background: var(--pill); color: #fff; border-radius: 9px; height: 2.3rem; display: grid; place-items: center; font-weight: 800; font-size: 1.05rem; cursor: pointer; }
.letter-row.active .pill { background: var(--red); }
.letter-row input { width: 100%; text-align: right; font-size: 1.05rem; padding: .45rem .55rem; border-radius: 8px; grid-column: 3; }
.letter-row .guess-badge { grid-column: 2; }
.letter-row:not(:has(.guess-badge)) input { grid-column: 2 / 4; }
.letter-row.invalid input { border-color: var(--red); box-shadow: 0 0 0 2px rgba(224, 0, 0, .15); color: var(--red); }
.check { width: 2.4rem; height: 2.3rem; border-radius: 9px; border: 2px solid #c4c9cf; background: #fff; color: #b4bac1; cursor: pointer; display: grid; place-items: center; padding: 0; }
.check svg { width: 1.3rem; height: 1.3rem; }
.check.on { border-color: var(--red); color: var(--red); }
.letter-row:not(.active) .check.on { border-color: var(--ok); color: var(--ok); }
.guess-badge { position: relative; display: inline-grid; place-items: center; width: 1.2rem; height: 1.2rem; border-radius: 99px; background: #ffe9b8; color: #8a5a00; font-size: .72rem; font-weight: 800; cursor: help; }
.guess-badge.static { vertical-align: middle; }
.guess-badge .tip { display: none; position: absolute; z-index: 5; bottom: 135%; left: 50%; transform: translateX(-50%); width: 230px; background: #1e1f22; color: #fff; font-weight: 500; font-size: .78rem; line-height: 1.35; padding: .5rem .6rem; border-radius: 8px; box-shadow: var(--shadow); }
.guess-badge:hover .tip, .guess-badge:focus .tip { display: block; }
.letter-help { color: var(--ink-2); min-height: 2.6em; margin: .8rem 0 .4rem; }
.wizard-foot { display: flex; justify-content: space-between; gap: .5rem; flex-wrap: wrap; margin-top: .6rem; }
.checks-card { grid-area: checks; }
.err-list, .warn-list { list-style: none; padding: 0; margin: 0 0 .6rem; display: grid; gap: .35rem; }
.err-list li { background: var(--bad-bg); color: var(--bad); padding: .45rem .6rem; border-radius: 8px; font-size: .9rem; }
.err-list li.ok-item { background: #e9f6ef; color: var(--ok); }
.warn-list li { background: var(--warn-bg); color: var(--warn); padding: .45rem .6rem; border-radius: 8px; font-size: .9rem; }
.warn-list li.check { background: #eef3fb; color: #2f5a8a; }
.table.imca tr.over td { color: var(--warn); font-weight: 600; }

/* ------------------------------------------------ template, artwork */
.side-card .dl-row { display: flex; gap: .5rem; flex-wrap: wrap; margin: .6rem 0; }
.howto li { margin: .25rem 0; }

/* ------------------------------------------------ 3D viewer */
.viewer-card { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); border: 1px solid #eceef1; padding: .8rem; }
.viewer { position: relative; width: 100%; aspect-ratio: 16 / 9; max-height: 72vh; min-height: 320px; border-radius: 10px; overflow: hidden; background: #e4e7ea; }
.viewer canvas { width: 100% !important; height: 100% !important; display: block; touch-action: none; }
.viewer-status { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); background: rgba(18, 18, 18, .82); color: #fff; padding: .7rem 1rem; border-radius: 10px; max-width: 80%; text-align: center; font-size: .92rem; }
.viewer-tools { display: flex; gap: .8rem; flex-wrap: wrap; align-items: center; margin: .8rem 0 .3rem; }
.tool-group { display: flex; gap: .3rem; flex-wrap: wrap; }
.version-pick { display: flex; gap: .3rem; flex-wrap: wrap; }
.chip-link { text-decoration: none; border: 1px solid #cfd5dc; border-radius: 99px; padding: .2rem .65rem; color: var(--ink); font-size: .86rem; font-weight: 600; background: #fff; }
.chip-link.active { background: var(--orange); border-color: var(--orange); color: #fff; }

/* ------------------------------------------------ renders */
.render-form { display: grid; gap: 1rem; }
.opt-head { display: flex; align-items: baseline; gap: .8rem; }
.chips { display: flex; flex-wrap: wrap; gap: .45rem; }
.chip-check { display: inline-flex; font-weight: 500; }
.chip-check input { position: absolute; opacity: 0; pointer-events: none; }
.chip-check span { border: 1px solid #cfd5dc; border-radius: 99px; padding: .35rem .8rem; cursor: pointer; background: #fff; font-size: .9rem; user-select: none; }
.chip-check input:checked + span { background: var(--orange); border-color: var(--orange); color: #fff; }
.chip-check input:focus-visible + span { outline: 3px solid rgba(255, 106, 0, .45); outline-offset: 2px; }
.opt-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: .8rem; }
.opt-row { display: flex; gap: 1.4rem; flex-wrap: wrap; }
.opt-submit { display: flex; justify-content: flex-end; align-items: center; gap: 1rem; flex-wrap: wrap; }
.batch-head { display: flex; justify-content: space-between; gap: 1rem; align-items: center; flex-wrap: wrap; }
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: .8rem; margin-top: .6rem; }
.shot { margin: 0; background: #f6f7f9; border-radius: 10px; overflow: hidden; border: 1px solid #eceef1; }
.shot img { width: 100%; display: block; aspect-ratio: 3 / 2; object-fit: cover; background: #e9ecef; }
.shot-ph { aspect-ratio: 3 / 2; display: grid; place-content: center; gap: .4rem; justify-items: center; padding: .6rem; text-align: center; }
.shot figcaption { display: flex; justify-content: space-between; gap: .5rem; padding: .4rem .6rem; font-size: .82rem; }
.shot-actions { display: flex; gap: .6rem; }

/* ------------------------------------------------ responsive */
@media (max-width: 980px) {
  .gen { grid-template-columns: 1fr; grid-template-areas: "head" "diagram" "wizard" "checks"; }
  .wizard-card { position: static; }
  .grid-2, .index-grid { grid-template-columns: 1fr; }
}
@media (max-width: 560px) {
  .wrap { margin-top: 1rem; }
  h1 { font-size: 1.35rem; }
  .gen-head h1 { font-size: 1.1rem; }
  .save-status { margin-left: 0; width: 100%; }
  .round-btn { width: 46px; height: 46px; }
  .letters { gap: .5rem; }
  .letter-row { grid-template-columns: 2.2rem auto 1fr 2.2rem; gap: .25rem; }
  .letter-row input { font-size: 1rem; padding: .4rem; }
  .check { width: 2.2rem; }
  .topbar, .project-bar { padding-left: 16px; padding-right: 16px; }
}
@media (max-width: 370px) { .letters { grid-template-columns: 1fr; } }

/* R1 advanced panel shape */
.panel-shape { margin-top: 1rem; border-top: 1px solid var(--line, #e3e3e3); padding-top: .75rem; }
.panel-shape summary { cursor: pointer; font-weight: 600; }
.curv-row { display: grid; grid-template-columns: 9rem 1fr 1fr; gap: .5rem; align-items: center; margin: .4rem 0; }
.curv-row input, .curv-row select { width: 100%; min-width: 0; }
@media (max-width: 560px) { .curv-row { grid-template-columns: 1fr; } }
