@import url("https://fonts.googleapis.com/css2?family=Bagel+Fat+One&family=Noto+Serif+KR:wght@500;600;700;900&display=swap");

:root {
  color-scheme: light;
  --paper: #f7efe0;
  --line: #3b2413;
  --ink: #202020;
  --cho: #164cbd;
  --han: #c51d28;
  --panel: #ffffff;
  --muted: #6f6a62;
  --board-line-width: 1px;
  --font-ui: system-ui, -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Malgun Gothic", "맑은 고딕", "Segoe UI", sans-serif;
  --font-control: system-ui, -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Malgun Gothic", "맑은 고딕", "Segoe UI", sans-serif;
  --font-janggi: "Noto Serif KR", "Source Han Serif KR", "Noto Serif CJK KR", "Hiragino Mincho ProN", "YuMincho", "Yu Mincho", "Songti SC", "STSong", "AppleMyungjo", "Batang", "Gungsuh", serif;
  --font-alert: "Bagel Fat One", system-ui, -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Malgun Gothic", "맑은 고딕", sans-serif;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

body {
  margin: 0;
  min-height: 100vh;
  background: #f5f3ee;
  color: var(--ink);
  font-family: var(--font-ui);
  font-feature-settings: "kern";
}

body:not(.in-game) {
  display: grid;
  place-items: center;
  background: #f8f8fb;
}

.app {
  width: min(1180px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 24px 0 32px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 18px;
  margin-bottom: 14px;
}

body:not(.in-game) .app {
  width: 100vw;
  min-height: 100vh;
  padding: 0;
}

body:not(.in-game) .topbar {
  display: block;
  margin: 0;
}

body:not(.in-game) .topbar > div:first-child,
body:not(.in-game) .status,
body:not(.in-game) .play {
  display: none;
}

body:not(.in-game) .actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
  width: 100%;
  align-content: center;
  justify-items: center;
  min-height: 100vh;
  padding: max(22px, env(safe-area-inset-top)) 22px max(22px, env(safe-area-inset-bottom));
  background: #f8f8fb;
  border: 0;
  border-radius: 0;
  box-shadow: none;
}

.gateScreen,
.entryScreen {
  width: 100%;
}

.gateScreen {
  min-height: calc(100vh - 44px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  display: grid;
  justify-items: center;
  align-content: center;
  gap: 14px;
  text-align: center;
}

.gateMenu {
  align-content: center;
}

.gateAvatar,
.lockIcon {
  width: 58px;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: #e9f2ff;
  color: #0f61b8;
  font-family: var(--font-janggi);
  font-size: 28px;
  font-weight: 900;
  box-shadow: 0 7px 18px rgba(15, 97, 184, .14);
}

.lockIcon {
  font-family: var(--font-control);
  font-size: 24px;
}

.gateScreen h2 {
  margin: 4px 0 0;
  font-size: 22px;
  line-height: 1.1;
}

.gateScreen p {
  max-width: 220px;
  font-size: 12px;
  line-height: 1.45;
}

.gateScreen > button:not(.backButton),
.confirmPassword {
  width: min(220px, 100%);
  height: 48px;
  border: 0;
  border-radius: 999px;
  background: #0b5fb3;
  color: #fff;
  font-size: 17px;
  font-weight: 900;
}

.gateMenu > button:not(.backButton) {
  height: 56px;
  background: #032313;
  font-size: 20px;
  letter-spacing: 0;
}

.passwordScreen {
  position: relative;
  align-content: start;
  padding-top: 8px;
}

.backButton {
  position: absolute;
  left: 0;
  top: 0;
  width: 34px;
  height: 34px;
  border: 0;
  background: transparent;
  color: #0b4f91;
  font-size: 28px;
  line-height: 1;
}

.passDots {
  display: flex;
  gap: 13px;
  justify-content: center;
  margin: 10px 0 6px;
}

.passDots span {
  width: 8px;
  aspect-ratio: 1;
  border: 1px solid #b8c6db;
  border-radius: 999px;
  background: transparent;
}

.passDots span.filled {
  border-color: #0b5fb3;
  background: #0b5fb3;
}

.keypad {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px 18px;
  margin: 8px 0 12px;
}

.keypad button {
  width: 48px;
  height: 48px;
  justify-self: center;
  border: 0;
  border-radius: 999px;
  background: #fff;
  color: #1f2f45;
  font-size: 13px;
  font-weight: 800;
  box-shadow: 0 5px 15px rgba(24, 36, 62, .06);
}

.keypad button:hover {
  background: #edf4ff;
  color: #0b5fb3;
}

.passError {
  min-height: 18px;
  color: #c33838;
  font-size: 11px;
  font-weight: 800;
}

.entryScreen {
  display: grid;
  gap: 16px;
  width: min(100%, 360px);
}

body:not(.in-game) .startPanel,
body:not(.in-game) #joinForm {
  display: grid;
  gap: 12px;
  padding: 18px;
  background: rgba(255, 255, 255, .94);
  border: 1px solid #ded8d1;
  border-radius: 10px;
  box-shadow: 0 10px 24px rgba(30, 24, 18, .08);
}

.entryLabel {
  color: #59483e;
  font-size: 12px;
  font-weight: 800;
}

body:not(.in-game) .actions form {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

.roomCodeLabel {
  grid-column: 1 / -1;
  font-family: var(--font-control);
  color: #59483e;
  font-size: 12px;
  font-weight: 800;
}

.roomCodeEntry {
  grid-column: 1 / -1;
  font-family: var(--font-control);
  height: 48px;
  width: 100%;
  background: #fbfaf8;
  border: 1px solid #d7d2cd;
  border-radius: 6px;
  color: #17315f;
  font-size: 20px;
  font-weight: 900;
  text-align: center;
  text-transform: uppercase;
  letter-spacing: .28em;
  box-shadow: 0 2px 4px rgba(20, 15, 10, .08);
  caret-color: #17315f;
  margin-bottom: 2px;
}

.roomCodeEntry::placeholder {
  color: #b8b0a8;
  letter-spacing: .18em;
}

body:not(.in-game) #newGame,
body:not(.in-game) .joinButton {
  grid-column: 1 / -1;
  height: 40px;
  width: 100%;
}

body:not(.in-game) #newGame {
  border-color: #041f13;
  border-radius: 6px;
  background: #032313;
  color: #fff;
  font-size: 12px;
  font-weight: 900;
}

body:not(.in-game) .joinButton {
  border: 1px solid #9c7e72;
  border-radius: 6px;
  background: transparent;
  color: #6d4d42;
  font-size: 12px;
  font-weight: 800;
}

h1 {
  margin: 0 0 4px;
  font-size: 28px;
}

p {
  margin: 0;
  color: var(--muted);
}

.actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

form {
  display: flex;
  gap: 8px;
}

button, input {
  height: 40px;
  border: 1px solid #bbb2a5;
  border-radius: 6px;
  font: inherit;
  font-family: var(--font-control);
}

button {
  padding: 0 14px;
  background: #263238;
  color: white;
  cursor: pointer;
}

button:hover { background: #111a1f; }

input {
  width: 96px;
  padding: 0 10px;
  text-transform: uppercase;
}

.status {
  display: grid;
  grid-template-columns: repeat(4, minmax(120px, 1fr));
  gap: 8px;
  margin-bottom: 16px;
}

.status div {
  background: var(--panel);
  border: 1px solid #d6d0c5;
  border-radius: 8px;
  padding: 10px 12px;
}

.status span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 4px;
}

.status strong {
  font-size: 18px;
}

.play {
  display: grid;
  grid-template-columns: 1fr;
  align-items: start;
  gap: 10px;
  width: min(100%, 720px);
  margin: 0 auto;
}

.playerCard {
  display: grid;
  grid-template-columns: 48px 1fr auto;
  align-items: center;
  gap: 10px;
  min-height: 58px;
  padding: 10px 12px;
  background: rgba(255, 255, 255, .94);
  border: 1px solid #e5e0d8;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(32, 28, 22, .08);
}

.roomHeader {
  display: none;
  align-items: center;
  gap: 9px;
  min-height: 42px;
  padding: 8px 10px;
  background: rgba(255, 255, 255, .94);
  border: 1px solid #e5e0d8;
  border-radius: 8px;
}

body.in-game .roomHeader {
  display: flex;
}

body.in-game .roomHeader .roomCodePill {
  margin-right: auto;
}

.brandMark {
  width: 28px;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: #ffe3d7;
  color: #9a432b;
  font-weight: 900;
}

.roomHeader strong {
  margin-right: auto;
  font-size: 16px;
}

.roomCodePill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-control);
  padding: 3px 12px 4px;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: #9b9490;
  font-size: 8px;
  font-weight: 800;
  letter-spacing: .16em;
  white-space: nowrap;
}

