@font-face {
  font-family: 'DM Sans';
  src: url('/fonts/dm-sans.woff2') format('woff2');
  font-weight: 400 800;
  font-display: swap;
}

@font-face {
  font-family: 'Space Grotesk';
  src: url('/fonts/space-grotesk.woff2') format('woff2');
  font-weight: 400 700;
  font-display: swap;
}

@font-face {
  font-family: 'JetBrains Mono';
  src: url('/fonts/jetbrains-mono.woff2') format('woff2');
  font-weight: 400 700;
  font-display: swap;
}

:root {
  color-scheme: dark;
  --bg: #0c1424;
  --surface: #141f33;
  --border: #2a3952;
  --foreground: #f0f5ff;
  --muted: #a7b5ca;
  --accent: #85e2f1;
  --accent-strong: #a6effa;
  --focus: #c0f1ff;
  --heading: 'Space Grotesk', sans-serif;
  --mono: 'JetBrains Mono', monospace;
  font: 16px / 1.45 'DM Sans', system-ui, sans-serif;
}

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

body {
  min-width: 280px;
  min-height: 100vh;
  margin: 0;
  color: var(--foreground);
  background: radial-gradient(ellipse at 33% 7%, #172841 0, transparent 55%), var(--bg);
}

h1, h2, p { margin: 0; }
button, input, select { font: inherit; }
button { color: inherit; }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--focus); outline-offset: 3px; }

