/* Ferma portāls — one small stylesheet, light + dark, desktop + phone. No external fonts (CSP: self only). */
:root {
  --bg: #f6f1e7; --surface: #ffffff; --surface-2: #fbf8f2; --ink: #2a2118; --ink-2: #5a4c3d; --muted: #8a7b68;
  --line: #e7dece; --line-2: #d8ccb7; --accent: #3f7d24; --accent-ink: #ffffff; --accent-soft: #e6f0dc;
  --bar: #4f8f2f; --bar-2: #c8b48e; --warn: #9a5b00; --warn-soft: #fbefd9; --bad: #a3361f; --bad-soft: #f8e1da;
  --ok: #2f6f1c; --ok-soft: #e3f0d9; --test: #6b4bb3; --test-soft: #ece6f8;
  --radius: 10px; --shadow: 0 1px 2px rgba(60, 40, 10, .06), 0 4px 16px rgba(60, 40, 10, .05);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17140f; --surface: #221e17; --surface-2: #1c1913; --ink: #f2eadc; --ink-2: #cfc2ad; --muted: #9c8f7a;
    --line: #353026; --line-2: #4a4235; --accent: #78b356; --accent-ink: #13200b; --accent-soft: #2a3a20;
    --bar: #7fbb5c; --bar-2: #6e6250; --warn: #e3a64a; --warn-soft: #3a2c14; --bad: #f08a70; --bad-soft: #3d1f17;
    --ok: #8fcf6c; --ok-soft: #22331a; --test: #b9a2f0; --test-soft: #2c2440;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3); color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.45 var(--font); -webkit-text-size-adjust: 100%; }
[hidden] { display: none !important; }
a { color: var(--accent); }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5em; }
h2 { font-size: 17px; font-weight: 650; }
h3 { font-size: 14px; font-weight: 650; color: var(--ink-2); text-transform: none; }
.muted { color: var(--muted); }
.mono { font-family: var(--mono); font-size: 12.5px; }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.noscript { padding: 24px; }

/* ---------- buttons, inputs */
.btn { appearance: none; border: 1px solid var(--line-2); background: var(--surface); color: var(--ink); border-radius: 8px;
  padding: 9px 14px; font: inherit; font-weight: 600; cursor: pointer; min-height: 40px; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.small { min-height: 32px; padding: 5px 10px; font-size: 13px; }
.btn.link { border: 0; background: none; color: var(--accent); padding: 6px 0; min-height: 0; font-weight: 500; }
.btn:disabled { opacity: .55; cursor: default; }
input[type=text], input[type=email], input[type=search], select {
  font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--line-2); border-radius: 8px; padding: 8px 10px; min-height: 40px; }
input:focus-visible, select:focus-visible, .btn:focus-visible, a:focus-visible, summary:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 45%, transparent); outline-offset: 1px; }
label { font-size: 13px; color: var(--ink-2); font-weight: 600; }
.check { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; font-weight: 500; color: var(--ink); }

/* ---------- sign-in */
.login { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.login-card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 28px 24px; box-shadow: var(--shadow); }
.login-card .brand { margin-bottom: 22px; }
.login-card h1 { font-size: 22px; }
.login-card form { display: grid; gap: 10px; }
.login-card input { width: 100%; font-size: 17px; }
#in-code { letter-spacing: .4em; font-family: var(--mono); font-size: 22px; text-align: center; }
.msg { min-height: 1.4em; margin: 14px 0 0; font-size: 14px; color: var(--ink-2); }
.msg.bad { color: var(--bad); }

/* ---------- shell */
.brand { display: flex; align-items: center; gap: 9px; font-size: 16px; white-space: nowrap; }
.brand b { font-weight: 700; }
.brand-mark { width: 22px; height: 22px; border-radius: 6px; background: var(--accent); position: relative; flex: none; }
.brand-mark::after { content: ""; position: absolute; left: 4px; right: 4px; bottom: 5px; height: 9px; background: var(--surface);
  clip-path: polygon(50% 0, 100% 60%, 100% 100%, 0 100%, 0 60%); }
.top { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 18px; padding: 10px 20px;
  padding-top: max(10px, env(safe-area-inset-top)); background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); }
.tabs { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; flex: 1; }
.tabs::-webkit-scrollbar { display: none; }
.tabs a { text-decoration: none; color: var(--ink-2); padding: 8px 12px; border-radius: 8px; font-weight: 600; white-space: nowrap; }
.tabs a:hover { background: var(--surface); }
.tabs a.on { background: var(--surface); color: var(--ink); box-shadow: inset 0 -2px 0 var(--accent); }
.who { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--muted); white-space: nowrap; }
.page { max-width: 1320px; margin: 0 auto; padding: 20px 20px 60px; outline: none; }
@media (max-width: 760px) {
  .top { flex-wrap: wrap; gap: 8px 12px; padding: 8px 12px; }
  .tabs { order: 3; flex-basis: 100%; margin: 0 -12px; padding: 0 8px; }
  .who { margin-left: auto; }
  #who-email { display: none; }
  .page { padding: 14px 12px 48px; }
}