.roomHeader b {
  color: #111;
  font-size: 12px;
  letter-spacing: 0;
}

.restartPill {
  width: auto;
  height: 32px;
  padding: 0 14px;
  border: 1px solid #d8d1c7;
  border-radius: 999px;
  background: #f5f0ea;
  color: #171717;
  font-size: 12px;
  font-weight: 800;
  line-height: 1;
}

.restartPill:hover {
  background: #ece4d8;
}

.restartPill:disabled {
  cursor: default;
  opacity: .58;
}

.restartStatus {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

body:not(.in-game) .playerCard,
body:not(.in-game) .roomHeader {
  display: none;
}

.playerCard.active .timer {
  background: #ffe7e5;
  color: var(--han);
}

.avatar {
  width: 40px;
  aspect-ratio: 1;
  border-radius: 9px;
  display: grid;
  place-items: center;
  font-weight: 900;
  background: #fffdfa;
  box-shadow: inset 0 0 0 2px currentColor;
}

.avatar.cho { color: var(--cho); }
.avatar.han { color: var(--han); }

.playerInfo {
  min-width: 0;
}

.playerInfo strong,
.playerInfo span {
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.playerInfo strong {
  font-size: 15px;
  line-height: 1.2;
}

.playerInfo span {
  margin-top: 3px;
  color: #5f5a52;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .02em;
}

.timer {
  min-width: 76px;
  padding: 7px 9px;
  border-radius: 6px;
  color: #111;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 17px;
  font-weight: 900;
  text-align: center;
}

.timer::before {
  content: none;
}

.boardShell {
  width: min(100%, 720px);
  display: grid;
  grid-template-columns: 1fr;
  gap: 0;
}

.files {
  display: none;
  grid-template-columns: repeat(9, 1fr);
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  text-align: center;
}

.boardRow {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: 1fr;
  gap: 0;
  align-items: stretch;
}

.ranks {
  display: none;
  grid-template-rows: repeat(10, 1fr);
  align-items: center;
  justify-items: end;
  color: #151515;
  font-size: 13px;
  font-weight: 700;
}

.board {
  position: relative;
  width: 100%;
  min-height: 320px;
  aspect-ratio: 9 / 10;
  background:
    linear-gradient(90deg, rgba(255,255,255,.04), rgba(0,0,0,.07)),
    repeating-linear-gradient(0deg, rgba(255,255,255,.035) 0 2px, transparent 2px 26px),
    #8a562d;
  border: 1px solid #4c2f18;
  border-radius: 0;
  overflow: hidden;
  box-shadow: 0 8px 20px rgba(36, 28, 20, .16);
}

.gridLine,
.diag {
  position: absolute;
  background: #2a180c;
  pointer-events: none;
}

.boardLines {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 1;
}

.boardLine {
  stroke: #2a180c;
  stroke-width: var(--board-line-width);
  stroke-linecap: square;
  vector-effect: non-scaling-stroke;
}

.boardLine.grid {
  shape-rendering: crispEdges;
}

.boardLine.palace {
  shape-rendering: geometricPrecision;
}

.boardIndexes {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
}

.boardIndex {
  position: absolute;
  transform: translate(-50%, -50%);
  color: rgba(43, 24, 12, .42);
  font-family: var(--font-control);
  font-size: clamp(10px, 2.6vw, 15px);
  font-weight: 900;
  line-height: 1;
  text-shadow: 0 1px 0 rgba(255, 220, 150, .23);
  user-select: none;
}

.fileIndex {
  transform: translate(-50%, 0);
}

.rankIndex {
  transform: translate(0, -50%);
}

.point {
  position: absolute;
  width: 10.6%;
  height: 9.6%;
  transform: translate(-50%, -50%);
  display: grid;
  place-items: center;
  border: 0;
  padding: 0;
  background: transparent;
  color: inherit;
  z-index: 2;
  touch-action: manipulation;
  outline: none;
  appearance: none;
  -webkit-appearance: none;
  -webkit-tap-highlight-color: transparent;
}

.point:hover {
  background: transparent !important;
}

.point:focus,
.point:focus-visible,
.point:active {
  outline: none;
  background: transparent !important;
  box-shadow: none;
}

.point:focus .piece,
.point:focus-visible .piece,
.point:active .piece,
.point.selectedPoint .piece {
  background: transparent;
}

.point.selectedPoint::before {
  content: "";
  position: absolute;
  width: 108%;
  aspect-ratio: 1;
  border-radius: 999px;
  background: rgba(255, 213, 79, .34);
  box-shadow: 0 0 0 4px rgba(255, 183, 0, .72), 0 0 18px rgba(255, 193, 7, .42);
  pointer-events: none;
  z-index: 0;
}

.point.legalMove::after,
.point.captureMove::after {
  content: "";
  position: absolute;
  width: 26%;
  aspect-ratio: 1;
  border-radius: 999px;
  background: rgba(255, 213, 79, .72);
  box-shadow: 0 0 0 2px rgba(255, 193, 7, .42);
  pointer-events: none;
  z-index: 3;
}

.point.captureMove::after {
  width: 104%;
  background: transparent;
  box-shadow: 0 0 0 4px rgba(255, 193, 7, .92), 0 0 18px rgba(255, 213, 79, .5);
  z-index: 4;
}

.piece {
  width: min(42px, 88%);
  aspect-ratio: 1;
  border: 0;
  background: transparent;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: clamp(15px, 2.9vw, 25px);
  line-height: 1;
  filter: none;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  pointer-events: none;
  position: relative;
  z-index: 1;
  -webkit-tap-highlight-color: transparent;
  box-shadow: none;
}

.piece::before {
  content: none;
}

.pieceSvg {
  width: 100%;
  height: 100%;
  display: block;
  overflow: visible;
}

.pieceShape {
  fill: #fffdfa;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
}

.pieceText {
  font-family: var(--font-janggi);
  font-weight: 700;
  font-size: 56px;
  fill: currentColor;
  stroke: none;
  paint-order: fill;
}

.piece.kind-P,
.piece.kind-A {
  width: min(28px, 64%);
}

.piece.kind-K {
  width: min(46px, 94%);
}

.piece.kind-P::before,
.piece.kind-A::before {
  content: none;
}

.piece.kind-P .pieceText,
.piece.kind-A .pieceText {
  font-size: 53px;
}

.piece.kind-K .pieceText {
  font-size: 58px;
}

.piece.cho {
  color: var(--cho);
}
.piece.han {
  color: var(--han);
}
.piece.selected {
  filter: none;
}

aside {
  width: 100%;
  background: var(--panel);
  border: 1px solid #d6d0c5;
  border-radius: 8px;
  padding: 14px;
  min-height: 280px;
}

.gameControls {
  display: grid;
  grid-template-columns: minmax(120px, auto) 1fr;
  align-items: center;
  gap: 10px;
  width: 100%;
  background: var(--panel);
  border: 1px solid #d6d0c5;
  border-radius: 8px;
  padding: 10px;
}

.gameControls button {
  height: 38px;
}

.gameControls button:disabled {
  cursor: default;
  opacity: .65;
}

.gameControls span {
  min-width: 0;
  color: var(--muted);
  font-size: 13px;
}

aside h2 {
  margin: 0 0 10px;
  font-size: 18px;
}

ol {
  margin: 0;
  padding-left: 22px;
  color: #3d3934;
  line-height: 1.55;
  font-size: 14px;
}

ol li {
  margin-bottom: 7px;
  padding: 6px 8px;
  background: #fbfaf7;
  border: 1px solid #eee8dc;
  border-radius: 6px;
}

.gameToast {
  position: fixed;
  z-index: 35;
  left: 50%;
  top: 48%;
  width: min(170px, calc(100vw - 64px));
  padding: 16px 14px 13px;
  display: grid;
  justify-items: center;
  gap: 5px;
  transform: translate(-50%, -50%) scale(.96);
  opacity: 0;
  color: #f3f6ee;
  background: rgba(47, 68, 56, .96);
  border: 1px solid rgba(255, 255, 255, .16);
  border-radius: 7px;
  box-shadow: 0 12px 28px rgba(0, 0, 0, .28);
  pointer-events: none;
  transition: opacity .18s ease, transform .18s ease;
}

.gameToast > * {
  position: relative;
  z-index: 1;
}

.gameToast[hidden] {
  display: none;
}

.gameToast.show {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

.gameToast strong {
  font-size: 17px;
  letter-spacing: 0;
}

.gameToast.compact {
  width: auto;
  min-width: 118px;
  padding: 18px 22px;
  background: rgba(33, 43, 36, .94);
}

.gameToast.compact strong {
  font-size: 28px;
  line-height: 1;
}

.gameToast.spotlight {
  --alert-main: #ff554c;
  --alert-shadow: rgba(110, 24, 21, .55);
  --alert-soft: rgba(255, 95, 82, .18);
  --alert-glow: rgba(255, 214, 102, .2);
  --alert-core: rgba(255, 238, 184, .86);
  --alert-burst: rgba(255, 91, 72, .34);
  --alert-burst-glow: rgba(255, 207, 76, .3);
  --alert-drop: rgba(255, 80, 54, .28);
  --alert-drop-glow: rgba(255, 214, 76, .24);
  --alert-star: #ff5d58;
  --alert-star-soft: #ffe9e7;
  --alert-star-dark: #9d151f;
  width: min(340px, calc(100vw - 18px));
  min-height: 300px;
  min-width: 0;
  align-content: center;
  overflow: visible;
  padding: 34px 16px;
  color: var(--alert-main);
  background: transparent;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  transition: opacity .16s ease, transform .16s ease;
}

.gameToast.spotlight.blue {
  --alert-main: #2775ff;
  --alert-shadow: rgba(18, 50, 126, .52);
  --alert-soft: rgba(39, 117, 255, .18);
  --alert-glow: rgba(121, 196, 255, .22);
  --alert-core: rgba(226, 243, 255, .78);
  --alert-burst: rgba(39, 117, 255, .34);
  --alert-burst-glow: rgba(121, 196, 255, .3);
  --alert-drop: rgba(39, 117, 255, .28);
  --alert-drop-glow: rgba(121, 196, 255, .25);
  --alert-star: #2f7dff;
  --alert-star-soft: #d7ecff;
  --alert-star-dark: #174ea6;
}

.gameToast.spotlight::before,
.gameToast.spotlight::after {
  content: "";
  position: absolute;
  pointer-events: none;
}

.gameToast.spotlight::before {
  inset: -88px -86px;
  border-radius: 0;
  background:
    radial-gradient(circle at 49% 51%, rgba(255, 255, 255, .98) 0 11%, var(--alert-core) 12% 22%, transparent 23%),
    radial-gradient(circle at 52% 48%, var(--alert-burst) 0 34%, transparent 58%),
    radial-gradient(circle at 47% 55%, var(--alert-burst-glow) 0 46%, transparent 68%);
  clip-path: polygon(
    50% 0,
    59% 29%,
    84% 10%,
    72% 38%,
    100% 50%,
    71% 58%,
    78% 91%,
    54% 70%,
    33% 100%,
    35% 66%,
    4% 78%,
    25% 53%,
    0 32%,
    32% 35%,
    34% 5%,
    50% 30%
  );
  filter:
    drop-shadow(0 10px 18px var(--alert-drop))
    drop-shadow(0 0 34px var(--alert-drop-glow));
  animation: spikePulse 1.18s ease-in-out infinite;
}

.gameToast.spotlight.blue::before {
  animation: spikePulse 1.18s ease-in-out infinite;
}

.gameToast.spotlight::after {
  display: none;
}

.gameToast.spotlight strong {
  color: var(--alert-main);
  font-family: var(--font-alert);
  font-size: clamp(58px, 18vw, 82px);
  font-weight: 400;
  line-height: .92;
  text-shadow:
    4px 5px 0 var(--alert-shadow),
    0 3px 0 #ffe6db,
    0 0 22px rgba(255, 255, 255, .68);
  animation: titleBounce .88s cubic-bezier(.2, 1.45, .38, 1) both;
}

.toastStar {
  display: block;
  position: absolute;
  z-index: 0;
  width: 32px;
  aspect-ratio: 1;
  background: var(--alert-star);
  clip-path: polygon(50% 0, 61% 35%, 98% 35%, 68% 56%, 79% 91%, 50% 70%, 21% 91%, 32% 56%, 2% 35%, 39% 35%);
  pointer-events: none;
  filter: drop-shadow(0 4px 0 rgba(0, 0, 0, .12));
  animation: starBounce 1.05s ease-in-out infinite;
}

.gameToast.compact .toastStar {
  display: block;
}

.toastStar::before,
.toastStar::after {
  content: none;
}

.toastStar.star1 { left: 7%; top: 27%; width: 42px; animation-delay: 0s; }
.toastStar.star2 { right: 7%; top: 17%; width: 34px; background: var(--alert-star-dark); animation-delay: .08s; }
.toastStar.star3 { right: 8%; top: 45%; width: 22px; background: var(--alert-star-soft); animation-delay: .16s; }
.toastStar.star4 { left: 9%; bottom: 24%; width: 25px; background: var(--alert-star-soft); animation-delay: .24s; }
.toastStar.star5 { left: 22%; top: 15%; width: 17px; animation-delay: .32s; }
.toastStar.star6 { right: 23%; bottom: 18%; width: 19px; background: var(--alert-star); animation-delay: .4s; }
.toastStar.star7 { left: 46%; top: 10%; width: 15px; background: var(--alert-star-soft); animation-delay: .48s; }

.gameToast.spotlight.show {
  animation: spotlightPop .24s ease-out both;
}

.gameToast.spotlight.compact {
  background: transparent;
}

@keyframes spotlightPop {
  0% { transform: translate(-50%, -50%) scale(.72) rotate(-2deg); }
  70% { transform: translate(-50%, -50%) scale(1.07) rotate(1deg); }
  100% { transform: translate(-50%, -50%) scale(1); }
}

@keyframes titleBounce {
  0% { transform: translateY(18px) scale(.78); opacity: 0; }
  55% { transform: translateY(-8px) scale(1.08); opacity: 1; }
  78% { transform: translateY(3px) scale(.98); }
  100% { transform: translateY(0) scale(1); }
}

@keyframes starBounce {
  0%, 100% { transform: translateY(0) rotate(0deg) scale(1); opacity: .82; }
  45% { transform: translateY(-10px) rotate(-5deg) scale(1.08); opacity: 1; }
  72% { transform: translateY(3px) rotate(3deg) scale(.98); }
}

@keyframes spikePulse {
  0%, 100% { transform: scale(.9) rotate(-2deg); opacity: .8; }
  45% { transform: scale(1.08) rotate(1.5deg); opacity: 1; }
  72% { transform: scale(.98) rotate(-.5deg); opacity: .94; }
}

@keyframes spotlightPulse {
  0%, 100% { transform: scale(.98); opacity: .86; }
  50% { transform: scale(1.04); opacity: 1; }
}

.gameToast.compact span,
.gameToast.compact small {
  display: none;
}

.gameToast span {
  width: 100%;
  color: #d8e7dd;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 13px;
  font-weight: 900;
  text-align: center;
}

.gameToast span::before,
.gameToast span::after {
  content: "";
  display: inline-block;
  width: 28px;
  height: 1px;
  margin: 0 8px;
  background: rgba(216, 231, 221, .62);
  vertical-align: middle;
}

.gameToast .toastStar {
  color: inherit;
  font: inherit;
  text-align: initial;
}

.gameToast .toastStar::before,
.gameToast .toastStar::after {
  content: none;
  display: none;
}

.gameToast small {
  color: #cbd7cf;
  font-size: 11px;
  font-weight: 800;
}

.confettiPiece {
  position: fixed;
  z-index: 45;
  width: 8px;
  height: 12px;
  border-radius: 2px;
  pointer-events: none;
  transform: translate(-50%, -50%);
  animation: confettiBurst 2.35s cubic-bezier(.15,.8,.2,1) forwards;
}

@keyframes confettiBurst {
  0% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(.75) rotate(0deg);
  }
  68% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: translate(calc(-50% + var(--burst-x)), calc(-50% + var(--burst-y))) scale(.96) rotate(var(--spin));
  }
}

.modalBackdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(24, 22, 19, .42);
}

