@font-face {
  font-family: "Kargo Sans";
  src: url("./assets/fonts/IFKargoSans-ExtraLight.woff") format("woff");
  font-weight: 300;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Kargo Sans";
  src: url("./assets/fonts/IFKargoSans-Regular.woff") format("woff");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Kargo Sans";
  src: url("./assets/fonts/IFKargoSans-Medium.woff") format("woff");
  font-weight: 500;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Kargo Sans";
  src: url("./assets/fonts/IFKargoSans-Bold.woff") format("woff");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

:root {
  color-scheme: light;
  --bg: #ffffff;
  --fg: #000000;
  --fg-muted: #555555;
  --fg-subtle: #999999;
  --ink-room: #313236;
  --stone: #d7d3c6;
  --accent: #9a7a3c;
  --accent-hover: #6b5527;
  --accent-fg: #fbfafd;
  --wood: #a8733f;
  font-family: "Kargo Sans", sans-serif;
}

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

html, body, #experience {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
}

body { background: var(--ink-room); color: var(--fg); }
button, input { font: inherit; }

button, .control-dock a {
  display: inline-flex;
  min-height: 44px;
  align-items: center;
  justify-content: center;
  padding: 0 15px;
  border: 1px solid var(--fg);
  border-radius: 6px;
  background: var(--bg);
  color: var(--fg);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: .1em;
  line-height: 1;
  text-decoration: none;
  text-transform: uppercase;
  white-space: nowrap;
  cursor: pointer;
  transition: background 120ms ease, color 120ms ease, border-color 120ms ease, transform 120ms ease, opacity 120ms ease;
}

button:hover, .control-dock a:hover { background: var(--fg); color: var(--bg); }
button[aria-pressed="true"] { border-color: var(--accent); background: var(--accent); color: var(--accent-fg); }
button:disabled { cursor: default; opacity: .4; }
button:not(.node):active, .control-dock a:active { transform: scale(.98); }
button:focus-visible, a:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.mobile-lab-link, .mobile-status-close { display: none; }

#experience {
  position: relative;
  isolation: isolate;
  background: var(--ink-room);
}

#experience::before {
  position: absolute;
  inset: 0;
  z-index: -2;
  content: "";
  pointer-events: none;
  background: radial-gradient(circle at 50% 44%, #3b3c40 0, var(--ink-room) 58%, #2a2b2e 100%);
}

.wall-mark {
  position: absolute;
  z-index: -1;
  top: 8%;
  left: 3%;
  width: 94%;
  height: 22%;
  object-fit: contain;
  filter: brightness(0) invert(1);
  opacity: .07;
  pointer-events: none;
}

.title-panel, .status-panel, .players-panel, .difficulty-panel, .control-dock {
  position: fixed;
  z-index: 5;
  border: 1px solid var(--fg);
  border-radius: 0;
  background: var(--bg);
  box-shadow: none;
}

.title-panel {
  top: clamp(16px, 3vw, 32px);
  left: clamp(16px, 3vw, 34px);
  width: min(390px, calc(100vw - 32px));
  padding: 22px 24px 24px;
}

.title-panel p, .status-panel > p, .difficulty-panel > span, .eyebrow, .online-status {
  margin: 0;
  color: var(--fg-muted);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: .14em;
  text-transform: uppercase;
}

.title-panel h1 {
  margin: 7px 0 10px;
  font-size: clamp(2.5rem, 4.1vw, 4.8rem);
  font-weight: 300;
  line-height: .9;
  letter-spacing: -.02em;
}

.title-panel > span { color: var(--fg-muted); font-size: 13px; line-height: 1.5; }

.status-panel {
  top: clamp(16px, 3vw, 32px);
  right: clamp(16px, 3vw, 34px);
  width: min(355px, calc(100vw - 32px));
  padding: 18px 20px;
}

.status-panel h2 { margin: 8px 0 0; font-size: 17px; font-weight: 500; line-height: 1.2; }
.online-status { display: block; margin-top: 10px; color: var(--accent); }
.online-status[hidden] { display: none; }

