:root {
  --bg: #12141a;
  --panel: #1b1e27;
  --line: #2c313f;
  --ink: #e8eaf0;
  --dim: #939bb0;
  --acc: #f0b429;
  --board: #16323a;
  --tile: #f3f1e7;
  --tileink: #1d2129;
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}
.hidden { display: none !important; }
button {
  font: inherit; cursor: pointer; border: 1px solid var(--line);
  background: #262b38; color: var(--ink); border-radius: 8px; padding: 8px 12px;
}
button:hover:not(:disabled) { background: #303648; }
button:disabled { opacity: .4; cursor: not-allowed; }
button.primary { background: var(--acc); color: #1a1206; border-color: transparent; font-weight: 700; }
button.primary:hover:not(:disabled) { background: #ffc849; }
button.danger { background: #7a2230; border-color: #a13040; }
input, select {
  font: inherit; background: #0f1218; color: var(--ink);
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; width: 100%;
}

.offline {
  position: fixed; top: 0; left: 0; right: 0; z-index: 90; text-align: center;
  background: #7a2230; color: #ffe3e3; padding: 6px 12px; font-size: 13px;
}

/* ---------------------------------------------------------- lobby */
.overlay {
  position: fixed; inset: 0; background: rgba(8, 10, 14, .85);
  display: grid; place-items: center; padding: 16px; z-index: 50; overflow: auto;
}
.overlay .card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 16px;
  padding: 22px; width: min(440px, 100%);
}
h1 { margin: 0 0 4px; font-size: 30px; letter-spacing: -.5px; }
.tag { margin: 0 0 16px; color: var(--dim); }
.hint { color: var(--dim); font-size: 13px; min-height: 18px; }
#joinBox, .row { display: flex; gap: 8px; }
#joinBox button, .row button { white-space: nowrap; }
.invite { margin-top: 14px; display: grid; gap: 6px; border-top: 1px solid var(--line); padding-top: 12px; }
.invite input { font-size: 13px; color: var(--dim); }
#codeBox { display: grid; gap: 8px; margin-bottom: 6px; }
.lobbylist { display: grid; gap: 6px; margin-bottom: 14px; }
.lobbylist div {
  background: #0f1218; border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 10px; display: flex; gap: 8px; align-items: center;
}
#startBtn, #leaveBtn { width: 100%; margin-top: 10px; }
.fullbox {
  background: #3a2a12; border: 1px solid #6b4c1a; color: #f4d79a;
  border-radius: 10px; padding: 10px 12px; font-size: 14px;
}

/* ---------------------------------------------------------- layout */
main {
  display: grid; grid-template-columns: minmax(0, 1fr) 360px;
  gap: 16px; padding: 16px; align-items: start; max-width: 1400px; margin: 0 auto;
}
.boardwrap { display: grid; place-items: center; }
.panel { display: grid; gap: 12px; position: sticky; top: 16px; }
@media (max-width: 980px) {
  main { grid-template-columns: 1fr; padding: 8px; }
  .panel { position: static; }
}

/* ---------------------------------------------------------- brädet */
#board {
  width: min(94vmin, 780px); aspect-ratio: 1; display: grid;
  grid-template-columns: 1.5fr repeat(9, 1fr) 1.5fr;
  grid-template-rows: 1.5fr repeat(9, 1fr) 1.5fr;
  background: var(--board); border: 3px solid #0c1c21; border-radius: 10px;
  padding: 4px; gap: 2px; position: relative;
}
.tile {
  background: var(--tile); color: var(--tileink); border-radius: 3px;
  display: flex; flex-direction: column; overflow: hidden;
  font-size: clamp(5px, .95vmin, 10px); line-height: 1.15; position: relative;
  padding: 2px; cursor: pointer;
}
.tile.corner { font-size: clamp(6px, 1.1vmin, 11px); align-items: center; justify-content: center; text-align: center; }
.tile .bar { height: 16%; min-height: 7px; margin: -2px -2px 2px; border-bottom: 1px solid rgba(0,0,0,.25); }
.tile .nm { font-weight: 700; word-break: break-word; hyphens: auto; }
.tile .pr { margin-top: auto; color: #4a5160; }
.tile.own { box-shadow: inset 0 0 0 2px var(--o); }
/* lämna plats åt pjäserna så priset inte hamnar under dem */
.tile.occupied { padding-bottom: clamp(19px, 3.1vmin, 30px); }
/* på liten skärm får pjäsen gå före priset – priset syns när man trycker på rutan */
@media (max-width: 700px) {
  .tile.occupied:not(.corner) .pr { display: none; }
}
.tile.mortgaged { filter: grayscale(1) brightness(.82); }
.tile.here { outline: 2px solid var(--acc); outline-offset: -2px; }
.houses { position: absolute; top: 2px; right: 2px; display: flex; gap: 1px; }
.houses i { width: 5px; height: 5px; border-radius: 1px; background: #2fae5b; border: .5px solid rgba(0,0,0,.4); }
.houses i.hotel { width: 11px; background: #d93b3b; }
.tokens {
  position: absolute; inset: auto 0 1px 0; display: flex; flex-wrap: wrap;
  gap: 2px; justify-content: center; pointer-events: none;
}
.tokens span {
  width: clamp(17px, 2.7vmin, 27px); height: clamp(17px, 2.7vmin, 27px);
  border-radius: 50%; display: grid; place-items: center;
  font-size: clamp(9px, 1.5vmin, 15px); line-height: 1;
  border: 2px solid rgba(255, 255, 255, .9);
  box-shadow: 0 1px 4px rgba(0, 0, 0, .55);
}
/* Pjäsen för den vars tur det är ska gå att hitta på en halv sekund. */
.tokens span.active {
  border-color: var(--acc);
  box-shadow: 0 0 0 3px rgba(240, 180, 41, .45), 0 0 12px rgba(240, 180, 41, .7), 0 1px 4px rgba(0, 0, 0, .55);
  animation: bob 1.4s ease-in-out infinite;
  z-index: 3;
}
@keyframes bob {
  0%, 100% { transform: translateY(0) scale(1); }
  50%      { transform: translateY(-4px) scale(1.08); }
}

/* Kopian som reser mellan rutorna – ligger utanför brädet så den inte klipps
   av rutornas overflow och inte försvinner när brädet ritas om. */
.ghost {
  position: fixed; border-radius: 50%; display: grid; place-items: center;
  border: 2px solid var(--acc); line-height: 1; pointer-events: none; z-index: 30;
  box-shadow: 0 0 0 4px rgba(240, 180, 41, .4), 0 0 18px rgba(240, 180, 41, .75), 0 8px 16px rgba(0, 0, 0, .55);
}

@media (prefers-reduced-motion: reduce) {
  .tokens span.active { animation: none; }
}
.center {
  grid-column: 2 / 11; grid-row: 2 / 11; display: grid; place-content: center;
  /* justify-items behövs: kortet har max-width och kan inte sträckas, och ett
     smalare block hamnar annars i vänsterkanten trots text-align: center. */
  justify-items: center;
  text-align: center; gap: 6px; color: #cfe7ef; padding: 0 8px; min-width: 0;
}
.center h2 { margin: 0; font-size: clamp(18px, 4vmin, 44px); letter-spacing: 3px; text-transform: uppercase; }
.center p { margin: 0; color: #7fa7b4; font-size: clamp(9px, 1.5vmin, 14px); }
.center .card2 {
  background: #f3f1e7; color: #1d2129; border-radius: 8px; padding: 10px 14px;
  max-width: min(44ch, 100%); margin-inline: auto;
  font-size: clamp(10px, 1.6vmin, 15px); box-shadow: 0 6px 18px rgba(0,0,0,.35);
}

/* ---------------------------------------------------------- panel */
.players { display: grid; gap: 6px; }
.pl {
  display: grid; grid-template-columns: auto 1fr auto; gap: 8px; align-items: center;
  background: var(--panel); border: 1px solid var(--line); border-left: 4px solid var(--c);
  border-radius: 10px; padding: 8px 10px;
}
.pl.turn { background: #232a1c; border-color: var(--acc); }
.pl.dead { opacity: .45; }
.pl .nm { font-weight: 600; }
.pl .meta { font-size: 12px; color: var(--dim); }
.pl .money { font-variant-numeric: tabular-nums; font-weight: 700; }
.dot { width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; background: var(--c); font-size: 12px; }

.turnbox { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 12px; display: grid; gap: 10px; }
.dice { display: flex; gap: 10px; justify-content: center; min-height: 46px; align-items: center; }
.dice b {
  width: 46px; height: 46px; background: #f7f5ec; color: #1d2129; border-radius: 10px;
  display: grid; place-items: center; font-size: 24px; font-weight: 800;
  box-shadow: 0 3px 0 #b9b5a4, 0 6px 12px rgba(0, 0, 0, .45);
}
.dice.rolling b {
  animation: tumble .28s linear infinite;
  box-shadow: 0 3px 0 #b9b5a4, 0 10px 20px rgba(0, 0, 0, .55);
}
.dice.rolling b:nth-child(2) { animation-delay: -.14s; animation-direction: reverse; }
.dice.landed b { animation: land .38s cubic-bezier(.3, 1.6, .5, 1); }
@keyframes tumble {
  0%   { transform: translateY(0) rotate(0deg) scale(1); }
  25%  { transform: translateY(-11px) rotate(90deg) scale(1.08); }
  50%  { transform: translateY(0) rotate(180deg) scale(.94); }
  75%  { transform: translateY(-7px) rotate(270deg) scale(1.05); }
  100% { transform: translateY(0) rotate(360deg) scale(1); }
}
@keyframes land {
  0%   { transform: scale(1.35) rotate(-9deg); }
  60%  { transform: scale(.94) rotate(3deg); }
  100% { transform: scale(1) rotate(0); }
}
@media (prefers-reduced-motion: reduce) {
  .dice.rolling b, .dice.landed b { animation: none; }
}
.prompt { text-align: center; min-height: 20px; }
.prompt strong { color: var(--acc); }
.actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.err { color: #ff8b8b; font-size: 13px; text-align: center; min-height: 16px; }

.tabs { display: flex; gap: 6px; }
.tab { flex: 1; border-radius: 8px 8px 0 0; }
.mute { flex: 0 0 auto; border-radius: 8px 8px 0 0; padding: 8px 10px; font-size: 15px; line-height: 1; }
.tab.active { background: var(--panel); border-bottom-color: var(--panel); color: var(--acc); }
.tabbody {
  background: var(--panel); border: 1px solid var(--line); border-radius: 0 10px 10px 10px;
  padding: 10px; max-height: 46vh; overflow: auto;
}
.log { display: grid; gap: 6px; font-size: 13px; }
.log div { color: var(--dim); border-bottom: 1px solid #232735; padding-bottom: 5px; }
.log div:first-child { color: var(--ink); }

.quitzone { display: grid; }
.quit {
  width: 100%; background: transparent; color: var(--dim);
  border-color: #3a2630; font-size: 13px; padding: 9px 12px;
}
.quit:hover:not(:disabled) { background: #2a1a20; color: #ffb4b4; border-color: #7a2230; }
.quit.armed {
  background: #7a2230; border-color: #c0455a; color: #ffe3e3; font-weight: 700;
  animation: warn 1s ease-in-out infinite;
}
@keyframes warn { 0%, 100% { opacity: 1; } 50% { opacity: .72; } }
@media (prefers-reduced-motion: reduce) { .quit.armed { animation: none; } }

.prow {
  display: grid; grid-template-columns: 1fr auto; gap: 6px; align-items: center;
  padding: 6px 0; border-bottom: 1px solid #232735;
}
.prow small { color: var(--dim); }
.prow .btns { display: flex; gap: 4px; }
.prow button { padding: 4px 8px; font-size: 12px; }
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; }
.tradecols { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.tradecols h4 { margin: 6px 0 4px; font-size: 13px; color: var(--dim); }
.tradecols label { display: flex; gap: 6px; align-items: flex-start; font-size: 12px; padding: 2px 0; }
.tradecols input[type=checkbox] { width: auto; }