.modalBackdrop[hidden] {
  display: none;
}

.gameEndBackdrop {
  z-index: 50;
  background: rgba(96, 86, 67, .34);
  backdrop-filter: blur(4px);
}

.nicknameDialog,
.setupDialog,
.restartDialog,
.gameEndDialog {
  width: min(360px, 100%);
  display: grid;
  gap: 10px;
  padding: 18px;
  background: #fffdfa;
  border: 1px solid #e5e0d8;
  border-radius: 10px;
  box-shadow: 0 18px 60px rgba(0,0,0,.22);
}

.setupDialog {
  gap: 14px;
}

.setupDialog p,
.setupDialog small {
  color: #75695f;
  font-size: 12px;
  line-height: 1.45;
}

.setupChoices {
  display: grid;
  gap: 10px;
}

.setupChoices button {
  width: 100%;
  height: 48px;
  border: 1px solid #d7c9ba;
  border-radius: 8px;
  background: #fbf8f2;
  color: #2c2118;
  font-family: var(--font-janggi);
  font-size: 22px;
  font-weight: 700;
  letter-spacing: .08em;
  box-shadow: 0 4px 12px rgba(44, 33, 24, .07);
}

.setupChoices button:hover {
  border-color: #5d3b21;
  background: #efe1ce;
}

