:root {
  color-scheme: dark;
  --coal: #111111;
  --coal-2: #1b1b1b;
  --panel: rgba(20, 20, 20, 0.86);
  --panel-solid: #181818;
  --line: rgba(212, 175, 55, 0.22);
  --line-soft: rgba(255, 255, 255, 0.09);
  --iron: #6b6f76;
  --ink: #ece7dc;
  --muted: #a39e93;
  --gold: #d4af37;
  --gold-soft: rgba(212, 175, 55, 0.16);
  --blood: #b3262b;
  --blood-soft: rgba(179, 38, 43, 0.22);
  --aurora-1: #1fd1a5;
  --aurora-2: #3b7bff;
  --aurora-3: #7d4dff;
  --radius: 12px;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { margin: 0; min-height: 100%; }
body {
  font: 16px/1.45 var(--sans);
  color: var(--ink);
  background: var(--coal);
  touch-action: manipulation;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }

/* ---------- Taustat ---------- */
#bg {
  position: fixed; inset: 0; z-index: -2;
  background-color: var(--coal);
  background-size: cover; background-position: center;
  transition: background-image .6s ease;
}
#bg::after {
  content: ""; position: absolute; inset: 0;
  background:
    radial-gradient(120% 80% at 50% 20%, rgba(0,0,0,.35), rgba(0,0,0,.82) 70%),
    linear-gradient(rgba(10,10,10,.55), rgba(10,10,10,.75));
}
body[data-bg="lobby"] #bg { background-image: radial-gradient(90% 60% at 50% 0%, rgba(212,175,55,.18), transparent 70%); }
body[data-bg="vala"] #bg { background-image: url(img/taustat/vala-levea.webp); }
body[data-bg="alttari"] #bg { background-image: url(img/taustat/alttari-levea.webp); }
body[data-bg="voitto"] #bg { background-image: url(img/taustat/voitto-levea.webp); }
body[data-bg="voitto"] #bg::after { background: linear-gradient(rgba(10,10,10,.45), rgba(10,10,10,.78)); }
@media (orientation: portrait) {
  body[data-bg="vala"] #bg { background-image: url(img/taustat/vala-pysty.webp); }
  body[data-bg="alttari"] #bg { background-image: url(img/taustat/alttari-pysty.webp); }
  body[data-bg="voitto"] #bg { background-image: url(img/taustat/voitto-pysty.webp); }
}

