:root {
  --bg: #f6f5f2; --card: #fff; --text: #1d1d1b; --muted: #77756f; --line: #e4e2dc;
  --accent: #2f6f4f; --accent-text: #fff; --good: #2f7d4a; --bad: #b8432f; --warn: #c98a12;
  --ok-bg: #dff1e5; --err-bg: #f7dcd6;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #161715; --card: #20211f; --text: #ecebe7; --muted: #9a988f; --line: #33342f;
    --accent: #4f9d73; --good: #6cc48d; --bad: #e57a64; --ok-bg: #22402e; --err-bg: #4a2a23;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
main { max-width: 1100px; margin: 0 auto; padding: 0 16px 48px; }
a { color: inherit; }
h1 { font-size: 1.6rem; margin: 8px 0 16px; }
h2 { font-size: 1.15rem; margin: 32px 0 8px; }
.muted { color: var(--muted); } .small { font-size: .85rem; font-weight: normal; }
.good { color: var(--good); } .bad { color: var(--bad); }
.top { max-width: 1100px; margin: 0 auto; padding: 14px 16px; display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.brand { font-weight: 700; text-decoration: none; }
.pager a { margin-left: 14px; text-decoration: none; color: var(--muted); }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 16px; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-top: 8px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; }
.stat b { display: block; font-size: 1.6rem; font-variant-numeric: tabular-nums; }
.stat span { color: var(--muted); font-size: .85rem; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; }
.test { padding: 0; overflow: hidden; text-decoration: none; display: flex; flex-direction: column; }
.test img { width: 100%; height: 120px; object-fit: cover; object-position: top; border-bottom: 1px solid var(--line); }
.test-body { padding: 12px 14px; }
.test-title { font-weight: 650; font-size: 1.05rem; }
.pill { font-size: .72rem; background: var(--warn); color: #fff; border-radius: 10px; padding: 1px 8px; vertical-align: middle; }
.cycles { display: flex; gap: 4px; margin: 8px 0; }
.cycles i { flex: 1; height: 6px; border-radius: 3px; background: var(--line); }
.cycles i.on { background: var(--accent); }
dl { display: grid; grid-template-columns: auto 1fr; gap: 2px 12px; margin: 0; font-size: .9rem; }
dt { color: var(--muted); } dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }

.scroll { overflow-x: auto; background: var(--card); border: 1px solid var(--line); border-radius: 14px; }
table { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
th, td { padding: 8px 12px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { font-size: .8rem; color: var(--muted); font-weight: 600; }
tr:last-child td { border-bottom: 0; }
.matrix td, .matrix th { text-align: center; padding: 6px 8px; }
.bar { height: 4px; background: var(--line); border-radius: 2px; margin-top: 4px; min-width: 80px; }
.bar i { display: block; height: 100%; background: var(--accent); border-radius: 2px; }

.panel { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; box-shadow: 0 4px 16px rgba(0,0,0,.06); }
.panel.paused .timer { color: var(--warn); }
.timer-row { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; }
.timer { font-size: clamp(2.6rem, 11vw, 4.2rem); font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1; }
.timer.over { color: var(--bad); }
.small-timer { font-size: 2rem; margin: 4px 0; }
.target { text-align: right; } .target #target { font-size: 1.3rem; font-weight: 650; font-variant-numeric: tabular-nums; }
.progress { height: 6px; background: var(--line); border-radius: 3px; margin: 12px 0; overflow: hidden; }
.progress i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .25s linear; }
.buttons { display: flex; gap: 10px; flex-wrap: wrap; }
.btn { font: inherit; border: 1px solid var(--line); background: var(--bg); color: var(--text); border-radius: 12px; padding: 10px 18px; cursor: pointer; }
.btn.big { flex: 1; min-width: 110px; font-size: 1.25rem; font-weight: 650; padding: 16px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.link { background: none; border: 0; color: var(--muted); text-decoration: underline; cursor: pointer; font: inherit; padding: 0; }
#puzzles-wrap { margin-top: 12px; }
.puzzles { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; margin: 8px 0; }
.pz { font: inherit; border: 1px solid var(--line); background: var(--bg); color: var(--text); border-radius: 10px; padding: 8px 0 6px; cursor: pointer; display: flex; flex-direction: column; align-items: center; min-height: 54px; }
.pz b { font-size: 1.15rem; } .pz small { font-size: .72rem; color: var(--muted); min-height: 1em; font-variant-numeric: tabular-nums; }
.pz.ok { background: var(--ok-bg); border-color: var(--good); }
.pz.err { background: var(--err-bg); border-color: var(--bad); }
.row-end { display: flex; justify-content: space-between; align-items: center; }

.photos { display: grid; gap: 16px; margin-top: 16px; }
.photos figure { margin: 0; }
.photos img { width: 100%; border-radius: 10px; border: 1px solid var(--line); cursor: zoom-in; display: block; background: #fff; }
.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.92); z-index: 50; overflow: auto; display: flex; cursor: zoom-in; }
.lightbox[hidden] { display: none !important; }  /* иначе .lightbox.zoomed (ниже) показывает закрытое окно */
.lightbox img { margin: auto; max-width: 100%; max-height: 100%; object-fit: contain; }
.lightbox.zoomed { display: block; cursor: zoom-out; }
.lightbox.zoomed img { max-width: none; max-height: none; width: 250%; }

dialog { border: 1px solid var(--line); border-radius: 16px; background: var(--card); color: var(--text); padding: 20px; width: min(92vw, 380px); }
dialog::backdrop { background: rgba(0,0,0,.45); }
dialog h2 { margin-top: 0; }
dialog label { display: flex; justify-content: space-between; align-items: center; margin: 10px 0; }
input { font: inherit; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); color: var(--text); width: 110px; }
.login { max-width: 340px; margin: 60px auto; display: grid; gap: 12px; } .login input { width: 100%; }

@media (min-width: 900px) { .photos { grid-template-columns: 1fr 1fr; } }
@media (max-width: 480px) { .puzzles { grid-template-columns: repeat(4, 1fr); } .btn.big { min-width: 90px; padding: 14px 8px; } }
.top-right { display: flex; align-items: center; gap: 4px; }
.visits { margin-left: 14px; text-decoration: none; color: var(--muted); font-size: .9rem; font-variant-numeric: tabular-nums; border: 1px solid var(--line); border-radius: 10px; padding: 2px 10px; }
.days { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0 16px; }
.days a { text-decoration: none; border: 1px solid var(--line); border-radius: 10px; padding: 4px 10px; font-size: .85rem; background: var(--card); }
.days a.on { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
td.ua { white-space: normal; max-width: 360px; font-size: .8rem; color: var(--muted); }

/* доска */
:root { --sq-light: #f0d9b5; --sq-dark: #b58863; --sq-sel: #e6c35c; --sq-last: rgba(214, 190, 60, .45); }
.board { border-radius: 0; display: grid; grid-template-columns: repeat(8, 1fr); grid-template-rows: repeat(8, 1fr); container-type: inline-size; width: 100%; aspect-ratio: 1; border-radius: 6px; overflow: hidden; user-select: none; touch-action: manipulation; box-shadow: 0 2px 10px rgba(0,0,0,.18); }
.sq { position: relative; min-width: 0; min-height: 0; overflow: hidden; display: flex; align-items: center; justify-content: center; cursor: pointer; }
.sq.l { background: var(--sq-light); } .sq.d { background: var(--sq-dark); }
.sq.last::before { content: ""; position: absolute; inset: 0; background: var(--sq-last); }
.sq.sel::before { content: ""; position: absolute; inset: 0; background: var(--sq-sel); opacity: .75; }
.sq.bad::before { content: ""; position: absolute; inset: 0; background: rgba(200, 50, 40, .5); }
.sq.check::before { content: ""; position: absolute; inset: 0; background: radial-gradient(circle, rgba(230,40,30,.8), transparent 70%); }
.sq.dot::after { content: ""; position: absolute; width: 28%; height: 28%; border-radius: 50%; background: rgba(30, 30, 30, .28); }
.sq.cap::after { content: ""; position: absolute; inset: 4%; border-radius: 50%; border: 5px solid rgba(30, 30, 30, .28); }
.pc { position: absolute; inset: 0; z-index: 1; background-size: 100% 100%; background-repeat: no-repeat; pointer-events: none; }
.coord { position: absolute; font-size: clamp(8px, 2.2cqw, 12px); font-weight: 700; z-index: 2; }
.sq.l .coord { color: #b58863; } .sq.d .coord { color: #f0d9b5; }
.coord.f { right: 3px; bottom: 1px; } .coord.r { left: 3px; top: 1px; }

/* решение задачи */
.solver { display: grid; grid-template-columns: minmax(0, 520px) minmax(0, 1fr); gap: 16px; margin-top: 12px; align-items: start; }
.solver-info h3 { margin: 0 0 4px; font-size: 1.2rem; }
.turn { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; }
.turn i { width: 14px; height: 14px; border-radius: 50%; border: 1px solid #555; display: inline-block; }
.turn.w i { background: #fff; } .turn.b i { background: #222; }
.msg { min-height: 1.5em; margin: 10px 0; font-weight: 600; }
.msg.ok { color: var(--good); } .msg.err { color: var(--bad); }
.moves-line { font-variant-numeric: tabular-nums; color: var(--muted); min-height: 1.4em; }
.diagram { max-width: 260px; width: 100%; border-radius: 8px; border: 1px solid var(--line); margin-top: 10px; }
.nav12 { display: grid; grid-template-columns: repeat(12, 1fr); gap: 4px; margin: 10px 0 0; }
.nav12 button { font: inherit; font-size: .85rem; border: 1px solid var(--line); background: var(--bg); color: var(--text); border-radius: 8px; padding: 6px 0; cursor: pointer; }
.nav12 .cur { outline: 2px solid var(--accent); outline-offset: 1px; }
.nav12 .ok { background: var(--ok-bg); border-color: var(--good); } .nav12 .err { background: var(--err-bg); border-color: var(--bad); }
.badge { font-size: .75rem; border-radius: 8px; padding: 1px 8px; background: var(--line); color: var(--text); }
.badge.checked { background: var(--ok-bg); } .badge.invalid { background: var(--err-bg); } .badge.recognized { background: #f3e7c4; color: #222; }

/* экран проверки */
.check-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 520px), 1fr)); gap: 14px; }
.check-card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 12px; }
.check-card .pair { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; align-items: start; }
.check-card img { width: 100%; border-radius: 6px; border: 1px solid var(--line); }
.palette { display: flex; flex-wrap: wrap; gap: 4px; margin: 8px 0; }
.palette button { font: inherit; width: 36px; height: 36px; border: 1px solid var(--line); border-radius: 8px; background: var(--sq-light); cursor: pointer; container-type: inline-size; display: flex; align-items: center; justify-content: center; padding: 0; }
.palette button { position: relative; }
.palette button.on { outline: 3px solid var(--accent); }
.fen { width: 100%; font-family: ui-monospace, monospace; font-size: .8rem; }
.row-btns { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; align-items: center; }
@media (max-width: 760px) { .solver { grid-template-columns: 1fr; } .nav12 { grid-template-columns: repeat(6, 1fr); } }
.badge.new { background: var(--line); }
.recog { margin-bottom: 14px; }
.recog-ways { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin: 10px 0 4px; }
.prompt-row { display: flex; gap: 8px; align-items: center; margin-top: 4px; flex-wrap: wrap; }
.prompt-row code { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; font-size: .9rem; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
@media (max-width: 700px) { .recog-ways { grid-template-columns: 1fr; } }
.foot { max-width: 1100px; margin: 0 auto; padding: 0 16px 24px; }
.sets { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 14px; }
.sets a { color: var(--text); text-decoration: none; background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 6px 12px; font-size: .92rem; }
.sets a.cur { border-color: var(--accent); outline: 1px solid var(--accent); }
.crumbs { margin: 0 0 4px; }
.board.dnd { touch-action: none; }
.sq.dragfrom .pc { opacity: .3; }
.sq.hover::before { content: ""; position: absolute; inset: 0; box-shadow: inset 0 0 0 3px rgba(255, 255, 255, .75); }
.drag-ghost { position: fixed; left: 0; top: 0; z-index: 1000; pointer-events: none; background-size: 100% 100%; background-repeat: no-repeat; filter: drop-shadow(0 4px 6px rgba(0,0,0,.35)); will-change: transform; }
.sound-btn { padding: 10px 12px; }
.lb-close { position: fixed; top: 12px; right: 12px; z-index: 60; width: 48px; height: 48px; border-radius: 50%; border: 0; background: rgba(0,0,0,.65); color: #fff; font-size: 24px; line-height: 48px; cursor: pointer; box-shadow: 0 2px 8px rgba(0,0,0,.4); }
.lb-close:hover { background: rgba(0,0,0,.85); }
.lb-hint { position: fixed; bottom: 10px; left: 50%; transform: translateX(-50%); z-index: 60; color: #fff; background: rgba(0,0,0,.6); padding: 4px 12px; border-radius: 10px; font-size: .85rem; pointer-events: none; white-space: nowrap; }
.lightbox.zoomed { cursor: grab; } .lightbox.panning { cursor: grabbing; user-select: none; }
.lightbox.zoomed img { cursor: zoom-out; }
@media (max-width: 480px) { .lb-hint { display: none; } }
.cycle-now { margin: 0 0 16px; }
.cn-head { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; align-items: end; }
.cn-num { font-size: 1.6rem; font-weight: 750; }
.cn-val { font-size: 1.25rem; font-weight: 650; }
.bar.big { height: 8px; margin: 12px 0 4px; }
.pill.ok { background: var(--good); }
@media (max-width: 600px) { .cn-head { grid-template-columns: 1fr 1fr; } }
.or-wrap { position: relative; margin-left: 8px; }
.or-badge { font: inherit; font-size: .9rem; font-variant-numeric: tabular-nums; color: var(--text); background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 2px 10px; cursor: pointer; }
.or-badge.warn { border-color: var(--warn); color: var(--warn); } .or-badge.bad { border-color: var(--bad); color: var(--bad); }
.or-pop { position: fixed; right: 16px; top: 52px; z-index: 40; width: 330px; max-width: calc(100vw - 32px); box-sizing: border-box; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; box-shadow: 0 8px 24px rgba(0,0,0,.18); font-size: .88rem; }
.or-pop table { width: 100%; margin: 6px 0; border: 0; } .or-pop td { padding: 3px 0; border: 0; } .or-pop td:first-child { padding-right: 10px; color: var(--muted); } .or-pop td:last-child { text-align: right; }
.or-pop td.wrap { white-space: normal; overflow-wrap: anywhere; }
@media (min-width: 1132px) { .or-pop { right: calc((100vw - 1100px) / 2 + 16px); } }
.or-pop p { margin: 6px 0 0; } .or-err { color: var(--bad); font-size: .8rem; word-break: break-word; }

/* Точность: ошибок больше 10% задач — не ускоряться в следующем цикле */
.warn-note { background: color-mix(in srgb, var(--warn) 14%, transparent); border-left: 3px solid var(--warn);
  border-radius: 6px; padding: 6px 10px; margin: 8px 0; font-size: .9rem; }
.warn-text { color: var(--warn); font-weight: 600; }
.card.test.warn { border-color: var(--warn); box-shadow: 0 0 0 2px color-mix(in srgb, var(--warn) 45%, transparent); }
