:root {
  color-scheme: light dark;
  --bg: #f4f2f7;
  --surface: #ffffff;
  --surface-2: #ece8f2;
  --text: #1d1a24;
  --muted: #6b6578;
  --border: #ddd7e6;
  --accent: #c2185b;
  --accent-text: #ffffff;
  --radius: 12px;
  --shadow: 0 1px 2px rgb(20 10 40 / 6%), 0 4px 16px rgb(20 10 40 / 6%);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121017;
    --surface: #1c1923;
    --surface-2: #26222f;
    --text: #ece9f2;
    --muted: #9a93a8;
    --border: #2f2a3a;
    --accent: #f06292;
    --accent-text: #1a0b12;
    --shadow: none;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

a { color: inherit; }

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.topbar h1 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 650;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; }
.brand img { width: 28px; height: 28px; }

.back {
  text-decoration: none;
  padding: 6px 10px;
  border-radius: 8px;
  background: var(--surface-2);
  font-size: 0.9rem;
  white-space: nowrap;
}

main { max-width: 1100px; margin: 0 auto; padding: 24px 16px 48px; }

.search {
  width: 100%;
  padding: 10px 14px;
  font: inherit;
  color: inherit;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 24px;
}

.search:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.system { margin-bottom: 32px; }
.system h2 { font-size: 1rem; margin: 0 0 12px; display: flex; gap: 8px; align-items: baseline; }
.system h2 .count { color: var(--muted); font-weight: 400; font-size: 0.9rem; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 12px;
}

.card {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 14px;
  min-height: 96px;
  text-decoration: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  transition: border-color .15s, transform .15s;
}

.card:hover, .card:focus-visible { border-color: var(--accent); transform: translateY(-1px); outline: none; }
.card .title { font-weight: 600; overflow-wrap: anywhere; }
.card .meta { color: var(--muted); font-size: 0.82rem; margin-top: auto; }

.empty {
  padding: 20px;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  color: var(--muted);
}

.empty code, .notice code {
  background: var(--surface-2);
  padding: 1px 6px;
  border-radius: 6px;
  color: var(--text);
  overflow-wrap: anywhere;
}

.notice {
  padding: 14px 16px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
  margin: 24px auto;
  max-width: 640px;
}

/* --- reproductor --- */

body.player { height: 100dvh; display: flex; flex-direction: column; overflow: hidden; }

.stage {
  flex: 1;
  min-height: 0;
  display: flex;
  justify-content: center;
  align-items: stretch;
  padding: 8px;
  background: #000;
}

#game {
  --aspect: 1.3333;                        /* ancho / alto de la consola: lo pone play.js */
  width: 100%;
  max-width: calc((100dvh - 80px) * var(--aspect));
  height: 100%;
}

