/* Atlas: mesa de luz escura (dark-first, com tema claro). O traço sob cada capa é a saúde (seeders). Funciona com toque (celular). */
:root {
  --bg: #0f1216; --panel: #161a20; --raise: #1c2129; --line: #262c35; --fg: #e8eaee; --muted: #8b94a3; --accent: #c8a45a;
  --verde: #2fa760; --amarelo: #dcc23f; --laranja: #e0802b; --vermelho: #c9433b; --sem: #566070;
  --display: "Bricolage Grotesque", "Helvetica Neue", Arial, sans-serif;
  --body: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, Menlo, Consolas, monospace;
  --safe-b: env(safe-area-inset-bottom, 0px); --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) { --bg: #f1f2f5; --panel: #ffffff; --raise: #f6f7f9; --line: #dde0e6; --fg: #171a20; --muted: #5d6677; --accent: #8a5a12;
    --verde: #1f8a4c; --amarelo: #b89a14; --laranja: #c8651a; --vermelho: #b02f28; --sem: #8a93a2; color-scheme: light; }
}
:root[data-theme="light"] { --bg: #f1f2f5; --panel: #ffffff; --raise: #f6f7f9; --line: #dde0e6; --fg: #171a20; --muted: #5d6677; --accent: #8a5a12;
  --verde: #1f8a4c; --amarelo: #b89a14; --laranja: #c8651a; --vermelho: #b02f28; --sem: #8a93a2; color-scheme: light; }

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body { height: 100dvh; background: var(--bg); color: var(--fg); font: 14px/1.45 var(--body); display: flex; flex-direction: column; overflow: hidden; overscroll-behavior: none; }
button, input, select { font: inherit; color: inherit; }
button { touch-action: manipulation; }
button:focus-visible, input:focus-visible, select:focus-visible, canvas:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.top { display: flex; align-items: center; gap: 8px 16px; padding: calc(10px + var(--safe-t)) 16px 10px; border-bottom: 1px solid var(--line); background: var(--panel); }
.brand { margin: 0; font: 700 20px var(--display); letter-spacing: -.01em; white-space: nowrap; }
.brand small { font: 400 12px var(--body); color: var(--muted); margin-left: 6px; letter-spacing: .06em; text-transform: uppercase; }
.heart { color: var(--vermelho); }
#q { flex: 1 1 220px; min-width: 0; max-width: 460px; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; }
.count { font: 500 13px var(--mono); font-variant-numeric: tabular-nums; color: var(--muted); white-space: nowrap; order: 3; margin-left: auto; }
.count b { color: var(--fg); font-weight: 500; }
.ghost { background: transparent; border: 1px solid var(--line); border-radius: 8px; padding: 7px 12px; cursor: pointer; }
.ghost:hover { background: var(--raise); }
.only-narrow { display: none; order: 4; }

.active { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.activesec { background: var(--raise); }
.chip { display: inline-flex; align-items: center; gap: 4px; background: var(--raise); border: 1px solid var(--line); border-radius: 999px; padding: 2px 4px 2px 10px; font-size: 12px; }
.chip button { background: transparent; border: 0; cursor: pointer; color: var(--muted); padding: 0 8px; font-size: 16px; line-height: 1.2; }
.chip button:hover { color: var(--fg); }

/* três colunas: à esquerda o filme selecionado (espaço fixo) + filtros compactos; no meio a parede; à direita as facetas em lista */
.layout { flex: 1; min-height: 0; display: grid; grid-template-columns: clamp(270px, 24vw, 340px) minmax(0, 1fr) clamp(260px, 22vw, 320px); position: relative; }
.layout > .side { grid-column: 1; }
.layout > .grid { grid-column: 2; }
.layout > .panel { grid-column: 3; }
.side { display: flex; flex-direction: column; min-height: 0; background: var(--panel); border-right: 1px solid var(--line); }
.side > .detail { position: relative; flex: 0 1 auto; max-height: 64%; border-bottom: 1px solid var(--line); }
.side-filters { flex: 1 1 0; min-height: 0; overflow-y: auto; overscroll-behavior: contain; }
.pick-hint { margin: 0; padding: 14px; border-bottom: 1px solid var(--line); color: var(--muted); font-size: 12.5px; text-align: center; }
body.has-detail .pick-hint { display: none; }
.grid { position: relative; min-width: 0; min-height: 0; overflow: hidden; }
#cv { position: absolute; inset: 0; width: 100%; height: 100%; display: block; cursor: grab; touch-action: none; user-select: none; -webkit-user-select: none; outline-offset: -2px; }
.tip { position: absolute; z-index: 5; pointer-events: none; background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 7px 10px; max-width: 280px; box-shadow: 0 8px 24px rgba(0,0,0,.35); font-size: 12px; }
.tip b { display: block; font: 700 14px var(--display); margin-bottom: 2px; }
.tip .m { color: var(--muted); font-family: var(--mono); font-size: 11px; font-variant-numeric: tabular-nums; }
.empty, .loading { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; color: var(--muted); gap: 12px; pointer-events: none; padding: 16px; }
.empty button { pointer-events: auto; justify-self: center; }

.hud { position: absolute; left: 12px; bottom: calc(12px + var(--safe-b)); display: flex; align-items: center; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 6px 20px rgba(0,0,0,.35); overflow: hidden; }
.hud button { width: 40px; height: 40px; background: transparent; border: 0; cursor: pointer; font-size: 20px; line-height: 1; }
.hud button:hover { background: var(--raise); }
.hud button + button, .hud .zoomlab + button { border-left: 1px solid var(--line); }
.zoomlab { min-width: 44px; text-align: center; font: 500 12px var(--mono); color: var(--muted); font-variant-numeric: tabular-nums; }

.minimap { position: absolute; right: 12px; bottom: calc(12px + var(--safe-b)); background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 3px; box-shadow: 0 6px 20px rgba(0,0,0,.35); touch-action: none; cursor: crosshair; }
.minimap canvas { display: block; border-radius: 4px; }
.minimap .vp { position: absolute; left: 3px; top: 3px; border: 2px solid var(--accent); background: rgba(200,164,90,.12); border-radius: 2px; pointer-events: none; box-sizing: border-box; }
.minimap .vp { margin: 3px 0 0 3px; }
.backdrop { display: none; }
.panel { border-left: 1px solid var(--line); background: var(--panel); overflow-y: auto; min-height: 0; overscroll-behavior: contain; }
.sheet-head { display: none; }
.sec { border-bottom: 1px solid var(--line); padding: 12px 14px; }
.sec h2 { display: flex; align-items: baseline; justify-content: space-between; margin: 0 0 8px; font: 700 12px var(--display); letter-spacing: .07em; text-transform: uppercase; color: var(--muted); }
.sec h2 .mode { font: 400 11px var(--body); text-transform: none; letter-spacing: 0; }
.sec h2 .mode button { background: transparent; border: 0; color: var(--muted); cursor: pointer; padding: 4px 4px; text-decoration: underline dotted; }
.sec input[type="search"], .sec input[type="number"] { width: 100%; background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; margin-bottom: 6px; }
.viewrow { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.viewrow label { display: grid; gap: 4px; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; min-width: 0; }
.viewrow select { width: 100%; background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 7px 8px; text-transform: none; letter-spacing: 0; font-size: 13px; }
.opts { list-style: none; margin: 0; padding: 0; display: grid; gap: 1px; max-height: 260px; overflow-y: auto; }
.opt { display: grid; grid-template-columns: 14px minmax(0, 1fr) auto; gap: 8px; align-items: center; width: 100%; text-align: left; background: transparent; border: 0; border-radius: 4px; padding: 5px 6px; cursor: pointer; }
.opt:hover { background: var(--raise); }
.opt .box { width: 13px; height: 13px; border: 1px solid var(--muted); border-radius: 3px; }
.opt[aria-pressed="true"] .box { background: var(--accent); border-color: var(--accent); }
.opt .n { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.opt .c { font: 400 11px var(--mono); color: var(--muted); font-variant-numeric: tabular-nums; }
.opt.zero { opacity: .4; }

/* seeders: as cinco cores numa única linha */
.seedrow { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 4px; }
.seedbtn { display: grid; justify-items: center; align-content: center; gap: 2px; background: var(--raise); border: 1px solid var(--line); border-radius: 8px; padding: 7px 2px 6px; cursor: pointer; min-width: 0; }
.seedbtn i { width: 10px; height: 10px; border-radius: 50%; display: block; }
.seedbtn span { font-size: 11px; line-height: 1.1; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.seedbtn small { color: var(--muted); font: 400 10.5px var(--mono); font-variant-numeric: tabular-nums; }
.seedbtn[aria-pressed="true"] { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.seedbtn:hover { background: var(--panel); }

.legend { margin: 8px 0 0; font-size: 11.5px; line-height: 1.45; color: var(--muted); }
.detail .nolink { margin: 0; font-size: 12.5px; color: var(--muted); background: var(--raise); border: 1px dashed var(--line); border-radius: 8px; padding: 8px 10px; }
.detail .links .torrentfile { text-align: center; }
.hist { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; align-items: end; gap: 3px; height: 54px; margin: 4px 0 6px; }
.hist button { display: block; width: 100%; background: var(--line); border: 0; border-radius: 2px 2px 0 0; cursor: pointer; padding: 0; min-height: 4px; }
.hist button[aria-pressed="true"] { background: var(--accent); }
.hist button:hover { filter: brightness(1.3); }
.histlab { display: flex; justify-content: space-between; font: 400 10px var(--mono); color: var(--muted); }
.yearrow { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 8px; }

/* cartão de detalhes: o aside não rola (o × fica sempre visível); o conteúdo rola em .dbody */
.detail { display: flex; flex-direction: column; overflow: hidden; background: var(--panel); }
.detail .dbody { min-height: 0; overflow-y: auto; overscroll-behavior: contain; scroll-behavior: smooth; -webkit-overflow-scrolling: touch;
  scrollbar-width: thin; scrollbar-color: var(--line) transparent; padding: 16px 16px 18px; display: grid; gap: 14px; align-content: start; }
.detail .x { position: absolute; top: 8px; right: 8px; z-index: 2; width: 40px; height: 40px; display: grid; place-items: center; padding: 0;
  background: var(--raise); border: 1px solid var(--line); border-radius: 50%; color: var(--muted); font-size: 22px; line-height: 1; cursor: pointer;
  box-shadow: 0 2px 8px rgba(0,0,0,.25); transition: color .15s, border-color .15s; }
.detail .x:hover { color: var(--fg); border-color: var(--muted); }
.detail .x:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; color: var(--fg); }
.detail .head { display: grid; gap: 8px; justify-items: center; text-align: center; }
.detail .cover { display: block; width: 200px; height: 300px; max-width: 100%; object-fit: cover; background: var(--bg); border-radius: 6px; box-shadow: 0 6px 20px rgba(0,0,0,.4); margin-bottom: 4px; }
.detail .titles { min-width: 0; max-width: 100%; display: grid; gap: 2px; }
.detail .head:not(:has(.cover)) .titles { padding: 0 40px; }   /* sem capa: o título não passa por baixo do × */
.detail h3 { font: 700 22px/1.12 var(--display); margin: 0; letter-spacing: -.015em; overflow-wrap: anywhere; text-wrap: balance; }
.detail .orig { color: var(--muted); margin: 0; font-size: 13px; font-style: italic; overflow-wrap: anywhere; text-wrap: balance; }
.detail .facts { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 6px; font: 400 12px var(--mono); font-variant-numeric: tabular-nums; color: var(--muted); }
.detail .facts > span { background: var(--raise); border: 1px solid var(--line); border-radius: 999px; padding: 3px 10px; }
.detail .facts .year { color: var(--fg); font-weight: 600; }
.detail .facts b { color: var(--fg); font-weight: 600; }
.detail dl { display: grid; grid-template-columns: 92px minmax(0, 1fr); gap: 8px 10px; margin: 0; font-size: 13px; align-items: baseline; padding-top: 12px; border-top: 1px solid var(--line); }
.detail dt { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .06em; }
.detail dd { margin: 0; display: flex; flex-wrap: wrap; gap: 4px; min-width: 0; }
.detail .tag { background: var(--bg); border: 1px solid var(--line); border-radius: 999px; padding: 1px 9px; cursor: pointer; font-size: 12px; max-width: 100%; overflow-wrap: anywhere; text-align: left; }
.detail .tag:hover { border-color: var(--accent); }
.detail .links { display: flex; flex-wrap: wrap; gap: 8px; }
.detail .links a { flex: 1 1 auto; white-space: nowrap; display: flex; align-items: center; justify-content: center; gap: 6px; min-height: 40px; background: var(--raise); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; color: var(--fg); text-decoration: none; font-weight: 500; text-align: center; transition: border-color .15s, filter .15s; }
.detail .links a:hover { border-color: var(--accent); }
.detail .links a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.detail .links .magnet { flex-basis: 100%; background: var(--accent); border-color: var(--accent); color: var(--bg); font-weight: 600; min-height: 44px; }
.detail .links .magnet:hover { filter: brightness(1.08); }
.detail .att h4 { margin: 0 0 6px; font: 700 11px var(--display); letter-spacing: .07em; text-transform: uppercase; color: var(--muted); }
.health { display: inline-flex; align-items: center; gap: 6px; }
.health i { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.files { margin: 0; padding: 0; list-style: none; font-size: 12px; display: grid; gap: 1px; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.files li { display: grid; gap: 1px; padding: 7px 10px; background: var(--raise); }
.files a { color: var(--accent); overflow-wrap: anywhere; text-decoration: none; }
.files a:hover { text-decoration: underline; }
.files .k { font: 400 10.5px var(--mono); color: var(--muted); font-variant-numeric: tabular-nums; }

/* desktop: capa ao lado do título, para o cartão caber no espaço fixo da coluna */
@media (min-width: 861px) {
  .detail .head:has(.cover) { grid-template-columns: minmax(84px, 36%) minmax(0, 1fr); align-items: start; justify-items: start; text-align: left; column-gap: 12px; }
  .detail .head:has(.cover) .cover { grid-row: span 2; width: 100%; height: auto; aspect-ratio: 2 / 3; margin: 0; }
  .detail .head:has(.cover) h3 { overflow-wrap: break-word; }
  .detail .head:has(.cover) .titles { padding-right: 36px; }
  .detail .head:has(.cover) .facts { justify-content: flex-start; align-self: start; }
  .detail h3 { font-size: 19px; }
}

/* ---------- celular / tela estreita ---------- */
@media (max-width: 860px) {
  .top { flex-wrap: wrap; gap: 8px 10px; padding: calc(8px + var(--safe-t)) 12px 8px; }
  .brand { font-size: 17px; flex: 1 1 auto; }
  .brand small { display: none; }
  .count { order: 2; margin-left: 0; font-size: 12px; }
  #q { order: 5; flex: 1 1 100%; max-width: none; font-size: 16px; padding: 10px 12px; }   /* 16px: o iOS não dá zoom ao focar */
  .only-narrow { display: inline-block; order: 3; padding: 8px 14px; }
  .hide-narrow { display: none; }
  .layout { grid-template-columns: minmax(0, 1fr); }
  .layout > .grid, .layout > .panel { grid-column: auto; }
  .side { display: contents; }
  .pick-hint { display: none; }
  .side > .detail { position: fixed; top: auto; width: auto; left: 0; right: 0; bottom: 0; z-index: 18; max-height: 58dvh; border: 1px solid var(--line); border-bottom: 0; border-radius: 16px 16px 0 0; box-shadow: 0 -12px 40px rgba(0,0,0,.45); }
  .detail .dbody { padding: 14px 14px calc(16px + var(--safe-b)); gap: 12px; }
  .detail .cover { width: 120px; height: 180px; }              /* cabe na gaveta (meia tela) */
  .detail h3 { font-size: 20px; }
  .detail .links a { min-height: 44px; }
  body.has-detail .hud, body.has-detail .minimap { display: none; }

  .backdrop { display: block; position: fixed; inset: 0; z-index: 19; background: rgba(0,0,0,.5); opacity: 0; pointer-events: none; transition: opacity .2s; }
  body.show-filters .backdrop { opacity: 1; pointer-events: auto; }
  .panel { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; max-height: 82dvh; height: 82dvh; border: 1px solid var(--line); border-bottom: 0; border-radius: 16px 16px 0 0;
    transform: translateY(105%); transition: transform .24s ease; box-shadow: 0 -12px 40px rgba(0,0,0,.45); padding-bottom: var(--safe-b); }
  body.show-filters .panel { transform: none; }
  .sheet-head { display: flex; align-items: center; justify-content: space-between; position: sticky; top: 0; z-index: 2; background: var(--panel); padding: 8px 12px 6px; border-bottom: 1px solid var(--line); }
  .grab { width: 40px; height: 4px; border-radius: 4px; background: var(--line); position: absolute; left: 50%; top: 5px; transform: translateX(-50%); }
  .sheet-head .ghost { margin-left: auto; padding: 8px 14px; }
  .sec { padding: 12px; }
  .sec input[type="search"], .sec input[type="number"], .viewrow select { font-size: 16px; padding: 10px; }
  .opt { padding: 10px 6px; }                                   /* alvo de toque confortável */
  .opts { max-height: 240px; }
  .hist { height: 64px; }
  .hud { left: 10px; bottom: calc(10px + var(--safe-b)); }
  .hud button { width: 46px; height: 46px; font-size: 22px; }
  .detail .tag { padding: 4px 11px; }
  .tip { display: none; }
}
/* alvos de toque ≥ 44 px no celular */
@media (max-width: 860px) {
  .only-narrow, .sheet-head .ghost { min-height: 44px; }
  .detail .tag { min-height: 36px; display: inline-flex; align-items: center; }
  .detail .files a { display: inline-block; padding: 8px 0; }
  .chip button { min-width: 40px; min-height: 32px; }
  .opt, .seedbtn { min-height: 44px; }
}
@media (max-width: 380px) { .seedbtn span { font-size: 10px; } .seedbtn small { font-size: 10px; } }
@media (prefers-reduced-motion: reduce) { .panel, .backdrop, .detail .x, .detail .links a { transition: none; } .detail .dbody { scroll-behavior: auto; } }
