:root {
  --paper: #f3eee4;
  --paper-2: #ebe4d6;
  --card: #fffdf8;
  --ink: #1f1c18;
  --muted: #6e675d;
  --red: #d2432c;
  --red-dark: #a8321f;
  --mustard: #efb431;
  --blue: #2e5c86;
  --green: #4e8757;
  --item-h: clamp(60px, 10vh, 108px);
  --shadow: 4px 4px 0 var(--ink);
  font-family: "Bricolage Grotesque", "Segoe UI", system-ui, sans-serif;
}

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

html, body { margin: 0; min-height: 100%; }
body {
  color: var(--ink);
  background-color: var(--paper);
  /* svak prikkete papirtekstur */
  background-image: radial-gradient(rgba(31, 28, 24, .07) 1px, transparent 1px);
  background-size: 18px 18px;
  min-height: 100vh;
}

button { font: inherit; color: inherit; cursor: pointer; }
input, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--blue); outline-offset: 2px; }

/* ---------- Topplinje ---------- */
.topbar {
  display: flex; align-items: center; gap: 12px 28px; flex-wrap: wrap;
  padding: 14px 28px;
  border-bottom: 2px solid var(--ink);
  background: var(--paper);
  position: sticky; top: 0; z-index: 10;
}
.brand { flex: 1; min-width: 140px; display: flex; align-items: baseline; gap: 10px; }
.brand-name { font-weight: 800; font-size: 1.35rem; letter-spacing: -.02em; }
.brand-class { color: var(--muted); font-weight: 500; }
.brand-class:empty { display: none; }

.tabs { display: flex; gap: 22px; }
.tab {
  border: 0; background: none; padding: 6px 0; font-weight: 600; font-size: 1.05rem;
  color: var(--muted); border-bottom: 3px solid transparent;
}
.tab:hover { color: var(--ink); }
.tab.active { color: var(--ink); border-bottom-color: var(--red); }
.badge { font-size: .8em; font-weight: 500; color: var(--muted); margin-left: 2px; font-variant-numeric: tabular-nums; }

.tools { display: flex; gap: 8px; }
.tool-btn {
  border: 2px solid var(--ink); background: var(--card);
  padding: 5px 12px; border-radius: 6px; font-size: .9rem; font-weight: 600;
}
.tool-btn:hover { background: var(--paper-2); }
.tool-btn[aria-pressed="false"] { color: var(--muted); }

main { padding: 32px 28px 64px; max-width: 1180px; margin: 0 auto; }
.view { display: none; }
.view.active { display: block; }

.muted { color: var(--muted); }
.panel {
  background: var(--card); border: 2px solid var(--ink); border-radius: 10px;
  padding: 24px; margin-bottom: 24px; box-shadow: var(--shadow);
}
.panel h2 { margin: 0 0 4px; font-size: 1.5rem; letter-spacing: -.01em; }
.panel p { margin: 0 0 12px; }
.panel-head { display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap; align-items: flex-start; }
.panel-actions { display: flex; gap: 10px; flex-wrap: wrap; }

.btn {
  border: 2px solid var(--ink); border-radius: 8px; padding: 9px 16px; font-weight: 700;
  background: var(--card); box-shadow: 3px 3px 0 var(--ink);
  transition: transform .06s, box-shadow .06s;
}
.btn:hover { background: var(--paper-2); }
.btn:active { transform: translate(3px, 3px); box-shadow: 0 0 0 var(--ink); }
.btn.primary { background: var(--mustard); }
.btn.primary:hover { background: #f5c34f; }
.link-btn { background: none; border: 0; color: var(--ink); text-decoration: underline; text-underline-offset: 3px; padding: 4px; font-weight: 600; }
.link-btn:hover { color: var(--red); }

/* ---------- Spilleautomat ---------- */
.stage { display: flex; flex-direction: column; align-items: center; gap: 26px; }

.machine {
  position: relative;
  width: min(700px, 100%);
  padding: 14px 22px 22px;
  background: var(--red);
  border: 3px solid var(--ink);
  border-radius: 22px 22px 14px 14px;
  box-shadow: 8px 8px 0 var(--ink);
}
.marquee {
  text-align: center;
  font-weight: 800; font-size: clamp(1.1rem, 2.6vw, 1.5rem);
  color: var(--paper);
  letter-spacing: .01em;
  padding: 4px 0 6px;
}

.lights { display: flex; justify-content: space-between; padding: 8px 4px; }
.bulb {
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--red-dark); border: 2px solid var(--ink);
}
.bulb.on { background: var(--mustard); }
.machine.spinning .bulb { animation: alt .3s steps(1) infinite; }
.machine.spinning .bulb:nth-child(even) { animation-delay: .15s; }
.machine.win .bulb { animation: alt .5s steps(1) infinite; }
@keyframes alt { 0% { background: var(--mustard); } 50% { background: var(--red-dark); } }

