:root {
  --bg: #0b1020;
  --panel: #121a30;
  --line: #22305a;
  --text: #eef2ff;
  --muted: #93a3c8;
  --kobolt: #3872fa;       /* danaids varumärkesfärg */
  --accent: #3872fa;
  --accent-text: #7ca4ff;  /* kobolt som text på mörk botten */
  --gold: #ffd166;
  color-scheme: dark;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(1200px 600px at 10% -10%, #1d3f99 0%, transparent 60%),
    radial-gradient(900px 500px at 110% 10%, #1a2f7a 0%, transparent 55%),
    radial-gradient(800px 500px at 50% 120%, #10245e 0%, transparent 60%),
    var(--bg);
  background-attachment: fixed;
  color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.top {
  padding: 28px 20px 8px; max-width: 1100px; margin: 0 auto;
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 14px 20px;
}
.top h1 { margin: 0; font-size: clamp(1.8rem, 6vw, 2.8rem); letter-spacing: -.02em; display: flex; align-items: center; gap: .3em; }
.logo { color: var(--kobolt); width: .82em; height: .88em; flex: none; }
.tag { margin: 4px 0 0; color: var(--muted); display: flex; align-items: center; gap: .45em; white-space: nowrap; }
.danaid { display: inline-flex; border-radius: 4px; }
.danaid img { height: 1.05em; width: auto; display: block; }
.danaid:hover img, .danaid:focus-visible img { filter: brightness(1.25); }

.btn.installera {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--kobolt); color: #fff;
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--kobolt) 22%, transparent);
}
.btn.installera svg { width: 20px; height: 20px; }
.btn.installera:hover { background: #4b81ff; }
@media (display-mode: standalone) { .btn.installera { display: none; } }
@media (max-width: 520px) {
  .top { flex-wrap: nowrap; align-items: flex-start; }
  .btn.installera { padding: 10px 14px; margin-top: 4px; }
  .btn.installera .lang { display: none; }
}

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

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

.status { color: var(--muted); grid-column: 1 / -1; }

.card {
  display: flex; flex-direction: column;
  background: var(--panel);
  border: 2px solid var(--line);
  border-radius: 18px;
  overflow: hidden;
  transition: transform .15s ease, border-color .15s ease;
}
.card:hover, .card:focus-within { transform: translateY(-3px); border-color: var(--accent); }

.card > a { text-decoration: none; }

.cover {
  display: block; aspect-ratio: 16 / 9; width: 100%;
  object-fit: cover; background: var(--line);
}
.cover.placeholder {
  display: flex; align-items: center; justify-content: center;
  font-size: 3rem; font-weight: 800; color: rgba(255,255,255,.85);
}

.body { padding: 14px 16px 16px; display: flex; flex-direction: column; gap: 8px; flex: 1; }
.body h2 { margin: 0; font-size: 1.25rem; }
.genre { font-size: .8rem; color: var(--muted); text-transform: uppercase; letter-spacing: .07em; }
.desc { margin: 0; color: #c9d4f0; flex: 1; }
.best { font-size: .9rem; color: var(--gold); min-height: 1.2em; }

.actions { display: flex; gap: 8px; margin-top: 4px; }
.btn {
  font: inherit; font-weight: 700; border: 0; cursor: pointer;
  padding: 12px 16px; border-radius: 12px; text-decoration: none; text-align: center;
}
.btn.play { flex: 1; background: var(--accent); color: #fff; }
.btn.play:hover { background: #4b81ff; }
.btn.list { background: #1b2a4d; color: var(--text); }

/* Topplistedialog */
.scores {
  width: min(560px, calc(100vw - 24px));
  background: var(--panel); color: var(--text);
  border: 2px solid var(--line); border-radius: 18px; padding: 20px;
}
.scores::backdrop { background: rgba(3, 6, 15, .7); backdrop-filter: blur(3px); }
.scores h2 { margin: 0 0 12px; padding-right: 40px; }
.close {
  position: absolute; top: 12px; right: 12px; width: 36px; height: 36px;
  border-radius: 50%; border: 0; background: #1b2a4d; color: var(--text); font-size: 1rem; cursor: pointer;
}
.lists { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 480px) { .lists { grid-template-columns: 1fr; } }
.lists h3 { margin: 0 0 6px; font-size: .85rem; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.lists ol { margin: 0; padding: 0; list-style: none; counter-reset: r; }
.lists li { display: flex; gap: 8px; padding: 5px 8px; border-radius: 8px; counter-increment: r; }
.lists li:nth-child(odd) { background: rgba(255,255,255,.04); }
.lists li::before { content: counter(r); width: 1.6em; color: var(--muted); text-align: right; }
.lists li span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lists li b { font-variant-numeric: tabular-nums; }
.empty { color: var(--muted); font-style: italic; padding: 5px 8px; }

/* Spelnyckel */
.knappar { display: flex; gap: 10px; align-items: center; }
.btn.nyckel {
  display: inline-flex; align-items: center; gap: 8px; max-width: 46vw;
  background: #1b2a4d; color: var(--text);
}
.btn.nyckel svg { width: 20px; height: 20px; flex: none; color: var(--accent-text); }
.btn.nyckel span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.btn.nyckel:hover { background: #24365f; }
@media (max-width: 520px) {
  .knappar { flex-direction: column; align-items: stretch; gap: 6px; }
  .btn.nyckel { padding: 10px 14px; max-width: 40vw; }
}

.keydlg { width: min(480px, calc(100vw - 24px)); }
.keydlg p { margin: 0 0 12px; color: #c9d4f0; }
.keydlg .muted { color: var(--muted); font-size: .9rem; }
.keydlg .stack { display: flex; flex-direction: column; gap: 8px; margin-top: 14px; }
.keydlg .row { display: flex; gap: 8px; flex-wrap: wrap; }
.keydlg .row > * { flex: 1; }
.keydlg .btn.primary { background: var(--accent); color: #fff; }
.keydlg .btn.primary:hover { background: #4b81ff; }
.keydlg .btn.secondary { background: #1b2a4d; color: var(--text); }
.keydlg .btn.danger { background: transparent; color: #ffb3a6; border: 2px solid #5a2a35; }
.keydlg .btn:disabled { opacity: .5; cursor: default; }
.keydlg input {
  width: 100%; font: inherit; padding: 12px; border-radius: 10px;
  border: 2px solid var(--line); background: var(--bg); color: inherit;
}
.keydlg input:focus { outline: none; border-color: var(--accent); }
.keydlg .key {
  font: 700 clamp(1.15rem, 5vw, 1.5rem)/1.3 ui-monospace, SFMono-Regular, Menlo, monospace;
  color: var(--accent-text); background: var(--bg); border: 2px dashed var(--line);
  border-radius: 12px; padding: 14px; text-align: center; word-break: break-word; margin: 0 0 12px;
  user-select: all;
}
.keydlg .name { font-size: 1.5rem; font-weight: 800; margin: 0 0 4px; }
.keydlg .warn { background: rgba(255, 209, 102, .1); border-left: 3px solid var(--gold); padding: 8px 10px; border-radius: 6px; color: #f3e2b3; }
.keydlg .msg { min-height: 1.3em; margin: 8px 0 0; color: #ffb3a6; }
.keydlg .msg.ok { color: #8ff0b0; }
.keydlg hr { border: 0; border-top: 1px solid var(--line); margin: 18px 0 14px; }
.keydlg details summary { cursor: pointer; color: var(--muted); }