.icon-library { position: absolute; width: 0; height: 0; overflow: hidden; }
.icon { flex: 0 0 auto; width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.topbar { background: #101a2be8; border-bottom: 1px solid #293850; }

.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 68px;
  max-width: 1176px;
  margin-inline: auto;
  padding-inline: 28px;
}

.brand { display: inline-flex; align-items: center; gap: 12px; font: 700 25px / 1 var(--heading); letter-spacing: -.055em; }
.brand-icon { display: grid; width: 38px; height: 38px; place-items: center; border-radius: 12px; background: var(--accent); color: #0b2132; box-shadow: inset 0 1px 0 #e1fbff95, 0 4px 12px #80e5fa28; }
.brand-icon .icon { width: 24px; height: 24px; transform: rotate(-10deg); }
.brand-accent { margin-left: .16em; color: var(--accent); }

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  min-height: 44px;
  padding: 8px 14px;
  border: 1px solid transparent;
  border-radius: 11px;
  background: none;
  cursor: pointer;
  font-size: .91rem;
  font-weight: 700;
  line-height: 1.2;
  transition: background-color .16s, color .16s, border-color .16s, box-shadow .16s;
}

.button:disabled { cursor: default; opacity: .53; }
.button .icon { width: 18px; height: 18px; }
.button-subtle { min-height: 39px; color: #d6e1f4; border-color: #31415b; }
.button-subtle:hover { background: #1d2b42; }
.button-primary { color: #102333; background: var(--accent); border-color: #b6f3fb; box-shadow: inset 0 1px 0 #e6fcff85, 0 4px 13px #66d9f522; }
.button-primary:hover:not(:disabled) { background: var(--accent-strong); }
.button-primary:active:not(:disabled) { background: #6ecbdb; }
.button-outline { background: #1d2a41; border-color: #3a4d6c; }
.button-outline:hover:not(:disabled) { background: #283a56; border-color: #607797; }
.button-quiet { color: #b6c7e0; }
.button-quiet:hover:not(:disabled) { background: #1f2e46; color: white; }
.icon-button { padding: 0; width: 44px; color: var(--muted); }
.icon-button:hover { background: #263650; color: white; }

.game-shell { max-width: 1110px; margin-inline: auto; padding: 29px 28px 42px; }
.game-heading { display: flex; justify-content: space-between; align-items: end; gap: 16px; margin: 0 0 21px; }
.mode-label { display: flex; align-items: center; gap: 7px; color: var(--accent); font-size: .86rem; font-weight: 700; }
.mode-label .icon { width: 16px; height: 16px; stroke-width: 1.9; }
h1 { margin-top: 4px; font: 700 clamp(2.05rem, 3.8vw, 3.125rem) / 1.04 var(--heading); letter-spacing: -.065em; }
.connection { display: flex; align-items: center; gap: 7px; flex-shrink: 0; margin-bottom: 3px; padding: 5px 10px; border: 1px solid #33425a; border-radius: 99px; background: #101b2c; color: #c7d3e6; font-size: .75rem; font-weight: 700; white-space: nowrap; }
.connection > :first-child { width: 7px; height: 7px; border-radius: 50%; background: #d5aa60; }
.connection[data-status="online"] > :first-child { background: #62dca8; box-shadow: 0 0 8px #62dca856; }
.connection[data-status="offline"] > :first-child { background: #f28a92; }

.game-layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(260px, 320px); align-items: start; gap: 22px; }
.table {
  position: relative;
  display: grid;
  justify-items: center;
  gap: 11px;
  padding: 15px 20px;
  border: 1px solid #31425e;
  border-radius: 22px;
  background:
    radial-gradient(ellipse at center, #314b6a 0, #24365075 48%, #18263c40 83%),
    repeating-linear-gradient(45deg, transparent 0 21px, #7899bd14 22px 23px, transparent 24px 44px),
    repeating-linear-gradient(-45deg, transparent 0 21px, #7899bd0e 22px 23px, transparent 24px 44px),
    #18263c;
  box-shadow: inset 0 1px 0 #7197c02c, 0 17px 36px #060e1e4d;
}

.seat-row { width: 100%; max-width: 506px; display: flex; justify-content: space-between; gap: 10px; min-height: 51px; }
.seat {
  display: grid;
  grid-template-columns: 31px minmax(0, 1fr);
  align-items: center;
  gap: 9px;
  width: min(47%, 166px);
  min-width: 0;
  min-height: 48px;
  padding: 5px 8px;
  border: 1px solid #314666;
  border-radius: 12px;
  background: #142238;
}
.seat.is-active { border-color: color-mix(in srgb, var(--piece) 72%, #22354d); box-shadow: 0 0 15px color-mix(in srgb, var(--piece) 19%, transparent); }
.seat.is-empty { border-style: dashed; background: #152034a3; }
.seat-avatar { display: grid; width: 31px; height: 31px; place-items: center; border: 1px solid color-mix(in srgb, var(--piece) 45%, transparent); border-radius: 9px; background: color-mix(in srgb, var(--piece) 16%, #1b2940); color: var(--piece-light); }
.seat-avatar .icon { width: 17px; height: 17px; }
.seat-copy { min-width: 0; align-self: center; }
.seat-name { overflow: hidden; font-size: .84rem; font-weight: 700; line-height: 1.15; text-overflow: ellipsis; white-space: nowrap; }
.seat-state { display: flex; align-items: center; gap: 5px; margin-top: 3px; color: #b3c2d8; font-size: .7rem; line-height: 1; }
.seat-state .icon { width: 11px; height: 11px; color: var(--piece-light); }

[data-color="red"], .color-red { --tile: #eb6274; --tile-dark: #ca4056; --tile-pale: #fbd2d4; --piece-light: #ffd2d8; --piece: #ff6c80; --piece-shadow: #a52e48; }
[data-color="green"], .color-green { --tile: #46bd96; --tile-dark: #218468; --tile-pale: #b6ebd9; --piece-light: #c0f5e1; --piece: #55d6a5; --piece-shadow: #167257; }
[data-color="yellow"], .color-yellow { --tile: #f5c755; --tile-dark: #dc9a2c; --tile-pale: #f9e3a8; --piece-light: #fff0b5; --piece: #ffcf61; --piece-shadow: #a5631b; }
[data-color="blue"], .color-blue { --tile: #60aafd; --tile-dark: #377cdb; --tile-pale: #c3ddff; --piece-light: #cde8ff; --piece: #6ab5ff; --piece-shadow: #235aab; }

.board-rim {
  width: min(100%, 506px);
  padding: clamp(4px, .75vw, 9px);
  border: 1px solid #597494;
  border-radius: 15px;
  background: linear-gradient(155deg, #4b6480, #223651 55%, #1f314a);
  box-shadow: 0 11px 20px #071326ab, inset 0 1px 1px #e3f2ff36;
}
.board {
  position: relative;
  display: grid;
  grid-template: repeat(15, minmax(0, 1fr)) / repeat(15, minmax(0, 1fr));
  aspect-ratio: 1;
  overflow: hidden;
  border-radius: 8px;
  isolation: isolate;
  background: #a3aebe;
  box-shadow: 0 0 0 1px #0e1c32;
}
.home {
  position: relative;
  display: grid;
  place-items: center;
  background: linear-gradient(145deg, var(--tile), var(--tile-dark));
  box-shadow: inset 0 1px 0 #fff3, inset 0 0 0 1px #192c4e3b;
}
.home-pad {
  position: relative;
  width: 67%;
  height: 67%;
  border: 1px solid #ffffff94;
  border-radius: 13%;
  background: linear-gradient(150deg, #fffcf6, var(--tile-pale));
  box-shadow: 0 4px 10px #14244138, inset 0 0 0 3px #ffffff42;
}
.home-pad::before { content: ''; position: absolute; inset: 5.5%; border: 1px solid color-mix(in srgb, var(--tile-dark) 25%, transparent); border-radius: 11%; }
.well {
  position: absolute;
  width: 30%;
  aspect-ratio: 1;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  border: 1px solid color-mix(in srgb, var(--tile-dark) 60%, white);
  background: color-mix(in srgb, var(--tile) 34%, var(--tile-pale));
  box-shadow: inset 0 2px 3px color-mix(in srgb, var(--tile-dark) 24%, transparent), 0 1px 0 #fff8;
}
.well:nth-child(odd) { left: 30.5%; }
.well:nth-child(even) { left: 69.5%; }
.well:nth-child(-n+2) { top: 30.5%; }
.well:nth-child(n+3) { top: 69.5%; }
.cell { display: grid; place-items: center; min-width: 0; min-height: 0; background: #f3f5f8; box-shadow: inset 0 0 0 .5px #a0afc0; color: #516580; }
.cell .icon { width: min(58%, 19px); height: min(58%, 19px); stroke-width: 1.75; }
.cell.is-lane { background: color-mix(in srgb, var(--tile) 72%, #fff8ea); color: #233750; box-shadow: inset 0 0 0 .5px color-mix(in srgb, var(--tile-dark) 65%, #788597); }
.cell.is-start { background: var(--tile); color: #172a3d; box-shadow: inset 0 0 0 .5px var(--tile-dark); }
.cell.is-start .icon { transform: rotate(var(--angle)); }
.cell.is-safe { background: #e4e9f1; }
.goal { position: relative; grid-area: 7 / 7 / 10 / 10; background: #304459; }
.goal-color { position: absolute; inset: 0; background: linear-gradient(145deg, var(--tile), var(--tile-dark)); }
.goal-color.color-red { clip-path: polygon(0 0, 50% 50%, 0 100%); }
.goal-color.color-green { clip-path: polygon(0 0, 100% 0, 50% 50%); }
.goal-color.color-yellow { clip-path: polygon(100% 0, 100% 100%, 50% 50%); }
.goal-color.color-blue { clip-path: polygon(0 100%, 50% 50%, 100% 100%); }
.goal-center { position: absolute; inset: 38%; display: grid; place-items: center; border-radius: 50%; background: #eef4fa; color: #28415c; box-shadow: 0 0 0 1px #26375280, 0 3px 6px #26375254; }
.goal-center .icon { width: 61%; height: 61%; stroke-width: 1.7; }

.pawn {
  position: absolute;
  z-index: 1;
  left: calc((var(--column) + .5 + var(--offset-x, 0)) * 100% / 15);
  top: calc((var(--row) + .5 + var(--offset-y, 0)) * 100% / 15);
  display: grid;
  width: calc(100% / 15 * var(--size, .93));
  aspect-ratio: 1;
  transform: translate(-50%, -50%);
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--piece-light);
  transition: left .22s ease-out, top .22s ease-out, width .16s ease-out;
}
.pawn-in-home { --size: 1.04; }
.pawn-shape {
  position: absolute;
  inset: 6%;
  border: 1px solid #18314b;
  border-radius: 50%;
  background: linear-gradient(145deg, var(--piece-light), var(--piece) 50%, var(--piece-shadow));
  box-shadow: inset 0 0 0 1px #fff8, 0 2px 2px #17294570;
}
.pawn-shape::before, .pawn-shape::after { position: absolute; left: 50%; transform: translateX(-50%); background: #223b52; content: ''; }
.pawn-shape::before { top: 25%; width: 26%; height: 26%; border-radius: 50%; }
.pawn-shape::after { bottom: 23%; width: 43%; height: 27%; border-radius: 100% 100% 27% 27%; }
.pawn.is-playable { z-index: 3; cursor: pointer; }
.pawn.is-playable .pawn-shape { outline: 2px solid #fffdec; outline-offset: 1px; box-shadow: 0 0 9px #fff6a6d9, inset 0 0 0 1px #fff7; }
.pawn.is-playable:hover .pawn-shape { scale: 1.12; }
.pawn:focus-visible { z-index: 4; outline-color: #172c47; outline-offset: 1px; }

.sidebar { display: grid; gap: 14px; min-width: 0; }
.panel { min-width: 0; padding: 17px; border: 1px solid var(--border); border-radius: 17px; background: var(--surface); box-shadow: inset 0 1px 0 #6c8cbd14, 0 10px 24px #080f1c29; }
.turn-panel { border-color: color-mix(in srgb, var(--piece) 39%, #2e4163); background: radial-gradient(ellipse at 1% 0, color-mix(in srgb, var(--piece) 12%, transparent), transparent 78%), #17243a; }
.turn-heading, .room-heading { display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: center; gap: 13px; }
.turn-copy, .room-heading > div { min-width: 0; }
.panel h2 { overflow-wrap: anywhere; font: 700 1.15rem / 1.16 var(--heading); letter-spacing: -.036em; }
.turn-copy p, .room-heading p { margin-top: 4px; color: var(--muted); font-size: .86rem; line-height: 1.35; }
.die { display: grid; width: 55px; height: 55px; grid-template: repeat(3, 1fr) / repeat(3, 1fr); place-items: center; padding: 6px; border: 1px solid #fbfdff; border-radius: 14px; background: linear-gradient(145deg, #fff, #d7e3f6); box-shadow: inset 0 -3px 0 #8ba3c82c, 0 4px 9px #0614268c; color: #213750; }
.die span { width: 55%; aspect-ratio: 1; border-radius: 50%; background: currentColor; opacity: 0; }
.die[data-value="0"] span:nth-child(5) { color: #9babbe; opacity: 1; }
.die:is([data-value="1"], [data-value="3"], [data-value="5"]) span:nth-child(5),
.die:is([data-value="2"], [data-value="3"], [data-value="4"], [data-value="5"], [data-value="6"]) :is(span:first-child, span:last-child),
.die:is([data-value="4"], [data-value="5"], [data-value="6"]) :is(span:nth-child(3), span:nth-child(7)),
.die[data-value="6"] :is(span:nth-child(4), span:nth-child(6)) { opacity: 1; }
.die.is-fresh { animation: dice-pop .24s ease-out; }
@keyframes dice-pop { 0% { transform: rotate(-12deg) scale(.86); } 70% { transform: rotate(4deg) scale(1.05); } }
.roll-button { width: 100%; margin-top: 16px; font-size: .99rem; }
.last-action { margin-top: 11px; color: #bdcbe2; font-size: .77rem; }
.move-options { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 7px; margin-top: 13px; }
.move-choice { padding: 4px; background: #22324d; border-color: #43597c; }
.move-choice:hover:not(:disabled) { background: #344969; }
.move-choice .icon { width: 15px; height: 15px; color: var(--piece-light); }
.panel-icon { display: grid; width: 43px; height: 43px; place-items: center; border: 1px solid #3b5270; border-radius: 11px; background: #243650; color: #bed4f2; }
.panel-icon .icon { width: 21px; height: 21px; }
.room-actions { display: grid; gap: 3px; margin-top: 14px; }
.room-actions .button { width: 100%; }
.copy-button { justify-content: flex-start; }
.copy-button span:first-child { margin-right: auto; color: #cdf6fa; font-family: var(--mono); letter-spacing: .04em; }
.copy-button span:last-child { white-space: nowrap; }
.legend { display: flex; flex-wrap: wrap; gap: 8px 15px; padding: 0 4px; color: var(--muted); font-size: .76rem; }
.legend span { display: flex; align-items: center; gap: 5px; }
.legend .icon { width: 14px; height: 14px; color: #aec8e9; }

.dialog { width: min(420px, calc(100% - 24px)); max-height: calc(100% - 20px); padding: 19px; border: 1px solid #486280; border-radius: 17px; color: var(--foreground); background: #17253b; box-shadow: 0 20px 70px #0009; }
.dialog::backdrop { background: #060c19b8; backdrop-filter: blur(2px); }
.dialog-header { display: flex; min-height: 44px; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; }
.dialog h2 { font: 700 1.5rem / 1.15 var(--heading); letter-spacing: -.038em; }
.dialog-header .icon-button { margin-right: -6px; }
.room-form { display: grid; gap: 7px; }
.room-form label { display: block; font-size: .84rem; font-weight: 700; }
.room-form input, .room-form select { display: block; width: 100%; min-height: 44px; padding: 8px 11px; border: 1px solid #435877; border-radius: 9px; background: #101d31; color: #f4f8ff; font: .9rem var(--mono); }
.room-form input::placeholder { color: #9dacbf; }
.room-form > div { margin-top: 7px; }
.room-form > div label { margin-bottom: 6px; }
.room-form > .button { margin-top: 8px; }
.form-error { margin-top: 6px; color: #ffb6bf; font-size: .86rem; }
.rules-dialog p, .rules-dialog li { color: #ced9ed; font-size: .92rem; }
.rules-dialog ul { padding-left: 20px; }
.rules-dialog li + li { margin-top: 8px; }
.rules-dialog form:last-child .button { width: 100%; }
.toast { position: fixed; z-index: 5; right: 16px; bottom: max(16px, env(safe-area-inset-bottom)); max-width: min(380px, calc(100% - 32px)); padding: 11px 15px; border: 1px solid #4d6588; border-radius: 12px; background: #21334e; color: #edf5ff; box-shadow: 0 6px 22px #09111bb8; font-size: .88rem; }

@media (max-width: 760px) {
  .topbar-inner { min-height: 59px; padding-inline: 16px; }
  .brand { gap: 9px; font-size: 23px; }
  .brand-icon { width: 34px; height: 34px; border-radius: 9px; }
  .brand-icon .icon { width: 21px; height: 21px; }
  .rules-button { min-height: 36px; padding-inline: 9px; gap: 6px; font-size: .8rem; }
  .rules-button .icon { width: 16px; height: 16px; }
  .game-shell { max-width: 584px; padding: 18px 13px 26px; }
  .game-heading { margin-bottom: 13px; padding-inline: 2px; }
  .mode-label { font-size: .76rem; }
  .game-layout { grid-template-columns: minmax(0, 1fr); gap: 12px; }
  .table { gap: 8px; padding: 9px 10px; border-radius: 15px; }
  .board-rim { border-radius: 10px; }
  .board { border-radius: 5px; }
  .seat-row { min-height: 43px; }
  .seat { min-height: 43px; grid-template-columns: 27px minmax(0, 1fr); gap: 6px; padding: 4px 6px; border-radius: 9px; }
  .seat-avatar { width: 27px; height: 27px; border-radius: 7px; }
  .seat-avatar .icon { width: 15px; height: 15px; }
  .seat-name { font-size: .79rem; }
  .sidebar { gap: 12px; }
  .panel { padding: 12px; border-radius: 14px; }
  .turn-heading, .room-heading { gap: 10px; }
  .die { width: 47px; height: 47px; border-radius: 11px; padding: 5px; }
  .roll-button { margin-top: 11px; }
  .room-actions { margin-top: 10px; }
}

@media (max-width: 360px) {
  .topbar-inner { padding-inline: 10px; }
  .game-shell { padding-inline: 7px; }
  .table { padding-inline: 6px; }
  .connection { padding-inline: 7px; }
  .seat { gap: 5px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