.players-panel {
  top: clamp(16px, 3vw, 32px);
  left: 50%;
  display: grid;
  width: min(430px, 34vw);
  min-width: 350px;
  grid-template-columns: 1fr 42px 1fr;
  transform: translateX(-50%);
}

.player-card {
  display: grid;
  min-width: 0;
  min-height: 70px;
  grid-template-columns: auto 1fr;
  grid-template-rows: auto auto;
  align-content: center;
  gap: 1px 10px;
  padding: 10px 14px;
  opacity: .46;
  transition: opacity 220ms ease, box-shadow 220ms ease;
}

.player-card.is-active { box-shadow: inset 0 -4px 0 var(--accent); opacity: 1; }
.player-card + .versus, .versus + .player-card { border-left: 1px solid var(--fg); }
.mini-piece { grid-row: 1 / 3; align-self: center; width: 25px; height: 25px; border: 1px solid var(--fg); border-radius: 50%; }
.sun-piece { background: var(--accent); }
.moon-piece { background: #dadada; }
.player-card > span:nth-child(2) { display: grid; }
.player-card small { color: var(--fg-muted); font-size: 9px; font-weight: 500; letter-spacing: .12em; text-transform: uppercase; }
.player-card b { overflow: hidden; font-size: 13px; font-weight: 500; text-overflow: ellipsis; white-space: nowrap; }
.pawn-count { grid-column: 2; color: var(--accent); font-size: 7px; letter-spacing: 3px; }
.player-card[data-player="moon"] .pawn-count { color: #555; }
.versus { display: grid; place-items: center; color: var(--fg-muted); font-size: 9px; font-weight: 500; letter-spacing: .1em; }

.difficulty-panel { left: clamp(16px, 3vw, 34px); bottom: 78px; padding: 12px; }
.difficulty-panel.is-hidden { display: none; }
.difficulty-panel > span { display: block; margin-bottom: 8px; }
.difficulty-panel > div { display: flex; gap: 6px; }
.difficulty-panel button { min-height: 36px; padding: 0 12px; font-size: 9px; }

.museum-stage {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: grid;
  place-items: center;
  perspective: 1200px;
  pointer-events: none;
}

.plinth {
  position: absolute;
  left: 50%;
  top: 53%;
  width: min(66vh, 680px);
  height: min(44vh, 450px);
  border: 1px solid rgba(0,0,0,.28);
  background: var(--stone);
  transform: translate(-50%, -42%) rotateX(67deg);
  box-shadow: 0 42px 38px rgba(0,0,0,.25);
}

.trias-board {
  position: relative;
  width: min(53vh, 540px, 68vw);
  aspect-ratio: 1;
  border: 1px solid #000;
  background:
    repeating-linear-gradient(2deg, rgba(255,255,255,.035) 0 1px, transparent 1px 8px),
    linear-gradient(135deg, #b58451, #9b6838 48%, #b07a46);
  box-shadow: 0 24px 30px rgba(0,0,0,.3), inset 0 0 0 8px rgba(255,255,255,.07);
  transform: translateY(2%) rotateX(4deg);
  isolation: isolate;
  pointer-events: auto;
}

.trias-board::before { position: absolute; inset: 3%; z-index: -1; border: 1px solid rgba(0,0,0,.34); content: ""; }
.trias-board::after { position: absolute; bottom: 3.5%; left: 50%; color: rgba(0,0,0,.46); content: "ΤΡΙΑΣ"; font-size: 2.5%; font-weight: 500; letter-spacing: .35em; transform: translateX(-50%); }
.scoreboard {
  position: absolute;
  z-index: 8;
  top: -42px;
  left: 50%;
  display: flex;
  min-width: 154px;
  min-height: 34px;
  align-items: center;
  justify-content: center;
  gap: 13px;
  border: 1px solid var(--fg);
  background: rgba(255,255,255,.96);
  color: var(--fg);
  box-shadow: 0 7px 18px rgba(0,0,0,.14);
  transform: translateX(-50%);
  pointer-events: none;
}
.score-side { display: inline-flex; min-width: 38px; align-items: center; justify-content: center; gap: 8px; }
.score-side b { font-size: 18px; font-weight: 500; font-variant-numeric: tabular-nums; line-height: 1; }
.score-dot { display: block; width: 14px; height: 14px; border: 1px solid var(--fg); border-radius: 50%; }
.score-divider { color: var(--fg-muted); font-size: 12px; }
.board-lines, .win-overlay { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.board-lines circle, .board-lines line { fill: none; stroke: rgba(43,24,13,.86); stroke-linecap: round; stroke-width: 1.15; }
.win-overlay { z-index: 4; pointer-events: none; }
.win-overlay path { fill: none; stroke: #fff; stroke-linecap: round; stroke-width: 1.8; filter: drop-shadow(0 0 3px rgba(255,255,255,.95)); opacity: 0; }
.win-overlay path.is-visible { opacity: 1; stroke-dasharray: 130; animation: drawWin 620ms cubic-bezier(.16,1,.3,1) both; }
@keyframes drawWin { from { stroke-dashoffset: 130; } to { stroke-dashoffset: 0; } }

.victory-burst { position: absolute; inset: 0; z-index: 7; overflow: visible; pointer-events: none; }
.victory-burst i { position: absolute; top: 50%; left: 50%; width: 7px; height: 7px; border: 1px solid rgba(0,0,0,.45); border-radius: 50%; background: #f4d189; opacity: 0; }
.victory-burst i:nth-child(even) { width: 5px; height: 5px; background: #fff; }
.victory-burst.is-active i { animation: victorySpark 980ms cubic-bezier(.16,1,.3,1) both; animation-delay: calc(var(--spark-index, 0) * 24ms); }
.victory-burst i:nth-child(2) { --spark-index: 1; }
.victory-burst i:nth-child(3) { --spark-index: 2; }
.victory-burst i:nth-child(4) { --spark-index: 3; }
.victory-burst i:nth-child(5) { --spark-index: 4; }
.victory-burst i:nth-child(6) { --spark-index: 5; }
.victory-burst i:nth-child(7) { --spark-index: 6; }
.victory-burst i:nth-child(8) { --spark-index: 7; }
.trias-board.is-celebrating { animation: victoryGlow 1350ms cubic-bezier(.16,1,.3,1) both; }
.node.is-winning .piece { animation: winnerPiece 680ms cubic-bezier(.16,1,.3,1) 2 alternate; }
@keyframes victorySpark { 0% { opacity: 0; transform: translate(-50%,-50%) scale(.25); } 18% { opacity: 1; } 100% { opacity: 0; transform: translate(calc(-50% + var(--dx)),calc(-50% + var(--dy))) scale(1); } }
@keyframes victoryGlow { 0%, 100% { filter: brightness(1); } 38% { filter: brightness(1.16) saturate(1.12); box-shadow: 0 30px 48px rgba(0,0,0,.34), 0 0 0 5px rgba(244,209,137,.82), inset 0 0 0 8px rgba(255,255,255,.13); } }
@keyframes winnerPiece { from { transform: scale(1); } to { transform: translateY(-5%) scale(1.13); } }

.node { position: absolute; z-index: 5; left: var(--x); top: var(--y); width: 13%; aspect-ratio: 1; padding: 0; border: 0; border-radius: 50%; background: transparent; transform: translate(-50%,-50%); touch-action: manipulation; user-select: none; cursor: pointer; }
.node:hover { background: transparent; }
.node:active { transform: translate(-50%,-50%) scale(.98); }
.node::before { position: absolute; inset: 27%; border: 1px solid rgba(0,0,0,.48); border-radius: 50%; background: rgba(50,27,13,.18); content: ""; transition: inset 120ms ease, background 120ms ease; }
.node:hover::before, .node.is-valid::before { inset: 20%; background: rgba(255,255,255,.28); }
.node.is-valid::after { position: absolute; inset: 13%; border: 1px solid #fff; border-radius: 50%; content: ""; }
.piece { position: absolute; inset: 7%; z-index: 2; border: 1px solid rgba(0,0,0,.72); border-radius: 50%; pointer-events: none; animation: pieceIn 220ms cubic-bezier(.16,1,.3,1); }
.piece::before { position: absolute; inset: 17%; border: 1px solid rgba(0,0,0,.28); border-radius: 50%; content: ""; }
.piece.sun { background: radial-gradient(circle at 35% 28%, #e6c47f, #9a7a3c 54%, #5f4821); box-shadow: 0 5px 8px rgba(0,0,0,.34); }
.piece.moon { background: radial-gradient(circle at 35% 28%, #fff, #d6d6d2 54%, #777); box-shadow: 0 5px 8px rgba(0,0,0,.34); }
.node.is-selected .piece { transform: translateY(-7%) scale(1.06); }
.node.is-winning .piece { box-shadow: 0 0 0 3px #fff, 0 5px 8px rgba(0,0,0,.34); }
@keyframes pieceIn { from { opacity: 0; transform: scale(.4); } }

.control-dock {
  right: 50%;
  bottom: 20px;
  display: flex;
  max-width: calc(100vw - 32px);
  align-items: stretch;
  padding: 0;
  transform: translateX(50%);
}
.control-dock > button, .control-dock > a, .control-dock .mode-group > button, .language-switch button { min-height: 46px; border: 0; border-left: 1px solid var(--fg); border-radius: 0; }
.control-dock > :first-child, .control-dock .mode-group > :first-child { border-left: 0; }
.mode-group, .language-switch { display: flex; }
.mode-group { border-right: 1px solid var(--fg); }
.language-switch { border-left: 1px solid var(--fg); border-right: 1px solid var(--fg); }
.language-switch button { min-width: 42px; padding: 0 9px; }

dialog { width: min(760px, calc(100% - 32px)); padding: clamp(28px, 4vw, 48px); border: 1px solid var(--fg); border-radius: 0; background: var(--bg); color: var(--fg); box-shadow: 0 18px 40px -18px rgba(49,50,54,.5); }
dialog::backdrop { background: rgba(49,50,54,.74); }
.dialog-close { position: absolute; top: 12px; right: 12px; min-width: 44px; padding: 0; border: 0; background: transparent; font-size: 24px; }
dialog h2 { margin: 9px 0 18px; font-size: clamp(2rem, 4vw, 3.8rem); font-weight: 300; line-height: .98; letter-spacing: -.02em; }
.dialog-copy { max-width: 570px; color: var(--fg-muted); font-size: 14px; line-height: 1.55; }
.rule-grid { display: grid; grid-template-columns: repeat(3,1fr); margin-top: 26px; border-top: 1px solid var(--fg); border-left: 1px solid var(--fg); }
.rule-grid article { min-height: 180px; padding: 18px; border-right: 1px solid var(--fg); border-bottom: 1px solid var(--fg); }
.rule-grid article > span { color: var(--accent); font-size: 11px; font-weight: 500; letter-spacing: .14em; }
.rule-grid h3 { margin: 28px 0 8px; font-size: 17px; font-weight: 500; }
.rule-grid p { margin: 0; color: var(--fg-muted); font-size: 12px; line-height: 1.55; }
.source-links { display: flex; gap: 20px; margin-top: 20px; }
.source-links a { color: var(--fg); font-size: 11px; font-weight: 500; letter-spacing: .1em; text-transform: uppercase; }
.dialog-action { margin-top: 26px; border-color: var(--accent); background: var(--accent); color: var(--accent-fg); }
.dialog-action:hover { background: var(--accent-hover); }
.dialog-secondary { margin-top: 26px; }

.online-dialog { width: min(620px, calc(100% - 32px)); }
.online-create .dialog-action { width: 100%; }
.join-divider { display: flex; align-items: center; gap: 12px; margin: 24px 0; color: var(--fg-muted); font-size: 10px; font-weight: 500; letter-spacing: .14em; text-transform: uppercase; }
.join-divider::before, .join-divider::after { height: 1px; flex: 1; background: var(--fg); content: ""; }
.join-form { display: grid; gap: 8px; }
.join-form label { font-size: 11px; font-weight: 500; letter-spacing: .14em; text-transform: uppercase; }
.join-form > div { display: grid; grid-template-columns: 1fr auto; }
.join-form input { min-width: 0; padding: 13px 15px; border: 2px solid var(--fg); border-radius: 6px 0 0 6px; font-size: 18px; font-weight: 500; letter-spacing: .28em; text-transform: uppercase; }
.join-form button { border-width: 2px; border-radius: 0 6px 6px 0; }
.room-card { margin-top: 24px; padding: 22px; border: 1px solid var(--fg); text-align: center; }
.room-card > span { color: var(--fg-muted); font-size: 10px; font-weight: 500; letter-spacing: .14em; text-transform: uppercase; }
.room-card strong { display: block; margin: 8px 0; color: var(--accent); font-size: 38px; font-weight: 500; letter-spacing: .18em; }
.room-card p { color: var(--fg-muted); font-size: 12px; }
.room-card div { display: flex; justify-content: center; gap: 8px; }
.form-error { min-height: 18px; color: #b00020; font-size: 12px; }

.result-dialog { width: min(430px, calc(100% - 32px)); text-align: center; }
.result-dialog[open] { position: fixed; inset: auto 34px 84px auto; width: 360px; margin: 0; padding: 30px 28px; }
.result-dialog h2 { margin-block: 6px 12px; font-size: 2.8rem; }
.result-dialog::backdrop { background: rgba(49,50,54,.32); backdrop-filter: blur(1px); }
.result-dialog > p:not(.eyebrow) { color: var(--fg-muted); line-height: 1.55; }
.result-actions { display: flex; justify-content: center; gap: 8px; }
.result-actions button { margin-top: 18px; }

.toast { position: fixed; z-index: 30; left: 50%; bottom: 88px; padding: 12px 18px; border: 1px solid var(--fg); border-radius: 0; background: var(--bg); color: var(--fg); font-size: 11px; font-weight: 500; opacity: 0; pointer-events: none; transform: translate(-50%,16px); transition: 220ms ease; }
.toast.is-visible { opacity: 1; transform: translate(-50%,0); }

@media (max-width: 1180px) {
  .players-panel { top: auto; bottom: 84px; width: min(430px, 40vw); }
  .difficulty-panel { bottom: 84px; }
  .trias-board { width: min(51vh, 520px, 66vw); }
}

@media (max-width: 760px) {
  .wall-mark { top: 3%; height: 12%; }
  .title-panel { top: 8px; right: 10px; left: 10px; width: auto; padding: 9px 14px 10px; }
  .title-panel h1 { margin: 2px 0 3px; font-size: 2.1rem; }
  .title-panel > span { display: block; font-size: 10px; line-height: 1.25; }
  .mobile-lab-link { position: fixed; z-index: 8; top: 20px; right: 18px; display: inline-flex; min-width: 54px; min-height: 32px; align-items: center; justify-content: center; border: 1px solid var(--fg); background: var(--bg); color: var(--fg); font-size: 10px; font-weight: 500; letter-spacing: .1em; text-decoration: none; text-transform: uppercase; }
  .desktop-lab-link { display: none !important; }
  .status-panel { top: 105px; right: 10px; left: 10px; width: auto; padding: 8px 40px 8px 12px; }
  .status-panel h2 { margin-top: 4px; font-size: 13px; }
  .mobile-status-close { position: absolute; top: 3px; right: 4px; display: grid; width: 28px; min-height: 28px; padding: 0; place-items: center; border: 0; background: transparent; color: var(--fg); font-size: 20px; font-weight: 300; line-height: 1; }
  .mobile-status-close:hover { background: transparent; color: var(--fg); }
  .status-panel.is-mobile-hidden { display: none; }
  .status-panel.is-mobile-hidden ~ .players-panel { top: 105px; }
  .status-panel.is-mobile-hidden ~ .difficulty-panel { top: 163px; }
  .status-panel.is-mobile-hidden ~ .museum-stage { padding-top: 205px; }
  .status-panel.is-mobile-hidden ~ .museum-stage .trias-board { width: min(92vw, clamp(310px, calc(100dvh - 272px), 430px)); }
  .players-panel { top: 160px; right: 10px; bottom: auto; left: 10px; width: auto; min-width: 0; transform: none; }
  .player-card { min-height: 52px; padding: 5px 9px; }
  .mini-piece { width: 22px; height: 22px; }
  .difficulty-panel { top: 218px; right: 10px; bottom: auto; left: 10px; display: flex; align-items: center; justify-content: space-between; padding: 5px 7px 5px 11px; }
  .difficulty-panel > span { margin: 0; }
  .difficulty-panel > div { gap: 4px; }
  .difficulty-panel button { min-height: 34px; padding: 0 9px; }
  .difficulty-panel.is-hidden { display: none; }
  .museum-stage { padding-top: 260px; padding-bottom: 56px; place-items: center; }
  .trias-board { width: min(92vw, clamp(300px, calc(100dvh - 327px), 430px)); transform: rotateX(3deg); }
  .scoreboard { top: 2%; width: 91%; min-width: 0; min-height: 0; justify-content: space-between; gap: 0; border: 0; background: transparent; box-shadow: none; }
  .score-side { min-width: 54px; min-height: 27px; gap: 7px; border: 1px solid var(--fg); background: rgba(255,255,255,.94); }
  .score-side b { font-size: 15px; }
  .score-dot { width: 12px; height: 12px; }
  .score-divider { visibility: hidden; }
  .plinth { top: 59%; width: min(98vw, 52vh); height: min(64vw, 34vh); }
  .control-dock { right: 0; bottom: 0; left: 0; max-width: none; overflow-x: auto; border-right: 0; border-left: 0; transform: none; scrollbar-width: none; }
  .control-dock::-webkit-scrollbar { display: none; }
  .control-dock > button, .control-dock > a, .control-dock .mode-group > button, .language-switch button { min-height: 52px; padding: 0 13px; }
  .source-links { flex-direction: column; gap: 10px; }
  .rule-grid { grid-template-columns: 1fr; }
  .rule-grid article { min-height: 0; }
  .rule-grid h3 { margin-top: 10px; }
  .room-card div, .result-actions { flex-direction: column; }
  .room-card div button, .result-actions button { width: 100%; }
  .result-dialog[open] { inset: auto 10px 62px; width: auto; padding: 20px; }
  .result-dialog h2 { font-size: 2.25rem; }
  .result-dialog .result-actions { display: grid; grid-template-columns: 1fr 1fr; }
  .result-dialog .result-actions button { margin-top: 12px; }
  .toast { bottom: 68px; }
}

@media (max-width: 760px) and (max-height: 620px) {
  .title-panel > .eyebrow, .title-panel > span { display: none; }
  .title-panel { padding-block: 7px; }
  .title-panel h1 { margin: 0; font-size: 1.9rem; }
  .status-panel { top: 58px; }
  .players-panel { top: 108px; }
  .difficulty-panel { top: 166px; }
  .museum-stage { padding-top: 214px; }
  .trias-board { width: min(84vw, clamp(270px, calc(100dvh - 280px), 320px)); }
  .mobile-lab-link { top: 14px; }
  .status-panel.is-mobile-hidden ~ .players-panel { top: 58px; }
  .status-panel.is-mobile-hidden ~ .difficulty-panel { top: 116px; }
  .status-panel.is-mobile-hidden ~ .museum-stage { padding-top: 164px; }
  .status-panel.is-mobile-hidden ~ .museum-stage .trias-board { width: min(88vw, clamp(280px, calc(100dvh - 230px), 340px)); }
}

@media (max-height: 700px) and (min-width: 761px) {
  .title-panel { padding: 15px 18px; }
  .title-panel h1 { font-size: 2.6rem; }
  .title-panel > span { font-size: 11px; }
  .status-panel { padding: 14px; }
  .trias-board { width: min(48vh, 450px, 60vw); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; scroll-behavior: auto !important; }
}