/* ---------- blocks */
.head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 8px 16px; margin: 6px 0 16px; }
.head h1 { font-size: 22px; margin: 0; }
.head .sp { flex: 1; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); min-width: 0; }
.grid { display: grid; gap: 14px; }
.grid.tiles { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(min(100%, 460px), 1fr)); }
.grid.three { grid-template-columns: repeat(auto-fit, minmax(min(100%, 300px), 1fr)); }
.section { margin-top: 18px; }
.tile .label { font-size: 13px; color: var(--ink-2); }
.tile .value { font-size: 26px; font-weight: 650; font-variant-numeric: tabular-nums; margin-top: 2px; letter-spacing: -.01em; }
.tile .sub { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.kv { display: grid; grid-template-columns: 1fr auto; gap: 6px 14px; font-size: 14px; margin: 0; }
.kv dt { color: var(--ink-2); }
.kv dd { margin: 0; font-variant-numeric: tabular-nums; text-align: right; font-weight: 600; }
.badge { display: inline-block; font-size: 11.5px; font-weight: 700; padding: 2px 7px; border-radius: 99px; background: var(--surface-2);
  border: 1px solid var(--line); color: var(--ink-2); vertical-align: middle; white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.badge.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.badge.bad { background: var(--bad-soft); color: var(--bad); border-color: transparent; }
.badge.test { background: var(--test-soft); color: var(--test); border-color: transparent; }
.note { font-size: 13px; color: var(--muted); margin: 8px 0 0; }
.empty { color: var(--muted); font-size: 14px; padding: 8px 0; }
.loading { color: var(--muted); padding: 30px 0; }
.err { color: var(--bad); padding: 12px 0; }
details > summary { cursor: pointer; color: var(--ink-2); font-weight: 600; font-size: 13.5px; padding: 4px 0; }
.list { margin: 6px 0 0; padding-left: 18px; font-size: 13.5px; }
.list li { margin: 2px 0; }

/* ---------- controls row */
.controls { display: flex; flex-wrap: wrap; gap: 8px 10px; align-items: center; margin-bottom: 14px; }
.controls input[type=search] { flex: 1 1 220px; min-width: 0; }
.seg { display: inline-flex; border: 1px solid var(--line-2); border-radius: 8px; overflow: hidden; }
.seg button { appearance: none; border: 0; background: var(--surface); color: var(--ink-2); font: inherit; font-weight: 600; padding: 7px 12px; cursor: pointer; min-height: 38px; }
.seg button + button { border-left: 1px solid var(--line-2); }
.seg button.on { background: var(--accent); color: var(--accent-ink); }
.subtabs { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 14px; }
.subtabs button { appearance: none; border: 1px solid var(--line-2); background: var(--surface); color: var(--ink-2); border-radius: 99px; padding: 6px 12px; font: inherit; font-size: 13.5px; font-weight: 600; cursor: pointer; }
.subtabs button.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.subtabs .n { font-weight: 500; opacity: .7; margin-left: 4px; }

/* ---------- tables */
.tablewrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); -webkit-overflow-scrolling: touch; }
table { border-collapse: collapse; width: 100%; font-size: 13.5px; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { position: sticky; top: 0; background: var(--surface-2); font-size: 12px; color: var(--ink-2); font-weight: 700; white-space: nowrap; }
th.sortable { cursor: pointer; user-select: none; }
th.sortable::after { content: " ↕"; color: var(--muted); font-weight: 400; }
th.asc::after { content: " ↑"; color: var(--ink); }
th.desc::after { content: " ↓"; color: var(--ink); }
tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: var(--surface-2); }
td .small { font-size: 12px; color: var(--muted); }
.pager { display: flex; align-items: center; gap: 10px; margin-top: 12px; font-size: 13.5px; color: var(--ink-2); }

/* ---------- charts */
.chart { width: 100%; height: auto; display: block; overflow: visible; }
.chart .grid-line { stroke: var(--line); stroke-width: 1; }
.chart .axis-text { fill: var(--muted); font-size: 11px; font-family: var(--font); }
.chart .bar { fill: var(--bar); }
.chart .bar.dim { fill: var(--bar-2); }
.chart .hit { fill: transparent; cursor: default; }
.chart .hit:hover + .bar, .chart g.col:hover .bar { fill: color-mix(in srgb, var(--bar) 80%, var(--ink)); }
.hbars { display: grid; grid-template-columns: auto 1fr; gap: 6px 10px; align-items: center; font-size: 13px; }
.hbars .lab { color: var(--ink-2); font-variant-numeric: tabular-nums; text-align: right; }
.hbars .track { display: flex; align-items: center; gap: 6px; min-width: 0; }
.hbars .fill { height: 14px; background: var(--bar); border-radius: 0 4px 4px 0; min-width: 2px; }
.hbars .val { font-variant-numeric: tabular-nums; color: var(--ink); font-weight: 600; font-size: 12.5px; }
.tip { position: fixed; z-index: 50; pointer-events: none; background: var(--ink); color: var(--bg); font-size: 12.5px; padding: 6px 9px; border-radius: 6px;
  box-shadow: var(--shadow); white-space: nowrap; transform: translate(-50%, calc(-100% - 10px)); }

