:root {
    --bg: #0f172a;
    --panel: #111827;
    --panel-2: #1f2937;
    --line: #d1a45a;
    --board: #e8c48a;
    --cell: #edc98f;
    --text: #e5e7eb;
    --muted: #94a3b8;
    --blue: #60a5fa;
    --red: #f87171;
    --gold: #fbbf24;
    --shadow: 0 20px 50px rgba(0,0,0,.28);
    --radius: 18px;
}

* { box-sizing: border-box; }
body {
    margin: 0;
    font-family: Inter, system-ui, sans-serif;
    color: var(--text);
    background:
        radial-gradient(circle at top, rgba(59,130,246,.12), transparent 30%),
        linear-gradient(180deg, #0b1120 0%, #111827 100%);
}

a { color: inherit; text-decoration: none; }

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 32px;
    border-bottom: 1px solid rgba(255,255,255,.08);
    background: rgba(17,24,39,.75);
    backdrop-filter: blur(10px);
}

.brand { display: flex; gap: 14px; align-items: center; }
.brand h1 { margin: 0; font-size: 1.2rem; }
.brand p { margin: 2px 0 0; color: var(--muted); font-size: .9rem; }
.brand-mark {
    width: 48px; height: 48px;
    display: grid; place-items: center;
    border-radius: 14px;
    background: linear-gradient(135deg, var(--gold), #b45309);
    color: #111827; font-weight: 800; font-size: 1.4rem;
}

.topnav { display: flex; gap: 18px; color: var(--muted); }
.topnav a:hover { color: white; }

.page-shell {
    max-width: 1440px;
    margin: 0 auto;
    padding: 32px;
}

.hero {
    padding: 36px;
    background: linear-gradient(135deg, rgba(31,41,55,.95), rgba(17,24,39,.95));
    border: 1px solid rgba(255,255,255,.08);
    border-radius: 28px;
    box-shadow: var(--shadow);
    margin-bottom: 28px;
}

.eyebrow {
    display: inline-block;
    color: var(--gold);
    font-size: .8rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .08em;
}

.hero h2 {
    margin: 12px 0;
    font-size: clamp(2rem, 3.5vw, 3.5rem);
    line-height: 1.05;
}

.hero p {
    max-width: 680px;
    color: var(--muted);
    font-size: 1.05rem;
}

.hero-actions {
    display: flex;
    gap: 12px;
    margin-top: 24px;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 12px 18px;
    border-radius: 12px;
    font-weight: 700;
}

.btn-primary {
    background: linear-gradient(135deg, var(--blue), #2563eb);
    color: white;
}

.btn-secondary {
    background: rgba(255,255,255,.06);
    border: 1px solid rgba(255,255,255,.08);
    color: white;
}

.board-layout {
    display: grid;
    grid-template-columns: 260px 1fr 260px;
    gap: 24px;
    align-items: start;
}

.side-panel,
.board-panel,
.panel-card {
    background: rgba(17,24,39,.88);
    border: 1px solid rgba(255,255,255,.08);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.side-panel {
    padding: 18px;
}

.side-panel h3,
.board-header h3,
.panel-card h4 {
    margin-top: 0;
}

.panel-card {
    padding: 16px;
    margin-top: 16px;
}

.panel-card p,
.board-header p,
.page-heading p {
    color: var(--muted);
}

.piece-bank {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
}

.captured-piece {
    display: grid;
    place-items: center;
    aspect-ratio: 1;
    background: rgba(255,255,255,.05);
    border: 1px solid rgba(255,255,255,.08);
    border-radius: 14px;
    font-size: 1.5rem;
    color: var(--blue);
}

.piece-bank.enemy .captured-piece {
    color: var(--red);
}

.board-panel {
    padding: 18px;
}

.board-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 18px;
}

.turn-indicator {
    padding: 10px 14px;
    border-radius: 999px;
    background: rgba(96,165,250,.12);
    color: var(--blue);
    font-weight: 700;
    border: 1px solid rgba(96,165,250,.25);
}

.janggi-board {
    width: 100%;
    max-width: 686px;
    margin: 0 auto;
    display: grid;
    grid-template-columns: repeat(9, 1fr);
    gap: 0;
    background: var(--board);
    border: 4px solid #8b5a2b;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: inset 0 0 0 2px rgba(0,0,0,.08);
}

.janggi-board.large {
    max-width: 776px;
}

.cell {
    position: relative;
    aspect-ratio: 1 / 1;
    border: 1px solid rgba(120,74,32,.5);
    background: var(--cell);
    cursor: pointer;
}

.cell:hover {
    background: #f5d8aa;
}

.piece {
    width: 70%;
    height: 70%;
    display: grid;
    place-items: center;
    margin: auto;
    border-radius: 999px;
    background: #f8f1e5;
    border: 2px solid #8b5a2b;
    box-shadow: 0 6px 14px rgba(0,0,0,.16);
    font-size: clamp(1rem, 2vw, 1.6rem);
    font-weight: 800;
    color: #111827;
}

.page-heading {
    margin-bottom: 24px;
}

@media (max-width: 1100px) {
    .board-layout {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 720px) {
    .topbar {
        padding: 18px;
        flex-direction: column;
        gap: 16px;
        align-items: flex-start;
    }

    .page-shell {
        padding: 18px;
    }

    .hero {
        padding: 22px;
    }
}

.blue-piece {
    color: #1d4ed8;
}

.red-piece {
    color: #b91c1c;
}

.selected-cell {
    background: #f8ddb4 !important;
}

.legal-cell::after {
    content: "";
    position: absolute;
    width: 18%;
    height: 18%;
    border-radius: 999px;
    background: rgba(37, 99, 235, 0.45);
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

.blue-piece {
    color: #1d4ed8;
}

.red-piece {
    color: #b91c1c;
}

.selected-cell {
    background: #f8ddb4 !important;
}

.legal-cell::after {
    content: "";
    position: absolute;
    width: 18%;
    height: 18%;
    border-radius: 999px;
    background: rgba(37, 99, 235, 0.45);
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

.game-banner {
    min-height: 24px;
    margin: 0 0 16px;
    padding: 10px 14px;
    border-radius: 12px;
    font-weight: 700;
}

.game-banner.is-check {
    background: rgba(248, 113, 113, 0.12);
    color: #fca5a5;
    border: 1px solid rgba(248, 113, 113, 0.25);
}

.game-banner.is-mate {
    background: rgba(251, 191, 36, 0.12);
    color: #fcd34d;
    border: 1px solid rgba(251, 191, 36, 0.25);
}

.move-history-card {
    max-height: 720px;
    overflow: auto;
}

.move-history-list {
    margin: 0;
    padding-left: 20px;
    color: var(--text);
}

.move-history-list li {
    margin: 0 0 10px;
    padding: 8px 10px;
    border-radius: 10px;
    background: rgba(255,255,255,.04);
    border: 1px solid rgba(255,255,255,.05);
    line-height: 1.4;
    font-size: .95rem;
}

.move-history-empty {
    color: var(--muted);
    font-size: .95rem;
}

.panel-card .btn {
    width: 100%;
    margin-bottom: 10px;
}

.panel-card .btn:last-child {
    margin-bottom: 0;
}

.piece-bank {
    min-height: 84px;
}

.captured-piece {
    user-select: none;
}

.cell.drag-over {
    background: #f8ddb4 !important;
    box-shadow: inset 0 0 0 3px rgba(37,99,235,.45);
}

.presence-dot {
    display: inline-block;
    margin-left: 8px;
    font-size: 12px;
    padding: 2px 8px;
    border-radius: 999px;
}

.presence-dot.online {
    background: rgba(34,197,94,.15);
    color: #4ade80;
}

.presence-dot.offline {
    background: rgba(239,68,68,.12);
    color: #f87171;
}

.games-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 18px;
}

.game-card h3 {
    margin-top: 0;
    margin-bottom: 10px;
}

.game-card p {
    margin: 6px 0;
    color: var(--muted);
}

button:disabled {
    opacity: .45;
    cursor: not-allowed;
}

input,
select,
textarea {
    background: rgba(255,255,255,.06);
    color: var(--text);
    border: 1px solid rgba(255,255,255,.12);
    outline: none;
}

input::placeholder,
textarea::placeholder {
    color: var(--muted);
}

input:focus,
select:focus,
textarea:focus {
    border-color: rgba(96,165,250,.7);
    box-shadow: 0 0 0 3px rgba(96,165,250,.18);
}

label {
    color: var(--text);
}

.hint-from-cell {
    box-shadow: inset 0 0 0 3px rgba(251,191,36,.8);
}

.hint-to-cell::before {
    content: "";
    position: absolute;
    inset: 18%;
    border: 3px dashed rgba(251,191,36,.85);
    border-radius: 999px;
}

.last-move-from {
    box-shadow: inset 0 0 0 3px rgba(59,130,246,.85);
}

.last-move-to {
    box-shadow: inset 0 0 0 4px rgba(34,197,94,.9);
    background: rgba(34,197,94,.12) !important;
}

.previous-move-from,
.previous-move-to {
    filter: blur(0.6px);
    opacity: 0.65;
    transition: opacity .3s ease;
}

.previous-move-from {
    box-shadow: inset 0 0 0 2px rgba(59,130,246,.35);
}

.previous-move-to {
    box-shadow: inset 0 0 0 2px rgba(34,197,94,.35);
}

.play-topbar {
    position: sticky;
    top: 0;
    z-index: 40;
    justify-content: flex-start;
    gap: 12px;
    padding: 12px 16px;
}

.play-page-heading {
    margin-bottom: 16px;
}

.play-focus-layout {
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.board-panel-main {
    order: 1;
}

.play-info-grid {
    order: 2;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 18px;
    align-items: start;
}

.play-info-grid .side-panel {
    min-width: 0;
}

.move-history-card {
    max-height: 420px;
    overflow: auto;
}

@media (max-width: 1100px) {
    .play-info-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 720px) {
    .play-topbar {
        padding: 10px 12px;
    }

    .play-page-heading {
        margin-bottom: 12px;
    }

    .board-panel-main {
        padding: 12px;
    }
}

.board-floating-indicator {
    width: fit-content;
    margin: 0 0 12px auto;
}


.board-bottom-indicator {
    width: fit-content;
    margin: 10px auto 0;
    padding: 6px 10px;
    font-size: 0.85rem;
    line-height: 1;
}


body:has(.play-topbar) .page-shell {
    padding-top: 10px;
}

.play-topbar {
    padding-bottom: 8px;
    margin-bottom: 0;
}

.play-focus-layout {
    gap: 10px;
}

.board-panel-main {
    padding-top: 10px;
}

.play-topbar {
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
}

.topbar-turn-indicator {
    justify-self: center;
    margin: 0;
    padding: 6px 10px;
    font-size: 0.85rem;
    line-height: 1;
}

#play-topnav {
    justify-self: end;
}


.board-panel-main {
    padding-top: 8px !important;
    padding-bottom: 8px !important;
}

.board-panel-main .game-banner {
    margin-bottom: 8px;
}

.board-panel-main .janggi-board {
    margin-top: 0;
    margin-bottom: 0;
}

.info-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.info-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: 12px;
    background: rgba(255,255,255,.04);
    border: 1px solid rgba(255,255,255,.05);
}

.info-label {
    color: var(--muted);
    font-weight: 700;
    min-width: 110px;
}

.info-actions {
    margin-top: 6px;
}

.controls-stack {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.reserve-card h4 {
    margin-bottom: 12px;
}

.reserve-empty {
    margin-top: 10px;
    color: var(--muted);
    font-size: .9rem;
}

.side-panel h3 {
    display: flex;
    align-items: center;
    gap: 8px;
}

.panel-card h4 {
    display: flex;
    align-items: center;
    gap: 8px;
}

.piece-bank {
    min-height: 88px;
    padding: 8px;
    border-radius: 14px;
    background: rgba(255,255,255,.03);
}

#blue-player-label,
#red-player-label,
#turn-label,
#turn-clock-label,
#status-label,
#spectator-count-label,
#selected-label,
#player-side-label {
    font-weight: 700;
}

.play-topnav-drawer {
    position: absolute;
    top: 52px;
    left: 12px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-width: 180px;
    padding: 12px;
    border-radius: 14px;
    background: rgba(17,24,39,.96);
    border: 1px solid rgba(255,255,255,.08);
    box-shadow: 0 18px 40px rgba(0,0,0,.35);
    opacity: 0;
    transform: translateY(-8px);
    pointer-events: none;
    transition: opacity .18s ease, transform .18s ease;
    z-index: 50;
}

.play-topnav-drawer.is-open {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}


.play-topbar-shell {
    position: sticky;
    top: 0;
    z-index: 60;
    overflow: visible;
}

.play-topnav-drawer {
    position: absolute;
    top: 48px;
    left: 12px;
    display: none;
    flex-direction: column;
    gap: 10px;
    min-width: 180px;
    padding: 12px;
    border-radius: 14px;
    background: rgba(17,24,39,.96);
    border: 1px solid rgba(255,255,255,.08);
    box-shadow: 0 18px 40px rgba(0,0,0,.35);
    z-index: 70;
}

.play-topnav-drawer.is-open {
    display: flex;
}

.floating-play-ui {
    position: fixed;
    top: 10px;
    left: 10px;
    right: 10px;
    z-index: 80;
    pointer-events: none;
}

.floating-menu-btn {
    position: absolute;
    top: 0;
    left: 0;
    pointer-events: auto;
}

.floating-turn-indicator {
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    margin: 0;
    padding: 6px 10px;
    font-size: 0.85rem;
    line-height: 1;
    pointer-events: none;
}

.play-topnav-drawer {
    position: absolute;
    top: 44px;
    left: 0;
    display: none;
    flex-direction: column;
    gap: 10px;
    min-width: 180px;
    padding: 12px;
    border-radius: 14px;
    background: rgba(17,24,39,.96);
    border: 1px solid rgba(255,255,255,.08);
    box-shadow: 0 18px 40px rgba(0,0,0,.35);
    z-index: 90;
    pointer-events: auto;
}

.play-topnav-drawer.is-open {
    display: flex;
}

body:has(.floating-play-ui) .page-shell {
    padding-top: 6px;
}

.janggi-board {
  position: relative;
  width: 100%;
  aspect-ratio: 9 / 10;
  max-width: 860px;
  margin: 0 auto;
}

.board-surface,
.board-svg,
.highlight-layer,
.piece-layer,
.hit-layer {
  position: absolute;
  inset: 0;
}

.piece-node {
  width: clamp(34px, 5vw, 56px);
  height: clamp(34px, 5vw, 56px);
  border-radius: 999px;
  border: 2px solid #9a6a35;
  background: #f7f0df;
  font-size: clamp(20px, 3vw, 34px);
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 6px rgba(0,0,0,.18);
  z-index: 3;
  padding: 0;
}

.intersection-hit {
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  z-index: 4;
  cursor: pointer;
  padding: 0;
}

.legal-marker {
  width: 14px;
  height: 14px;
  border-radius: 999px;
  background: rgba(30, 144, 255, .85);
  z-index: 2;
}

.selected-marker,
.last-from-marker,
.last-to-marker,
.hint-from-marker,
.hint-to-marker,
.previous-from-marker,
.previous-to-marker {
  width: clamp(40px, 5.8vw, 62px);
  height: clamp(40px, 5.8vw, 62px);
  border-radius: 999px;
  z-index: 2;
  box-sizing: border-box;
}

.selected-marker { border: 3px solid #2563eb; }
.last-from-marker { border: 3px solid #f59e0b; }
.last-to-marker { border: 3px solid #ef4444; }
.hint-from-marker { border: 3px dashed #10b981; }
.hint-to-marker { border: 3px dashed #06b6d4; }
.previous-from-marker,
.previous-to-marker { border: 2px solid rgba(255,255,255,.45); }

.board-panel-main {
  min-height: 760px;
}

/* Intersection board override */
#janggi-board.janggi-board {
  position: relative;
  display: block;
  width: min(860px, 100%);
  height: min(88vw, 920px);
  min-height: 620px;
  max-height: 920px;
  margin: 0 auto;
  padding: 0;
  overflow: visible;
  background: transparent !important;
}

#janggi-board.janggi-board.large {
  height: min(88vw, 920px);
  min-height: 620px;
}

.board-surface {
  position: absolute;
  inset: 0;
}

.board-svg,
.highlight-layer,
.piece-layer,
.hit-layer {
  position: absolute;
  inset: 0;
}

.piece-layer,
.highlight-layer,
.hit-layer {
  pointer-events: none;
}

.hit-layer {
  pointer-events: auto;
}

.piece-node {
  width: clamp(34px, 5vw, 56px);
  height: clamp(34px, 5vw, 56px);
  border-radius: 999px;
  border: 2px solid #9a6a35;
  background: #f7f0df;
  font-size: clamp(20px, 3vw, 34px);
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 6px rgba(0,0,0,.18);
  z-index: 3;
  padding: 0;
  pointer-events: auto;
}

.intersection-hit {
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  z-index: 4;
  cursor: pointer;
  padding: 0;
}

.legal-marker {
  width: 14px;
  height: 14px;
  border-radius: 999px;
  background: rgba(30, 144, 255, .85);
  z-index: 2;
}

.selected-marker,
.last-from-marker,
.last-to-marker,
.hint-from-marker,
.hint-to-marker,
.previous-from-marker,
.previous-to-marker {
  width: clamp(40px, 5.8vw, 62px);
  height: clamp(40px, 5.8vw, 62px);
  border-radius: 999px;
  z-index: 2;
  box-sizing: border-box;
}

.selected-marker { border: 3px solid #2563eb; }
.last-from-marker { border: 3px solid #f59e0b; }
.last-to-marker { border: 3px solid #ef4444; }
.hint-from-marker { border: 3px dashed #10b981; }
.hint-to-marker { border: 3px dashed #06b6d4; }
.previous-from-marker,
.previous-to-marker { border: 2px solid rgba(255,255,255,.45); }


#janggi-board.janggi-board,
#janggi-board.janggi-board.large {
  width: min(760px, 92vw);
  height: min(920px, 110vw);
  min-height: 760px;
  max-height: 920px;
}

@media (max-width: 900px) {
  #janggi-board.janggi-board,
  #janggi-board.janggi-board.large {
    width: 94vw;
    height: min(110vw, 92vh);
    min-height: 620px;
  }
}

.piece-node {
  width: clamp(30px, 4.2vw, 50px);
  height: clamp(30px, 4.2vw, 50px);
  font-size: clamp(18px, 2.6vw, 30px);
}

.intersection-hit {
  width: 34px;
  height: 34px;
}

.selected-marker,
.last-from-marker,
.last-to-marker,
.hint-from-marker,
.hint-to-marker,
.previous-from-marker,
.previous-to-marker {
  width: clamp(34px, 5vw, 56px);
  height: clamp(34px, 5vw, 56px);
}


#janggi-board.janggi-board,
#janggi-board.janggi-board.large {
  width: min(860px, 92vw);
  height: min(860px, 92vw);
  min-height: 620px;
  max-height: 860px;
  aspect-ratio: 1 / 1;
}

@media (max-width: 900px) {
  #janggi-board.janggi-board,
  #janggi-board.janggi-board.large {
    width: 94vw;
    height: 94vw;
    min-height: 520px;
  }
}


.piece-node {
  width: clamp(32px, 4.6vw, 52px);
  height: clamp(32px, 4.6vw, 52px);
  border-radius: 999px;
  border: 2px solid #b07a3b;
  background: #f7f0df;
  font-size: clamp(19px, 2.8vw, 31px);
  font-family: "Noto Serif KR", "Malgun Gothic", serif;
  font-weight: 700;
  box-shadow:
    0 1px 0 rgba(255,255,255,.5) inset,
    0 2px 8px rgba(0,0,0,.16);
}

.red-piece {
  color: #c92424;
}

.blue-piece {
  color: #2455e6;
}

.legal-marker {
  width: 12px;
  height: 12px;
  background: rgba(37, 99, 235, .88);
}

.selected-marker { border: 3px solid #2563eb; }
.last-from-marker { border: 3px solid #f59e0b; }
.last-to-marker { border: 3px solid #ef4444; }

