:root {
  color-scheme: dark;
  --bg: #0b0d0f; --surface: #131719; --raised: #1a1f22; --border: #272d30; --line: #363e42;
  --ink: #ebeeed; --muted: #969e9e; --subtle: #6f7a7b;
  --accent: #b0f4cf; --accent-ink: #10251b;
  --motile: #7ef0b4; --immotile: #ff9b74; --grid: #ff5ad1; --danger: #ff8a80;
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; font-size: 14px;
  color: var(--ink); background: var(--bg);
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; display: flex; flex-direction: column; background: var(--bg); }
a { color: var(--accent); text-decoration: none; }
button, input, select { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
[hidden] { display: none !important; }

button { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 36px; padding: 8px 14px;
  border: 1px solid var(--line); border-radius: 9px; background: var(--raised); cursor: pointer; font-weight: 550; font-size: 13px; }
button:hover { background: #242b2e; border-color: #4d5856; }
button:disabled { opacity: .4; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 650; min-height: 42px; }
button.primary:hover:not(:disabled) { background: #caffdf; }
button.text { background: none; border-color: transparent; color: var(--muted); padding: 6px 8px; min-height: 0; }
button.text:hover { color: var(--accent); }
button.icon { width: 34px; height: 34px; min-height: 0; padding: 0; font-size: 12px; }
select { background: var(--raised); border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.top { display: flex; align-items: center; justify-content: space-between; padding: 12px 20px; border-bottom: 1px solid var(--border); }
.brand { display: flex; align-items: center; gap: 10px; color: var(--ink); font-weight: 650; }
.brand img { width: 26px; height: 26px; }
.brand em { font-style: normal; font-weight: 450; color: var(--subtle); }

main { flex: 1; min-height: 0; display: flex; }
footer { display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap; padding: 10px 20px; color: var(--subtle); font-size: 11.5px; border-top: 1px solid var(--border); }
footer a { color: var(--muted); }
footer a:hover { color: var(--accent); }

/* Start */
.start { width: 100%; max-width: 860px; margin: 0 auto; padding: 40px 20px 48px; }
.intro { margin: 0 0 16px; color: var(--muted); font-size: 13.5px; line-height: 1.5; }
.drop { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; height: 220px;
  border: 1.5px dashed var(--line); border-radius: 16px; background: var(--surface); cursor: pointer; text-align: center; transition: border-color .15s, background .15s; }
.drop strong { font-size: 17px; font-weight: 600; }
.drop span { color: var(--muted); }
.drop u { color: var(--accent); text-decoration: none; }
.drop:hover, .drop.over { border-color: var(--accent); background: #142019; }
.examples { margin-top: 32px; }
.examples h2, .recent h2 { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--subtle); margin: 0 0 10px; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.card { display: block; padding: 0; min-height: 0; text-align: left; border-radius: 12px; overflow: hidden; background: var(--surface); }
.card img { display: block; width: 100%; aspect-ratio: 16 / 9; object-fit: cover; background: #000; }
.card div { padding: 10px 12px; display: flex; flex-direction: column; gap: 2px; }
.card strong { font-size: 13px; }
.card span { color: var(--muted); font-size: 12px; font-weight: 450; }
.card.loading { opacity: .6; cursor: wait; }
.recent { margin-top: 36px; }
.recent table { width: 100%; border-collapse: collapse; }
.recent td, .recent th { padding: 9px 8px; border-bottom: 1px solid var(--border); text-align: left; font-weight: 450; }
.recent th { color: var(--subtle); font-size: 12px; }
.recent tbody tr { cursor: pointer; }
.recent tbody tr:hover { background: var(--surface); }
.num { text-align: right !important; font-variant-numeric: tabular-nums; }
.recent .del { opacity: 0; }
.recent tr:hover .del { opacity: 1; }

/* Blocking overlay while a video loads and the grid is located */
.overlay { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; background: rgba(5, 7, 8, .72); backdrop-filter: blur(3px); animation: fadein .18s ease-out; }
.overlay-card { display: flex; flex-direction: column; align-items: center; gap: 8px; width: min(360px, calc(100vw - 32px)); padding: 28px 28px 24px; border: 1px solid var(--line); border-radius: 16px; background: var(--surface); box-shadow: 0 20px 60px #000a; text-align: center; }
.overlay-card strong { font-size: 16px; font-weight: 600; margin-top: 6px; }
.overlay-card span { color: var(--muted); font-size: 12.5px; min-height: 1.2em; }
.gridanim { width: 220px; height: auto; }
.gridanim .field { fill: #ff5ad10d; stroke: none; }
.gridanim .lines line { stroke: var(--grid); stroke-width: 1.6; stroke-linecap: round; stroke-dasharray: 1; stroke-dashoffset: 1; animation: drawline 2.6s ease-in-out infinite; }
.gridanim .lines line:nth-child(1) { animation-delay: 0.00s; }
.gridanim .lines line:nth-child(2) { animation-delay: 0.08s; }
.gridanim .lines line:nth-child(3) { animation-delay: 0.16s; }
.gridanim .lines line:nth-child(4) { animation-delay: 0.24s; }
.gridanim .lines line:nth-child(5) { animation-delay: 0.32s; }
.gridanim .lines line:nth-child(6) { animation-delay: 0.40s; }
.gridanim .lines line:nth-child(7) { animation-delay: 0.50s; }
.gridanim .lines line:nth-child(8) { animation-delay: 0.62s; }
.gridanim .lines line:nth-child(9) { animation-delay: 0.74s; }
.gridanim .scan { animation: scan 1.7s linear infinite; }
.gridanim .corner:nth-of-type(2) { animation-delay: .2s; }
.gridanim .corner:nth-of-type(3) { animation-delay: .4s; }
.gridanim .corner { fill: var(--accent); transform-box: fill-box; transform-origin: center; animation: pulse 1.3s ease-in-out infinite; }
@keyframes drawline { 0% { stroke-dashoffset: 1; opacity: 1; } 45% { stroke-dashoffset: 0; } 82% { stroke-dashoffset: 0; opacity: 1; } 100% { stroke-dashoffset: 0; opacity: 0; } }
@keyframes scan { from { transform: translateX(0); } to { transform: translateX(230px); } }
@keyframes pulse { 0%, 100% { transform: scale(.7); opacity: .55; } 50% { transform: scale(1.25); opacity: 1; } }
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }
@media (prefers-reduced-motion: reduce) {
  .gridanim .lines line { animation: none; stroke-dashoffset: 0; }
  .gridanim .scan, .gridanim .corner, .overlay { animation: none; }
}

/* Workspace */
.work { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr) 320px; }
.viewer { min-width: 0; min-height: 0; display: flex; flex-direction: column; border-right: 1px solid var(--border); }
.bar { display: flex; align-items: center; gap: 12px; min-height: 52px; padding: 8px 16px; border-bottom: 1px solid var(--border); font-size: 13px; }
.bar .spacer { flex: 1; }
.bar button, .bar label { white-space: nowrap; flex: none; }
#hint { min-width: 0; }
.inline { display: flex; align-items: center; gap: 8px; color: var(--muted); }
#hint { color: var(--grid); }
#hint.done { color: var(--muted); }
#scrub { width: 220px; accent-color: var(--accent); }
.legend { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12.5px; }
.legend span:not(.muted) { color: var(--ink); font-variant-numeric: tabular-nums; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-left: 8px; }
.dot.m { background: var(--motile); }
.dot.i { border: 2px solid var(--immotile); }
.canvaswrap { position: relative; flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; padding: 16px; background: #070809; }
#view { display: block; max-width: 100%; max-height: 100%; border-radius: 6px; }
#view.picking { cursor: crosshair; }
.loupe { position: absolute; pointer-events: none; width: 160px; height: 160px; border-radius: 50%; border: 2px solid var(--grid); box-shadow: 0 6px 24px #000a; }
.tip { position: absolute; pointer-events: none; padding: 6px 9px; border-radius: 7px; background: #000d; border: 1px solid var(--line); font-size: 12px; white-space: nowrap; }

.panel { display: flex; flex-direction: column; gap: 16px; padding: 20px; overflow-y: auto; background: var(--surface); }
.fname { font-weight: 600; word-break: break-all; }
.file .muted { font-size: 12px; margin-top: 4px; }
.field { display: flex; flex-direction: column; gap: 6px; color: var(--muted); font-size: 12px; }
.field select { color: var(--ink); font-size: 14px; padding: 8px; }
.fieldhead, .reshead { display: flex; align-items: center; gap: 6px; }
.reshead { color: var(--subtle); font-size: 12px; margin-bottom: 4px; }

/* Small "?" explanations */
button.info { width: 18px; height: 18px; min-height: 0; padding: 0; border-radius: 50%; border: 1px solid var(--line); background: transparent; color: var(--muted); font-size: 11px; font-weight: 600; line-height: 1; flex: none; }
button.info:hover, button.info[aria-expanded="true"] { color: var(--accent); border-color: var(--accent); background: transparent; }
.pop { position: fixed; z-index: 40; width: min(320px, calc(100vw - 32px)); padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--raised); box-shadow: 0 12px 40px #000b; font-size: 12.5px; line-height: 1.55; color: var(--ink); }
.pop strong { display: block; margin-bottom: 4px; font-size: 13px; }
.pop p { margin: 0; color: #c9d0ce; white-space: pre-line; }
.prog .track { height: 6px; border-radius: 3px; background: var(--raised); overflow: hidden; }
#progfill { height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.progrow { display: flex; justify-content: space-between; align-items: center; margin-top: 6px; font-size: 12px; }
.error { color: var(--danger); font-size: 13px; line-height: 1.45; }

table.nums { width: 100%; border-collapse: collapse; }
table.nums td { padding: 8px 0; border-bottom: 1px solid var(--border); }
table.nums td:first-child { color: var(--muted); font-size: 12.5px; }
table.nums td.big { font-size: 20px; font-weight: 600; }
.details { color: var(--subtle); font-size: 12px; line-height: 1.55; margin: 0; }
.actions { display: flex; gap: 8px; margin-top: 4px; }
.actions button { flex: 1; }
.new { align-self: flex-start; margin-top: auto; }

.page-licenses { max-width: 820px; margin: 0 auto; padding: 32px 20px; line-height: 1.55; display: block; }

@media (max-width: 900px) {
  /* Narrow screens: one column and the whole page scrolls (no nested scroll areas). */
  html, body { height: auto; }
  main { display: block; }
  .work { display: block; }
  .viewer { border-right: 0; border-bottom: 1px solid var(--border); }
  .canvaswrap { flex: none; aspect-ratio: 16 / 10; max-height: 70vh; padding: 10px; }
  .panel { overflow: visible; }
  .new { margin-top: 8px; }
  #scrub { width: 120px; }
  .bar { flex-wrap: wrap; row-gap: 6px; }
}