.hint { color: var(--muted); font-size: 0.85rem; white-space: nowrap; }
.player .topbar h1 { flex: 1; min-width: 0; }
.player .topbar label[hidden] { display: none; }
.player .topbar .slot { flex-direction: row; align-items: center; gap: 6px; font-size: 0.85rem; font-weight: 500; }
.player .topbar select {
  font: inherit; color: inherit; background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 8px; padding: 3px 6px;
}
.cloud[data-kind="ok"]::before { content: "☁ "; }
.cloud[data-kind="error"] { color: #c62828; }
@media (prefers-color-scheme: dark) { .cloud[data-kind="error"] { color: #ef9a9a; } }

@media (max-width: 640px) {
  .hint { display: none; }
  main { padding-top: 16px; }
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .card { padding: 12px; min-height: 88px; }
}

/* --- cuentas: formularios, botones, tablas --- */

.nav { margin-left: auto; display: flex; gap: 8px; align-items: center; }
.nav a { text-decoration: none; padding: 6px 10px; border-radius: 8px; font-size: 0.9rem; }
.nav a:hover, .nav a:focus-visible { background: var(--surface-2); outline: none; }
.nav .who { color: var(--muted); font-size: 0.9rem; }

.auth { max-width: 380px; margin: 8vh auto 48px; padding: 0 16px; }
.auth .brand { justify-content: center; margin-bottom: 20px; }
.auth .brand img { width: 40px; height: 40px; }
.auth h1 { font-size: 1.3rem; margin: 0; }

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}
.panel + .panel { margin-top: 16px; }
.panel h2 { font-size: 1rem; margin: 0 0 12px; }
.panel p { margin: 0 0 12px; }

form.stack { display: flex; flex-direction: column; gap: 12px; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 0.9rem; font-weight: 550; }
label.check { flex-direction: row; align-items: center; gap: 8px; font-weight: 400; }
.hint-text { color: var(--muted); font-size: 0.82rem; font-weight: 400; }

input[type=text], input[type=password] {
  font: inherit;
  color: inherit;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
}
input:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.btn {
  font: inherit;
  font-weight: 600;
  padding: 9px 14px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: var(--accent);
  color: var(--accent-text);
  cursor: pointer;
}
.btn:disabled { opacity: .6; cursor: progress; }
a.btn { text-decoration: none; display: inline-block; }
.btn.secondary { background: var(--surface-2); color: var(--text); border-color: var(--border); }
.btn.small { padding: 5px 10px; font-size: 0.85rem; }
.btn:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; }

.msg { font-size: 0.9rem; margin: 0; }
.msg.error { color: #c62828; }
.msg.ok { color: #2e7d32; }
@media (prefers-color-scheme: dark) {
  .msg.error { color: #ef9a9a; }
  .msg.ok { color: #a5d6a7; }
}

.link-box {
  display: flex; gap: 8px; align-items: center;
  background: var(--surface-2); border-radius: 8px; padding: 8px 10px; margin-top: 8px;
}
.link-box code { flex: 1; overflow-wrap: anywhere; font-size: 0.85rem; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { color: var(--muted); font-weight: 550; font-size: 0.82rem; }
td.actions { text-align: right; }
td.actions .btn + .btn { margin-left: 6px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.tag { font-size: 0.75rem; padding: 1px 7px; border-radius: 999px; background: var(--surface-2); color: var(--muted); margin-left: 6px; }
.tag.accent { background: var(--accent); color: var(--accent-text); }
.page { max-width: 820px; }
.footnote { text-align: center; margin-top: 16px; }

@media (max-width: 640px) {
  .hide-sm { display: none; }
  .nav .who { display: none; }
  td.actions .btn { display: block; width: 100%; margin: 0 0 6px; }
  td.actions .btn + .btn { margin-left: 0; }
  .panel { padding: 16px; }
}

/* --- mis partidas --- */
.game-saves h2 { display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.game-saves h2 .system-name { color: var(--muted); font-weight: 400; font-size: 0.85rem; }
.save-row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; padding: 10px 0; border-top: 1px solid var(--border); }
.save-row:first-of-type { border-top: 0; }
.save-row .what { flex: 1; min-width: 180px; }
.save-row .what strong { display: block; font-weight: 600; }
.save-row .buttons { display: flex; gap: 6px; flex-wrap: wrap; }
.save-row img.preview { width: 96px; height: 72px; object-fit: contain; background: #000; border-radius: 6px; }
.versions { width: 100%; margin: 4px 0 0; padding: 8px 12px; background: var(--surface-2); border-radius: 8px; }
.versions li { display: flex; justify-content: space-between; gap: 8px; align-items: center; padding: 4px 0; flex-wrap: wrap; font-size: 0.85rem; }
.versions ul { list-style: none; margin: 0; padding: 0; }

/* --- portadas --- */
.card.has-cover { padding: 0; overflow: hidden; }
.card.has-cover .title, .card.has-cover .meta { padding: 0 14px; }
.card.has-cover .meta { padding-bottom: 12px; }
.card .cover { width: 100%; aspect-ratio: 1; object-fit: contain; background: var(--surface-2); display: block; margin-bottom: 6px; }

/* --- reproductor: pantallas de la DS y mando --- */
.player .topbar .tool { font-size: 0.85rem; }
.pad { font-size: 0.85rem; color: var(--muted); white-space: nowrap; }
.pad[hidden] { display: none; }

/* --- diálogos --- */
.dialog {
  border: 1px solid var(--border); border-radius: var(--radius); padding: 20px;
  background: var(--surface); color: var(--text); max-width: min(460px, calc(100vw - 32px));
  box-shadow: 0 10px 40px rgb(0 0 0 / 35%);
}
.dialog.wide { max-width: min(640px, calc(100vw - 32px)); }
.dialog::backdrop { background: rgb(10 5 20 / 55%); }
.dialog h2 { margin: 0 0 12px; font-size: 1.1rem; }
.dialog-body p { margin: 0 0 10px; }
.dialog-actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; margin-top: 16px; }

/* --- guía de controles --- */
.controls-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; margin: 4px 0 12px; }
.controls-table th, .controls-table td { padding: 6px 8px; border-bottom: 1px solid var(--border); text-align: left; }
.controls-table th { color: var(--muted); font-weight: 550; font-size: 0.8rem; }
kbd {
  font: 600 0.82rem ui-monospace, SFMono-Regular, Menlo, monospace; padding: 1px 6px; border-radius: 5px;
  background: var(--surface-2); border: 1px solid var(--border); border-bottom-width: 2px; white-space: nowrap;
}
.tips { margin: 0; padding-left: 18px; color: var(--muted); font-size: 0.88rem; }
.tips li { margin: 3px 0; }

/* --- biblioteca: filtros, seguir jugando, favoritos --- */
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin: 0 0 16px; }
.chip {
  font: inherit; font-size: 0.85rem; padding: 5px 12px; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
}
.chip[aria-pressed="true"] { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.chip:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.row-scroll { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(170px, 200px); gap: 12px; overflow-x: auto; padding-bottom: 6px; scroll-snap-type: x mandatory; }
.row-scroll > * { scroll-snap-align: start; }
.card-wrap { position: relative; display: flex; }
.card-wrap .card { flex: 1; }
.star {
  position: absolute; top: 6px; right: 6px; width: 32px; height: 32px; border-radius: 999px; cursor: pointer;
  border: 0; background: rgb(0 0 0 / 0%); color: var(--muted); font-size: 1.15rem; line-height: 1;
}
.star:hover, .star:focus-visible { background: var(--surface-2); outline: none; }
.star[aria-pressed="true"] { color: #f5a623; }
.card-wrap .card .title { padding-right: 28px; }
.card .meta .when { display: block; }

/* --- reproductor: aviso de partida en otro dispositivo --- */
.lost-banner {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 50; max-width: calc(100vw - 32px);
  background: var(--surface); color: var(--text); border: 1px solid var(--accent); border-radius: var(--radius);
  padding: 12px 16px; display: flex; gap: 12px; align-items: center; flex-wrap: wrap; box-shadow: 0 6px 24px rgb(0 0 0 / 35%);
}

/* --- administración: portadas --- */
.buttons-row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-bottom: 8px; }
progress { width: 100%; height: 8px; accent-color: var(--accent); }
.missing-list { margin: 8px 0 0; padding-left: 18px; font-size: 0.85rem; color: var(--muted); max-height: 240px; overflow: auto; }
.card-wrap:has(.has-cover) .star { background: rgb(0 0 0 / 45%); color: #fff; }
.card-wrap:has(.has-cover) .star[aria-pressed="true"] { color: #f5a623; }
.card-wrap:has(.has-cover) .card .title { padding-right: 14px; }