/* ---------- asset grid */
.sprites { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.sprite { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; cursor: pointer; text-align: left; padding: 0; font: inherit; color: inherit; display: flex; flex-direction: column; }
.sprite:hover { border-color: var(--muted); }
.sprite.missing { border-color: var(--bad); }
.thumb { aspect-ratio: 1 / 1; display: grid; place-items: center; padding: 8px;
  background-color: var(--surface-2);
  background-image: linear-gradient(45deg, var(--line) 25%, transparent 25%), linear-gradient(-45deg, var(--line) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, var(--line) 75%), linear-gradient(-45deg, transparent 75%, var(--line) 75%);
  background-size: 16px 16px; background-position: 0 0, 0 8px, 8px -8px, -8px 0; }
.thumb img { max-width: 100%; max-height: 100%; object-fit: contain; image-rendering: auto; }
.thumb .gone { color: var(--bad); font-weight: 700; font-size: 13px; }
.sprite .meta { padding: 7px 9px 9px; font-size: 12px; line-height: 1.35; border-top: 1px solid var(--line); }
.sprite .meta b { display: block; font-size: 12.5px; font-family: var(--mono); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sprite .meta span { color: var(--muted); }
dialog { border: 1px solid var(--line); border-radius: 14px; background: var(--surface); color: var(--ink); padding: 0; max-width: min(960px, 96vw); width: 100%; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(20, 15, 8, .5); }
.dlg-head { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.dlg-head h2 { margin: 0; font-family: var(--mono); font-size: 15px; }
.dlg-head .sp { flex: 1; }
.dlg-body { padding: 16px; display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 260px), 1fr)); }
.dlg-body .thumb { aspect-ratio: auto; min-height: 220px; border-radius: 8px; }
.dlg-body figure { margin: 0; }
.dlg-body figcaption { font-size: 12.5px; color: var(--ink-2); margin-top: 6px; }
.games { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.game { display: grid; grid-template-columns: 64px 1fr; gap: 12px; align-items: center; }
.game .thumb { width: 64px; height: 64px; border-radius: 8px; padding: 4px; aspect-ratio: auto; }
audio { width: 220px; max-width: 100%; height: 32px; }
@media (max-width: 760px) {
  .sprites { grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 8px; }
  .tile .value { font-size: 22px; }
  audio { width: 160px; }
}

/* ---------- round W2: session end, the errors row, phone cards for long tables */
.who .until { font-variant-numeric: tabular-nums; padding: 3px 8px; border-radius: 99px; background: var(--surface); border: 1px solid var(--line); color: var(--ink-2); }
.grid.errs { grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); }
@media (max-width: 1000px) { .grid.errs { grid-template-columns: minmax(0, 1fr); } }
td.main { min-width: 180px; }
.card .controls { margin: 4px 0 10px; }
@media (max-width: 640px) {
  .tablewrap.stack { border: 0; background: none; overflow: visible; }
  .tablewrap.stack table, .tablewrap.stack tbody { display: block; }
  .tablewrap.stack thead { display: none; }
  .tablewrap.stack tr { display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; padding: 10px 12px; margin: 0 0 8px;
    background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
  .tablewrap.stack td { display: contents; border: 0; padding: 0; }
  .tablewrap.stack td::before { content: attr(data-label); color: var(--muted); font-size: 12px; align-self: baseline; }
  .tablewrap.stack td.num { text-align: left; }
  .tablewrap.stack td.main { display: block; grid-column: 1 / -1; font-weight: 650; font-size: 14.5px; margin-bottom: 2px; }
  .tablewrap.stack td.main::before { content: none; }
  .tablewrap.stack td.opt { display: none; }
  .tablewrap.stack tbody tr:hover td { background: none; }
  .who .until { display: none; }
}
/* a tall sprite (a tree, a fence) must not stretch its row: the picture fits inside the square, whatever its own size */
.sprite .thumb { position: relative; padding: 0; width: 100%; height: auto; flex: 0 0 auto; }
.sprite .thumb img { position: absolute; inset: 8px; width: calc(100% - 16px); height: calc(100% - 16px); max-width: none; max-height: none; object-fit: contain; }
.sprites { align-items: start; }
.badge.me { margin-left: 6px; vertical-align: 1px; }
.subtabs.section { margin-top: 18px; }
