:root {
  --bg: #1b1145;
  --bg-2: #2a1a6b;
  --card: rgba(255, 255, 255, 0.09);
  --line: rgba(255, 255, 255, 0.18);
  --text: #fff;
  --muted: #bdb4e6;
  --sun: #ffd23f;
  --pink: #ff4f8b;
  --mint: #3ddc97;
  --ink: #1b1145;
  --radius: 18px;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
}

body {
  font-family: 'Nunito', system-ui, -apple-system, 'Segoe UI', sans-serif;
  font-size: 18px;
  line-height: 1.25;
  color: var(--text);
  background: radial-gradient(120% 80% at 50% 0%, var(--bg-2), var(--bg) 70%) fixed;
  overscroll-behavior: none;
}

#app {
  max-width: 480px;
  min-height: 100dvh;
  margin: 0 auto;
  padding: calc(16px + env(safe-area-inset-top)) 16px calc(24px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 16px;
}

h1,
h2,
p {
  margin: 0;
}

.logo {
  font-size: 46px;
  font-weight: 800;
  line-height: 1;
  text-align: center;
  color: var(--sun);
  text-shadow: 0 4px 0 var(--pink);
  transform: rotate(-3deg);
  margin: 28px 0 12px;
}

.center {
  text-align: center;
}

.muted {
  color: var(--muted);
}

.grow {
  flex: 1;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
}

/* ---- pogas un lauki ---- */

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

.btn {
  display: block;
  width: 100%;
  min-height: 56px;
  padding: 10px 18px;
  border: 0;
  border-radius: var(--radius);
  background: var(--sun);
  color: var(--ink);
  font-size: 20px;
  font-weight: 800;
  box-shadow: 0 5px 0 #c99a00;
  cursor: pointer;
  transition: transform 0.06s, box-shadow 0.06s;
}

.btn:active:not(:disabled) {
  transform: translateY(4px);
  box-shadow: 0 1px 0 #c99a00;
}

.btn:disabled {
  opacity: 0.4;
  cursor: default;
}

.btn.ghost {
  background: transparent;
  color: var(--text);
  border: 2px solid var(--line);
  box-shadow: none;
  font-weight: 700;
}

.link {
  background: none;
  border: 0;
  padding: 10px;
  color: var(--muted);
  text-decoration: underline;
  cursor: pointer;
}

.field {
  width: 100%;
  min-height: 54px;
  padding: 10px 16px;
  border-radius: var(--radius);
  border: 2px solid var(--line);
  background: rgba(0, 0, 0, 0.25);
  font-size: 18px;
  outline: none;
}

.field:focus {
  border-color: var(--sun);
}

.field::placeholder {
  color: #8f86bd;
}

.field.code {
  text-align: center;
  font-size: 30px;
  font-weight: 800;
  letter-spacing: 0.3em;
  text-transform: uppercase;
}

.tabs,
.segments {
  display: flex;
  gap: 6px;
  padding: 5px;
  border-radius: var(--radius);
  background: rgba(0, 0, 0, 0.25);
}

.tabs button,
.segments button {
  flex: 1;
  min-height: 44px;
  border: 0;
  border-radius: 13px;
  background: transparent;
  font-weight: 700;
  cursor: pointer;
}

.tabs button.on,
.segments button.on {
  background: var(--pink);
}

.segments button:disabled {
  cursor: default;
}

.error {
  color: #ff9db9;
  min-height: 1.3em;
}

/* ---- spēlētāji ---- */

.avatar {
  flex: none;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: inline-grid;
  place-items: center;
  font-weight: 800;
  font-size: 20px;
  color: #fff;
  text-transform: uppercase;
  border: 2px solid rgba(255, 255, 255, 0.6);
}

.avatar.photo {
  background-size: cover;
  background-position: center;
}

.avatar.sm {
  width: 28px;
  height: 28px;
  font-size: 14px;
}

.avatar.lg {
  width: 84px;
  height: 84px;
  font-size: 42px;
}

.avatar.off {
  opacity: 0.35;
}

.players {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.player {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  border-radius: 14px;
  background: var(--card);
}

.player .name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 700;
}

.player .tag {
  font-size: 14px;
  color: var(--muted);
}

.player .score {
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.player .delta {
  color: var(--mint);
  font-weight: 800;
  min-width: 3.2em;
  text-align: right;
}

.player.me {
  outline: 2px solid var(--sun);
}

.player .place {
  width: 1.6em;
  font-weight: 800;
  color: var(--sun);
}

.chips {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}

.chips .avatar {
  opacity: 0.3;
}

.chips .avatar.done {
  opacity: 1;
  box-shadow: 0 0 0 3px var(--mint);
}

/* ---- spēles galvene ---- */

.bar-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.pill {
  padding: 3px 12px;
  border-radius: 99px;
  background: var(--card);
  font-size: 15px;
  font-weight: 700;
  white-space: nowrap;
}

.timer {
  height: 8px;
  border-radius: 99px;
  background: rgba(0, 0, 0, 0.35);
  overflow: hidden;
}

.timer-fill {
  height: 100%;
  width: 100%;
  border-radius: 99px;
  background: var(--mint);
  transition: width 0.1s linear;
}

.timer-fill.low {
  background: var(--pink);
}

/* ---- raundi ---- */

.kicker {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--pink);
  text-align: center;
}

