:root {
  --ink: #2b2350;
  --ink-soft: #6a6390;
  --card: #fffaf2;
  --line: #eadfce;
  --purple: #7a5cff;
  --purple-d: #5a3fd6;
  --pink: #ff6fa5;
  --yellow: #ffcb47;
  --green: #22b573;
  --red: #f0524f;
  --font: ui-rounded, "SF Pro Rounded", "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #a8dcff;
  color: var(--ink);
  font-family: var(--font);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

#c {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  display: block;
  touch-action: none;
  cursor: grab;
}
#c:active { cursor: grabbing; }

button, input { font: inherit; color: inherit; }
button { cursor: pointer; }

.card {
  background: var(--card);
  border-radius: 26px;
  box-shadow: 0 10px 0 rgba(43, 35, 80, .16), 0 24px 60px rgba(43, 35, 80, .28);
}

/* ---------- knapper ---------- */
.btn {
  border: 0;
  border-radius: 16px;
  padding: 11px 18px;
  font-weight: 800;
  font-size: 16px;
  background: #fff;
  color: var(--ink);
  box-shadow: inset 0 0 0 2px var(--line), 0 4px 0 var(--line);
  transition: transform .08s, box-shadow .08s, filter .15s;
}
.btn:hover { filter: brightness(1.04); }
.btn:active { transform: translateY(3px); box-shadow: inset 0 0 0 2px var(--line), 0 1px 0 var(--line); }
.btn.primary { background: var(--purple); color: #fff; box-shadow: 0 4px 0 var(--purple-d); }
.btn.primary:active { box-shadow: 0 1px 0 var(--purple-d); }
.btn.big { padding: 14px 20px; font-size: 18px; }
.btn.small { padding: 8px 10px; font-size: 14px; border-radius: 12px; width: 100%; }
.btn.ghost { background: transparent; box-shadow: none; color: var(--ink-soft); text-decoration: underline; text-underline-offset: 3px; }
.btn.on { background: #e5f8ee; color: #12754a; box-shadow: inset 0 0 0 2px #9fdcbd, 0 4px 0 #9fdcbd; }
.btn:disabled { opacity: .45; cursor: not-allowed; filter: grayscale(.4); }
.btn:focus-visible, .mini:focus-visible, .round:focus-visible, input:focus-visible { outline: 3px solid var(--yellow); outline-offset: 2px; }

.mini {
  border: 0;
  border-radius: 10px;
  padding: 5px 10px;
  font-weight: 700;
  font-size: 13px;
  background: rgba(43, 35, 80, .08);
  color: var(--ink);
}
.mini:hover { background: rgba(43, 35, 80, .15); }

.round {
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: var(--card);
  font-weight: 900;
  font-size: 18px;
  box-shadow: 0 4px 0 rgba(43, 35, 80, .2);
}
.round:active { transform: translateY(2px); box-shadow: 0 2px 0 rgba(43, 35, 80, .2); }

/* ---------- startmeny ---------- */
.menu {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  padding: 20px clamp(16px, 5vw, 72px);
  overflow-y: auto;
  background: linear-gradient(90deg, rgba(168, 220, 255, .55), rgba(168, 220, 255, 0) 60%);
}
.menu-card { width: min(440px, 100%); padding: 26px 26px 20px; margin: auto 0; }
.logo {
  margin: 0;
  font-size: clamp(38px, 6vw, 52px);
  line-height: 1;
  font-weight: 900;
  letter-spacing: -.02em;
  color: var(--purple);
}
.logo b { color: var(--pink); font-weight: 900; }
.tag { margin: 8px 0 18px; color: var(--ink-soft); font-weight: 600; line-height: 1.35; }

.field { display: block; }
.field span, .look-row > span { font-weight: 800; font-size: 13px; color: var(--ink-soft); text-transform: uppercase; letter-spacing: .06em; }
input {
  width: 100%;
  border: 0;
  border-radius: 14px;
  padding: 12px 14px;
  background: #fff;
  box-shadow: inset 0 0 0 2px var(--line);
  font-weight: 700;
  font-size: 18px;
  user-select: text;
  -webkit-user-select: text;
}
.field input { margin-top: 6px; }

.looks { margin: 16px 0 18px; display: grid; gap: 10px; }
.look-row { display: grid; grid-template-columns: 82px 1fr; align-items: center; gap: 8px; }
.swatches, .chips { display: flex; flex-wrap: wrap; gap: 7px; }
.swatches button {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 3px solid #fff;
  box-shadow: 0 0 0 2px var(--line);
  padding: 0;
}
.swatches button.on { box-shadow: 0 0 0 3px var(--purple); transform: scale(1.08); }
.chips button {
  border: 0;
  border-radius: 999px;
  padding: 6px 12px;
  font-weight: 700;
  font-size: 14px;
  background: #fff;
  box-shadow: inset 0 0 0 2px var(--line);
}
.chips button.on { background: var(--purple); color: #fff; box-shadow: none; }

.menu-actions { display: grid; gap: 10px; }
.join-row { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.join-row input { text-transform: uppercase; letter-spacing: .25em; text-align: center; font-weight: 900; }
.join-row input::placeholder { letter-spacing: .1em; font-weight: 700; opacity: .5; }
.menu-msg { min-height: 20px; margin: 10px 0 0; font-weight: 700; color: var(--red); text-align: center; }
.menu-msg.info { color: var(--ink-soft); }

/* ---------- spillskjerm ---------- */
#hud > * { position: fixed; z-index: 2; }
.hud-tl { top: 14px; left: 14px; display: flex; flex-direction: column; align-items: flex-start; gap: 8px; }
.minimap {
  width: 168px;
  height: 168px;
  border-radius: 50%;
  border: 4px solid var(--card);
  box-shadow: 0 4px 0 rgba(43, 35, 80, .2);
  cursor: pointer;
  background: #4fb7e6;
}
.veh { font-size: 16px; font-variant-numeric: tabular-nums; }
.bigmap { display: block; margin: 0 auto; border-radius: 18px; max-width: 100%; height: auto; box-shadow: inset 0 0 0 2px var(--line); }
.code {
  display: block;
  width: 100%;
  border: 0;
  border-radius: 14px;
  padding: 10px 12px;
  background: #fff;
  box-shadow: inset 0 0 0 2px var(--line);
  font: 13px/1.4 ui-monospace, Consolas, monospace;
  color: var(--ink);
  resize: none;
  word-break: break-all;
  user-select: text;
  -webkit-user-select: text;
}
.hud-tr { top: 14px; right: 14px; display: flex; flex-direction: column; align-items: flex-end; gap: 8px; }
.hud-btns { display: flex; align-items: center; gap: 8px; }
.pill {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 6px 14px;
  border-radius: 999px;
  background: var(--card);
  font-weight: 800;
  box-shadow: 0 4px 0 rgba(43, 35, 80, .2);
}
.stars { font-size: 22px; }
.stars b { font-variant-numeric: tabular-nums; min-width: 1ch; }
.stars.bump { animation: bump .5s; }
@keyframes bump { 40% { transform: scale(1.25) rotate(-4deg); } }
.room span { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-soft); }
.room b { font-size: 20px; letter-spacing: .14em; color: var(--purple); user-select: text; -webkit-user-select: text; }
.players { display: flex; flex-direction: column; align-items: flex-end; gap: 5px; }
.players div {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 4px 11px 4px 6px;
  border-radius: 999px;
  background: rgba(255, 250, 242, .88);
  font-weight: 700;
  font-size: 14px;
}
.players i { width: 14px; height: 14px; border-radius: 50%; box-shadow: inset 0 0 0 2px rgba(0, 0, 0, .12); }

.hud-bottom { left: 50%; bottom: 16px; transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 12px; }
.prompt {
  border: 0;
  border-radius: 999px;
  padding: 12px 22px;
  background: var(--yellow);
  color: var(--ink);
  font-weight: 900;
  font-size: 18px;
  box-shadow: 0 5px 0 #d9a520;
  animation: bob 1.2s ease-in-out infinite;
  white-space: nowrap;
}
.prompt kbd {
  display: inline-block;
  margin-right: 8px;
  padding: 1px 9px;
  border-radius: 8px;
  background: #fff;
  font: inherit;
  box-shadow: 0 2px 0 rgba(43, 35, 80, .25);
}
.touch .prompt kbd { display: none; }
@keyframes bob { 50% { transform: translateY(-4px); } }
.emotes { display: flex; gap: 6px; padding: 6px; border-radius: 999px; background: rgba(255, 250, 242, .88); }
.emotes button {
  width: 42px;
  height: 42px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  font-size: 22px;
  transition: transform .1s, background .1s;
}
.emotes button:hover { background: #fff; transform: scale(1.15); }

.joy, .jump { display: none; }
.touch .joy {
  display: block;
  left: 22px;
  bottom: 22px;
  width: 124px;
  height: 124px;
  border-radius: 50%;
  background: rgba(255, 250, 242, .45);
  box-shadow: inset 0 0 0 3px rgba(255, 255, 255, .8);
  touch-action: none;
}
.joy i {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 54px;
  height: 54px;
  margin: -27px;
  border-radius: 50%;
  background: var(--card);
  box-shadow: 0 4px 0 rgba(43, 35, 80, .25);
  pointer-events: none;
}
.touch .jump {
  display: block;
  right: 22px;
  bottom: 30px;
  width: 92px;
  height: 92px;
  border: 0;
  border-radius: 50%;
  background: var(--pink);
  color: #fff;
  font-weight: 900;
  font-size: 18px;
  box-shadow: 0 6px 0 #d94a82;
  touch-action: none;
}
.touch .jump.down { display: none; right: 128px; bottom: 30px; width: 76px; height: 76px; background: var(--purple); box-shadow: 0 6px 0 var(--purple-d); }
.touch.in-plane .jump.down { display: block; }
.touch .hud-bottom { bottom: 12px; }
.in-lesson .hud-bottom, .in-lesson .joy, .in-lesson .jump { display: none; }

/* ---------- mattetime ---------- */
.lesson {
  position: fixed;
  z-index: 3;
  left: 50%;
  bottom: 14px;
  transform: translateX(-50%);
  width: min(600px, calc(100vw - 20px));
  padding: 14px 18px 16px;
}
.l-top { display: flex; align-items: center; gap: 12px; font-size: 14px; color: var(--ink-soft); }
.l-top b { white-space: nowrap; }
.l-timer { flex: 1; height: 8px; border-radius: 99px; background: var(--line); overflow: hidden; }
.l-timer i { display: block; height: 100%; width: 100%; border-radius: 99px; background: var(--green); }
.l-q { margin: 10px 0 6px; font-size: clamp(22px, 4.4vw, 34px); font-weight: 900; line-height: 1.2; text-align: center; text-wrap: balance; }
.l-fb { min-height: 26px; text-align: center; font-weight: 700; line-height: 1.3; color: var(--ink-soft); }
.l-fb.ok { color: var(--green); }
.l-fb.bad { color: var(--red); }
.l-fb.tip { color: #b5651d; }
.l-form { display: grid; grid-template-columns: 1fr auto; gap: 8px; margin-top: 8px; }
.l-form input { text-align: center; font-size: 26px; font-weight: 900; padding: 8px; }
.l-form input.shake { animation: shake .3s; }
@keyframes shake { 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }
.l-pad { display: none; grid-template-columns: repeat(8, 1fr); gap: 6px; margin-top: 8px; }
.touch .l-pad { display: grid; }
.l-pad button {
  border: 0;
  border-radius: 12px;
  padding: 10px 0;
  background: #fff;
  font-weight: 900;
  font-size: 20px;
  box-shadow: inset 0 0 0 2px var(--line), 0 3px 0 var(--line);
}
.l-pad button:active { transform: translateY(2px); box-shadow: inset 0 0 0 2px var(--line); }
.l-who { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; margin-top: 10px; }
.l-who span { padding: 3px 10px; border-radius: 99px; background: rgba(43, 35, 80, .07); font-weight: 700; font-size: 13px; }
.l-who span.ok { background: #dff6ea; color: #12754a; }
.l-who span.bad { background: #fde3e2; color: #a52e2b; }

/* ---------- vinduer ---------- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 5;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(43, 35, 80, .35);
  backdrop-filter: blur(3px);
}
.modal-card { position: relative; width: min(560px, 100%); max-height: calc(100dvh - 32px); overflow-y: auto; padding: 24px; }
.modal-card h2 { margin: 0 0 6px; font-size: 28px; font-weight: 900; color: var(--purple); }
.modal-card .sub { margin: 0 0 16px; color: var(--ink-soft); font-weight: 600; line-height: 1.4; }
.x { position: absolute; top: 14px; right: 14px; width: 36px; height: 36px; border: 0; border-radius: 50%; background: rgba(43, 35, 80, .08); font-weight: 900; }
.x:hover { background: rgba(43, 35, 80, .16); }

.levels { display: grid; gap: 10px; }
.level { display: grid; grid-template-columns: 1fr auto; text-align: left; gap: 2px 12px; padding: 14px 18px; }
.level b { font-size: 20px; }
.level span { grid-column: 1; font-weight: 600; color: var(--ink-soft); font-size: 14px; }
.level i { grid-row: 1 / span 2; grid-column: 2; align-self: center; font-style: normal; font-size: 20px; }

.shop { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 10px; margin-bottom: 14px; }
.animal { display: grid; justify-items: center; gap: 6px; padding: 12px 8px 10px; border-radius: 18px; background: #fff; box-shadow: inset 0 0 0 2px var(--line); }
.animal.owned { box-shadow: inset 0 0 0 2px #9fdcbd; }
.animal .emoji { font-size: 40px; line-height: 1; }

.help { display: grid; gap: 10px; margin: 0 0 18px; padding: 0; list-style: none; }
.help li { display: grid; grid-template-columns: 96px 1fr; gap: 12px; align-items: center; font-weight: 600; line-height: 1.35; }
.help li b { padding: 6px 8px; border-radius: 10px; background: #fff; box-shadow: inset 0 0 0 2px var(--line); text-align: center; font-size: 14px; }

.scores { display: grid; gap: 8px; margin: 0 0 18px; }
.scores div { display: flex; justify-content: space-between; padding: 10px 16px; border-radius: 14px; background: #fff; box-shadow: inset 0 0 0 2px var(--line); font-weight: 800; font-size: 18px; }
.center { text-align: center; }

/* ---------- beskjeder og konfetti ---------- */
.toasts { position: fixed; z-index: 6; top: 70px; left: 50%; transform: translateX(-50%); display: grid; gap: 8px; justify-items: center; pointer-events: none; width: max-content; max-width: calc(100vw - 24px); }
.toast { padding: 10px 18px; border-radius: 999px; background: var(--ink); color: #fff; font-weight: 700; text-align: center; animation: toast 3.4s forwards; }
@keyframes toast { 0% { opacity: 0; transform: translateY(-10px); } 8%, 85% { opacity: 1; transform: none; } 100% { opacity: 0; transform: translateY(-10px); } }

.confetti { position: fixed; inset: 0; z-index: 7; pointer-events: none; overflow: hidden; }
.confetti span { position: absolute; top: -40px; font-size: 26px; animation: fall linear forwards; }
@keyframes fall { to { transform: translateY(110vh) rotate(540deg); } }

@media (max-width: 720px) {
  .menu { padding: 12px; align-items: flex-start; }
  .menu-card { margin: auto; padding: 20px 18px 16px; }
  .emotes button { width: 36px; height: 36px; font-size: 19px; }
  .room span { display: none; }
  .touch .emotes { display: none; }
  .minimap { width: 112px; height: 112px; }
}

@media (prefers-reduced-motion: reduce) {
  .prompt, .toast, .confetti span, .stars.bump { animation: none; }
}
