:root {
  --ink: #17243a;
  --muted: #52647a;
  --blue: #2456c4;
  --blue-soft: #eff4ff;
  --navy: #172d56;
  --green: #14734b;
  --green-soft: #f0faf4;
  --red: #a82c37;
  --red-soft: #fff6f6;
  --amber: #9a6410;
  --amber-soft: #fff6e2;
  --border: #dce4ef;
  --radius: 14px;
}

* { box-sizing: border-box }

body {
  margin: 0;
  background: #f1f5fa;
  color: var(--ink);
  font: 17px/1.55 system-ui, -apple-system, 'Segoe UI', sans-serif;
}

header.top {
  background: var(--navy);
  color: #fff;
  padding: 25px max(20px, calc((100vw - 1060px) / 2));
}

header.top .crumb {
  margin: 0;
  color: #ccdbf9;
  font-size: 13px;
  letter-spacing: 1.6px;
  text-transform: uppercase;
  font-weight: 700;
}

header.top h1 { font-size: clamp(23px, 4vw, 36px); line-height: 1.15; margin: 7px 0 0 }
header.top .row { display: flex; gap: 16px; align-items: flex-end; justify-content: space-between; flex-wrap: wrap }
header.top .who { font-size: 14px; color: #d5e2ff; font-weight: 650 }
header.top a { color: #d5e2ff }

main { max-width: 1060px; margin: 20px auto 55px; padding: 0 16px }
main.wide { max-width: 1400px }
body.admin header.top { padding: 25px max(20px, calc((100vw - 1400px) / 2)) }

.panel {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: clamp(18px, 4vw, 34px);
  box-shadow: 0 6px 24px #172d5608;
  margin-bottom: 16px;
}

.panel.flat { box-shadow: none }
h2 { font-size: clamp(22px, 3vw, 29px); line-height: 1.25; margin: 0 0 14px }
h3 { margin: 18px 0 8px; font-size: 20px }
p { margin: 8px 0 14px }
.muted { color: var(--muted); font-size: 15px }
.small { font-size: 13px }
.tag { display: inline-block; background: var(--blue-soft); color: var(--blue); font-size: 13px; font-weight: 750; border-radius: 20px; padding: 4px 11px; margin-bottom: 12px }
.note { border-left: 4px solid var(--blue); background: var(--blue-soft); padding: 12px 16px; border-radius: 5px; margin: 14px 0 }
.note.warn { background: var(--amber-soft); border-left-color: #b7791f }
.note.good { background: var(--green-soft); border-left-color: var(--green) }
.note.bad { background: var(--red-soft); border-left-color: var(--red) }
details.accordion { border: 1px solid var(--border); border-radius: 12px; background: #f6f8fc; margin: 14px 0 0 }
details.accordion > summary { cursor: pointer; padding: 11px 14px; font-size: 15px; color: var(--ink); list-style: none; display: flex; justify-content: space-between; align-items: center; gap: 10px }
details.accordion > summary::-webkit-details-marker { display: none }
details.accordion > summary::after { content: '▾'; color: var(--muted); font-size: 13px }
details.accordion[open] > summary::after { content: '▴' }
details.accordion > summary:focus-visible { outline: 2px solid var(--blue); outline-offset: -2px; border-radius: 12px }
details.accordion > .note { margin: 0 12px 12px }
.formula { font-size: clamp(20px, 3vw, 28px); font-weight: 650; line-height: 1.8; overflow-wrap: anywhere }
sup { font-size: .65em }
.split { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 14px }
.tile { background: #f6f8fc; border: 1px solid var(--border); border-radius: 12px; padding: 15px }
.tile p { margin: 5px 0 }
.power-demo { display: flex; align-items: center; gap: 20px; flex-wrap: wrap }
.bigpower { font-size: 64px; font-weight: 800; line-height: 1.3; color: var(--blue); white-space: nowrap }
.bigpower sup { color: #c35a1d; font-size: .55em }
.label-blue { color: var(--blue); font-weight: bold }
.label-orange { color: #a84914; font-weight: bold }
.place { display: grid; grid-template-columns: repeat(4, 1fr); max-width: 540px; text-align: center; border: 1px solid var(--border); border-radius: 10px; overflow: hidden }
.place div { border: 1px solid var(--border); padding: 7px 4px }
.place .digit { font-size: 27px; font-weight: bold; background: #e8efff }
.place .head { font-size: 12px; background: #f3f6fb }
.place .pow { font-size: 15px }

label { font-weight: 650; display: block; margin: 10px 0 5px }
input, select, textarea {
  font: inherit;
  border: 1.5px solid #aebdd2;
  border-radius: 10px;
  padding: 11px 12px;
  color: var(--ink);
  background: #fff;
  min-width: 0;
  width: 100%;
}
textarea { min-height: 78px; resize: vertical }
input:focus, select:focus, textarea:focus { outline: 3px solid #c5d6ff; border-color: var(--blue) }
input[type=checkbox] { width: auto }

button {
  background: var(--blue);
  border: 0;
  border-radius: 10px;
  padding: 12px 19px;
  font: inherit;
  font-weight: 700;
  color: #fff;
  cursor: pointer;
}
button:hover:not(:disabled) { filter: brightness(1.07) }
button.green { background: var(--green) }
button.red { background: var(--red) }
button.amber { background: #b7791f }
button.secondary { color: var(--blue); background: #e8efff }
button.ghost { color: var(--muted); background: #eef2f8 }
button.link { background: none; color: var(--blue); padding: 4px 6px; text-decoration: underline }
button.sm { padding: 6px 11px; font-size: 14px; border-radius: 8px }
button:disabled { opacity: .5; cursor: not-allowed }
.actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 20px; align-items: center }

.progress { height: 9px; background: #dce5f4; border-radius: 10px; overflow: hidden; margin: 12px 0 0 }
.progress > div { height: 100%; background: #3566d6; transition: width .25s }
.topline { display: flex; gap: 12px; justify-content: space-between; align-items: center; flex-wrap: wrap; font-size: 14px; font-weight: 650 }

.qgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 13px; margin: 18px 0 }
.question { border: 1px solid var(--border); border-radius: 12px; padding: 14px; background: #fff; min-width: 0 }
.question.locked { background: #f7f9fd }
.question.wrong { border-color: #e4a4aa; background: var(--red-soft) }
.question.right { border-color: #86c8aa; background: var(--green-soft) }
.question.redo { border-color: #e0b878; background: var(--amber-soft) }
.qid { font-size: 12px; color: var(--muted); font-weight: 700; display: flex; gap: 8px; align-items: center; justify-content: space-between }
.expression { font-size: 22px; line-height: 1.6; font-weight: 650; margin: 5px 0 10px; overflow-wrap: anywhere }
.feedback { font-size: 14px; font-weight: 650; margin-top: 8px }
.right .feedback { color: var(--green) }
.wrong .feedback { color: var(--red) }
.redo .feedback { color: var(--amber) }
.compare { display: grid; grid-template-columns: 1fr 65px 1fr; align-items: center; gap: 8px; text-align: center }
.compare select { padding: 10px 4px }
.compare span { font-size: 18px; overflow-wrap: anywhere }

.pill { display: inline-block; font-size: 12px; font-weight: 750; border-radius: 20px; padding: 3px 10px; white-space: nowrap }
.pill.blue { background: var(--blue-soft); color: var(--blue) }
.pill.green { background: var(--green-soft); color: var(--green) }
.pill.red { background: var(--red-soft); color: var(--red) }
.pill.amber { background: var(--amber-soft); color: var(--amber) }
.pill.grey { background: #eef2f8; color: var(--muted) }

.tablewrap { overflow: auto; border: 1px solid var(--border); border-radius: 12px; margin: 12px 0 }
table { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums }
th, td { text-align: center; padding: 8px 7px; border: 1px solid #e1e7f1; white-space: nowrap }
th { background: #e9effc; color: #234991; font-size: 14px }
td.left, th.left { text-align: left; white-space: normal; vertical-align: top }
tr.click { cursor: pointer }
tr.click:hover td { background: #f3f7ff }
.sqtable { font-size: 14px; min-width: 620px }
.review { font-size: 14px; min-width: 540px }
.review tr.grp td { background: #eef3fb; color: var(--navy); font-weight: 750; text-align: left }
th.highlight, td.highlight { background: #d7e6ff; color: #143e98; font-weight: bold }

.metrics { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; margin: 20px 0 }
.metric { border: 1px solid var(--border); border-radius: 12px; padding: 15px; background: #f8faff }
.metric b { font-size: 30px; display: block; line-height: 1.25 }
.metric span { font-size: 13px; color: var(--muted) }
.goodtxt { color: var(--green) }
.badtxt { color: var(--red) }
.ambertxt { color: var(--amber) }

.overlay { position: fixed; inset: 0; background: #142644df; z-index: 10; display: flex; align-items: center; justify-content: center; padding: 20px }
.overlay .panel { max-width: 540px; width: 100%; margin: 0 }
[hidden] { display: none !important }

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%);
  background: #16294d;
  color: #fff;
  padding: 12px 18px;
  border-radius: 12px;
  font-weight: 650;
  box-shadow: 0 10px 30px #10203c55;
  z-index: 30;
  max-width: min(92vw, 620px);
}
.toast.err { background: #7d2029 }

.nav { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 14px }
.nav a { color: #d5e2ff; text-decoration: none; font-size: 14px; font-weight: 700; padding: 7px 13px; border-radius: 9px }
.nav a.on { background: #fff; color: var(--navy) }

.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 14px }
.grid3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px }
.inline { display: flex; gap: 10px; align-items: center; flex-wrap: wrap }
.card { border: 1px solid var(--border); border-radius: 12px; padding: 15px; background: #fff }
.card h3 { margin-top: 0 }
.row-between { display: flex; gap: 12px; align-items: center; justify-content: space-between; flex-wrap: wrap }
.segment { display: inline-flex; border: 1px solid var(--border); border-radius: 9px; overflow: hidden }
.segment button { border-radius: 0; background: #f3f6fb; color: var(--muted); padding: 6px 12px; font-size: 14px }
.segment button.on.green { background: var(--green); color: #fff }
.segment button.on.red { background: var(--red); color: #fff }
.palette { display: flex; gap: 4px; flex-wrap: wrap; margin: 6px 0 }
.palette button { background: #fff; border: 1px solid var(--border); color: var(--ink); padding: 3px 8px; font-size: 15px; border-radius: 7px }
.qhead { display: flex; gap: 10px; align-items: center; flex-wrap: wrap }
footer { font-size: 13px; color: var(--muted); text-align: center; margin-top: 18px }

@media (max-width: 500px) {
  .qgrid { grid-template-columns: 1fr }
  .actions button { width: 100% }
  .place .head { font-size: 10px }
}

@media print {
  body { background: #fff }
  header.top { background: #fff; color: #000; padding: 8px }
  header.top .crumb, header.top .who { color: #000 }
  main { max-width: none; margin: 0; padding: 0 }
  .panel { box-shadow: none; border: 0; padding: 12px }
  .actions, footer, .status, .overlay, .nav { display: none !important }
  .review { min-width: 0 }
  .tablewrap { overflow: visible }
  .review tr { break-inside: avoid }
}