.question {
  font-size: 26px;
  font-weight: 800;
  line-height: 1.15;
  text-align: center;
  text-wrap: balance;
}

.intro {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  text-align: center;
}

.intro .big {
  font-size: 44px;
  font-weight: 800;
  line-height: 1.05;
  color: var(--sun);
  text-shadow: 0 3px 0 var(--pink);
}

.options {
  display: grid;
  gap: 10px;
}

.options.two {
  grid-template-columns: 1fr 1fr;
}

.option {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 60px;
  padding: 8px 12px;
  border-radius: var(--radius);
  border: 2px solid var(--line);
  background: var(--card);
  font-weight: 700;
  text-align: left;
  cursor: pointer;
  min-width: 0;
}

.option span {
  min-width: 0;
  overflow-wrap: anywhere;
}

.option.on {
  border-color: var(--sun);
  background: rgba(255, 210, 63, 0.22);
}

.option:disabled {
  cursor: default;
  opacity: 0.55;
}

.option.on:disabled {
  opacity: 1;
}

.joker {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  border-radius: var(--radius);
  border: 2px dashed var(--line);
  background: transparent;
  font-weight: 700;
  cursor: pointer;
}

.joker.on {
  border-style: solid;
  border-color: var(--pink);
  background: rgba(255, 79, 139, 0.25);
}

/* ---- zīmēšana ---- */

.board {
  align-self: center;
  width: min(100%, 50dvh);
  aspect-ratio: 1;
  border-radius: var(--radius);
  background: #fff;
  touch-action: none;
  display: block;
}

.board.locked {
  opacity: 0.7;
}

.tools {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px;
}

.swatch,
.tool {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 3px solid transparent;
  cursor: pointer;
  padding: 0;
}

.swatch.on,
.tool.on {
  border-color: var(--sun);
}

.tool {
  background: var(--card);
  display: grid;
  place-items: center;
  font-size: 18px;
}

.tool i {
  display: block;
  border-radius: 50%;
  background: #fff;
}

.gallery {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.frame {
  position: relative;
  padding: 0;
  border: 4px solid transparent;
  border-radius: var(--radius);
  background: #fff;
  overflow: hidden;
  cursor: pointer;
  color: var(--ink);
}

.frame canvas,
.frame img {
  display: block;
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
}

.shot {
  align-self: center;
  width: min(100%, 46dvh);
  aspect-ratio: 1;
  border-radius: var(--radius);
  overflow: hidden;
  background: rgba(0, 0, 0, 0.35);
  display: grid;
  place-items: center;
  font-size: 64px;
}

.shot video,
.shot img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.shot video {
  transform: scaleX(-1);
}

.frame.on {
  border-color: var(--sun);
}

.frame.best {
  border-color: var(--mint);
}

.frame:disabled {
  cursor: default;
}

.frame.dim {
  opacity: 0.5;
}

.frame .cap {
  display: flex;
  justify-content: space-between;
  gap: 6px;
  padding: 4px 8px;
  background: #efeaff;
  font-size: 15px;
  font-weight: 700;
}

.frame .badge {
  position: absolute;
  top: 6px;
  left: 6px;
  padding: 0 8px;
  border-radius: 99px;
  background: var(--ink);
  color: #fff;
  font-size: 13px;
}

/* ---- rezultāti ---- */

.headline {
  font-size: 34px;
  font-weight: 800;
  text-align: center;
  color: var(--mint);
}

.headline.zero {
  font-size: 22px;
  color: var(--muted);
}

.tally {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.tally-row {
  padding: 10px 12px;
  border-radius: 14px;
  background: var(--card);
  border: 2px solid transparent;
}

.tally-row.top {
  border-color: var(--mint);
  background: rgba(61, 220, 151, 0.16);
}

.tally-head {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
}

.tally-head .label {
  flex: 1;
  min-width: 0;
}

.tally-head .count {
  font-size: 22px;
  font-weight: 800;
}

.voters {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 6px;
  align-items: center;
}

#offline,
#toast {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  width: max-content;
  max-width: calc(100vw - 32px);
  padding: 10px 18px;
  border-radius: 99px;
  font-weight: 700;
  text-align: center;
}

#offline {
  top: calc(8px + env(safe-area-inset-top));
  background: var(--pink);
}

#toast {
  bottom: calc(24px + env(safe-area-inset-bottom));
  background: #fff;
  color: var(--ink);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.4);
}

[hidden] {
  display: none !important;
}