/* Yö: revontulet pelkällä CSS:llä */
#aurora { position: fixed; inset: 0; z-index: -1; pointer-events: none; overflow: hidden; opacity: 0; transition: opacity 1.2s ease; }
body[data-bg="yo"] #aurora { opacity: 1; }
body[data-bg="yo"] #bg { background: #05070b; }
#aurora span {
  position: absolute; top: -20%; width: 70vmax; height: 55vmax; border-radius: 50%;
  filter: blur(60px); opacity: .32; mix-blend-mode: screen;
  animation: drift 26s ease-in-out infinite alternate;
}
#aurora span:nth-child(1) { left: -20%; background: var(--aurora-1); }
#aurora span:nth-child(2) { left: 25%; background: var(--aurora-2); animation-duration: 34s; animation-delay: -8s; opacity: .22; }
#aurora span:nth-child(3) { left: 55%; background: var(--aurora-3); animation-duration: 40s; animation-delay: -16s; opacity: .2; }
@keyframes drift {
  0% { transform: translate3d(0, 0, 0) scale(1) rotate(0deg); }
  100% { transform: translate3d(8vw, 6vh, 0) scale(1.15) rotate(12deg); }
}
@media (prefers-reduced-motion: reduce) { #aurora span { animation: none; } }

/* ---------- Runko ---------- */
#app { max-width: 720px; margin: 0 auto; min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; }
header {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 10px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: linear-gradient(rgba(12,12,12,.95), rgba(12,12,12,.8));
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(6px);
}
.emblem { width: 30px; height: 30px; flex: none; border-radius: 7px; object-fit: cover; }
h1 { font: 700 21px/1 var(--serif); margin: 0; letter-spacing: .5px; }
#hdr-right { margin-left: auto; display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.timer { font: 700 18px/1 var(--sans); font-variant-numeric: tabular-nums; color: var(--gold); min-width: 52px; text-align: right; }
.timer.low { color: #ff6b5e; }
.iconbtn { background: none; border: 1px solid var(--line-soft); border-radius: 9px; padding: 6px 10px; font-size: 13px; color: var(--ink); }

main { flex: 1; padding: 16px 16px calc(32px + env(safe-area-inset-bottom)); }
.panel {
  background: var(--panel); border: 1px solid var(--line-soft); border-radius: var(--radius);
  padding: 16px; margin-bottom: 12px; backdrop-filter: blur(4px);
}
.panel h2 { font: 700 20px/1.2 var(--serif); margin: 0 0 6px; }
.panel h3 { font: 700 16px/1.2 var(--serif); margin: 0 0 10px; }
.muted { color: var(--muted); font-size: 14px; }
.small { font-size: 13px; }
p { margin: 0 0 10px; }

label.fld { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--muted); margin-bottom: 12px; }
label.fld input {
  font: 600 16px var(--sans); padding: 12px; border-radius: 10px;
  border: 1.5px solid var(--line-soft); background: rgba(0,0,0,.4); color: var(--ink); width: 100%;
}
label.fld input:focus { border-color: var(--gold); outline: none; }

.btn {
  display: block; width: 100%; min-height: 50px; padding: 12px 16px;
  border: 0; border-radius: 11px; font-weight: 700; font-size: 16px; text-align: center;
  background: var(--gold); color: #1a1405;
}
.btn small { display: block; font-weight: 500; font-size: 12px; opacity: .85; }
.btn.alt { background: transparent; color: var(--ink); border: 1.5px solid var(--line-soft); }
.btn.dark { background: #262626; color: var(--ink); border: 1px solid var(--line-soft); }
.btn.red { background: var(--blood); color: #fff; }
.btn:disabled { opacity: .45; cursor: default; }
.btn + .btn { margin-top: 10px; }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; margin-top: 0 !important; }
.err { background: var(--blood-soft); border: 1px solid rgba(179,38,43,.5); border-radius: 10px; padding: 10px 12px; font-size: 14px; margin-bottom: 12px; }

/* ---------- Aloitus ---------- */
.hero { text-align: center; padding: 18px 4px 8px; }
.hero .emblem { width: 96px; height: 96px; margin-bottom: 10px; object-fit: contain; border-radius: 0; }
.hero h2 { font: 700 30px/1.1 var(--serif); margin: 0 0 8px; }
.hero p { color: var(--muted); max-width: 46ch; margin: 0 auto 6px; }
.motto { font: italic 14px var(--serif); color: var(--gold); letter-spacing: .5px; }

/* ---------- Aula ---------- */
.code { font: 700 36px/1 var(--serif); letter-spacing: 6px; text-align: center; color: var(--gold); padding: 6px 0 12px; }
.avatars { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.av {
  position: relative; padding: 0; border: 2px solid transparent; border-radius: 12px; overflow: hidden;
  background: #000; aspect-ratio: 1;
}
.av img { width: 100%; height: 100%; object-fit: cover; display: block; }
.av .lbl {
  position: absolute; left: 0; right: 0; bottom: 0; padding: 3px 2px;
  font-size: 11px; font-weight: 700; text-align: center;
  background: linear-gradient(transparent, rgba(0,0,0,.85));
}
.av.mine { border-color: var(--gold); box-shadow: 0 0 0 2px rgba(212,175,55,.35); }
.av.taken { cursor: default; }
.av.taken img { filter: grayscale(.85) brightness(.45); }
.av.taken .lbl { color: var(--muted); }

.plist { list-style: none; margin: 0; padding: 0; }
.plist li { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line-soft); }
.plist li:last-child { border: 0; }
.plist img { width: 38px; height: 38px; border-radius: 9px; object-fit: cover; flex: none; }
.plist .nm { font-weight: 700; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tag { font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 8px; background: var(--gold-soft); color: var(--gold); white-space: nowrap; }
.tag.grey { background: rgba(255,255,255,.08); color: var(--muted); }
.tag.red { background: var(--blood-soft); color: #ff8f86; }
.linkbtn { background: none; border: 0; color: #ff8f86; font-size: 13px; text-decoration: underline; padding: 4px; }

.opt { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line-soft); }
.opt:last-of-type { border: 0; }
.opt .t { font-weight: 700; font-size: 15px; }
.opt .d { color: var(--muted); font-size: 12.5px; }
.stepper { display: flex; align-items: center; gap: 8px; flex: none; }
.stepper button { width: 38px; height: 38px; border-radius: 10px; border: 1.5px solid var(--line-soft); background: rgba(0,0,0,.35); font: 700 18px var(--sans); }
.stepper b { min-width: 54px; text-align: center; font-variant-numeric: tabular-nums; }
.switch { width: 52px; height: 30px; border-radius: 15px; border: 0; background: #3a3a3a; position: relative; flex: none; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #ddd; transition: left .15s; }
.switch[aria-checked="true"] { background: var(--gold); }
.switch[aria-checked="true"]::after { left: 25px; }
.stepper button:disabled, .switch:disabled { opacity: .45; }

/* ---------- Peli ---------- */
.phase { text-align: center; padding: 6px 4px 14px; }
.phase .kicker { font-size: 12px; letter-spacing: 1.6px; text-transform: uppercase; color: var(--gold); font-weight: 700; }
.phase h2 { font: 700 28px/1.15 var(--serif); margin: 4px 0 6px; text-shadow: 0 2px 12px rgba(0,0,0,.7); }
.phase p { color: #d6d0c4; max-width: 48ch; margin: 0 auto; text-shadow: 0 1px 8px rgba(0,0,0,.8); }

.rolecard {
  width: 100%; text-align: left; border: 1px solid var(--line); border-radius: var(--radius);
  background: linear-gradient(135deg, rgba(40,32,12,.92), rgba(18,18,18,.92));
  padding: 14px 16px; margin-bottom: 12px; display: block;
}
.rolecard .peek { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-weight: 700; }
.rolecard .peek span:last-child { color: var(--muted); font-weight: 500; font-size: 13px; }
.rolecard .body { margin-top: 12px; }
.rolecard .rname { font: 700 24px/1.1 var(--serif); }
.rolecard .rside { font-size: 13px; font-weight: 700; letter-spacing: 1px; text-transform: uppercase; margin: 2px 0 8px; }
.rolecard .rside.u { color: var(--gold); }
.rolecard .rside.v { color: #ff6b5e; }
.rolecard .rbody { font-size: 14.5px; color: #ddd6c8; }
.rolecard.traitor { background: linear-gradient(135deg, rgba(70,14,16,.94), rgba(18,18,18,.94)); border-color: rgba(179,38,43,.55); }
.privlist { margin: 10px 0 0; padding: 10px 0 0; border-top: 1px solid var(--line-soft); list-style: none; font-size: 14px; }
.privlist li { padding: 3px 0; }
.privlist b { color: var(--gold); }

.actionbox { border: 1px solid var(--line); }
.actionbox .choice { font-weight: 700; color: var(--gold); }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 10px; }
.pc {
  position: relative; border: 1.5px solid var(--line-soft); border-radius: 12px; overflow: hidden;
  background: rgba(12,12,12,.85); display: flex; flex-direction: column;
}
.pc .face { position: relative; padding: 0; border: 0; background: #000; display: block; width: 100%; aspect-ratio: 1; }
.pc .face img { width: 100%; height: 100%; object-fit: cover; display: block; }
.pc .face:disabled { cursor: default; }
.pc .meta { padding: 6px 8px 4px; }
.pc .nm { font-weight: 700; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pc .st { font-size: 11.5px; color: var(--muted); min-height: 16px; }
.pc .notebtn {
  border: 0; border-top: 1px solid var(--line-soft); background: rgba(255,255,255,.03);
  font-size: 12px; color: var(--muted); padding: 6px 8px; text-align: left;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.pc .notebtn.has { color: #e9dcb4; }
.pc .badges { position: absolute; top: 6px; left: 6px; right: 6px; display: flex; gap: 4px; justify-content: space-between; pointer-events: none; }
.pc .badges .tag { background: rgba(0,0,0,.72); }
.pc.me { border-color: var(--gold); }
.pc.dead .face img { filter: grayscale(1) brightness(.35); }
.pc.dead .nm { color: var(--muted); text-decoration: line-through; }
.pc.target .face { cursor: pointer; }
.pc.target:hover, .pc.target:focus-within { border-color: rgba(212,175,55,.6); }
.pc.chosen { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(212,175,55,.45); }
.pc.chosen.kill { border-color: var(--blood); box-shadow: 0 0 0 3px rgba(179,38,43,.6); }
.pc.suspect .face::after { content: "?"; position: absolute; right: 6px; bottom: 6px; width: 26px; height: 26px; border-radius: 50%; background: #5a3fb0; color: #fff; font: 700 16px/26px var(--sans); text-align: center; }
.pc .stamp {
  position: absolute; left: 50%; top: 46%; transform: translate(-50%,-50%) rotate(-8deg);
  font: 800 12px/1 var(--sans); letter-spacing: 1px; text-transform: uppercase;
  padding: 5px 8px; border-radius: 6px; border: 2px solid; white-space: nowrap; background: rgba(0,0,0,.6);
}
.pc .stamp.v { color: #ff6b5e; border-color: #ff6b5e; }
.pc .stamp.u { color: var(--gold); border-color: var(--gold); }
.pc .stamp.y { color: #c9c3b8; border-color: #c9c3b8; }

.tally { list-style: none; margin: 8px 0 0; padding: 0; }
.tally li { padding: 6px 0; border-bottom: 1px solid var(--line-soft); }
.tally li:last-child { border: 0; }
.tally .trow { display: flex; align-items: center; gap: 10px; }
.tally .tname { flex: 0 0 38%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 700; }
.tally .voters { font-size: 13px; color: var(--muted); margin-top: 2px; }
.tally .bar { height: 10px; border-radius: 5px; background: var(--gold); }
.tally .n { font-variant-numeric: tabular-nums; font-weight: 700; min-width: 20px; }

.verdict { text-align: center; padding: 10px 0 4px; }
.verdict .big { font: 700 26px/1.15 var(--serif); }
.verdict .v { color: #ff6b5e; }
.verdict .u { color: var(--gold); }

.ghostbar { background: rgba(90,63,176,.25); border: 1px solid rgba(125,77,255,.45); border-radius: var(--radius); padding: 10px 14px; margin-bottom: 12px; font-size: 14px; }

details.log { margin-top: 12px; }
details.log summary { cursor: pointer; font-weight: 700; padding: 6px 0; color: var(--muted); }
details.log ol { margin: 6px 0 0; padding-left: 20px; font-size: 14px; color: #cfc9bd; }
details.log li { padding: 2px 0; }

.winner { text-align: center; padding: 10px 0; }
.winner .big { font: 700 32px/1.1 var(--serif); }
.winner.u .big { color: var(--gold); }
.winner.v .big { color: #ff6b5e; }

/* ---------- Ikkunat ---------- */
.veil { position: fixed; inset: 0; background: rgba(0,0,0,.66); display: flex; align-items: flex-end; justify-content: center; z-index: 20; }
.sheet {
  width: 100%; max-width: 720px; max-height: 88vh; overflow: auto;
  background: var(--panel-solid); border-top: 1px solid var(--line); border-radius: 18px 18px 0 0;
  padding: 20px 18px calc(20px + env(safe-area-inset-bottom));
}
.sheet h2 { font: 700 24px/1.15 var(--serif); margin: 0 0 10px; }
.sheet h3 { font: 700 17px var(--serif); margin: 16px 0 6px; }
.sheet textarea {
  width: 100%; min-height: 130px; resize: vertical; padding: 12px; border-radius: 10px;
  border: 1.5px solid var(--line-soft); background: rgba(0,0,0,.4); font-size: 16px; line-height: 1.4;
}
.sheet textarea:focus { border-color: var(--gold); outline: none; }
.sheet table { width: 100%; border-collapse: collapse; font-size: 14px; }
.sheet th, .sheet td { padding: 6px 8px; border-bottom: 1px solid var(--line-soft); text-align: left; }
.sheet th { color: var(--muted); font-size: 12.5px; }
.rolerow { padding: 10px 0; border-bottom: 1px solid var(--line-soft); }
.rolerow b { font-family: var(--serif); font-size: 17px; }
.rolerow .rside { font-size: 11.5px; letter-spacing: 1px; text-transform: uppercase; font-weight: 700; margin-left: 6px; }
.rolerow .rside.u { color: var(--gold); }
.rolerow .rside.v { color: #ff6b5e; }

.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: rgba(20,20,20,.96); border: 1px solid var(--line); color: var(--ink);
  padding: 10px 16px; border-radius: 11px; font-size: 14px; z-index: 30; max-width: 90%; text-align: center;
  box-shadow: 0 6px 24px rgba(0,0,0,.5);
}

@media (min-width: 560px) {
  .avatars { grid-template-columns: repeat(5, 1fr); gap: 10px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(124px, 1fr)); }
}

/* ---------- Pelimuodot ja uudet teot ---------- */
.modes { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.modes.col { grid-template-columns: 1fr; margin-top: 12px; }
.modecard {
  display: flex; flex-direction: column; gap: 3px; text-align: left;
  padding: 12px; border-radius: 11px; border: 1.5px solid var(--line-soft); background: rgba(0,0,0,.35);
}
.modecard .mt { font: 700 15px/1.2 var(--serif); }
.modecard .ms { font-size: 12.5px; color: var(--muted); line-height: 1.35; }
.modecard.on { border-color: var(--gold); background: var(--gold-soft); }
.modecard:disabled { opacity: .7; cursor: default; }
.modes.col .modecard { padding: 14px 16px; }
.modes.col .modecard .mt { font-size: 18px; }
.modes.col .modecard .ms { font-size: 14px; }
@media (max-width: 420px) { .modes:not(.col) .modecard .ms { display: none; } .modes:not(.col) .modecard { text-align: center; } }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 1.5px solid var(--line-soft); background: rgba(0,0,0,.35); border-radius: 999px;
  padding: 7px 12px; font-size: 13.5px; font-weight: 700; white-space: nowrap;
}
.chip.on { border-color: var(--gold); background: var(--gold); color: #1a1405; }
.chip:disabled { opacity: .6; cursor: default; }

.actrow { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line-soft); }
.actrow:last-of-type { border-bottom: 0; }
.actrow .t { font-weight: 700; font-size: 15px; }
.actrow .d { font-size: 13.5px; color: var(--muted); }
.actrow.on .t { color: var(--gold); }

.rolecard .rside.s, .rolerow .rside.s { color: #b99cff; }
.rolecard.wolf { background: linear-gradient(135deg, rgba(48,30,90,.94), rgba(18,18,18,.94)); border-color: rgba(125,77,255,.55); }
.pc .stamp.s { color: #b99cff; border-color: #b99cff; }
.verdict .s { color: #b99cff; }
.pc .stamp { max-width: 92%; white-space: normal; text-align: center; line-height: 1.15; }
.pc .stamp.long { font-size: 10px; letter-spacing: .5px; padding: 4px 6px; }

/* ---------- Roolit ja säännöt -värit ---------- */
.sheet h2.rules-title { color: #D4AF37; }
.sheet h3.h-v { color: #B3262B; }
.sheet h3.h-u { color: #F2C94C; }
.sheet h3.h-s { color: #B99CFF; }
.rolerow .rdesc { margin-top: 3px; color: #D6D0C4; font-size: 15px; line-height: 1.45; }
.rolerow.side-vannomaton b { color: #B3262B; }
.rolerow.side-uskollinen b { color: #F2C94C; }
.rolerow.side-susi b { color: #B99CFF; }

/* ---------- Discord-nappi ---------- */
.btn.discord { display: flex; flex-direction: column; align-items: center; justify-content: center; text-decoration: none; background: #5865F2; color: #fff; margin: 0 0 12px; }
.btn.discord small { opacity: .9; }
.btn.discord .dc-ico { width: 22px; height: 22px; margin-bottom: 2px; }