.gameEndDialog {
  width: min(176px, calc(100vw - 64px));
  justify-items: center;
  gap: 8px;
  padding: 22px 18px 16px;
  border-radius: 7px;
  text-align: center;
}

.winnerIcon {
  width: 44px;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: #143927;
  color: #fff;
  font-size: 22px;
  font-weight: 900;
}

.nicknameDialog h2,
.restartDialog h2,
.gameEndDialog h2 {
  margin: 0;
  font-size: 20px;
}

.gameEndDialog h2 {
  margin-top: 3px;
  font-size: 17px;
}

.nicknameDialog p,
.restartDialog p,
.gameEndDialog p {
  font-size: 13px;
}

.gameEndDialog p {
  color: #7a7067;
  font-size: 11px;
  line-height: 1.35;
}

.nicknameDialog input {
  width: 100%;
}

.modalActions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.modalActions button[type="button"] {
  background: #f4f0e8;
  color: #222;
}

.gameEndDialog .modalActions {
  width: 100%;
}

.gameEndDialog .modalActions button {
  height: 32px;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 900;
}

.gameEndDialog #gameEndRestart {
  border-color: #143927;
  background: #143927;
  color: #fff;
}

.gameEndDialog #gameEndLeave {
  border-color: #eee7dd;
  background: #fffdfa;
  color: #8a8178;
}

