:root {
  --bg: #0f1722; --card: #182231; --line: #2a3647; --fg: #eef2f7; --muted: #9aa8ba;
  --accent: #ff2d55; --ok: #16a34a; --mid: #ca8a04; --bad: #dc2626; --btn: #26344a;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--fg); }
body { font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; overflow-x: hidden; }
.wrap { max-width: 920px; margin: 0 auto; padding: 16px max(14px, env(safe-area-inset-left)) 48px; }
h1 { font-size: 2rem; margin: 8px 0 4px; }
h2 { font-size: 1.15rem; margin: 22px 0 8px; }
.lead { color: var(--muted); margin-top: 0; }
.steps { padding-left: 1.2em; } .steps li { margin: 6px 0; }
.note { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 4px 16px 10px; margin-top: 22px; }
.note ul { padding-left: 1.1em; } .note li { margin: 4px 0; }
.note a { color: #8cc4ff; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line);
  background: var(--btn); color: var(--fg); border-radius: 10px; padding: 9px 14px; font: inherit; cursor: pointer;
  min-height: 42px; text-align: center; }
.btn.primary { background: var(--accent); border-color: var(--accent); font-weight: 600; }
.btn.big { width: 100%; min-height: 54px; font-size: 1.05rem; margin: 10px 0 4px; }
.btn.small { padding: 6px 10px; min-height: 36px; font-size: .9rem; }
.btn.danger { color: #ffb4b4; }
.btn[disabled], .btn.busy { opacity: .55; pointer-events: none; }
.row { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0; }
.hint { color: var(--muted); font-size: .9rem; margin: 4px 0; }
.status { min-height: 1.4em; color: #ffd27a; margin: 6px 0; }
.status.err { color: #ff9a9a; }
.top { display: flex; gap: 8px; align-items: center; }
.home { color: var(--fg); font-weight: 700; text-decoration: none; font-size: 1.2rem; }
.name { flex: 1; min-width: 0; background: transparent; border: 1px solid transparent; color: var(--fg);
  font: inherit; padding: 6px 8px; border-radius: 8px; }
.name:hover, .name:focus { border-color: var(--line); outline: none; background: var(--card); }

.cropbox { position: relative; touch-action: none; user-select: none; -webkit-user-select: none; line-height: 0; }
.cropbox img { width: 100%; display: block; border-radius: 6px; }
#croprect { position: absolute; border: 2px solid var(--accent); box-shadow: 0 0 0 9999px rgba(0,0,0,.55); cursor: move; }
.cropbox { overflow: hidden; border-radius: 6px; }
#croprect i { position: absolute; width: 30px; height: 30px; border: 0 solid #fff; }
#croprect i::after { content: ""; position: absolute; inset: -10px; }
#croprect i[data-h=nw] { left: 0; top: 0; border-width: 5px 0 0 5px; }
#croprect i[data-h=ne] { right: 0; top: 0; border-width: 5px 5px 0 0; }
#croprect i[data-h=sw] { left: 0; bottom: 0; border-width: 0 0 5px 5px; }
#croprect i[data-h=se] { right: 0; bottom: 0; border-width: 0 5px 5px 0; }

.boardwrap { position: relative; line-height: 0; margin-top: 8px; }
.boardwrap img { width: 100%; display: block; border-radius: 6px; }
#overlay { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
#overlay .mk { pointer-events: all; cursor: pointer; }

.pieces { display: grid; grid-template-columns: 1fr; gap: 12px; }
@media (min-width: 700px) { .pieces { grid-template-columns: 1fr 1fr; } }
.piece { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px; }
.piece.sel { border-color: var(--accent); }
.piece .vis { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.piece .cell { position: relative; aspect-ratio: 1; background: #0b111a; border-radius: 8px; overflow: hidden; }
.piece .cell img { position: absolute; inset: 0; margin: auto; max-width: 70%; max-height: 70%; }
.piece .zoom { background-repeat: no-repeat; }
.piece .ring { position: absolute; border: 3px solid var(--accent); border-radius: 50%;
  box-shadow: 0 0 0 2px #fff, 0 0 0 4px rgba(0,0,0,.6); }
.piece .lbl { position: absolute; left: 6px; top: 6px; font-size: .75rem; line-height: 1.2; background: rgba(0,0,0,.6);
  padding: 2px 6px; border-radius: 6px; color: #dbe4ee; }
.piece .info { margin-top: 8px; }
.piece .turn { font-size: 1.1rem; font-weight: 600; }
.badge { display: inline-block; font-size: .8rem; font-weight: 700; padding: 2px 8px; border-radius: 999px; color: #fff; }
.badge.high { background: var(--ok); } .badge.medium { background: var(--mid); } .badge.low, .badge.none { background: var(--bad); }
.num { display: inline-flex; width: 24px; height: 24px; border-radius: 50%; background: var(--accent); color: #fff;
  font-weight: 700; font-size: .85rem; align-items: center; justify-content: center; margin-right: 6px; }
.alts { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.alts .btn { min-height: 32px; padding: 4px 8px; font-size: .82rem; }
.alts .btn.on { border-color: var(--accent); background: #3a1a25; }
.spinner { display: inline-block; width: 1em; height: 1em; border: 2px solid currentColor; border-right-color: transparent;
  border-radius: 50%; animation: s .8s linear infinite; vertical-align: -2px; margin-right: 6px; }
@keyframes s { to { transform: rotate(360deg); } }
