/* Plate III · Polar Coordinate Systems, Roundness & Area Charts — Module styles (tokens via ../plate-theme.css) */
:root {
  --primary: #7aa3c8;
  --primary-light: rgba(122, 163, 200, 0.11);
  --accent: #ff7d61;
  --accent-blue: #7aa3c8;
  --accent-green: #58b691;
  --accent-2: #ed864b;
  --ok: #58b691;
  --bad: #ff695d;
  --bg-app: #090d16;
  --bg-card: #111722;
  --bg-alt: #0e131d;
  --border: rgba(233, 237, 245, 0.19);
  --border-subtle: rgba(233, 237, 245, 0.12);
  --text: #e9edf5;
  --muted: #a8b3c5;
  --light: #7f8b9f;
  --ink: #e9edf5;
  --grid: rgba(233, 237, 245, 0.16);
  --dia-top: #141a25;
  --dia-bottom: #0f151f;
  --hl: #ed864b;
  --example-bg: rgba(88, 182, 145, 0.06);
  --example-border: #58b691;
  --shadow: 0 8px 22px -6px rgba(24, 23, 21, 0.10);
  --radius: 11px;
  --font: var(--xt-text);
  --font-dia: var(--xt-sub);
  --dia-plain: #141a24;
  --pt-fill: #141a24;
  --mono: var(--xt-mono);
  --bar-fill: #f38a6b;
  --sec-yellow: #cfae55;
  --sec-blue: #7fabd2;
  --sec-orange: #ff7d61;
  --sec-green: #69b49b;
  --sec-purple: #af9acb;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 15px/1.5 var(--font); background: var(--bg-app); color: var(--text); -webkit-font-smoothing: antialiased; }

.plate-header { background: var(--bg-panel); color: var(--text); }
.plate-top { max-width: 1360px; margin: 0 auto; padding: 11px 22px; display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.plate-meta { display: flex; align-items: center; gap: 12px; min-width: 0; }
.plate-meta h1 { margin: 0; font-size: 1.06rem; font-weight: 800; }
.plate-meta .sub { font-size: 0.76rem; color: var(--muted); }
.plate-tools { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }

main { max-width: 1320px; margin: 0 auto; padding: 18px 20px 30px; }
.tab { display: none; }
.tab.active { display: block; }
.tab-head h2 { margin: 0 0 4px; font-size: 1.3rem; color: var(--primary); }
.tab-head p { margin: 0 0 14px; color: var(--muted); max-width: 940px; }

.layout { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 16px; align-items: start; }
@media (max-width: 1000px) { .layout { grid-template-columns: 1fr; } }
.card { background: var(--bg-card); border: 1px solid var(--border-subtle); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px; min-width: 0; }
.card + .card { margin-top: 14px; }
.card h3 { margin: 0 0 8px; font-size: 0.95rem; color: var(--primary); display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
.side .card h3 { font-size: 0.9rem; }

/* Diagram canvas */
.dia { width: 100%; height: auto; display: block; touch-action: none; user-select: none; -webkit-user-select: none; font-family: var(--font-dia); --halo: var(--dia-bottom); }
#p-svg, #r-svg, #c-pie-svg { --halo: var(--dia-plain); }
.dia text { fill: var(--ink); }
.dia .bg { fill: url(#diaGrad); }
.dia .bg-plain { fill: var(--dia-plain); }
.dia .halo { paint-order: stroke; stroke: var(--halo); stroke-width: 4px; stroke-linejoin: round; }
.dia .ax { stroke: var(--ink); fill: none; stroke-linecap: square; }
.dia .ax-head { fill: var(--ink); stroke: none; }
.dia .tick { stroke: var(--ink); }
.dia .grid { stroke: var(--grid); fill: none; }
.dia .curve { fill: none; stroke-linecap: round; stroke-linejoin: round; }
.dia .curve-rm { stroke: var(--accent); fill: none; }
.dia .curve-re { stroke: var(--accent-blue); fill: none; }
.dia .curve-rp { stroke: var(--accent-green); fill: none; }
.dia .curve-mono { stroke: var(--ink); fill: none; }
.dia .band.curve-rm { fill: var(--accent); fill-opacity: 0.14; stroke: none; }
.dia .band.curve-re { fill: var(--accent-blue); fill-opacity: 0.14; stroke: none; }
.dia .band.curve-rp { fill: var(--accent-green); fill-opacity: 0.14; stroke: none; }

/* Data point markers (×, ○, □) */
.dia .pt-mark { stroke-width: 1.6; }
.dia .pt-mark.curve-rm { stroke: var(--accent); }
.dia .pt-mark.curve-re { stroke: var(--accent-blue); }
.dia .pt-mark.curve-rp { stroke: var(--accent-green); }
.dia .pt-mark.curve-mono { stroke: var(--ink); }
.dia .mark-open { fill: var(--pt-fill); }
.dia .mark-cross { fill: none; stroke-linecap: round; }

.dia .proj { stroke: var(--accent); stroke-width: 1.5; fill: none; }
.dia .pt { fill: var(--pt-fill); stroke: var(--ink); stroke-width: 1.5; }
.dia .pt.sel { stroke: var(--primary); stroke-width: 2.5; }
.dia .pt-hit { fill: transparent; cursor: grab; }
.dia .pt-hit:active { cursor: grabbing; }
.dia text.sel-text { font-weight: 700; }
.dia .read { stroke: var(--ink); stroke-width: 1.3; fill: none; }
.dia .read-head { fill: var(--ink); }
.dia .callout { stroke: var(--ink); stroke-width: 0.9; fill: none; }
.dia .hl { stroke: var(--hl) !important; fill: none; opacity: 0.75; stroke-linecap: round; }
.dia .hl-ring { fill: none; stroke: var(--hl); stroke-width: 2.5; }
.dia .hl-fill { fill: var(--hl) !important; }
.dia .hl-stroke { stroke: var(--hl) !important; }
.dia .grid.hl-lines line, .dia .grid.hl-lines circle { stroke: var(--hl); opacity: 1; }
.dia text.hl-text { fill: var(--hl) !important; font-weight: 700; }
.dia .target { fill: none; stroke: var(--hl); stroke-width: 2; stroke-dasharray: 4 3; }
.dia .ok-mark { fill: var(--ok); }
.dia .bad-cross { stroke: var(--bad); stroke-width: 3; stroke-linecap: round; fill: none; }
.dia .quiz-pt { fill: var(--hl); stroke: var(--ink); stroke-width: 1.5; }
.dia .legend-box { fill: var(--bg-card); fill-opacity: 0.88; stroke: var(--border); stroke-width: 1; }
.dia text.lbl-strong { font-weight: 700; }
.dia text.lbl-muted { fill: var(--muted); }

/* Roundness testing: tolerance band & chuck jaws */
.dia .tol-band-ok { fill: var(--ok); fill-opacity: 0.12; }
.dia .tol-band-bad { fill: var(--bad); fill-opacity: 0.12; }
.dia .tol-line-ok { stroke: var(--ok); stroke-width: 1.3; stroke-dasharray: 4 3; }
.dia .tol-line-bad { stroke: var(--bad); stroke-width: 1.3; stroke-dasharray: 4 3; }
.dia .jaw-arrow { stroke: var(--accent-2); }
.dia .jaw-head { fill: var(--accent-2); }

/* Area charts: pie sectors & bars */
.dia .pie-sec { stroke: var(--ink); stroke-width: 1.3; transition: opacity 0.12s; }
.dia .pie-sec:hover { opacity: 0.92; }
.dia .pie-sec.sel { stroke-width: 2.1; }
.dia .sec-yellow { fill: var(--sec-yellow); }
.dia .sec-blue { fill: var(--sec-blue); }
.dia .sec-orange { fill: var(--sec-orange); }
.dia .sec-green { fill: var(--sec-green); }
.dia .sec-purple { fill: var(--sec-purple); }
.dia .bar-rect { fill: var(--bar-fill); stroke: var(--ink); stroke-width: 1.3; }

/* Controls */
.ctl-row { display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: center; margin: 8px 0; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; flex-wrap: wrap; }
.seg button { appearance: none; border: 0; background: var(--bg-card); color: var(--muted); font: 600 0.8rem var(--font); padding: 5px 10px; cursor: pointer; }
.seg button + button { border-left: 1px solid var(--border); }
.seg button.on { background: var(--primary); color: #111722; }
label.chk { display: inline-block; font-size: 0.85rem; color: var(--text); cursor: pointer; }
label.chk input { vertical-align: middle; margin: 0 5px 2px 0; }
.slider { display: grid; grid-template-columns: auto 1fr auto; gap: 8px; align-items: center; font-size: 0.85rem; margin: 6px 0; }
.slider input[type=range] { width: 100%; accent-color: var(--accent); }
.slider output { font: 600 0.85rem var(--mono); min-width: 72px; text-align: right; }
.btn { appearance: none; border: 1px solid var(--accent); background: var(--accent); color: #111722; font: 600 0.82rem var(--font); padding: 6px 12px; border-radius: 6px; cursor: pointer; }
.btn.ghost { background: transparent; color: var(--ink); border-color: var(--border); }
.btn:disabled { opacity: 0.5; cursor: default; }
input.num, input.txt { font: 0.9rem var(--mono); padding: 5px 8px; border: 1px solid var(--border); border-radius: 6px; background: var(--bg-alt); color: var(--text); }
input.num { width: 84px; }
input.txt { width: 155px; }
input.num:focus, input.txt:focus { outline: 2px solid var(--primary); outline-offset: -1px; }

/* Rules / key takeaways */
.rules { list-style: none; margin: 0; padding: 0; }
.rules li { border-left: 3px solid var(--border); padding: 6px 10px; margin: 6px 0; font-size: 0.85rem; border-radius: 0 6px 6px 0; background: var(--bg-alt); cursor: default; }
.rules li b { color: var(--text); }
.rules li.hover-able { cursor: pointer; }
.rules li.hover-able:hover, .rules li.active { border-left-color: var(--hl); background: var(--primary-light); }
.note { font-size: 0.82rem; color: var(--muted); margin: 8px 0 0; }

/* Point list & tables */
.pt-list { list-style: none; margin: 0; padding: 0; }
.pt-list li { display: flex; justify-content: space-between; align-items: center; gap: 6px; padding: 4px 0; border-bottom: 1px solid var(--border-subtle); font: 0.88rem var(--mono); cursor: pointer; }
.pt-list li.cur { font-weight: 700; color: var(--primary); }
.pt-list button { appearance: none; border: 0; background: none; color: var(--bad); cursor: pointer; font-size: 1rem; }
.quad { font-size: 0.8rem; color: var(--muted); font-family: var(--font); }

/* Worked example specimen card */
.example { background: var(--example-bg); border-left: 4px solid var(--example-border); border-radius: 0 var(--radius) var(--radius) 0; padding: 12px 14px; }
.example h3 { color: var(--text); }
.vtable { border-collapse: collapse; font-size: 0.86rem; margin: 6px 0; width: 100%; }
.vtable th, .vtable td { border: 1.5px solid var(--border); padding: 4px 6px; text-align: center; }
.vtable th { font-weight: 600; background: var(--bg-alt); }
.vtable tr.cur-row { background: var(--primary-light); }
.vtable input { width: 100%; min-width: 44px; border: 0; background: transparent; color: var(--text); font: 0.86rem var(--mono); text-align: center; padding: 2px 0; }
.vtable input:focus { outline: 2px solid var(--primary); }
.vtable-wrap { overflow-x: auto; }

/* Fraction rendering for the central angle formula */
.formula-line { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font: 0.96rem var(--mono); margin: 8px 0; padding: 8px 10px; background: var(--bg-alt); border-radius: 6px; border: 1px solid var(--border-subtle); }
.frac { display: inline-flex; flex-direction: column; align-items: center; vertical-align: middle; line-height: 1.2; font-size: 0.9em; }
.frac > span:first-child { border-bottom: 1.5px solid var(--text); padding: 0 4px 2px; }
.frac > span:last-child { padding: 2px 4px 0; }

.result { font: 700 1.08rem var(--mono); color: var(--accent); }
.badge { display: inline-block; font: 700 0.76rem var(--font); padding: 2px 8px; border-radius: 99px; margin-left: 6px; vertical-align: middle; }
.badge.ok { background: rgba(91, 186, 115, 0.15); color: var(--ok); border: 1px solid var(--ok); }
.badge.bad { background: rgba(255, 119, 107, 0.15); color: var(--bad); border: 1px solid var(--bad); }
.bad-txt { color: var(--bad); font-weight: 600; }
.feedback { margin-top: 8px; font-size: 0.9rem; min-height: 1.4em; }
.feedback.ok { color: var(--ok); }
.feedback.bad { color: var(--bad); }
.score { font: 600 0.8rem var(--mono); color: var(--muted); }
.kv { display: grid; grid-template-columns: 1fr auto; gap: 3px 10px; font-size: 0.86rem; margin-top: 6px; }
.kv span:nth-child(even) { font-family: var(--mono); text-align: right; }

footer { max-width: 1320px; margin: 0 auto; padding: 0 20px 28px; color: var(--muted); font-size: 0.78rem; }

@media (max-width: 640px) {
  main { padding: 12px 12px 24px; }
  .plate-top { padding: 8px 12px; }
  .plate-meta h1 { font-size: 1rem; }
  .card { padding: 12px; }
}