@media (max-width: 820px) {
  body {
    background: #f8f8fb;
  }

  .app {
    width: 100vw;
    padding: 0;
  }

  body.in-game .app {
    width: min(100vw - 14px, 560px);
    padding: 10px 0 18px;
  }

  body.in-game .topbar,
  body.in-game .status {
    display: none;
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 10px;
  }

  h1 {
    font-size: 22px;
  }

  p {
    font-size: 13px;
    line-height: 1.35;
  }

  .actions,
  form {
    display: grid;
    grid-template-columns: 1fr 1fr;
    width: 100%;
    gap: 8px;
  }

  body:not(.in-game) .actions,
  body:not(.in-game) .entryScreen,
  body:not(.in-game) .startPanel,
  body:not(.in-game) #joinForm {
    grid-template-columns: 1fr;
  }

  form {
    grid-column: 1 / -1;
  }

  button,
  input {
    width: 100%;
    min-width: 0;
    height: 42px;
  }

  .status {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
    margin-bottom: 10px;
  }

  .status div {
    padding: 8px 9px;
  }

  .status strong {
    font-size: 15px;
  }

  .play {
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .playerCard {
    grid-template-columns: 48px 1fr auto;
  }

  .roomHeader {
    display: flex;
  }

  .boardShell {
    width: 100%;
    grid-template-columns: 1fr;
    grid-template-rows: auto;
    gap: 0;
    padding: 8px 8px 10px;
    background: #6d4526;
    border-radius: 4px;
  }

  .boardRow {
    grid-template-columns: 1fr;
    gap: 0;
  }

  .files,
  .ranks {
    font-size: 11px;
  }

  aside {
    min-height: 0;
    max-height: 118px;
    overflow: auto;
    padding: 10px;
  }

  aside h2 {
    font-size: 15px;
    margin-bottom: 6px;
  }

  .piece {
    width: min(34px, 90%);
    font-size: clamp(13px, 5.3vw, 22px);
  }

  .piece.kind-P,
  .piece.kind-A {
    width: min(22px, 64%);
    font-size: clamp(10px, 3.4vw, 14px);
  }

  .piece.kind-K {
    width: min(37px, 94%);
    font-size: clamp(15px, 5.8vw, 24px);
  }
}

@media (max-width: 420px) {
  .app {
    width: calc(100vw - 8px);
  }

  .boardShell {
    grid-template-columns: 1fr;
  }

  .boardRow {
    grid-template-columns: 1fr;
  }

  .status {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .status span {
    font-size: 10px;
  }

  .status strong {
    font-size: 12px;
  }

  .playerCard {
    grid-template-columns: 42px 1fr auto;
    gap: 8px;
    min-height: 56px;
    padding: 9px 10px;
  }

  .avatar {
    width: 36px;
    border-radius: 9px;
  }

  .playerInfo strong {
    font-size: 14px;
  }

  .timer {
    min-width: 72px;
    padding: 6px 7px;
    font-size: 16px;
  }

  .roomHeader strong {
    font-size: 14px;
  }

  .roomCodePill {
    padding: 5px 8px;
    font-size: 9px;
    white-space: nowrap;
  }

  body.in-game .roomHeader .roomCodePill {
    margin-right: auto;
  }

  .restartPill {
    height: 28px;
    padding: 0 10px;
    font-size: 11px;
  }
}
