/* Tjuvlyssnaren – gemensam stil */
:root {
  --bg: #0d1320;
  --bg2: #151d2f;
  --bg3: #1d2740;
  --line: #2a3654;
  --text: #eef2f8;
  --muted: #98a4ba;
  --accent: #f4b740;
  --accent-ink: #1c1405;
  --ja: #2fbf71;
  --nej: #ef5b5b;
  --vet: #7f8ba1;
  --info: #6ea8ff;
  --radius: 14px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}
a { color: var(--accent); }
h1, h2, h3 { margin: 0 0 .4em; line-height: 1.2; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 .6em; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.center { text-align: center; }
.hidden { display: none !important; }

.wrap { max-width: 560px; margin: 0 auto; padding: 12px 16px 48px; }

/* Sidhuvud */
.top {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 0 12px;
}
.logo { font-weight: 800; letter-spacing: .01em; font-size: 1.05rem; display: flex; align-items: center; gap: 6px; }
.logo .ear { font-size: 1.2em; }
.top .grow { flex: 1; min-width: 0; }
.top .sub { color: var(--muted); font-size: .85rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conn { width: 9px; height: 9px; border-radius: 50%; background: var(--ja); flex: none; }
.conn.bad { background: var(--nej); }

/* Kort */
.card {
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin: 0 0 12px;
}
.card.flat { background: transparent; }
.card-head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.card-head h2 { margin: 0; flex: 1; }

/* Knappar */
.btn {
  appearance: none; border: 1px solid var(--line); background: var(--bg3); color: var(--text);
  font: inherit; font-weight: 600; border-radius: 12px; padding: 12px 16px; min-height: 48px;
  cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  text-decoration: none; text-align: center; touch-action: manipulation;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: default; transform: none; }
.btn.block { display: flex; width: 100%; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: transparent; }
.btn.small { min-height: 36px; padding: 6px 12px; font-size: .9rem; border-radius: 10px; }
.btn.danger { color: var(--nej); }
.btn.ja { background: var(--ja); border-color: var(--ja); color: #06200f; }
.btn.nej { background: var(--nej); border-color: var(--nej); color: #2a0606; }
.btn.vet { background: var(--vet); border-color: var(--vet); color: #0d1320; }
.btn.sel { outline: 3px solid var(--accent); outline-offset: 2px; }
.stack > * + * { margin-top: 10px; }
.row { display: flex; gap: 10px; align-items: center; }
.row > .grow { flex: 1; }
.answers { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; margin-top: 14px; }
.answers .btn { min-height: 64px; font-size: 1.15rem; }

/* Formulär */
label { display: block; font-weight: 600; margin: 0 0 6px; }
input[type=text], input[type=search] {
  width: 100%; font: inherit; color: var(--text); background: var(--bg);
  border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; min-height: 48px;
}
input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.field { margin-bottom: 12px; }
.err { color: var(--nej); font-weight: 600; margin-top: 8px; min-height: 1.2em; }

/* Flikar */
.tabs { display: flex; gap: 6px; background: var(--bg2); border: 1px solid var(--line); border-radius: 12px; padding: 4px; margin-bottom: 14px; }
.tabs button {
  flex: 1; appearance: none; border: 0; background: transparent; color: var(--muted);
  font: inherit; font-weight: 700; padding: 10px; border-radius: 9px; cursor: pointer;
}
.tabs button.on { background: var(--bg3); color: var(--text); }

/* Rollkortet */
.role {
  background: linear-gradient(160deg, #1f2a46, #151d2f);
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; margin-bottom: 12px; cursor: pointer; user-select: none;
}
.role .label { color: var(--muted); font-size: .85rem; display: flex; justify-content: space-between; gap: 8px; }
.role .big { font-size: 1.9rem; font-weight: 800; letter-spacing: .01em; margin-top: 2px; }
.role .big.tl { color: var(--accent); }
.role.veiled .big, .role.veiled .veil-txt { filter: blur(14px); }
.role .veil-txt { margin-top: 4px; }

/* Fråga */
.qbig { font-size: 1.5rem; font-weight: 800; line-height: 1.25; margin: 4px 0 2px; }
.kicker { color: var(--muted); font-size: .85rem; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; }
.clock {
  white-space: nowrap; flex: none;
  margin-left: auto; font-variant-numeric: tabular-nums; font-weight: 700; color: var(--muted);
  background: var(--bg); border: 1px solid var(--line); border-radius: 999px; padding: 2px 10px; font-size: .9rem;
}
.clock.low { color: var(--nej); border-color: var(--nej); }
.offer .btn { justify-content: flex-start; text-align: left; font-size: 1.05rem; min-height: 56px; }

/* Namnchips */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 4px; padding: 4px 10px; border-radius: 999px;
  background: var(--bg3); border: 1px solid var(--line); font-size: .9rem; font-weight: 600;
}
.chip.done { border-color: var(--ja); }
.chip.me { outline: 2px solid var(--accent); outline-offset: 1px; }
.chip.dim { opacity: .5; }

/* Historik */
.hist .q { border-top: 1px solid var(--line); padding: 10px 0; }
.hist .q:first-child { border-top: 0; padding-top: 0; }
.hist .qt { font-weight: 700; }
.hist .by { color: var(--muted); font-size: .8rem; font-weight: 500; }
.ansrow { display: flex; gap: 8px; align-items: baseline; margin-top: 4px; font-size: .92rem; }
.ansrow .tag { flex: none; width: 52px; font-weight: 800; font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; }
.tag.ja { color: var(--ja); } .tag.nej { color: var(--nej); } .tag.vet { color: var(--vet); }
.mine { text-decoration: underline; text-decoration-color: var(--accent); text-underline-offset: 3px; text-decoration-thickness: 2px; }
.marker {
  margin: 8px 0; padding: 8px 12px; border-radius: 10px; background: var(--bg); border: 1px dashed var(--line);
  color: var(--muted); font-size: .9rem; font-weight: 600;
}

/* Spelarlista */
.plist { list-style: none; margin: 0; padding: 0; }
.plist li { display: flex; align-items: center; gap: 8px; padding: 8px 0; border-top: 1px solid var(--line); }
.plist li:first-child { border-top: 0; }
.plist .nm { flex: 1; min-width: 0; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.plist .pts { font-variant-numeric: tabular-nums; font-weight: 800; min-width: 2.5ch; text-align: right; }
.badge { font-size: .72rem; font-weight: 700; color: var(--muted); border: 1px solid var(--line); border-radius: 999px; padding: 1px 7px; }
.badge.host { color: var(--accent); border-color: var(--accent); }
.badge.ok { color: var(--ja); border-color: var(--ja); }
.x { appearance: none; border: 0; background: transparent; color: var(--muted); font-size: 1.2rem; cursor: pointer; padding: 4px 8px; }

/* Inställningar */
.set { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-top: 1px solid var(--line); }
.set:first-of-type { border-top: 0; }
.set .lbl { flex: 1; }
.set .lbl small { display: block; color: var(--muted); }
.stepper { display: inline-flex; align-items: center; gap: 4px; }
.stepper .btn { min-height: 40px; width: 40px; padding: 0; font-size: 1.2rem; }
.stepper .n { min-width: 2ch; text-align: center; font-weight: 800; font-size: 1.1rem; font-variant-numeric: tabular-nums; }
.catpick { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 4px 0 10px; }
.catpick .btn { min-height: 44px; }
.catpick .btn.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }

/* Gissa ordet / rösta */
.wordlist { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 6px; margin-top: 10px; max-height: 46vh; overflow: auto; }
.wordlist .btn { min-height: 42px; font-weight: 600; padding: 6px 8px; }
.wordlist.static { max-height: none; }
.wordlist.static span { background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 6px 8px; text-align: center; font-size: .92rem; }
.votelist { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 12px; }
.votelist .btn { min-height: 52px; }

/* Resultat */
.result-head { font-size: 1.5rem; font-weight: 800; margin-bottom: 6px; }
.result-head.tl { color: var(--accent); }
.result-head.inv { color: var(--ja); }
table.votes { width: 100%; border-collapse: collapse; font-size: .9rem; margin-top: 8px; }
table.votes th, table.votes td { padding: 6px 4px; border-top: 1px solid var(--line); text-align: left; }
table.votes th { color: var(--muted); font-weight: 600; font-size: .8rem; }
table.votes td.ok { color: var(--ja); font-weight: 600; }
table.votes td.bad { color: var(--nej); font-weight: 600; }
.plus { color: var(--ja); font-weight: 800; }

/* QR */
.qr { background: #fff; border-radius: 12px; padding: 10px; display: inline-block; line-height: 0; }
.qr svg { width: 100%; height: auto; display: block; }
.joinurl { font-weight: 700; word-break: break-all; }

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: 18px; transform: translateX(-50%) translateY(20px);
  background: #f6f7fb; color: #0d1320; font-weight: 600; padding: 12px 16px; border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0,0,0,.4); max-width: calc(100% - 32px); width: max-content;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 50; text-align: center;
}
.toast.on { opacity: 1; transform: translateX(-50%) translateY(0); }

/* Regler som ruta ovanpå */
.overlay {
  position: fixed; inset: 0; background: rgba(5,8,15,.75); z-index: 40; overflow: auto;
  -webkit-overflow-scrolling: touch; padding: 16px;
}
.overlay .sheet { max-width: 640px; margin: 0 auto; background: var(--bg2); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 18px 22px; }
.overlay .close { position: sticky; top: 0; float: right; }

/* Regeltext */
.rules h2 { font-size: 1.3rem; }
.rules h3 { margin-top: 1.1em; color: var(--accent); }
.rules ol, .rules ul { padding-left: 1.3em; margin: .3em 0 .8em; }
.rules li { margin: .3em 0; }
.rules .lead { font-size: 1.05rem; }
.rules .box { background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; margin: 10px 0; }

/* ---------------- Storskärmen ---------------- */
body.tv { font-size: clamp(16px, 1.25vw, 26px); }
.screen { display: grid; grid-template-columns: minmax(240px, 22%) 1fr; min-height: 100vh; }
.screen .side { background: var(--bg2); border-right: 1px solid var(--line); padding: 1.4em 1.2em; display: flex; flex-direction: column; gap: 1em; }
.screen .side .logo { font-size: 1.4em; }
.screen .side .gname { font-size: 1.1em; font-weight: 700; color: var(--muted); margin-top: .2em; }
.screen .side .qr { width: 100%; max-width: 260px; }
.screen .stage { padding: 1.4em 1.8em; min-width: 0; }
.screen .plist li { padding: .45em 0; }
.screen .plist .pts { font-size: 1.1em; }
.stage-head { display: flex; align-items: center; gap: .8em; color: var(--muted); font-weight: 700; margin-bottom: .8em; }
.stage-head .clock { font-size: 1.2em; }
.stage-panel { background: var(--bg2); border: 1px solid var(--line); border-radius: 18px; padding: 1.2em 1.4em; margin-bottom: 1.2em; }
.stage-q { font-size: 2.4em; font-weight: 800; line-height: 1.15; margin: .1em 0 .3em; }
.stage-sub { font-size: 1.2em; color: var(--muted); }
.lobby-hero { display: grid; grid-template-columns: auto 1fr; gap: 2em; align-items: center; }
.lobby-hero .qr { width: min(34vh, 380px); }
.lobby-hero h1 { font-size: 2.4em; }
.lobby-hero .joinurl { font-size: 1.4em; }
table.grid { border-collapse: separate; border-spacing: 4px; font-size: 1em; }
table.grid th { color: var(--muted); font-weight: 700; padding: .2em .4em; text-align: center; white-space: nowrap; }
table.grid th.who { text-align: left; }
table.grid td { text-align: center; border-radius: 8px; padding: .35em .5em; min-width: 3.2em; font-weight: 800; }
table.grid td.who { text-align: left; background: transparent; font-weight: 700; padding-right: 1em; white-space: nowrap; }
table.grid td.ja { background: var(--ja); color: #06200f; }
table.grid td.nej { background: var(--nej); color: #2a0606; }
table.grid td.vet { background: var(--vet); color: #0d1320; }
table.grid td.none { background: var(--bg3); color: var(--muted); }
table.grid td.wait { background: var(--bg3); color: var(--ja); }
table.grid td.empty { background: var(--bg2); }
table.grid .after-vote { box-shadow: 4px 0 0 var(--accent); }
table.grid tr.tl td.who { color: var(--accent); }
.legend { columns: 2; column-gap: 2em; margin-top: 1em; color: var(--muted); }
.legend div { break-inside: avoid; margin: .15em 0; }
.legend b { color: var(--text); }
.screen .result-head { font-size: 2.4em; }
@media (max-width: 800px) {
  .screen { grid-template-columns: 1fr; }
  .screen .side { border-right: 0; border-bottom: 1px solid var(--line); }
  .lobby-hero { grid-template-columns: 1fr; }
  .legend { columns: 1; }
}