.window {
  position: relative; overflow: hidden;
  height: calc(var(--item-h) * 3);
  border-radius: 8px;
  background: var(--card);
  border: 3px solid var(--ink);
}
.reel { will-change: transform; }
.reel-item {
  height: var(--item-h);
  display: flex; align-items: center; justify-content: center;
  padding: 0 28px;
  font-size: calc(var(--item-h) * 0.4);
  font-weight: 700; letter-spacing: -.01em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.reel.fast { filter: blur(1.2px); }
.reel.bump { animation: bump .3s ease-out; }
@keyframes bump { 35% { margin-top: 8px; } 100% { margin-top: 0; } }
.reel-item.hit { color: var(--ink); font-weight: 800; }

.payline {
  position: absolute; left: 0; right: 0; top: var(--item-h); height: var(--item-h);
  border-top: 2px solid var(--ink); border-bottom: 2px solid var(--ink);
  background: rgba(239, 180, 49, .18);
  pointer-events: none;
}
.payline::before, .payline::after {
  content: ""; position: absolute; top: 50%; transform: translateY(-50%);
  border: 11px solid transparent;
}
.payline::before { left: 0; border-left-color: var(--ink); }
.payline::after { right: 0; border-right-color: var(--ink); }
/* navnene over og under tones ned mot kantene */
.glass {
  position: absolute; inset: 0; pointer-events: none;
  background: linear-gradient(180deg, var(--card) 0%, transparent 28%, transparent 72%, var(--card) 100%);
}

/* Spak */
.lever {
  position: absolute; right: -54px; top: 50%; transform: translateY(-50%);
  width: 48px; height: 220px; background: none; border: 0; padding: 0;
}
.lever-base {
  position: absolute; left: 0; bottom: 52px; width: 26px; height: 64px;
  background: var(--paper-2); border: 3px solid var(--ink); border-left: 0; border-radius: 0 8px 8px 0;
}
.lever-stick {
  position: absolute; left: 18px; bottom: 84px; width: 9px; height: 124px;
  background: var(--paper-2); border: 2px solid var(--ink); border-radius: 5px;
  transform-origin: bottom center; transition: transform .25s ease-in;
}
.lever-ball {
  position: absolute; left: 50%; top: -24px; transform: translateX(-50%);
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--mustard); border: 3px solid var(--ink);
}
.lever.pulled .lever-stick { transform: scaleY(-0.55); transition: transform .18s ease-in; }

.spin-btn {
  font-size: clamp(1.3rem, 3vw, 1.7rem); font-weight: 800; letter-spacing: .02em;
  padding: 12px 52px; border-radius: 10px;
  border: 3px solid var(--ink);
  background: var(--mustard);
  box-shadow: 5px 5px 0 var(--ink);
  transition: transform .06s, box-shadow .06s;
}
.spin-btn:hover { background: #f5c34f; }
.spin-btn:active, .spin-btn.pressed { transform: translate(5px, 5px); box-shadow: 0 0 0 var(--ink); }
.spin-btn:disabled { opacity: .55; cursor: default; }

.winner {
  min-height: 1.25em;
  font-size: clamp(2.2rem, 6vw, 4rem); font-weight: 800; letter-spacing: -.03em;
  text-align: center; line-height: 1.1;
}
.winner span {
  /* markeringstusj bak navnet */
  background: linear-gradient(transparent 58%, var(--mustard) 58%, var(--mustard) 90%, transparent 90%);
  padding: 0 .12em;
}
.winner.show span { animation: land .45s cubic-bezier(.3, 1.5, .5, 1); display: inline-block; }
@keyframes land { from { transform: translateY(14px) rotate(-2deg); opacity: 0; } to { transform: none; opacity: 1; } }

.draw-options { display: flex; gap: 18px; align-items: center; flex-wrap: wrap; justify-content: center; }
.check { display: flex; gap: 8px; align-items: center; cursor: pointer; font-weight: 500; }
.check input { width: 18px; height: 18px; accent-color: var(--ink); }
.drawn-list { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; max-width: 860px; align-items: center; }
.drawn-label { font-size: .9rem; color: var(--muted); margin-right: 4px; }
.drawn-list .mini {
  font-size: .9rem; padding: 2px 10px; border-radius: 999px;
  border: 1.5px solid var(--ink); background: var(--card);
}

/* ---------- Klasse ---------- */
.summary { font-weight: 700; margin: 10px 0 16px !important; }
.chips { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 10px; }
.chip {
  text-align: left; padding: 11px 14px; border-radius: 8px;
  background: var(--card); border: 2px solid var(--ink);
  font-weight: 600; box-shadow: 2px 2px 0 var(--ink);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  transition: transform .06s, box-shadow .06s;
}
.chip:active { transform: translate(2px, 2px); box-shadow: none; }
.chip.absent {
  background: transparent; border-style: dashed; border-color: #a69e91; box-shadow: none;
  color: #9a9286; text-decoration: line-through; text-decoration-thickness: 2px;
}

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; font-weight: 700; }
.field input, .field textarea {
  background: var(--paper); border: 2px solid var(--ink); border-radius: 8px;
  padding: 10px 12px; font-weight: 400;
}
.field textarea { resize: vertical; line-height: 1.55; }
.prettify-row {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  margin: -4px 0 20px; padding-bottom: 20px; border-bottom: 1.5px dashed #cfc7b8;
}

