:root { font-size: 62.5%; }

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, sans-serif;
  background: #0f172a;
  color: #e2e8f0;
  min-height: 100vh;
}

h1 { font-size: 2.2rem; margin: 0; }
h2 { font-size: 1.8rem; margin: 0 0 1.6rem; color: #f8fafc; }

.muted { color: #94a3b8; font-size: 1.4rem; }

/* --- Name screen --------------------------------------------------- */

.screen-center {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
}

.card {
  width: 40rem;
  max-width: 100%;
  background: #111827;
  border-radius: 1.2rem;
  box-shadow: 0 0.6rem 2rem rgba(0, 0, 0, 0.4);
  padding: 2.8rem;
}

.card h1 { margin-bottom: 0.8rem; }
.card .muted { margin: 0 0 2rem; }

.name-form { display: flex; flex-direction: column; gap: 1.2rem; }

.text-input {
  font-size: 1.6rem;
  padding: 1.2rem;
  border-radius: 0.8rem;
  border: 0.1rem solid #334155;
  background: #0b1220;
  color: #e2e8f0;
  outline: none;
}
.text-input:focus {
  border-color: #60a5fa;
  box-shadow: 0 0 0 0.3rem rgba(96, 165, 250, 0.25);
}

/* --- Buttons -------------------------------------------------------- */

.btn {
  font-size: 1.6rem;
  font-weight: 600;
  padding: 1.2rem 1.8rem;
  border-radius: 0.8rem;
  border: none;
  cursor: pointer;
  color: #fff;
}
.btn-primary { background: #3b82f6; }
.btn-primary:hover { background: #2563eb; }
.btn-danger { background: #dc2626; }
.btn-danger:hover { background: #b91c1c; }

/* --- Top bar -------------------------------------------------------- */

.topbar {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1.6rem;
  padding: 1.8rem 2.4rem;
  background: #111827;
  border-bottom: 0.1rem solid #1e293b;
}

.topbar-right { display: flex; align-items: center; gap: 1.6rem; }

.btn-ghost {
  font-size: 1.3rem;
  font-weight: 600;
  padding: 0.7rem 1.4rem;
  border: 0.1rem solid #334155;
  border-radius: 0.7rem;
  background: transparent;
  color: #e2e8f0;
  cursor: pointer;
}
.btn-ghost:hover { border-color: #3b82f6; }

.content { padding: 2.4rem; max-width: 80rem; margin: 0 auto; }

/* --- Peer list ------------------------------------------------------ */

.peer-list { display: flex; flex-direction: column; gap: 1rem; }

.peer {
  display: flex;
  align-items: center;
  gap: 1.4rem;
  width: 100%;
  text-align: left;
  padding: 1.4rem 1.6rem;
  background: #111827;
  border: 0.1rem solid #1e293b;
  border-radius: 1rem;
  color: #e2e8f0;
  cursor: pointer;
  font-size: 1.6rem;
}
.peer:hover:not(:disabled) { border-color: #3b82f6; background: #16213a; }
.peer:disabled { opacity: 0.5; cursor: default; }

.peer-avatar {
  width: 4rem;
  height: 4rem;
  border-radius: 50%;
  background: #3b82f6;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.8rem;
  font-weight: 700;
  flex-shrink: 0;
}
.peer-name { flex: 1; font-weight: 600; }
.peer-action { color: #60a5fa; font-size: 1.4rem; }

/* --- Game lobby ----------------------------------------------------- */

.lobby .muted { margin: -0.8rem 0 2rem; }

.game-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(24rem, 1fr));
  gap: 1.4rem;
}

.game-card {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  text-align: left;
  padding: 2rem;
  background: #111827;
  border: 0.1rem solid #1e293b;
  border-radius: 1.2rem;
  color: #e2e8f0;
  cursor: pointer;
}
.game-card:hover { border-color: #3b82f6; background: #16213a; }
.game-card-title { font-size: 1.8rem; font-weight: 700; }
.game-card-desc { font-size: 1.4rem; color: #94a3b8; }

/* --- Picture-in-picture call video ---------------------------------- */

.pip {
  position: fixed;
  top: 1.2rem;
  right: 1.2rem;
  width: 22rem;
  height: 22rem;
  border-radius: 1.2rem;
  overflow: hidden;
  background: #000;
  box-shadow: 0 0.6rem 2rem rgba(0, 0, 0, 0.6);
  border: 0.1rem solid #1e293b;
  z-index: 50;
}

.pip-remote {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.pip-local {
  position: absolute;
  left: 0.8rem;
  bottom: 0.8rem;
  width: 7rem;
  height: 7rem;
  object-fit: cover;
  border-radius: 0.6rem;
  border: 0.2rem solid #0f172a;
  background: #000;
}

.pip-hangup {
  position: absolute;
  top: 0.6rem;
  right: 0.6rem;
  width: 3rem;
  height: 3rem;
  border: none;
  border-radius: 50%;
  background: rgba(220, 38, 38, 0.92);
  color: #fff;
  font-size: 1.6rem;
  line-height: 1;
  cursor: pointer;
}
.pip-hangup:hover { background: #dc2626; }

/* --- Call prompt overlay -------------------------------------------- */

.call-overlay {
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 23, 0.92);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  z-index: 100;
}

.call-panel {
  background: #111827;
  border-radius: 1.4rem;
  padding: 2.8rem;
  box-shadow: 0 1rem 3rem rgba(0, 0, 0, 0.6);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2rem;
}

.call-status { font-size: 1.8rem; font-weight: 600; }
.call-actions { display: flex; gap: 1.2rem; }

/* --- Reconnect banner ----------------------------------------------- */

.call-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 200;
  background: #b45309;
  color: #fff;
  display: flex;
  justify-content: center;
  padding: 1rem 1.4rem;
  box-shadow: 0 0.2rem 1rem rgba(0, 0, 0, 0.4);
}
.call-banner-error { background: #b91c1c; }

.call-banner-inner {
  display: flex;
  align-items: center;
  gap: 1.2rem;
  font-size: 1.5rem;
  flex-wrap: wrap;
  justify-content: center;
}

.banner-btn {
  font-size: 1.3rem;
  font-weight: 600;
  padding: 0.6rem 1.2rem;
  border: none;
  border-radius: 0.6rem;
  background: rgba(0, 0, 0, 0.28);
  color: #fff;
  cursor: pointer;
}
.banner-btn:hover { background: rgba(0, 0, 0, 0.45); }

.spinner {
  width: 1.6rem;
  height: 1.6rem;
  border: 0.25rem solid rgba(255, 255, 255, 0.35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* --- Update banner -------------------------------------------------- */

.update-banner {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 210;
  background: #1d4ed8;
  color: #fff;
  display: flex;
  justify-content: center;
  padding: 1rem 1.4rem;
  box-shadow: 0 -0.2rem 1rem rgba(0, 0, 0, 0.4);
}
.update-banner-inner {
  display: flex;
  align-items: center;
  gap: 1.2rem;
  font-size: 1.5rem;
  flex-wrap: wrap;
  justify-content: center;
}

/* --- Game container ------------------------------------------------- */

.game-container {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.2rem;
}

.leave-game {
  position: fixed;
  top: 1.2rem;
  left: 1.2rem;
  z-index: 60;
  padding: 0.9rem 1.4rem;
  font-size: 1.4rem;
  font-weight: 600;
  border: 0.1rem solid #334155;
  border-radius: 0.8rem;
  background: rgba(17, 24, 39, 0.92);
  color: #e2e8f0;
  cursor: pointer;
}
.leave-game:hover { border-color: #3b82f6; }

/* --- Fia med Knuff board -------------------------------------------- */

.fia-wrap {
  display: flex;
  align-items: center;
  gap: 2.4rem;
  flex-wrap: wrap;
  justify-content: center;
}

.fia-board {
  width: 88vmin;
  height: 88vmin;
  max-width: 92vw;
  border-radius: 1rem;
  overflow: hidden;
  box-shadow: 0 0.6rem 2rem rgba(0, 0, 0, 0.5);
}

.fia-svg {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;          /* let us handle drag gestures */
}

.fia-lines line {
  stroke: #1a1a1a;
  stroke-width: 0.16;
  stroke-linecap: round;
}

.fia-spots circle {
  stroke: #1a1a1a;
  stroke-width: 0.055;
}

.fia-trail-line {
  stroke-width: 0.14;
  stroke-linecap: round;
  stroke-dasharray: 0.36 0.28;
  opacity: 0.9;
}
.fia-trail-dot {
  fill: none;
  stroke-width: 0.11;
  opacity: 0.9;
}

.fia-piece { cursor: grab; }
.fia-piece-body { stroke: #14110d; stroke-width: 0.1; }
.fia-piece:hover .fia-piece-body { stroke-width: 0.16; }
.fia-piece.dragging { cursor: grabbing; }
.fia-piece.dragging .fia-piece-body { stroke-width: 0.16; }
.fia-piece.highlight .fia-piece-body { stroke: #fff; stroke-width: 0.13; }

/* --- Side panel: hint, dice, reset ---------------------------------- */

.fia-side {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.6rem;
  max-width: 24rem;
}
.fia-hint { font-size: 1.4rem; color: #94a3b8; margin: 0; text-align: center; }

.fia-turn {
  width: 100%;
  text-align: center;
  font-size: 1.8rem;
  font-weight: 700;
  padding: 1.2rem 1rem;
  border-radius: 1rem;
  background: #1e293b;
  color: #cbd5e1;
  border: 0.2rem solid #334155;
}
.fia-turn.mine {
  background: #14532d;
  color: #bbf7d0;
  border-color: #22c55e;
  box-shadow: 0 0 1.2rem rgba(34, 197, 94, 0.4);
}

.fia-dicebox {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.8rem;
}

.fia-dice {
  width: 9rem;
  height: 9rem;
  background: #fbfbf7;
  border: 0.1rem solid #cbd5e1;
  border-radius: 1.4rem;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  padding: 1.1rem;
  gap: 0.5rem;
  cursor: pointer;
  box-shadow: 0 0.4rem 1rem rgba(0, 0, 0, 0.5);
}
.fia-dice:hover { background: #fff; }
.fia-dice:active { transform: scale(0.96); }

@keyframes fia-roll {
  0%   { transform: rotate(0deg) scale(1); }
  20%  { transform: rotate(-19deg) scale(1.09); }
  50%  { transform: rotate(17deg) scale(1.05); }
  80%  { transform: rotate(-11deg) scale(1.09); }
  100% { transform: rotate(0deg) scale(1); }
}
.fia-dice.rolling {
  animation: fia-roll 0.42s ease-in-out infinite;
  pointer-events: none;
  box-shadow: 0 0.4rem 1.4rem rgba(0, 0, 0, 0.6);
}

.fia-pip { border-radius: 50%; background: transparent; }
.fia-pip.on { background: #0f172a; }

.fia-dicelabel { font-size: 1.5rem; color: #cbd5e1; }
.fia-dicelabel strong { color: #f8fafc; }
