:root {
  --bg: #0f1a17;
  --bg-2: #16251f;
  --panel: #1c2e27;
  --line: #2b4339;
  --ink: #f1ece0;
  --ink-2: #a9b8ae;
  --accent: #f2c44d;
  --accent-ink: #1b1408;
  --good: #7fd49b;
  --bad: #ff8a7a;
  --cell: #22382f;
  --DB: #3a6f8f;
  --TB: #2f5fb3;
  --DO: #a8566f;
  --TO: #c0563a;
  --tile: #f3e6c4;
  --tile-ink: #2a2116;
  --radius: 10px;
  --board: min(100vw - 16px, 620px);
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
/* Själva sidan scrollar. body får inte bli en egen scrollbehållare, för då fastnar hjul och svep där. */
html { overflow-x: hidden; overscroll-behavior: none; scrollbar-gutter: stable; }
body {
  font: 16px/1.45 Rubik, system-ui, -apple-system, "Segoe UI", sans-serif;
  min-height: 100dvh;
  overflow-x: clip;
  -webkit-tap-highlight-color: transparent;
}
button, input, select { font: inherit; color: inherit; }
h1, h2, h3 { font-family: Fraunces, Georgia, serif; font-weight: 600; margin: 0; }
h1 { font-size: 1.4rem; }
h2 { font-size: 1.05rem; color: var(--ink-2); margin: 0 0 8px; }
.muted { color: var(--ink-2); }
.center { text-align: center; }
.row { display: flex; gap: 8px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.stack.center { align-items: center; }

/* ---------- Knappar ---------- */
.btn {
  border: 1px solid var(--line); background: var(--panel); border-radius: var(--radius);
  padding: 10px 14px; cursor: pointer; transition: transform .08s, background .15s;
  display: inline-flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
}
.btn:active:not(:disabled) { transform: scale(.97); }
.btn:disabled { opacity: .4; cursor: default; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; font-weight: 700; }
.btn.danger { border-color: #6d2e27; color: var(--bad); }
.btn.ghost { background: transparent; }
.btn.big { padding: 14px 18px; font-size: 1.05rem; width: 100%; }
.btn small { font-weight: 400; font-size: .78rem; opacity: .8; }
.btn.duo.on { background: #6a4cc9; border-color: #8f74ff; color: #fff; }
.icon-btn { background: none; border: 0; font-size: 1.4rem; padding: 6px 10px; cursor: pointer; color: var(--ink); }

/* ---------- Start ---------- */
.home { max-width: 460px; margin: 0 auto; padding: 48px 20px; display: flex; flex-direction: column; gap: 36px; }
.logo { text-align: center; }
.logo-tiles { display: flex; justify-content: center; gap: 5px; }
.logo-tiles .tile { width: min(40px, 10vw); height: min(40px, 10vw); font-size: min(1.4rem, 6vw); position: static; }
.logo-tiles { gap: 4px; }
.tagline { color: var(--ink-2); margin: 14px 0 0; font-family: Fraunces, serif; font-size: 1.1rem; }
.loading { display: grid; place-items: center; gap: 14px; min-height: 80dvh; color: var(--ink-2); }
.spinner { width: 36px; height: 36px; border: 3px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Inställningar ---------- */
.setup { max-width: 640px; margin: 0 auto; padding: 12px 16px 48px; display: flex; flex-direction: column; gap: 18px; }
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 4px;
  margin: -12px -16px 0; padding: max(6px, env(safe-area-inset-top)) 8px 6px;
  background: color-mix(in srgb, var(--bg) 96%, transparent); -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.topbar h1 { min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .icon-btn { flex: none; width: 44px; height: 44px; padding: 0; border-radius: 12px; }
@media (hover: hover) { .topbar .icon-btn:hover { background: var(--panel); } }
.choices { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px; }
.choice { border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; cursor: pointer; display: flex; flex-direction: column; gap: 2px; background: var(--bg-2); }
.choice input { position: absolute; opacity: 0; pointer-events: none; }
.choice small { color: var(--ink-2); font-size: .8rem; }
.choice.on { border-color: var(--accent); background: #2a2a17; }
.text, select { background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; width: 100%; }
select { width: auto; }
.switch { display: flex; gap: 10px; align-items: center; padding: 6px 0; cursor: pointer; }
.switch input { width: 20px; height: 20px; accent-color: var(--accent); }
.card { text-align: left; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; display: flex; flex-direction: column; cursor: pointer; }
.card small { color: var(--ink-2); }
.champion { font-family: Fraunces, serif; font-size: 1.4rem; text-align: center; padding: 12px; border: 1px solid var(--accent); border-radius: var(--radius); }
.standings { width: 100%; border-collapse: collapse; font-size: .9rem; }
.standings th, .standings td { padding: 6px 4px; border-bottom: 1px solid var(--line); text-align: right; }
.standings th:nth-child(2), .standings td:nth-child(2) { text-align: left; }
.match { border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; margin-bottom: 8px; background: var(--bg-2); }
.match.locked { opacity: .45; }
.match .win { color: var(--accent); font-weight: 700; }
.games { display: flex; gap: 12px; flex-wrap: wrap; color: var(--ink-2); font-size: .85rem; margin-top: 4px; }
.prose ul { padding-left: 20px; }
.prose li { margin-bottom: 6px; }

/* ---------- Spel ---------- */
.game { max-width: calc(var(--board) + 16px); margin: 0 auto; padding: 6px 8px 24px; display: flex; flex-direction: column; gap: 8px; touch-action: manipulation; }
.game-top { display: flex; align-items: center; gap: 4px; }
.players { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; flex: 1; }
.player { background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 6px 10px; display: grid; grid-template-columns: 1fr auto; align-items: center; }
.player.active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.pname { font-size: .85rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pname small { color: var(--ink-2); }
.pscore { font-family: Fraunces, serif; font-size: 1.35rem; font-weight: 800; grid-row: span 2; }
.token { font-size: .72rem; color: var(--ink-2); }
.token.on { color: #b9a6ff; }
.info { display: flex; gap: 14px; font-size: .8rem; color: var(--ink-2); padding: 0 4px; }
.gold-count { color: var(--accent); }
.epic-count { color: #c9a8ff; }

.board {
  width: var(--board); aspect-ratio: 1; margin: 0 auto; display: grid;
  grid-template-columns: repeat(15, minmax(0, 1fr)); grid-template-rows: repeat(15, minmax(0, 1fr)); gap: 2px; padding: 3px; background: var(--line); border-radius: 8px;
  user-select: none;
}
.cell {
  background: var(--cell); border-radius: 3px; position: relative; display: grid; place-items: center;
  font-size: calc(var(--board) / 15 * .3); font-weight: 700; color: rgba(255,255,255,.75); letter-spacing: -.02em;
}
.cell.prem-DB { background: var(--DB); }
.cell.prem-TB { background: var(--TB); }
.cell.prem-DO { background: var(--DO); }
.cell.prem-TO { background: var(--TO); }
.cell.prem-START { color: var(--accent); font-size: calc(var(--board) / 15 * .55); }

.tile {
  position: absolute; inset: 0; border-radius: 4px; background: var(--tile); color: var(--tile-ink);
  display: grid; place-items: center; font-weight: 700; box-shadow: 0 1px 0 rgba(0,0,0,.35);
  touch-action: none;
}
.tile .l { font-size: 1em; line-height: 1; }
.tile .v { position: absolute; right: 7%; bottom: 3%; font-size: .38em; font-weight: 500; }
.cell .tile { font-size: calc(var(--board) / 15 * .58); }
.tile.blank .l { color: #8b6f3e; }
.tile.gold { background: linear-gradient(145deg, #ffe89a, #f2c44d 45%, #c9952b); color: #3a2604; }
.tile.epic {
  background: linear-gradient(135deg, #e7d4ff, #a77bff 40%, #6fd3ff 75%, #c49bff);
  background-size: 200% 200%; color: #23103f; animation: shimmer 4s ease-in-out infinite;
  box-shadow: 0 0 8px rgba(176, 130, 255, .7);
}
@keyframes shimmer { 0%, 100% { background-position: 0% 50%; } 50% { background-position: 100% 50%; } }
.tile.pending { background: #fff4d6; outline: 2px solid var(--accent); cursor: grab; }
.tile.pending.gold { outline-color: #fff; }

.rack {
  display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 6px; width: min(var(--board), 440px); margin: 2px auto 0;
  min-height: calc(min(var(--board), 440px) / 7);
}
.rack .tile, .rack .slot { position: relative; aspect-ratio: 1; font-size: calc(min(var(--board), 440px) / 7 * .52); cursor: grab; }
.rack .slot { border: 1px dashed var(--line); border-radius: 6px; }
.rack .tile.selected { transform: translateY(-6px); box-shadow: 0 0 0 3px var(--accent), 0 6px 10px rgba(0,0,0,.4); }
.rack .tile.swap { transform: translateY(-6px); box-shadow: 0 0 0 3px var(--bad); }
.rack.covered .tile { visibility: hidden; }
.tile.ghost { position: fixed; width: 54px; height: 54px; inset: auto; transform: translate(-50%, -70%); z-index: 50; font-size: 30px; pointer-events: none; box-shadow: 0 10px 20px rgba(0,0,0,.5); }
.tile.pick { position: relative; aspect-ratio: 1; font-size: 1.3rem; border: 0; cursor: pointer; }

.preview { text-align: center; min-height: 1.5em; font-size: .9rem; }
.preview.good { color: var(--good); }
.preview.bad { color: var(--bad); }
.controls { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; }
.controls .btn { min-width: 70px; }
.log-wrap { font-size: .85rem; color: var(--ink-2); }
.log-wrap summary { cursor: pointer; padding: 4px; }
.log { margin: 4px 0; padding-left: 24px; max-height: 220px; overflow: auto; }
.log .pts { color: var(--good); }

.handoff {
  position: fixed; inset: 0; background: rgba(8, 14, 12, .96); display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 12px; z-index: 40; text-align: center;
}
.handoff h2 { font-size: 2rem; color: var(--ink); }

/* ---------- Modal och toast ---------- */
.modal-back { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: grid; place-items: center; z-index: 60; padding: 16px; }
.modal { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 20px; width: min(420px, 100%); }
.modal h3 { margin-bottom: 12px; }
.modal .final { font-family: Fraunces, serif; font-size: 1.3rem; margin: 0; }
.letter-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 6px; }
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); opacity: 0; transition: .25s;
  background: #0b1310; border: 1px solid var(--line); padding: 10px 16px; border-radius: 999px; z-index: 70; max-width: 92vw; text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (min-width: 900px) {
  .game { padding-top: 16px; }
}
@media (prefers-reduced-motion: reduce) {
  .tile.epic { animation: none; }
  * { transition: none !important; }
}

/* =====================================================================
   Teman, brickstilar och 3D (nivåbelöningar). Allt är utseende.
   ===================================================================== */
:root {
  --frame: #2b4339; --frame-edge: #16231d; --cell-shade: rgba(0, 0, 0, .45);
  --tile-top: #fbf1d6; --tile-bot: #ecdcb2; --tile-edge: #b8a072; --tile-val: #7a5a2a;
}
:root[data-theme="natt"] {
  --bg: #0b1020; --bg-2: #121a30; --panel: #18213b; --line: #2a3658; --ink-2: #a5b0cc;
  --cell: #19223e; --frame: #2a3658; --frame-edge: #0e1426;
  --DB: #2f6f9a; --TB: #3651c4; --DO: #7c4fa8; --TO: #b0476b;
}
:root[data-theme="sand"] {
  --bg: #efe6d2; --bg-2: #f7f0e1; --panel: #fff8ea; --line: #d9c9a6; --ink: #2e2617; --ink-2: #6d5f45;
  --cell: #e4d6b6; --frame: #c9b48a; --frame-edge: #9c8458; --cell-shade: rgba(90, 60, 20, .25);
  --DB: #8fb6c9; --TB: #5e8bc2; --DO: #d9a0a6; --TO: #d7774f; --accent-ink: #1b1408;
  color-scheme: light;
}
:root[data-theme="sand"] .cell { color: rgba(40, 30, 10, .65); }
:root[data-theme="marmor"] {
  --bg: #15171a; --bg-2: #1d2024; --panel: #24282d; --line: #3a3f46; --ink-2: #b4b9bf;
  --cell: linear-gradient(135deg, #e9e6e0, #d6d2ca); --frame: #8c7a4c; --frame-edge: #4d4228; --cell-shade: rgba(0, 0, 0, .25);
  --DB: #9fb8c6; --TB: #6f93b7; --DO: #c9a3a8; --TO: #c48a5c;
}
:root[data-theme="marmor"] .cell { background: linear-gradient(135deg, #e9e6e0, #d3cec5); color: rgba(40, 34, 20, .55); }
:root[data-theme="marmor"] .cell[class*="prem-"] { color: rgba(255, 255, 255, .9); }
:root[data-theme="marmor"] .cell.prem-DB { background: var(--DB); } :root[data-theme="marmor"] .cell.prem-TB { background: var(--TB); }
:root[data-theme="marmor"] .cell.prem-DO { background: var(--DO); } :root[data-theme="marmor"] .cell.prem-TO { background: var(--TO); }
:root[data-theme="marmor"] .cell.prem-START { background: linear-gradient(135deg, #e9e6e0, #d3cec5); color: #a8862e; }
:root[data-theme="norrsken"] {
  --bg: #05080d; --bg-2: #0b1119; --panel: #101823; --line: #1d2b3a; --ink-2: #9fb3c3;
  --cell: #0c141e; --frame: #16303a; --frame-edge: #071017;
  --DB: #1f7a6b; --TB: #1f9a8a; --DO: #6b3fa0; --TO: #a03f9a;
}
:root[data-theme="norrsken"] body {
  background: radial-gradient(ellipse 80% 40% at 30% 0%, rgba(60, 220, 160, .14), transparent 70%),
    radial-gradient(ellipse 70% 40% at 80% 5%, rgba(150, 90, 255, .14), transparent 70%), var(--bg);
}

:root[data-theme="koppar"] {
  --bg: #171210; --bg-2: #211916; --panel: #2a201b; --line: #4a382c; --ink-2: #c2b1a4; --accent: #e8a860;
  --cell: #2c221c; --frame: #7a4f30; --frame-edge: #3d2616;
  --DB: #4f8a80; --TB: #2f6f73; --DO: #b5683f; --TO: #d0542c;
}
:root[data-theme="vulkan"] {
  --bg: #0e0b0b; --bg-2: #181313; --panel: #211a19; --line: #3d2f2c; --ink-2: #b9aaa5; --accent: #ff9a3d;
  --cell: #1f1a19; --frame: #3a2a26; --frame-edge: #120c0b;
  --DB: #8a5a2e; --TB: #b5762a; --DO: #b83c2a; --TO: #e8501f;
}
:root[data-theme="vulkan"] body { background: radial-gradient(ellipse 90% 35% at 50% 100%, rgba(255, 90, 30, .16), transparent 70%), var(--bg); }
:root[data-theme="djuphav"] {
  --bg: #04121c; --bg-2: #081c2a; --panel: #0d2536; --line: #1a3d52; --ink-2: #9dbccb; --accent: #56e0d0; --accent-ink: #04201d;
  --cell: #0a2130; --frame: #123f55; --frame-edge: #05202e;
  --DB: #1c7a94; --TB: #1fa7b0; --DO: #5a4fb8; --TO: #b0408f;
}
:root[data-theme="djuphav"] body { background: radial-gradient(ellipse 80% 40% at 50% 0%, rgba(60, 200, 210, .13), transparent 70%), var(--bg); }
:root[data-theme="guldalder"] {
  --bg: #0b0a08; --bg-2: #15130e; --panel: #1d1a13; --line: #4a3f22; --ink-2: #c2b68f; --accent: #ffd766;
  --cell: #17150f; --frame: #b08f35; --frame-edge: #5a4716;
  --DB: #6e6135; --TB: #8f7a33; --DO: #a8701f; --TO: #d49a1c;
}

:root[data-tiles="malakit"] { --tile-top: #2f7d62; --tile-bot: #17523f; --tile-edge: #0b3022; --tile-ink: #effae9; --tile-val: #b9e6cd; }
:root[data-tiles="barnsten"] { --tile-top: #f6bf5c; --tile-bot: #d98c26; --tile-edge: #8f5512; --tile-ink: #2c1a05; --tile-val: #55330a; }
:root[data-tiles="mansten"] { --tile-top: #eef3fb; --tile-bot: #bcc9de; --tile-edge: #7d8ca6; --tile-ink: #1c2c52; --tile-val: #3b4d78; }
:root[data-tiles="valnot"] { --tile-top: #8a5a36; --tile-bot: #5e3a20; --tile-edge: #3a2210; --tile-ink: #f6e6c8; --tile-val: #e8c98f; }
:root[data-tiles="porslin"] { --tile-top: #ffffff; --tile-bot: #e9eef5; --tile-edge: #a9b6c8; --tile-ink: #1d4f9c; --tile-val: #3f6db3; }
:root[data-tiles="obsidian"] { --tile-top: #3a3a42; --tile-bot: #121216; --tile-edge: #000; --tile-ink: #f2c44d; --tile-val: #c9a24a; }

/* ---------- Bräde ---------- */
.board-wrap { padding: 2px 0 14px; }
.board {
  background: var(--frame);
  border-radius: 10px;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, .08),
    0 3px 0 var(--frame-edge), 0 7px 0 -1px var(--frame-edge),
    0 26px 40px -14px rgba(0, 0, 0, .75);
}
.cell { box-shadow: inset 0 1px 2px var(--cell-shade), inset 0 -1px 0 rgba(255, 255, 255, .04); }
.cell[class*="prem-"]:not(.prem-START) {
  background-image: linear-gradient(160deg, rgba(255, 255, 255, .18), transparent 55%);
}

/* ---------- 3D: brickor ---------- */
.tile {
  background: linear-gradient(160deg, var(--tile-top), var(--tile-bot));
  color: var(--tile-ink);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, .65), inset 0 -2px 0 rgba(0, 0, 0, .12),
    0 2px 0 var(--tile-edge), 0 4px 6px -1px rgba(0, 0, 0, .45);
}
.tile .v { color: var(--tile-val); }
.cell .tile { inset: 1px 1px 2px; }
.tile.gold {
  background: linear-gradient(150deg, #fff1b0, #f2c44d 45%, #c9952b);
  color: #3a2604;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .8), inset 0 -2px 0 rgba(120, 70, 0, .25), 0 2px 0 #8d6a1a, 0 4px 8px -1px rgba(0, 0, 0, .5), 0 0 10px rgba(242, 196, 77, .25);
}
.tile.gold .v, .tile.epic .v { color: inherit; opacity: .8; }
.tile.epic {
  background: linear-gradient(135deg, #e7d4ff, #a77bff 40%, #6fd3ff 75%, #c49bff);
  background-size: 200% 200%;
  color: #23103f;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .8), inset 0 -2px 0 rgba(40, 0, 90, .25), 0 2px 0 #5a3aa8, 0 4px 8px -1px rgba(0, 0, 0, .5), 0 0 14px rgba(176, 130, 255, .55);
}
.tile.blank .l { color: color-mix(in srgb, var(--tile-ink) 55%, transparent); }
.tile.pending { background: linear-gradient(160deg, #fffaf0, #fbe9bd); color: #2a2116; outline: 2px solid var(--accent); outline-offset: -1px; }
.cell .tile.pending { transform: translateY(-2px) scale(1.04); box-shadow: 0 4px 0 var(--tile-edge), 0 10px 14px -2px rgba(0, 0, 0, .55); }
.tile.drop { animation: drop .45s cubic-bezier(.2, 1.4, .4, 1) backwards; }
@keyframes drop { from { transform: translateY(-14px) scale(1.3); opacity: 0; } }
.rack .tile { transition: transform .15s ease, box-shadow .15s ease; }
@media (hover: hover) { .rack .tile:hover { transform: translateY(-3px); } }
.rack .tile.selected { transform: translateY(-8px) rotate(-2deg); }
.tile.ghost { transform: translate(-50%, -70%) rotate(-4deg) scale(1.05); }

@media (prefers-reduced-motion: reduce) {
  .tile.drop { animation: none; }
}

/* ---------- Startsidan: nivårad och guideknapp ---------- */
.xp { display: flex; align-items: center; gap: 10px; width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 14px; background: var(--bg-2); color: inherit; text-align: left; cursor: pointer; }
.xp-badge { width: 38px; height: 38px; flex: none; border-radius: 50%; display: grid; place-items: center;
  background: radial-gradient(circle at 35% 30%, #fff1b0, var(--accent) 55%, #a87418); color: var(--accent-ink);
  font: 800 18px/1 Fraunces, Georgia, serif; box-shadow: 0 2px 0 #8d6a1a; }
.xp-body { flex: 1; min-width: 0; display: grid; gap: 4px; }
.xp-text { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.xp-text b { color: var(--ink); }
.xp-next { font-size: 11.5px; font-weight: 700; color: var(--accent); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar { display: block; height: 8px; border-radius: 999px; background: rgba(255, 255, 255, .1); overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 999px; background: linear-gradient(90deg, color-mix(in srgb, var(--accent) 78%, #000), var(--accent)); transition: width .8s cubic-bezier(.2, .8, .2, 1); }
:root[data-theme="sand"] .bar { background: rgba(0, 0, 0, .1); }
.row.two { display: grid; grid-template-columns: 1fr 1fr; }
.guidebtn { display: grid; grid-template-columns: 44px minmax(0, 1fr); gap: 12px; align-items: center; text-align: left; padding: 12px 14px; border-radius: 14px; border: 1px dashed var(--line); background: transparent; color: inherit; cursor: pointer; }
.guidebtn.first { border: 0; background: linear-gradient(135deg, #2c2a14, #3d3412); box-shadow: inset 0 0 0 1.5px var(--accent); }
:root[data-theme="sand"] .guidebtn.first { background: #fff3cf; }
.guidebtn small { display: block; color: var(--ink-2); font-size: .8rem; margin-top: 2px; }
.gb-icon { width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; background: var(--accent); color: var(--accent-ink); font: 800 22px/1 Fraunces, serif; }

/* ---------- Profil ---------- */
.card-sec { background: var(--bg-2); border: 1px solid var(--line); border-radius: 14px; padding: 14px; }
.card-sec h2 { margin-bottom: 10px; }
.note { font-size: .82rem; margin: 10px 0 0; }
.profile { gap: 14px; }
.pf-top {
  position: sticky; top: 0; z-index: 20; margin: -12px -16px 0; padding: max(6px, env(safe-area-inset-top)) 8px 0;
  background: color-mix(in srgb, var(--bg) 96%, transparent); -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.pf-top .topbar { position: static; margin: 0; padding: 0; background: none; border: 0; -webkit-backdrop-filter: none; backdrop-filter: none; }
.pf-tabs { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; }
.pf-tabs::-webkit-scrollbar { display: none; }
.pf-tab { flex: 1 0 auto; min-height: 44px; padding: 0 10px; border: 0; border-bottom: 2px solid transparent; background: none; color: var(--ink-2); font-size: .88rem; font-weight: 700; cursor: pointer; transition: color .15s, border-color .15s; }
.pf-tab.on { color: var(--ink); border-bottom-color: var(--accent); }
.pf-tab:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; border-radius: 8px; }
@media (hover: hover) { .pf-tab:hover { color: var(--ink); } }
.pf-panel { display: flex; flex-direction: column; gap: 12px; animation: rise .25s ease; }
.pf-hero {
  display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 16px; align-items: center; padding: 18px 16px; border-radius: 18px;
  border: 1px solid color-mix(in srgb, var(--accent) 35%, var(--line));
  background: linear-gradient(135deg, color-mix(in srgb, var(--accent) 16%, var(--panel)), var(--bg-2) 70%);
}
.pf-ring {
  width: 84px; height: 84px; border-radius: 50%; display: grid; place-items: center;
  background: conic-gradient(var(--accent) var(--fill), color-mix(in srgb, var(--ink) 14%, transparent) 0);
}
.pf-ring span { width: 68px; height: 68px; border-radius: 50%; display: grid; place-items: center; background: var(--bg-2); color: var(--accent); font: 800 32px/1 Fraunces, Georgia, serif; }
.pf-who { display: grid; gap: 6px; min-width: 0; }
.pf-name { width: 100%; min-width: 0; margin-left: -6px; padding: 2px 6px; border: 1px solid transparent; border-radius: 8px; background: none; font-size: 1.15rem; font-weight: 700; }
.pf-name:hover, .pf-name:focus { border-color: var(--line); background: var(--bg-2); outline: none; }
.pf-title { font-family: Fraunces, serif; font-size: .98rem; color: var(--accent); }
:root[data-theme="sand"] .pf-title, :root[data-theme="sand"] .pf-ring span { color: #8a6418; }
.pf-kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.pf-kpi { display: grid; gap: 2px; padding: 10px 6px; text-align: center; border: 1px solid var(--line); border-radius: 12px; background: var(--bg-2); }
.pf-kpi b { font: 800 1.15rem/1.2 Fraunces, Georgia, serif; font-variant-numeric: tabular-nums; }
.pf-kpi small { color: var(--ink-2); font-size: .7rem; }
@media (max-width: 400px) { .pf-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.pf-reward { display: grid; gap: 8px; }
.pf-reward .eyebrow { color: var(--accent); }
:root[data-theme="sand"] .pf-reward .eyebrow { color: #8a6418; }
.pf-more { border: 1px solid var(--line); border-radius: 14px; background: var(--bg-2); padding: 0 14px; }
.pf-more summary { padding: 12px 0; font-weight: 700; cursor: pointer; }
.pf-more[open] { padding-bottom: 14px; }
.pf-more .note { margin: 0 0 10px; }
.pf-empty { margin: 0; padding: 12px 14px; border-radius: 12px; background: color-mix(in srgb, var(--accent) 12%, transparent); }
.pf-wins { margin: 0; padding: 0; list-style: none; display: grid; gap: 12px; font-size: .9rem; }
.pf-wins li { display: grid; grid-template-columns: minmax(0, 1fr) auto 3.2em; gap: 4px 10px; align-items: baseline; }
.pf-wins b { text-align: right; font-variant-numeric: tabular-nums; }
.pf-wins small { font-variant-numeric: tabular-nums; }
.pf-wins .bar { grid-column: 1 / -1; height: 6px; }
.pf-achsum { display: grid; gap: 8px; }
.pf-achsum-top { display: flex; align-items: baseline; gap: 6px; }
.pf-achsum-top b { font: 800 1.3rem/1.2 Fraunces, Georgia, serif; }
.lvl-badge { width: 92px; height: 92px; border-radius: 50%; display: grid; place-items: center; margin: 0 auto;
  background: radial-gradient(circle at 35% 30%, #fff3c4, var(--accent) 55%, #a87418); color: var(--accent-ink);
  font: 800 44px/1 Fraunces, serif; box-shadow: 0 0 0 4px #3a2a0e, 0 0 36px rgba(242, 196, 77, .6); animation: lvlpop .7s cubic-bezier(.2, 1.6, .4, 1) backwards; }
@keyframes lvlpop { 0% { transform: scale(0) rotate(-30deg); } }
.lvl-panel .eyebrow { color: var(--accent); }
.eyebrow { font-size: .75rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-2); }
.gifts { margin: 0; padding: 0; list-style: none; display: grid; gap: 8px; text-align: left; }
.gifts li { display: flex; gap: 10px; align-items: center; padding: 8px 10px; border-radius: 10px; background: rgba(242, 196, 77, .1); }
.gifts li i { font-style: normal; color: var(--accent); }
.look { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.look-opt { position: relative; display: grid; gap: 2px; align-content: start; justify-items: start; text-align: left; padding: 8px 8px 10px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel); color: inherit; cursor: pointer; }
.look-opt.on { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.look-opt.on::after { content: "✓"; position: absolute; top: 14px; right: 14px; width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; background: var(--accent); color: var(--accent-ink); font-size: 13px; font-weight: 800; }
.look-opt:disabled { cursor: default; }
.look-opt:disabled .swatch { filter: grayscale(.8); opacity: .45; }
.look-opt:disabled b { color: var(--ink-2); }
.look-opt small { color: var(--ink-2); font-size: .74rem; }
.swatch { width: 100%; height: 56px; border-radius: 8px; margin-bottom: 6px; }
.sw-skog { background: linear-gradient(90deg, #22382f 50%, #c0563a 50% 62%, #3a6f8f 62%); }
.sw-natt { background: linear-gradient(90deg, #19223e 50%, #b0476b 50% 62%, #3651c4 62%); }
.sw-sand { background: linear-gradient(90deg, #e4d6b6 50%, #d7774f 50% 62%, #5e8bc2 62%); }
.sw-marmor { background: linear-gradient(90deg, #e3dfd8 50%, #c48a5c 50% 62%, #8c7a4c 62%); }
.sw-norrsken { background: linear-gradient(90deg, #0c141e 40%, #1f9a8a 40% 60%, #6b3fa0 60%); }
.sw-koppar { background: linear-gradient(90deg, #2c221c 50%, #d0542c 50% 62%, #2f6f73 62%); }
.sw-vulkan { background: linear-gradient(90deg, #1f1a19 50%, #e8501f 50% 62%, #b5762a 62%); }
.sw-djuphav { background: linear-gradient(90deg, #0a2130 50%, #b0408f 50% 62%, #1fa7b0 62%); }
.sw-guldalder { background: linear-gradient(90deg, #17150f 50%, #d49a1c 50% 62%, #8f7a33 62%); }
.sw-malakit { background: linear-gradient(160deg, #2f7d62, #17523f); }
.sw-barnsten { background: linear-gradient(160deg, #f6bf5c, #d98c26); }
.sw-mansten { background: linear-gradient(160deg, #eef3fb, #bcc9de); box-shadow: inset 0 0 0 1px #7d8ca6; }
.sw-elfenben { background: linear-gradient(160deg, #fbf1d6, #ecdcb2); }
.sw-valnot { background: linear-gradient(160deg, #8a5a36, #5e3a20); }
.sw-porslin { background: linear-gradient(160deg, #fff, #e9eef5); box-shadow: inset 0 0 0 1px #a9b6c8; }
.sw-obsidian { background: linear-gradient(160deg, #3a3a42, #121216); box-shadow: inset 0 0 0 1px #f2c44d55; }
.stats { display: grid; margin: 0; font-size: .9rem; }
.stats > div { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-top: 1px solid var(--line); }
.stats > div:first-child { border-top: 0; padding-top: 0; }
.stats > div:last-child { padding-bottom: 0; }
.stats dt { color: var(--ink-2); } .stats dd { margin: 0; text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.ladder { margin: 0; padding: 0; list-style: none; display: grid; gap: 6px; }
.ladder li { display: grid; grid-template-columns: 34px minmax(0, 1fr) auto; gap: 10px; align-items: center; padding: 6px 8px; border-radius: 12px; background: rgba(255, 255, 255, .03); }
.lr-n { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; background: var(--panel); color: var(--ink-2); font: 700 15px/1 Fraunces, serif; }
.lr-g { display: flex; flex-wrap: wrap; gap: 6px; }
.lr-chip { display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px; border-radius: 999px; background: var(--panel); font-size: 12.5px; font-weight: 700; }
.lr-chip i { font-style: normal; color: var(--accent); }
.lr-s { font-size: 12px; font-weight: 700; color: var(--ink-2); }
.ladder li.got { opacity: .6; } .ladder li.got .lr-n { background: var(--accent); color: var(--accent-ink); }
.ladder li.next { background: rgba(242, 196, 77, .12); box-shadow: inset 0 0 0 1.5px var(--accent); } .ladder li.next .lr-s { color: var(--accent); }
.pill { margin-left: auto; padding: 4px 10px; border-radius: 999px; background: var(--panel); font-weight: 700; font-variant-numeric: tabular-nums; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.nu-head { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; }
.nu-head small { font-variant-numeric: tabular-nums; }
.chip { padding: 6px 12px; border-radius: 999px; border: 1px solid var(--line); background: transparent; color: inherit; cursor: pointer; font-size: .85rem; }
.chip.on { background: var(--accent); color: var(--accent-ink); border-color: transparent; font-weight: 700; }
.next-up, .ach-list { margin: 0; padding: 0; list-style: none; display: grid; gap: 8px; }
.next-up { gap: 14px; }
.next-up li { display: grid; gap: 4px; }
.next-up small { color: var(--ink-2); }
.ach-list li { display: grid; grid-template-columns: 34px minmax(0, 1fr) 76px; gap: 10px; align-items: center; padding: 10px; border-radius: 12px; background: var(--bg-2); border: 1px solid var(--line); }
.ach-list li.done { border-color: color-mix(in srgb, var(--accent) 60%, transparent); }
.ach-text { display: grid; gap: 3px; } .ach-text small { color: var(--ink-2); font-size: .8rem; }
.ach-date { color: var(--ink-2); font-size: .75rem; font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.medal { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; background: var(--panel); color: var(--ink-2); font-size: 18px; }
.ach-list li.done .medal, .new-ach .medal { background: radial-gradient(circle at 35% 30%, #fff1b0, var(--accent) 60%, #a87418); color: #3a2604; }

/* ---------- Resultat: XP och nya prestationer ---------- */
.xpgain { width: 100%; display: grid; gap: 8px; padding: 12px 14px; border-radius: 14px; background: var(--bg); text-align: left; }
.xg-head { display: flex; align-items: center; gap: 10px; }
.xg-title { flex: 1; min-width: 0; font-size: 13px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.xg-gain { font: 800 22px/1 Fraunces, serif; color: var(--accent); }
.xg-bar { position: relative; height: 10px; }
.xg-bar > i { position: absolute; inset: 0 auto 0 0; }
.xg-bar > .xg-old { background: #8d6a1a; transition: none; }
.xg-bar > .xg-new { background: linear-gradient(90deg, var(--accent), #fff3c4); box-shadow: 0 0 10px rgba(242, 196, 77, .7); }
.xg-parts { margin: 0; padding: 0; list-style: none; display: grid; gap: 2px; font-size: .82rem; color: var(--ink-2); }
.xg-parts li { display: flex; justify-content: space-between; } .xg-parts b { color: var(--ink); font-variant-numeric: tabular-nums; }
.new-ach { width: 100%; text-align: left; display: grid; gap: 8px; }
.new-ach ul { margin: 0; padding: 0; list-style: none; display: grid; gap: 6px; }
.new-ach li { display: grid; grid-template-columns: 34px minmax(0, 1fr); gap: 10px; align-items: center; animation: rise .4s ease backwards; }
.new-ach li span:last-child { display: grid; } .new-ach small { color: var(--ink-2); }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }
.modal { max-height: calc(100dvh - 32px); overflow: auto; }

/* ---------- Så spelar du ---------- */
.help h3 { margin: 16px 0 8px; font-size: 1.05rem; }
.help-list { margin: 0; padding: 0; list-style: none; display: grid; gap: 10px; }
.help-list li { display: grid; grid-template-columns: 52px minmax(0, 1fr); gap: 12px; align-items: center; font-size: .92rem; }
.hm { width: 40px; height: 40px; border-radius: 8px; display: grid; place-items: center; background: var(--panel); font-weight: 800; justify-self: center; }
.hm.prem-DB { background: var(--DB); } .hm.prem-TB { background: var(--TB); } .hm.prem-DO { background: var(--DO); } .hm.prem-TO { background: var(--TO); }
.hm.prem-START { color: var(--accent); background: var(--cell); }
.hm.duo { background: #6a4cc9; color: #fff; } .hm.blitz { background: var(--accent); color: var(--accent-ink); }
.hm-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 3px; } .hm-pair .hm { width: 24px; height: 40px; font-size: 10px; border-radius: 6px; }
.tile.mini { position: relative; display: inline-grid; width: 40px; height: 40px; font-size: 22px; justify-self: center; vertical-align: middle; }
.help-modal { max-width: 520px; }
.modal-back .modal:has(.help-modal) { width: min(560px, 100%); }

/* ---------- Guiden ---------- */
.g-ring { position: fixed; z-index: 80; border-radius: 12px; pointer-events: none; opacity: 0;
  box-shadow: 0 0 0 3px var(--accent), 0 0 24px 6px rgba(242, 196, 77, .5), 0 0 0 200vmax rgba(4, 8, 7, .55);
  transition: left .3s ease, top .3s ease, width .3s ease, height .3s ease, opacity .2s; }
.g-ring.soft { box-shadow: 0 0 0 3px var(--accent), 0 0 22px 6px rgba(242, 196, 77, .45), 0 0 0 200vmax rgba(4, 8, 7, .22); }
.g-box { position: fixed; z-index: 85; display: grid; gap: 8px; padding: 14px 16px 16px; border-radius: 16px;
  background: #fff8e8; color: #2c2a26; box-shadow: 0 18px 40px rgba(0, 0, 0, .5); }
.g-box.in { animation: rise .3s cubic-bezier(.2, .8, .2, 1); }
.g-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.g-head .eyebrow, .g-show .eyebrow { color: #8a6418; }
.g-acts { display: flex; gap: 14px; }
.g-quit, .g-hide { border: 0; background: none; padding: 4px 0; color: #6e624c; font-size: 12.5px; font-weight: 700; text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }
.g-title { font: 600 21px/1.15 Fraunces, Georgia, serif; color: #14201b; }
.g-text { font-size: 15px; line-height: 1.45; } .g-text b { color: #14201b; }
.g-more { border: 0; background: none; padding: 0; color: #8a6418; font: inherit; font-weight: 800; text-decoration: underline; cursor: pointer; }
.g-minis { display: flex; gap: 8px; align-items: center; margin: 8px 0; }
.g-minis .tile.mini { color: #2a2116; }
.g-wait { font-size: 13px; font-weight: 800; color: #8a6418; display: flex; gap: 8px; align-items: center; }
.g-wait::before { content: ""; width: 10px; height: 10px; border-radius: 50%; background: var(--accent); animation: gdot 1s ease-in-out infinite; }
@keyframes gdot { 50% { opacity: .3; transform: scale(.7); } }
.g-box.doing { padding: 10px 14px 12px; gap: 5px; } .g-box.doing .g-title { font-size: 18px; } .g-box.doing .g-text { font-size: 14.5px; }
.g-box.min { padding: 0; background: none; box-shadow: none; }
.g-show { width: 100%; display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 8px; align-items: center; padding: 8px 12px; border-radius: 999px; border: 0; background: #fff8e8; color: #2c2a26; cursor: pointer; text-align: left; box-shadow: 0 8px 20px rgba(0, 0, 0, .4); }
.g-show b { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.g-open { font-size: 12.5px; font-weight: 800; color: #8a6418; text-decoration: underline; }
.g-box .btn.primary { min-height: 44px; }

/* =====================================================================
   Senaste draget per spelare, och ett spel som alltid får plats på skärmen.
   ===================================================================== */
:root { --p0: #49c2ff; --p1: #ff9a4d; }
:root[data-theme="sand"] { --p0: #1f7fc2; --p1: #d9631c; }
.pdot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; vertical-align: 1px; flex: none; }
.pdot.p0 { background: var(--p0); box-shadow: 0 0 6px var(--p0); }
.pdot.p1 { background: var(--p1); box-shadow: 0 0 6px var(--p1); }
.player.active { border-color: var(--accent); }

/* Varje spelares senaste ord: ram och list i spelarens färg. Det allra senaste lyser och pulserar till. */
.cell.last-p0 { background: color-mix(in srgb, var(--p0) 45%, var(--cell)); }
.cell.last-p1 { background: color-mix(in srgb, var(--p1) 45%, var(--cell)); }
.cell.last-p0 .tile, .cell.last-p1 .tile { inset: 2px 2px 3px; }
.cell.last-p0 .tile { box-shadow: inset 0 1px 0 rgba(255, 255, 255, .65), inset 0 -3px 0 var(--p0), 0 0 0 2px var(--p0), 0 3px 6px rgba(0, 0, 0, .45); }
.cell.last-p1 .tile { box-shadow: inset 0 1px 0 rgba(255, 255, 255, .65), inset 0 -3px 0 var(--p1), 0 0 0 2px var(--p1), 0 3px 6px rgba(0, 0, 0, .45); }
.cell.newest.last-p0 .tile { box-shadow: inset 0 1px 0 rgba(255, 255, 255, .65), inset 0 -3px 0 var(--p0), 0 0 0 2px var(--p0), 0 0 12px 2px color-mix(in srgb, var(--p0) 70%, transparent); }
.cell.newest.last-p1 .tile { box-shadow: inset 0 1px 0 rgba(255, 255, 255, .65), inset 0 -3px 0 var(--p1), 0 0 0 2px var(--p1), 0 0 12px 2px color-mix(in srgb, var(--p1) 70%, transparent); }
.cell.pulse .tile { animation: lastpulse 1.1s ease-in-out 3; }
@keyframes lastpulse { 50% { transform: scale(1.12); filter: brightness(1.15); } }
.cell.pulse .tile.drop { animation: drop .45s cubic-bezier(.2, 1.4, .4, 1) backwards, lastpulse 1.1s ease-in-out .45s 3; }
@media (prefers-reduced-motion: reduce) { .cell.pulse .tile { animation: none; } }

.info { flex-wrap: nowrap; align-items: center; gap: 10px; white-space: nowrap; overflow: hidden; }
.lastwords { flex: 1; min-width: 0; display: flex; gap: 10px; justify-content: flex-end; overflow: hidden; }
.lastword { display: inline-flex; align-items: center; min-width: 0; overflow: hidden; text-overflow: ellipsis; color: var(--ink); font-weight: 700; }
.logbtn { flex: none; border: 1px solid var(--line); background: transparent; color: var(--ink-2); border-radius: 999px; padding: 2px 10px; font-size: .78rem; cursor: pointer; }
.log { margin: 0; padding-left: 0; list-style: none; max-height: 60dvh; overflow: auto; display: grid; gap: 6px; font-size: .9rem; }
.log li { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.log .pts { color: var(--good); }

/* Hela spelet syns alltid: brädet tar den yta som blir över och är kvadratiskt inom den. */
body.in-game { overflow: hidden; }
html:has(body.in-game) { scrollbar-gutter: auto; }
.game {
  width: 100%; max-width: 760px; height: 100dvh; margin: 0 auto; overflow: hidden;
  padding: max(6px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
  display: flex; flex-direction: column; gap: 6px;
  --rt: min(calc((min(100vw - 16px, 460px) - 36px) / 7), 8.5dvh, 64px);
}
.game > * { flex: none; }
.board-area { flex: 1 1 auto; min-height: 150px; container-type: size; display: grid; place-items: center; }
.board-wrap { --board: calc(100cqmin - 6px); width: var(--board); padding: 0 0 8px; }
.board { width: var(--board); margin: 0; }
.rack { width: auto; min-height: 0; margin: 2px auto 0; grid-template-columns: repeat(7, var(--rt)); justify-content: center; }
.rack .tile, .rack .slot { width: var(--rt); height: var(--rt); aspect-ratio: auto; font-size: calc(var(--rt) * .52); }
.preview { min-height: 1.3em; line-height: 1.3; font-size: .85rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.controls { flex-wrap: nowrap; }
.controls .btn { min-width: 0; flex: 1 1 0; max-width: 130px; padding: 9px 6px; white-space: nowrap; }
.controls .btn.main { flex: 2 1 0; max-width: 260px; }

@media (max-height: 720px) {
  .game { gap: 4px; }
  .player { padding: 4px 8px; }
  .pscore { font-size: 1.15rem; }
  .controls .btn { padding: 7px 6px; font-size: .9rem; }
  .token { display: none; }
}
@media (max-height: 600px) and (orientation: portrait) {
  .preview { display: none; }
}

/* Mobil i liggande läge: brädet till vänster, allt annat till höger. */
@media (orientation: landscape) and (max-height: 560px) {
  .game {
    max-width: none; display: grid; column-gap: 12px; row-gap: 6px;
    grid-template-columns: auto minmax(0, 1fr);
    grid-template-rows: auto auto minmax(0, 1fr) auto auto;
    grid-template-areas: "board top" "board info" "board preview" "board rack" "board controls";
    --rt: min(calc((100vw - 100dvh - 40px - 36px) / 7), 13dvh, 60px);
  }
  .game-top { grid-area: top; } .info { grid-area: info; } .preview { grid-area: preview; align-self: end; display: block; }
  .rack { grid-area: rack; } .controls { grid-area: controls; }
  .board-area { grid-area: board; width: calc(100dvh - 16px); height: 100%; min-height: 0; }
  .lastwords { display: none; }
}

/* Spelarrutan: namn, poäng och senaste ordet i spelarens färg. */
.player { grid-template-columns: minmax(0, 1fr) auto; grid-template-rows: auto auto; column-gap: 8px; }
.pname { display: flex; align-items: center; min-width: 0; }
.pname small { white-space: nowrap; }
.pscore { grid-row: 1 / span 2; grid-column: 2; }
.plast { font-size: .74rem; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; letter-spacing: .02em; }
.player.p0 .plast { color: var(--p0); } .player.p1 .plast { color: var(--p1); }
.token { display: inline !important; font-size: .8rem; margin-left: 4px; color: #b9a6ff; }
.token.off { color: var(--ink-2); }
/* I spelet visas meddelanden överst, så att de aldrig täcker hållaren eller knapparna. */
body.in-game .toast { bottom: auto; top: calc(max(6px, env(safe-area-inset-top)) + 112px); transform: translate(-50%, -10px); }
body.in-game .toast.show { transform: translate(-50%, 0); }

/* Nivå och XP under partiet. */
.top-main { flex: 1; min-width: 0; display: grid; grid-template-columns: minmax(0, 1fr); gap: 4px; }
.pname-text { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.pname .pdot { flex: none; }
.pname .plv { flex: none; margin-left: 6px; padding: 0 5px; border-radius: 999px; border: 1px solid var(--line); color: var(--ink-2); font-size: .68rem; font-weight: 700; line-height: 1.5; font-variant-numeric: tabular-nums; }
.pname .plv.me { border-color: var(--accent); color: var(--accent); }
.game-xp { display: flex; align-items: center; gap: 6px; min-height: 14px; font-size: 11px; line-height: 14px; color: var(--ink-2); font-variant-numeric: tabular-nums; white-space: nowrap; }
.gx-bar { flex: 1; min-width: 24px; height: 5px; }
.gx-gain { min-width: 26px; text-align: right; color: var(--accent); font-size: 12px; }
.gx-gain.bump { animation: xp-bump .6s cubic-bezier(.2, .8, .2, 1); }
@keyframes xp-bump { 30% { transform: scale(1.5); color: #fff3c4; } }
/* Topplistan. */
.lb-rows { margin: 0; padding: 0; list-style: none; background: var(--bg-2); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; }
.lb-rows li + li { border-top: 1px solid var(--line); }
.lb-row { display: grid; grid-template-columns: 26px 40px minmax(0, 1fr) auto; gap: 10px; align-items: center; width: 100%; min-height: 64px; padding: 10px 14px 10px 10px; border: 0; background: none; text-align: left; cursor: pointer; transition: background .15s; }
.lb-row:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; border-radius: 12px; }
@media (hover: hover) { .lb-row:hover { background: var(--panel); } }
.lb-row.mine { background: color-mix(in srgb, var(--accent) 10%, transparent); }
.lb-rank { font: 800 1.1rem/1 Fraunces, Georgia, serif; text-align: center; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.lb-row.first .lb-rank { color: var(--accent); }
.lb-avatar { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 50%; background: var(--panel); box-shadow: inset 0 0 0 1px var(--line); font: 800 1.05rem/1 Fraunces, Georgia, serif; }
.lb-row.first .lb-avatar { background: radial-gradient(circle at 35% 30%, #fff1b0, var(--accent) 60%, #a87418); color: var(--accent-ink); box-shadow: none; }
.lb-who { display: flex; flex-direction: column; min-width: 0; }
.lb-who b { display: flex; align-items: center; gap: 6px; min-width: 0; }
.lb-name { min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lb-who > small { font-size: .78rem; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lb-you { flex: none; padding: 0 6px; border-radius: 999px; background: var(--accent); color: var(--accent-ink); font-size: .66rem; font-weight: 700; line-height: 1.6; }
.lb-value { max-width: 42vw; font-weight: 700; text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.player-page { gap: 14px; }
.player-name { font: 600 1.25rem/1.2 Fraunces, Georgia, serif; overflow-wrap: anywhere; }
.player-ach { margin: 0; padding: 0; list-style: none; display: grid; gap: 8px; }
.player-ach li { display: flex; align-items: center; gap: 10px; font-size: .92rem; }
.player-ach .medal { flex: none; width: 28px; height: 28px; font-size: .85rem; background: radial-gradient(circle at 35% 30%, #fff1b0, var(--accent) 60%, #a87418); color: #3a2604; }
:root[data-theme="sand"] .lb-row.first .lb-rank { color: #8a6418; }

/* Kontot. */
.account { display: flex; flex-direction: column; gap: 10px; }
.account[hidden] { display: none; }
.account h2 { margin: 0; }
.account p { margin: 0; line-height: 1.45; }
.account-who { display: flex; align-items: center; gap: 12px; }
.account-who .ico { color: var(--accent); }
.account-who small { overflow-wrap: anywhere; }
.account-actions { align-items: stretch; }
.account-actions > * { flex: 1 1 0; text-decoration: none; color: inherit; text-align: center; white-space: nowrap; padding-inline: 8px; font-size: .92rem; }
.modal .stack:has(.btn.danger) p { margin: 0; line-height: 1.45; }
.account-actions .btn.danger { color: var(--bad); }

/* Kretsen av inbjudna. */
.circle { display: flex; flex-direction: column; gap: 10px; }
.circle h2 { margin: 0; color: var(--ink); font-size: 1.15rem; }
.circle p { margin: 0; line-height: 1.45; }
.circle-actions { display: flex; flex-direction: column; gap: 8px; }
.circle a.btn, .circle-tools a.btn { text-decoration: none; color: inherit; text-align: center; }
.circle a.btn.primary { color: var(--accent-ink); }
.circle-error { color: var(--bad); font-size: .88rem; }
.circle-error:empty { display: none; }
.circle-tools { display: flex; flex-direction: column; gap: 10px; }
.circle-tools .note { margin: 0; }
.circle-tools .row.two > * { flex: 1 1 0; }
.circle-link { margin: 0; padding: 10px 12px; border-radius: 10px; background: var(--bg-2); border: 1px solid var(--line); font-size: .85rem; overflow-wrap: anywhere; user-select: all; }

/* Ritade ikoner. */
.ico { display: inline-grid; place-items: center; flex: none; }

/* Startsidan: dina partier. */
.game-list { display: flex; flex-direction: column; gap: 20px; margin-top: -8px; }
.game-group h2 { margin: 0 0 8px; }
.game-rows { display: flex; flex-direction: column; background: var(--bg-2); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; }
.game-card { display: grid; grid-template-columns: 56px minmax(0, 1fr) auto; gap: 12px; align-items: center; width: 100%; min-height: 80px; padding: 12px; border: 0; border-top: 1px solid var(--line); background: none; text-align: left; cursor: pointer; transition: background .15s; }
.game-card:first-child { border-top: 0; }
.game-card:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; border-radius: 12px; }
@media (hover: hover) { .game-card:hover { background: var(--panel); } }
.game-card:active { background: var(--panel); }
.mini-board { display: block; width: 56px; height: 56px; padding: 2px; border-radius: 6px; background: var(--cell); box-shadow: inset 0 0 0 1px var(--line); }
.mini-board svg { display: block; width: 100%; height: 100%; }
.mini-board .m-a { fill: color-mix(in srgb, var(--p0) 55%, var(--bg)); }
.mini-board .m-b { fill: color-mix(in srgb, var(--p1) 55%, var(--bg)); }
.mini-board .m-star { fill: color-mix(in srgb, var(--accent) 45%, transparent); }
.home:has(.game-list) { padding-top: 24px; gap: 28px; }
.home:has(.game-list) .tagline { display: none; }
.mini-board .m-A { fill: var(--p0); }
.mini-board .m-B { fill: var(--p1); }
.gc-main { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.gc-top { display: flex; align-items: center; gap: 6px; min-width: 0; }
.gc-name { font-size: 1rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.gc-top .plv { flex: none; padding: 0 5px; border-radius: 999px; border: 1px solid var(--line); color: var(--ink-2); font-size: .68rem; font-weight: 700; line-height: 1.5; font-variant-numeric: tabular-nums; }
.gc-last { font-size: .86rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.gc-meta { font-size: .74rem; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.gc-side { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.gc-pill { padding: 2px 8px; border-radius: 999px; font-size: .74rem; font-weight: 700; white-space: nowrap; color: var(--ink-2); background: var(--panel); }
.game-card.mine .gc-pill { background: var(--accent); color: var(--accent-ink); }
.game-card.done .gc-pill { color: var(--ink); box-shadow: inset 0 0 0 1px var(--line); }
.gc-score { display: flex; flex-direction: column; align-items: flex-end; line-height: 1.1; font-variant-numeric: tabular-nums; }
.gc-score b { font: 800 1.2rem/1.1 Fraunces, Georgia, serif; }
.gc-score b.lead { color: var(--accent); }
.gc-score small { font-size: .74rem; color: var(--ink-2); }
:root[data-theme="sand"] .gc-score b.lead { color: #8a6418; }
.notify-offer { display: flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 8px 12px; border: 1px dashed var(--line); border-radius: 12px; background: none; color: var(--ink-2); font-size: .88rem; cursor: pointer; }
@media (hover: hover) { .notify-offer:hover { color: var(--ink); border-color: var(--ink-2); } }
@media (max-width: 359px) {
  .game-card { grid-template-columns: 44px minmax(0, 1fr) auto; gap: 8px; padding: 10px; }
  .mini-board { width: 44px; height: 44px; }
}

/* Menyn i partiet: ett ark som glider upp nerifrån på mobil. */
.modal-back:has(.sheet) { place-items: end center; padding: 0; }
.modal:has(.sheet) { width: min(460px, 100%); padding: 16px 16px max(16px, env(safe-area-inset-bottom)); border-radius: 18px 18px 0 0; border-width: 1px 1px 0; animation: sheet-up .28s cubic-bezier(.16, 1, .3, 1); }
@keyframes sheet-up { from { transform: translateY(40px); opacity: 0; } }
@media (min-width: 620px) and (min-height: 560px) {
  .modal-back:has(.sheet) { place-items: center; padding: 16px; }
  .modal:has(.sheet) { border-radius: 18px; border-width: 1px; }
}
.sheet { display: flex; flex-direction: column; gap: 14px; }
.sheet-head, .help-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.sheet-score { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; flex: 1; min-width: 0; }
.sheet-side { display: grid; grid-template-columns: auto minmax(0, 1fr); column-gap: 6px; align-items: center; font-size: .86rem; color: var(--ink-2); min-width: 0; }
.sheet-side b { grid-column: 1 / -1; font: 800 1.9rem/1.1 Fraunces, Georgia, serif; color: var(--ink); font-variant-numeric: tabular-nums; }
.sheet-close { width: 44px; height: 44px; margin: -8px -8px 0 0; padding: 0; border-radius: 12px; color: var(--ink-2); display: grid; place-items: center; flex: none; }
@media (hover: hover) { .sheet-close:hover { background: var(--bg-2); color: var(--ink); } }
.sheet-rows { display: flex; flex-direction: column; background: var(--bg-2); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; }
.sheet-row { display: flex; align-items: center; gap: 14px; width: 100%; min-height: 60px; padding: 10px 14px; border: 0; border-top: 1px solid var(--line); background: none; text-align: left; cursor: pointer; transition: background .15s; }
.sheet-rows .sheet-row:first-child { border-top: 0; }
.sheet-row .ico { color: var(--accent); }
.sheet-row:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; border-radius: 12px; }
@media (hover: hover) { .sheet-row:hover { background: var(--panel); } .sheet > .sheet-row:hover { background: var(--bg-2); } }
.sheet-text { display: flex; flex-direction: column; min-width: 0; }
.sheet-text small { font-size: .8rem; color: var(--ink-2); }
.sheet > .sheet-row { border: 0; border-radius: 12px; min-height: 52px; color: var(--bad); }
.sheet-row.danger .ico { color: var(--bad); }
:root[data-theme="sand"] .sheet-row .ico { color: #8a6418; }
:root[data-theme="sand"] .sheet-row.danger .ico { color: var(--bad); }

/* Så spelar du. */
.modal:has(.help-modal) { padding: 16px; }
.help-head h2 { margin: 0; font-size: 1.3rem; color: var(--ink); }
.help-tabs { margin: 0 -4px 14px; border-bottom: 1px solid var(--line); }
.help-panel { display: flex; flex-direction: column; gap: 12px; animation: rise .25s ease; }
.help-panel p { margin: 0; max-width: 62ch; line-height: 1.5; }
.help-panel h3 { margin: 10px 0 0; font-size: 1.05rem; }
.help-lead { font-family: Fraunces, Georgia, serif; font-size: 1.12rem; line-height: 1.35; }
.help-credit { font-size: .8rem; }
.hx { margin: 0; padding: 14px; display: flex; flex-direction: column; align-items: center; gap: 10px; background: var(--bg-2); border: 1px solid var(--line); border-radius: 14px; }
.hx-word { display: flex; gap: 4px; }
.hx-c { position: relative; display: grid; place-items: center; width: 46px; height: 46px; border-radius: 8px; background: var(--cell); }
.hx-c small { position: absolute; left: 50%; bottom: -9px; transform: translateX(-50%); padding: 0 5px; border-radius: 999px; background: var(--DO); color: #fff; font-size: 10px; font-weight: 700; line-height: 1.5; }
.hx-do { background: var(--DO); }
.hx figcaption, .hx > figcaption { margin-top: 4px; text-align: center; font-size: .9rem; line-height: 1.4; max-width: 44ch; }
.hx figcaption b { font: 800 1.15rem Fraunces, Georgia, serif; color: var(--accent); }
:root[data-theme="sand"] .hx figcaption b { color: #8a6418; }
.hf-list { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 12px; }
.hf { display: grid; grid-template-columns: 86px minmax(0, 1fr); gap: 12px; align-items: center; font-size: .92rem; line-height: 1.45; }
.hf-v { display: flex; justify-content: center; gap: 4px; }
.hc { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 8px; background: var(--cell); color: rgba(255, 255, 255, .85); font-size: 12px; font-weight: 700; }
.hc.prem-DB { background: var(--DB); } .hc.prem-TB { background: var(--TB); } .hc.prem-DO { background: var(--DO); } .hc.prem-TO { background: var(--TO); }
.hc.prem-START { color: var(--accent); font-size: 20px; }
.hc-seven { background: var(--accent); color: var(--accent-ink); font: 800 1.2rem Fraunces, Georgia, serif; }
.hc-duo { background: #6a4cc9; color: #fff; font-size: 1rem; }
.hc-blitz { background: var(--accent); color: var(--accent-ink); font-size: 1rem; }
:root[data-theme="sand"] .hc:not([class*="prem-"]):not(.hc-seven):not(.hc-duo):not(.hc-blitz) { color: var(--ink); }
.setup.prose .help-tabs { margin-top: 0; }
@media (prefers-reduced-motion: reduce) { .modal:has(.sheet) { animation: none; } }

.preview-xp { color: var(--accent); }
.info .bag { color: var(--ink); font-weight: 700; }
@media (max-width: 379px) { .info .mode-name { display: none; } }
.xp-day { font-size: 11.5px; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.xg-next { margin: 0; font-size: 12.5px; font-weight: 700; color: var(--accent); }
@media (prefers-reduced-motion: reduce) { .gx-gain.bump { animation: none; } }
