* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  overflow: hidden;
  background: #120b07;
  color: #f5ead6;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

canvas {
  display: block; position: fixed; inset: 0; touch-action: none;
  transition: transform .9s cubic-bezier(.6, -0.3, .3, 1.3);
}
canvas.flipped { transform: rotate(180deg); }

.hidden { display: none !important; }

/* ---------- HUD ---------- */
#hud {
  position: fixed; top: 0; left: 0; right: 0;
  display: flex; justify-content: space-between; align-items: flex-start; gap: 8px;
  padding: max(12px, env(safe-area-inset-top)) 16px 12px;
  pointer-events: none;
  text-shadow: 0 2px 6px rgba(0,0,0,.8);
}
body.flipped-mode #hud {
  top: auto; bottom: 0; align-items: flex-end;
  padding: 12px 16px max(12px, env(safe-area-inset-bottom));
}
body.flipped-mode .hud-mid { flex-direction: column-reverse; }
#score { font-size: clamp(30px, 6vw, 52px); font-weight: 800; line-height: 1; }
#combo { color: #ffd54a; font-weight: 800; font-size: clamp(14px, 2.6vw, 20px); min-height: 1.2em; }
.hud-mid { display: flex; flex-direction: column; align-items: center; gap: 6px; }
#lives { font-size: clamp(20px, 4.5vw, 34px); letter-spacing: 2px; }
.flip-badge {
  padding: 4px 10px; border-radius: 999px; text-align: center;
  font-weight: 800; font-size: clamp(12px, 2.4vw, 16px);
  background: rgba(140, 60, 220, .75); border: 1px solid rgba(255,255,255,.35);
  animation: wobble 1.2s ease-in-out infinite;
}
@keyframes wobble { 0%, 100% { transform: rotate(-4deg); } 50% { transform: rotate(4deg); } }
.hud-right { display: flex; align-items: center; gap: 8px; }
#tempo { font-weight: 800; font-size: clamp(13px, 2.6vw, 20px); }
.icon-btn {
  pointer-events: auto; cursor: pointer;
  width: 40px; height: 40px; border-radius: 10px;
  background: rgba(0,0,0,.45); border: 1px solid rgba(255,255,255,.25);
  color: #fff; font-size: 18px;
}

#center-msg {
  position: fixed; left: 0; right: 0; top: 36%;
  text-align: center; pointer-events: none;
  font-size: clamp(48px, 13vw, 130px); font-weight: 900;
  text-shadow: 0 4px 24px rgba(0,0,0,.85);
  opacity: 0; transform: scale(.85);
  transition: opacity .15s, transform .15s;
}
#center-msg.show { opacity: 1; transform: scale(1); }

/* ---------- Overlays ---------- */
.overlay {
  position: fixed; inset: 0;
  display: flex; align-items: flex-start; justify-content: center;
  padding: 16px; overflow-y: auto;
  background: rgba(6, 3, 2, .5);
  backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px);
}
.panel {
  margin: auto;
  width: 100%; max-width: 500px;
  padding: 24px 22px;
  border-radius: 18px;
  background: rgba(28, 19, 13, .94);
  border: 1px solid rgba(232, 176, 74, .35);
  box-shadow: 0 20px 60px rgba(0,0,0,.6);
}
.panel.center { text-align: center; }