/* ---------- Grupper ---------- */
.group-controls { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.spacer { flex: 1; }
.segmented { display: flex; border: 2px solid var(--ink); border-radius: 8px; overflow: hidden; }
.seg { border: 0; background: var(--card); padding: 8px 14px; font-weight: 600; }
.seg + .seg { border-left: 2px solid var(--ink); }
.seg.active { background: var(--ink); color: var(--paper); }
.stepper { display: flex; align-items: stretch; border: 2px solid var(--ink); border-radius: 8px; overflow: hidden; }
.stepper button { width: 40px; border: 0; background: var(--card); font-size: 1.3rem; font-weight: 700; }
.stepper button:hover { background: var(--paper-2); }
.stepper input {
  width: 56px; height: 40px; text-align: center; font-size: 1.2rem; font-weight: 800;
  background: var(--paper); border: 0; border-left: 2px solid var(--ink); border-right: 2px solid var(--ink);
  -moz-appearance: textfield;
}
.stepper input::-webkit-outer-spin-button, .stepper input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

.groups { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 20px; }
.group {
  --c: var(--blue);
  background: var(--card); border: 2px solid var(--ink); border-radius: 10px;
  box-shadow: var(--shadow); overflow: hidden;
  animation: deal .4s cubic-bezier(.3, 1.4, .5, 1) both;
}
.group:nth-child(3n+1) { rotate: -.6deg; }
.group:nth-child(3n+2) { rotate: .5deg; }
.group h3 {
  margin: 0; padding: 10px 14px; font-size: 1.15rem;
  background: var(--c); color: var(--paper);
  border-bottom: 2px solid var(--ink);
  display: flex; justify-content: space-between; align-items: baseline;
}
.group h3 small { font-weight: 500; font-size: .85rem; opacity: .85; }
.group.light-head h3 { color: var(--ink); }
.group ul { list-style: none; margin: 0; padding: 6px 14px 10px; }
.group li {
  padding: 7px 0; font-size: 1.12rem; font-weight: 600;
  border-bottom: 1px solid #e3dccf;
}
.group li:last-child { border-bottom: 0; }
@keyframes deal { from { opacity: 0; transform: translateY(24px); } to { opacity: 1; transform: none; } }

.empty { text-align: center; color: var(--muted); padding: 48px 0; font-size: 1.1rem; }

/* ---------- Diverse ---------- */
#confetti { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 50; }
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px);
  background: var(--ink); color: var(--paper); font-weight: 600;
  padding: 10px 18px; border-radius: 8px;
  opacity: 0; transition: opacity .2s, transform .2s; z-index: 60; pointer-events: none;
  max-width: calc(100% - 32px); text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 900px) {
  .lever { display: none; }
}
@media (max-width: 600px) {
  .topbar { padding: 12px 16px; }
  main { padding: 20px 16px 48px; }
  .machine { padding: 10px 12px 16px; box-shadow: 5px 5px 0 var(--ink); }
  .bulb { width: 9px; height: 9px; }
  .tabs { gap: 16px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
