:root {
  --paper: #f3eee2;
  --card: #fffdf7;
  --ink: #17202c;
  --muted: #5d6673;
  --line: #d9d0bd;
  --blue: #1d4f91;
  --blue-dark: #16335c;
  --blue-soft: #dbe6f5;
  --red: #b8322a;
  --red-soft: #f6dcd8;
  --gold: #f1c84b;
  --green: #2f7a4d;
  --radius: 14px;
  --display: "Avenir Next Condensed", "Roboto Condensed", "Arial Narrow", "Helvetica Neue", system-ui, sans-serif;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--paper); color: var(--ink);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background-image: radial-gradient(rgba(23, 32, 44, .045) 1px, transparent 1px);
  background-size: 6px 6px;
}
h1, h2, h3 { font-family: var(--display); text-transform: uppercase; letter-spacing: .04em; margin: 0; line-height: 1.1; }
h2 { font-size: 1.05rem; color: var(--blue-dark); margin-bottom: 10px; }
p { margin: 0 0 10px; }
a { color: var(--blue); }
button { font: inherit; cursor: pointer; }
.loading { text-align: center; padding: 60px 20px; color: var(--muted); }

/* ---------- topp ---------- */
.top {
  background: var(--blue-dark); color: #fff; display: flex; align-items: center; gap: 12px;
  padding: 10px 16px; padding-top: calc(10px + env(safe-area-inset-top)); border-bottom: 5px solid var(--gold);
}
.brand { font-family: var(--display); font-weight: 800; font-size: 1.35rem; letter-spacing: .09em; text-transform: uppercase; color: #fff; text-decoration: none; }
.brand b { color: var(--gold); }
.top .code { font-family: var(--display); font-weight: 700; letter-spacing: .2em; background: rgba(255, 255, 255, .14); padding: 3px 10px; border-radius: 8px; }
.top .spacer { flex: 1; }
.top button, .top a.link { background: none; border: 1px solid rgba(255, 255, 255, .4); color: #fff; border-radius: 999px; padding: 5px 12px; font-size: .85rem; text-decoration: none; white-space: nowrap; }
.top button:hover, .top a.link:hover { background: rgba(255, 255, 255, .12); }

.wrap { max-width: 560px; margin: 0 auto; padding: 14px 14px 60px; display: grid; gap: 14px; }
.panel { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; box-shadow: 0 1px 0 rgba(23, 32, 44, .05); }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.center { text-align: center; }

/* ---------- knappar ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 46px;
  padding: 10px 18px; border-radius: 12px; border: 2px solid var(--blue-dark); background: var(--blue-dark); color: #fff;
  font-family: var(--display); font-weight: 700; font-size: 1.02rem; letter-spacing: .06em; text-transform: uppercase; text-decoration: none;
}
.btn:hover { filter: brightness(1.12); }
.btn:disabled { opacity: .45; cursor: not-allowed; filter: none; }
.btn.ghost { background: transparent; color: var(--blue-dark); }
.btn.gold { background: var(--gold); border-color: var(--gold); color: var(--ink); }
.btn.red { background: var(--red); border-color: var(--red); }
.btn.sm { min-height: 34px; padding: 4px 12px; font-size: .85rem; border-width: 1.5px; }
.btn.block { width: 100%; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.row > .grow { flex: 1; }
input[type=text], select {
  font: inherit; width: 100%; min-height: 46px; padding: 8px 12px; border-radius: 12px; border: 2px solid var(--line); background: #fff; color: var(--ink);
}
input[type=text]:focus, select:focus, button:focus-visible, a:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
label { display: block; font-weight: 600; font-size: .9rem; margin-bottom: 4px; }
.field { margin-bottom: 12px; }

/* ---------- start ---------- */
.hero { text-align: center; padding: 26px 10px 6px; }
.hero h1 { font-size: clamp(2.6rem, 13vw, 4.4rem); color: var(--blue-dark); letter-spacing: .06em; }
.hero h1 b { color: var(--red); }
.hero .rule { width: 90px; height: 6px; background: var(--gold); margin: 12px auto; border-radius: 3px; }
.hero p { color: var(--muted); max-width: 30em; margin: 0 auto; }
.foot { text-align: center; color: var(--muted); font-size: .78rem; padding: 0 10px; }

/* ---------- status & handling ---------- */
.status { background: var(--blue-dark); color: #fff; border-radius: var(--radius); padding: 14px 16px; }
.status .phase { font-family: var(--display); text-transform: uppercase; letter-spacing: .1em; font-size: .78rem; color: var(--gold); }
.status .what { font-size: 1.1rem; font-weight: 600; margin-top: 2px; }
.status.your { background: var(--gold); color: var(--ink); }
.status.your .phase { color: var(--blue-dark); }
.status.win-D { background: var(--blue); }
.status.win-K { background: var(--red); }

.choices { display: grid; gap: 8px; }
.choice {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; padding: 10px 12px; min-height: 48px;
  background: #fff; border: 2px solid var(--line); border-radius: 12px; color: var(--ink);
}
.choice.sel { border-color: var(--blue-dark); background: var(--blue-soft); }
.choice .sub { color: var(--muted); font-size: .8rem; margin-left: auto; text-align: right; }
.votes { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.votes .btn { min-height: 84px; font-size: 1.6rem; }
.btn.ja { background: var(--green); border-color: var(--green); }
.btn.nej { background: var(--ink); border-color: var(--ink); }

.cards { display: flex; gap: 10px; justify-content: center; margin: 6px 0 12px; }
.law {
  flex: 1; max-width: 130px; aspect-ratio: 3 / 4; border-radius: 12px; border: 3px solid transparent; color: #fff; padding: 8px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; text-align: center;
  font-family: var(--display); font-weight: 800; text-transform: uppercase; letter-spacing: .05em; font-size: .86rem; line-height: 1.15;
}
.law .ico { font-size: 1.9rem; line-height: 1; }
.law.B { background: var(--blue); }
.law.R { background: var(--red); }
button.law.sel { border-color: var(--gold); box-shadow: 0 0 0 4px var(--gold); transform: translateY(-4px); }

/* ---------- tips ---------- */
.tips { border-left: 6px solid var(--gold); }
.tips ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.tips li { display: grid; grid-template-columns: 26px 1fr; gap: 6px; font-size: .95rem; }
.tips li.varning { color: #7d1f19; font-weight: 600; }
.tips li.fakta { color: var(--muted); }
.head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.head h2 { margin: 0; }
.linkbtn { background: none; border: 0; color: var(--blue); text-decoration: underline; padding: 4px; font-size: .88rem; }

/* ---------- roll ---------- */
.role { border: 2px dashed var(--line); text-align: center; }
.role.open.D { background: var(--blue-soft); border: 2px solid var(--blue); }
.role.open.K, .role.open.L { background: var(--red-soft); border: 2px solid var(--red); }
.role .title { font-family: var(--display); font-weight: 800; font-size: 1.6rem; text-transform: uppercase; letter-spacing: .08em; }
.role.D .title { color: var(--blue-dark); }
.role.K .title, .role.L .title { color: var(--red); }
.role ul { text-align: left; margin: 8px 0 0; padding-left: 20px; font-size: .92rem; }

/* ---------- bordet ---------- */
.track { display: grid; gap: 6px; margin-bottom: 12px; }
.track .label { font-family: var(--display); font-weight: 700; text-transform: uppercase; letter-spacing: .08em; font-size: .8rem; display: flex; justify-content: space-between; }
.slots { display: grid; gap: 5px; }
.slots.five { grid-template-columns: repeat(5, 1fr); }
.slots.six { grid-template-columns: repeat(6, 1fr); }
.slot {
  aspect-ratio: 4 / 5; border-radius: 8px; border: 2px dashed; display: flex; align-items: center; justify-content: center; text-align: center;
  font-size: .62rem; line-height: 1.1; padding: 2px; font-weight: 600; text-transform: uppercase; letter-spacing: .02em; overflow: hidden;
}
.blue .slot { border-color: #9db6d8; color: var(--blue); background: #eef3fa; }
.blue .slot.on { background: var(--blue); border: 2px solid var(--blue); color: #fff; }
.red .slot { border-color: #dba9a4; color: var(--red); background: #fbefed; }
.red .slot.on { background: var(--red); border: 2px solid var(--red); color: #fff; }
.red .slot.danger:not(.on) { background: #f6dcd8; }
.slot .pwname { display: none; }
.red .slot:not(.on) .pwico { font-size: 1.1rem; }
.meta { display: flex; flex-wrap: wrap; gap: 8px 16px; font-size: .88rem; color: var(--muted); align-items: center; }
.crisis { display: inline-flex; gap: 5px; align-items: center; }
.crisis i { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--ink); display: inline-block; }
.crisis i.on { background: var(--gold); }

/* ---------- spelare ---------- */
.players { display: grid; gap: 6px; }
.pl { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; padding: 8px 10px; border-radius: 10px; background: #fff; border: 1px solid var(--line); }
.pl.me { border: 2px solid var(--blue-dark); }
.pl.dead { opacity: .55; }
.pl.dead .nm { text-decoration: line-through; }
.pl .nm { font-weight: 700; }
.pl .tags { display: flex; flex-wrap: wrap; gap: 4px; margin-left: auto; justify-content: flex-end; }
.tag { font-size: .68rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; padding: 2px 7px; border-radius: 999px; background: #ece6d6; color: var(--ink); white-space: nowrap; }
.tag.pres { background: var(--gold); }
.tag.chan { background: var(--blue-dark); color: #fff; }
.tag.nom { background: #fff; border: 1.5px solid var(--blue-dark); }
.tag.ja { background: var(--green); color: #fff; }
.tag.nej { background: var(--ink); color: #fff; }
.tag.D { background: var(--blue); color: #fff; }
.tag.K, .tag.L { background: var(--red); color: #fff; }
.tag.safe { background: #dcefe2; color: #1d5233; }
.meter { flex-basis: 100%; height: 6px; border-radius: 3px; background: linear-gradient(90deg, #9db6d8, #e6dfcf 50%, #dba9a4); position: relative; margin-top: 2px; }
.meter i { position: absolute; top: -3px; width: 4px; height: 12px; background: var(--ink); border-radius: 2px; transform: translateX(-2px); }
.legend { display: flex; justify-content: space-between; font-size: .72rem; color: var(--muted); margin-top: 8px; }

/* ---------- historik & logg ---------- */
table { width: 100%; border-collapse: collapse; font-size: .86rem; }
th { text-align: left; font-size: .7rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 4px 6px; border-bottom: 2px solid var(--line); }
td { padding: 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.scroll { overflow-x: auto; }
.pill { display: inline-block; font-size: .7rem; font-weight: 700; text-transform: uppercase; padding: 2px 7px; border-radius: 999px; white-space: nowrap; }
.pill.B { background: var(--blue); color: #fff; }
.pill.R { background: var(--red); color: #fff; }
.pill.fail { background: #ece6d6; }
.log { list-style: none; margin: 0; padding: 0; max-height: 260px; overflow-y: auto; font-size: .88rem; display: grid; gap: 4px; }
.log li { padding: 4px 8px; border-left: 4px solid var(--line); }
.log li.blue { border-color: var(--blue); }
.log li.red { border-color: var(--red); }
.log li.vote { border-color: var(--ink); }
.log li.power, .log li.chaos { border-color: var(--gold); font-weight: 600; }
.log li.claim { border-color: var(--line); font-style: italic; color: var(--muted); }
.log li.win { border-color: var(--green); font-weight: 700; }

/* ---------- statistik ---------- */
.kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.kpi { background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 10px; text-align: center; }
.kpi b { display: block; font-family: var(--display); font-size: 1.7rem; color: var(--blue-dark); }
.kpi span { font-size: .75rem; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.split { display: flex; height: 30px; border-radius: 8px; overflow: hidden; font-size: .8rem; font-weight: 700; color: #fff; margin: 8px 0; background: #ece6d6; }
.split span { display: flex; align-items: center; justify-content: center; white-space: nowrap; overflow: hidden; }
.split .d { background: var(--blue); }
.split .k { background: var(--red); }
.bar { display: grid; grid-template-columns: 11em 1fr 3em; gap: 8px; align-items: center; font-size: .86rem; margin-bottom: 5px; }
.bar div { height: 12px; background: #ece6d6; border-radius: 6px; overflow: hidden; }
.bar div i { display: block; height: 100%; background: var(--blue-dark); }

/* ---------- regler ---------- */
dialog { border: 0; border-radius: var(--radius); padding: 0; max-width: min(640px, 94vw); max-height: 88vh; background: var(--card); color: var(--ink); }
dialog::backdrop { background: rgba(23, 32, 44, .6); }
.rules { padding: 18px; }
.rules h3 { margin: 16px 0 6px; color: var(--blue-dark); font-size: .95rem; }
.rules ul, .rules ol { margin: 0 0 8px; padding-left: 20px; }
.rules li { margin-bottom: 4px; }

#toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 10px; max-width: 90vw; opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 50; }
#toast.show { opacity: 1; }

/* ---------- storskärm ---------- */
.screen { max-width: 1500px; margin: 0 auto; padding: 16px; display: grid; gap: 16px; grid-template-columns: 1fr; }
.lobby-big { display: grid; gap: 18px; grid-template-columns: 1fr; align-items: start; }
.joinbox { text-align: center; }
.joinbox .bigcode { font-family: var(--display); font-weight: 800; font-size: clamp(3.4rem, 11vw, 7rem); letter-spacing: .18em; color: var(--blue-dark); line-height: 1; margin: 6px 0; }
.joinbox .url { font-weight: 700; word-break: break-all; }
.qr { width: min(300px, 70vw); margin: 10px auto; background: #fff; padding: 10px; border-radius: 12px; border: 1px solid var(--line); }
.qr svg { display: block; width: 100%; height: auto; }
.adminbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.adminbar .sep { flex: 1; }
.pl .x { border: 0; background: #ece6d6; border-radius: 999px; padding: 2px 9px; font-size: .75rem; }

@media (min-width: 980px) {
  .screen { grid-template-columns: 1.25fr 1fr; align-items: start; }
  .screen .full { grid-column: 1 / -1; }
  .screen .status .what { font-size: 1.7rem; }
  .screen .status .phase { font-size: 1rem; }
  .screen .slot { font-size: .85rem; aspect-ratio: 5 / 4; }
  .screen .slot .pwname { display: inline; }
  .screen .slot.on { font-size: 1.8rem; }
  .screen .pl { font-size: 1.15rem; padding: 10px 14px; }
  .screen .tag { font-size: .8rem; }
  .screen .players { grid-template-columns: 1fr 1fr; }
  .screen .log { max-height: 330px; font-size: 1rem; }
  .lobby-big { grid-template-columns: 1fr 1fr; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

.wrap > *, .screen > *, .screen > div > *, .lobby-big > * { min-width: 0; }
td:first-child { white-space: nowrap; }

/* ---------- förenklad spelarvy ---------- */
.wrap.tabbed { padding-bottom: calc(96px + env(safe-area-inset-bottom)); }
.panel h3 { font-size: .95rem; color: var(--blue-dark); margin: 0 0 6px; }
.panel.why h3:not(:first-child) { margin-top: 14px; }
.panel.happened { background: transparent; border-style: dashed; padding: 10px 14px; }
.panel.happened .log { max-height: none; font-size: .9rem; }
.panel.todo { border: 3px solid var(--gold); }
.panel.todo .big { font-size: 1.12rem; line-height: 1.4; margin-bottom: 12px; }
.panel.todo h2 { display: none; }
.tiplist { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.tiplist li { display: grid; grid-template-columns: 26px 1fr; gap: 6px; }
.tiplist li.varning { color: #7d1f19; font-weight: 600; }
.tiplist li.fakta { color: var(--muted); }
.scoreline { display: grid; grid-template-columns: 1fr 1fr; gap: 0; padding: 0; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: none; width: 100%; color: #fff; font-size: .95rem; }
.scoreline span { padding: 10px 6px; }
.scoreline .b { background: var(--blue); }
.scoreline .r { background: var(--red); }
.tabs { position: fixed; left: 0; right: 0; bottom: 0; display: grid; grid-template-columns: repeat(4, 1fr); background: var(--card); border-top: 2px solid var(--line); padding-bottom: env(safe-area-inset-bottom); z-index: 20; }
.tabs button { background: none; border: 0; padding: 8px 2px 10px; font-size: .78rem; font-weight: 600; color: var(--muted); display: grid; gap: 2px; justify-items: center; border-top: 4px solid transparent; margin-top: -2px; }
.tabs button span { font-size: 1.3rem; line-height: 1; }
.tabs button.on { color: var(--blue-dark); border-top-color: var(--gold); }
.steps { list-style: none; margin: 12px 0 14px; padding: 0 !important; display: grid; gap: 10px; }
.steps li { display: grid; grid-template-columns: 34px 1fr; gap: 8px; align-items: start; margin: 0; }
.steps li > span { font-size: 1.5rem; line-height: 1.1; }
dialog#help { width: min(520px, 94vw); }
dialog#help p { font-size: 1.02rem; }
.explain { margin: 10px 4px 0; color: var(--muted); font-size: 1.05rem; }
@media (min-width: 980px) { .explain { font-size: 1.3rem; } }
#toast { bottom: calc(86px + env(safe-area-inset-bottom)); }
.law small { font-size: .62rem; font-weight: 600; opacity: .85; letter-spacing: .04em; }