h1 {
  font-size: clamp(38px, 10vw, 58px); font-weight: 900; text-align: center; letter-spacing: -1px;
  background: linear-gradient(#ffe7a3, #d08a2e);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
h2 { font-size: clamp(22px, 5vw, 30px); margin-bottom: 8px; }
h3 { margin: 22px 0 8px; font-size: 16px; color: #e8b04a; }
.sub { text-align: center; opacity: .8; margin: 6px 0 14px; }

label { display: block; margin: 14px 0 6px; font-weight: 700; font-size: 14px; color: #e8b04a; }
input {
  width: 100%; padding: 12px 14px; font-size: 18px; border-radius: 10px;
  border: 1px solid rgba(255,255,255,.2); background: rgba(0,0,0,.35); color: #fff;
  -webkit-user-select: text; user-select: text;
}
input:focus { outline: 2px solid #e8b04a; }

.choice-row { display: flex; flex-wrap: wrap; gap: 8px; }
.choice {
  flex: 1 1 auto; cursor: pointer;
  padding: 10px 12px; border-radius: 10px; font-size: 16px; font-weight: 700;
  background: rgba(255,255,255,.06); color: #f5ead6;
  border: 2px solid rgba(255,255,255,.12);
}
.choice.active { border-color: #e8b04a; background: rgba(232,176,74,.18); }
.avatars .choice { flex: 0 0 auto; font-size: 26px; padding: 6px 8px; line-height: 1; }

button.big {
  display: block; width: 100%; margin-top: 18px; padding: 14px; cursor: pointer;
  font-size: 22px; font-weight: 900; border: 0; border-radius: 12px;
  color: #2a1606; background: linear-gradient(#ffd77a, #e09a35);
  box-shadow: 0 4px 0 #9a5d16;
}
button.big:active { transform: translateY(2px); box-shadow: 0 2px 0 #9a5d16; }
button.secondary {
  display: block; width: 100%; margin-top: 10px; padding: 12px; cursor: pointer;
  font-size: 16px; font-weight: 700; border-radius: 12px;
  color: #f5ead6; background: transparent; border: 1px solid rgba(255,255,255,.25);
}
button.link {
  background: none; border: 0; color: #f5ead6; opacity: .5; cursor: pointer;
  font-size: 12px; margin-top: 8px; text-decoration: underline;
}

.help { margin-top: 16px; background: rgba(0,0,0,.25); border-radius: 10px; padding: 10px 14px; }
.help summary { cursor: pointer; font-weight: 700; }
.help ul { margin: 10px 0 2px 18px; line-height: 1.5; font-size: 14px; }

.hs { list-style: none; counter-reset: hs; }
.hs li {
  counter-increment: hs;
  display: flex; justify-content: space-between; gap: 10px;
  padding: 7px 10px; border-radius: 8px; font-size: 15px;
}
.hs li:nth-child(odd) { background: rgba(255,255,255,.05); }
.hs li::before { content: counter(hs) "."; width: 1.8em; opacity: .6; }
.hs li .n { flex: 1; text-align: left; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hs li .s { font-weight: 800; }
.hs li.me { background: rgba(232,176,74,.28); }
.hs li.empty::before { content: ""; width: 0; }
.hs li.empty { opacity: .6; justify-content: center; }

/* ---------- Quiz ---------- */
.quiz-head { font-weight: 800; color: #ffd54a; text-align: center; margin-bottom: 10px; }
.timer { height: 8px; border-radius: 4px; background: rgba(255,255,255,.12); overflow: hidden; margin-bottom: 16px; }
#quizBar { height: 100%; width: 100%; background: linear-gradient(90deg, #ff6b4a, #ffd54a, #7ddc6a); }
#quizQ { font-size: clamp(19px, 4.5vw, 26px); line-height: 1.3; margin-bottom: 16px; }
.answers { display: grid; grid-template-columns: 1fr; gap: 10px; }
@media (min-width: 640px) { .answers { grid-template-columns: 1fr 1fr; } .quiz-panel { max-width: 680px; } }
.answer {
  display: flex; align-items: center; gap: 10px; text-align: left; cursor: pointer;
  padding: 12px 14px; border-radius: 12px; font-size: 17px; font-weight: 600;
  background: rgba(255,255,255,.07); color: #f5ead6; border: 2px solid rgba(255,255,255,.15);
}
.answer .k {
  flex: 0 0 auto; width: 26px; height: 26px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  background: rgba(255,255,255,.15); font-size: 14px; font-weight: 800;
}
.answer:not(:disabled):hover { border-color: #e8b04a; }
.answer.correct { background: rgba(80, 200, 100, .35); border-color: #6fdc7f; }
.answer.wrong { background: rgba(230, 70, 60, .35); border-color: #ff6b5a; }
.answer:disabled { cursor: default; }
.result { margin-top: 14px; font-size: 17px; line-height: 1.4; min-height: 1px; }
.result.ok { color: #9ff0a5; }
.result.bad { color: #ffb0a5; }
.result .flip-note { margin-top: 8px; font-weight: 800; color: #d9b3ff; }
.result .fact { margin-top: 8px; color: #f5ead6; opacity: .85; font-size: 15px; }

/* ---------- Game over ---------- */
.final-name { font-size: 20px; margin-top: 4px; }
.final { font-size: clamp(54px, 15vw, 84px); font-weight: 900; color: #ffd54a; line-height: 1.1; }
.rank { font-weight: 800; font-size: 18px; min-height: 1.4em; }
.stats {
  display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin: 14px 0;
  font-size: 14px; text-align: left;
}
.stats div { background: rgba(255,255,255,.06); border-radius: 8px; padding: 8px 10px; }
.stats b { display: block; font-size: 18px; }
.tip { font-style: italic; opacity: .85; margin-top: 4px; }

/* ---------- Arrangement (event) ---------- */
.notice {
  margin: 10px 0; padding: 10px 12px; border-radius: 10px; font-size: 14px; line-height: 1.4;
  background: rgba(255, 170, 60, .12); border: 1px solid rgba(255, 170, 60, .35);
}
.notice code { background: rgba(0,0,0,.35); padding: 1px 5px; border-radius: 4px; }
.error { color: #ff9a8a; font-weight: 700; min-height: 1.2em; margin-top: 10px; text-align: center; }

.inline { display: flex; gap: 8px; }
.inline input { flex: 1; min-width: 0; }
.code-input { text-transform: uppercase; letter-spacing: 6px; font-weight: 800; text-align: center; }
button.small {
  flex: 0 0 auto; cursor: pointer; padding: 10px 16px; border-radius: 10px; border: 0;
  font-size: 16px; font-weight: 800; color: #2a1606; background: linear-gradient(#ffd77a, #e09a35);
}
button.small.ghost { background: transparent; color: #f5ead6; border: 1px solid rgba(255,255,255,.3); }

.ev-list { display: flex; flex-direction: column; gap: 6px; margin-top: 10px; }
.ev-item {
  display: flex; align-items: center; gap: 10px; width: 100%; cursor: pointer; text-align: left;
  padding: 10px 12px; border-radius: 10px; font-size: 15px; color: #f5ead6;
  background: rgba(255,255,255,.06); border: 1px solid rgba(255,255,255,.12);
}
.ev-item:hover { border-color: #e8b04a; }
.ev-item .t { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 700; }
.ev-item .m { opacity: .7; font-size: 13px; white-space: nowrap; }
.ev-item .c { font-weight: 800; letter-spacing: 2px; color: #e8b04a; }

.ev-banner {
  display: flex; align-items: center; gap: 10px; margin-top: 12px;
  padding: 10px 12px; border-radius: 12px;
  background: rgba(232,176,74,.12); border: 1px solid rgba(232,176,74,.4);
}
.ev-banner.local { background: rgba(255,255,255,.05); border-color: rgba(255,255,255,.15); }
.ev-info { flex: 1; min-width: 0; }
.ev-name { font-weight: 800; font-size: 17px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ev-sub { font-size: 13px; opacity: .8; }
.ev-sub b { letter-spacing: 2px; color: #ffd54a; }
.ev-actions { display: flex; gap: 6px; }
.ev-actions button.small { padding: 8px 12px; font-size: 14px; }
.ev-status { font-size: 13px; color: #ffb27a; min-height: 0; margin-top: 6px; }
.ev-status:empty { display: none; }

.players { margin-bottom: 8px; }
.players:empty { display: none; }
.players .choice { flex: 0 0 auto; font-size: 15px; padding: 6px 10px; }

/* Toppliste-tabell */
.lb { width: 100%; border-collapse: collapse; font-size: 15px; }
.lb th { text-align: left; font-size: 12px; font-weight: 700; opacity: .65; padding: 4px 8px; }
.lb td { padding: 7px 8px; }
.lb th.num, .lb td.num { text-align: right; white-space: nowrap; }
.lb td.rank { width: 2em; opacity: .6; }
.lb td.name { max-width: 0; width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-align: left; }
.lb td.best { font-weight: 800; }
.lb tbody tr:nth-child(odd) { background: rgba(255,255,255,.05); }
.lb tbody tr.me { background: rgba(232,176,74,.28); }
.lb tbody tr.none { opacity: .55; }
.lb-empty { opacity: .6; text-align: center; padding: 8px; }

/* ---------- Innlogging ---------- */
.tabs { margin-top: 6px; }
.center-text { text-align: center; margin-top: 8px; }
.center-text a, .live-link { color: #e8b04a; }
.live-link { display: block; text-align: center; margin-top: 14px; font-size: 14px; font-weight: 700; text-decoration: none; }
.live-link:hover { text-decoration: underline; }
.account {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  margin-top: 14px; font-size: 15px;
}
.account b { color: #ffd54a; }
.account .link { margin-top: 0; font-size: 13px; }
.account > span:last-child { white-space: nowrap; }
.account .link + .link { margin-left: 10px; }
.rename { margin-top: 10px; }
.rename input { font-size: 16px; padding: 10px 12px; }
.rename button.small { padding: 10px 12px; font-size: 15px; }

/* Installer som app */
.install-tip {
  display: flex; align-items: center; gap: 10px; margin-top: 14px; padding: 10px 12px; border-radius: 10px;
  font-size: 14px; line-height: 1.35; background: rgba(232,176,74,.1); border: 1px solid rgba(232,176,74,.35);
}
.install-tip span { flex: 1; }
.install-tip button.small { padding: 8px 12px; font-size: 14px; }
.install-tip .close { background: none; border: 0; color: #f5ead6; opacity: .6; font-size: 18px; cursor: pointer; }
.live-link.admin-link { margin-top: 8px; opacity: .85; }

/* Gjest */
.guest-join { margin-top: 6px; }
.guest-join h3 { margin-top: 10px; }
.guest-join .code-input { flex: 0 0 118px; letter-spacing: 4px; }
.guest-join .ev-sub { text-align: center; margin-top: 8px; }
.divider { display: flex; align-items: center; gap: 10px; margin: 18px 0 8px; font-size: 13px; color: #e8b04a; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: rgba(232,176,74,.35); }
