/* Twelve Janggi — board, pieces and chrome. */

:root {
  --bg: #14110e;
  --bg-soft: #1d1917;
  --line: #322b26;
  --ink: #f0e7dc;
  --ink-dim: #a2958a;
  --wood: #d9b479;
  --wood-dark: #c39a5e;
  --grid: #8a6435;
  --red: #c8352f;
  --red-soft: #f0605a;
  --blue: #27479b;
  --blue-soft: #7ba2f2;
  --gold: #e8b64c;
  --disc: #f6e7c9;
  --disc-edge: #a9803f;
  --radius: 12px;
}

* { box-sizing: border-box; }

/* .layout and .games set display, which would otherwise beat the UA rule for
   [hidden] and leave both screens on top of each other. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 "Segoe UI", system-ui, -apple-system, sans-serif;
  -webkit-text-size-adjust: 100%;
}

button, select { font: inherit; color: inherit; }

/* ---- chrome -------------------------------------------------------------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; padding: 14px 22px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #1f1a16, #14110e);
}
.topbar h1 {
  margin: 0; font-size: 20px; font-weight: 700; letter-spacing: .12em;
  text-transform: uppercase; color: var(--gold);
}
.topbar-actions { display: flex; gap: 8px; }

button.primary, button.ghost {
  border-radius: 8px; padding: 8px 14px; cursor: pointer;
  border: 1px solid var(--line); background: var(--bg-soft);
  transition: background .15s, border-color .15s, opacity .15s;
}
button.primary { background: var(--gold); color: #241a08; border-color: var(--gold); font-weight: 600; }
button.primary:hover { background: #f3c661; }
button.ghost:hover { background: #2a2421; border-color: #4a3f37; }
button:disabled { opacity: .4; cursor: default; }

/* ---- layout -------------------------------------------------------------- */
.layout {
  display: grid; grid-template-columns: minmax(0, 1fr) 320px;
  gap: 28px; padding: 24px; max-width: 1080px; margin: 0 auto;
  align-items: start;
}
.board-area { display: flex; flex-direction: column; align-items: center; gap: 10px; }

/* ---- board --------------------------------------------------------------- */
/* The trailing 22px column mirrors the rank gutter so the board stays centred. */
.board-wrap {
  display: grid;
  grid-template-columns: 22px auto 22px;
  grid-template-rows: auto 20px;
  gap: 4px; align-items: center;
}
.ranks {
  grid-column: 1; grid-row: 1;
  display: grid; grid-template-rows: repeat(4, 1fr); height: 100%;
}
.files {
  grid-column: 2; grid-row: 2;
  display: grid; grid-template-columns: repeat(3, 1fr);
}
.ranks span, .files span {
  display: grid; place-items: center;
  font-size: 11px; color: var(--ink-dim); letter-spacing: .1em;
}

.board {
  grid-column: 2; grid-row: 1;
  display: grid;
  grid-template-columns: repeat(3, 96px);
  grid-template-rows: repeat(4, 96px);
  gap: 3px; padding: 12px;
  background: linear-gradient(160deg, var(--wood), var(--wood-dark));
  border: 3px solid #6d4a22;
  border-radius: 10px;
  box-shadow: 0 18px 40px rgba(0,0,0,.55), inset 0 0 40px rgba(120,74,26,.35);
}

.cell {
  position: relative; padding: 0; cursor: pointer;
  background: rgba(255,255,255,.05);
  border: 1px solid rgba(109,74,34,.55);
  border-radius: 4px;
  display: grid; place-items: center;
  transition: background .12s;
}
.cell:hover { background: rgba(255,255,255,.13); }
.cell.goal-red   { box-shadow: inset 0 3px 0 rgba(200,53,47,.55); }
.cell.goal-blue { box-shadow: inset 0 -3px 0 rgba(39,71,155,.75); }

.cell.from { background: rgba(232,182,76,.18); }
.cell.to   { background: rgba(232,182,76,.3); }
.cell.sel  { background: rgba(232,182,76,.35); outline: 2px solid var(--gold); outline-offset: -2px; }

/* empty destination: a floating dot; occupied destination: a ring */
.cell.target::after {
  content: ''; position: absolute; inset: 0; margin: auto;
  width: 26px; height: 26px; border-radius: 50%;
  background: rgba(30,20,10,.4);
}
.cell.target-capture { outline: 3px solid rgba(30,20,10,.5); outline-offset: -4px; }
.cell.target.danger::after { background: var(--red); box-shadow: 0 0 0 3px rgba(200,53,47,.35); }
.cell.target-capture.danger { outline-color: var(--red); }
.cell.check { animation: pulse 1.1s ease-in-out infinite; }

@keyframes pulse {
  0%, 100% { box-shadow: inset 0 0 0 3px rgba(240,96,90,.85); }
  50%      { box-shadow: inset 0 0 0 3px rgba(240,96,90,.25); }
}

/* ---- pieces -------------------------------------------------------------- */
.piece {
  position: relative;
  width: 82px; height: 82px;
  display: grid; place-items: center; align-content: center;
  background: radial-gradient(circle at 35% 28%, #fff6e2, var(--disc) 60%, #e6d2ab);
  border: 2px solid var(--disc-edge);
  clip-path: polygon(30% 0, 70% 0, 100% 30%, 100% 70%, 70% 100%, 30% 100%, 0 70%, 0 30%);
  box-shadow: 0 3px 6px rgba(0,0,0,.35);
  pointer-events: none;
}
.piece.small { width: 46px; height: 46px; border-width: 1.5px; }

.piece .art { width: 46%; height: 46%; margin-top: 6px; }
.piece.small .art { width: 52%; height: 52%; margin-top: 2px; }
.piece .art svg { width: 100%; height: 100%; display: block; }
.piece .art svg path, .piece .art svg circle { fill: currentColor; }
/* .cut punches a hole back out to the disc colour — the palace gate's doorway. */
.piece .art svg .cut { fill: var(--disc); }

.piece.red   { color: var(--red); }
.piece.blue { color: var(--blue); }

.plabel {
  font-size: 9px; font-weight: 700; letter-spacing: .06em;
  text-transform: uppercase; color: currentColor; opacity: .85;
  margin-top: 2px; line-height: 1;
}
.piece.small .plabel { display: none; }

.dot {
  position: absolute; width: 7px; height: 7px; border-radius: 50%;
  background: currentColor; opacity: .9;
  transform: translate(-50%, -50%);
}
.piece.small .dot { width: 4.5px; height: 4.5px; }

/* ---- hands --------------------------------------------------------------- */
.hand {
  width: 100%; max-width: 336px;
  display: flex; align-items: center; gap: 12px;
  padding: 8px 12px; min-height: 62px;
  background: var(--bg-soft); border: 1px solid var(--line); border-radius: var(--radius);
}
.hand.active { border-color: var(--gold); box-shadow: 0 0 0 1px rgba(232,182,76,.3); }
.hand-label {
  font-size: 11px; letter-spacing: .1em; text-transform: uppercase;
  color: var(--ink-dim); white-space: nowrap; width: 108px;
}
.hand-slots { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.hand-empty { font-size: 12px; color: #5f544c; font-style: italic; }
.chip {
  padding: 2px; border: 2px solid transparent; border-radius: 8px;
  background: none; cursor: pointer; line-height: 0;
}
.chip:hover { border-color: #4a3f37; }
.chip.sel { border-color: var(--gold); background: rgba(232,182,76,.14); }

/* ---- status -------------------------------------------------------------- */
.status {
  width: 100%; max-width: 336px; text-align: center;
  padding: 11px 14px; border-radius: var(--radius);
  background: var(--bg-soft); border: 1px solid var(--line); font-size: 14px;
}
.status.alert { border-color: var(--red); color: var(--red-soft); }
.status.thinking { color: var(--ink-dim); font-style: italic; }
.status.over { font-weight: 600; font-size: 15px; }
.status.win-red   { border-color: var(--red); color: var(--red-soft); }
.status.win-blue { border-color: var(--blue); color: var(--blue-soft); }

/* ---- side panel ---------------------------------------------------------- */
.panel { display: flex; flex-direction: column; gap: 16px; }
.card {
  background: var(--bg-soft); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px 16px;
}
.card h2 {
  margin: 0 0 12px; font-size: 11px; letter-spacing: .14em;
  text-transform: uppercase; color: var(--ink-dim); font-weight: 600;
}
.field { display: block; margin-bottom: 10px; }
.field span { display: block; font-size: 12px; color: var(--ink-dim); margin-bottom: 4px; }
.field select, .field input {
  width: 100%; padding: 7px 9px; border-radius: 7px;
  background: #100d0b; border: 1px solid var(--line); color: var(--ink);
}
.row { display: flex; gap: 8px; }
.row button { flex: 1; }

.log {
  margin: 0; padding: 0; list-style: none;
  max-height: 190px; overflow-y: auto; font-size: 13px;
  font-family: "Cascadia Mono", Consolas, monospace;
}
.log li { display: flex; gap: 8px; padding: 2px 0; }
.log li b { color: #5f544c; font-weight: 400; min-width: 22px; text-align: right; }
.log li.red span { color: var(--red-soft); }
.log li.blue span { color: var(--blue-soft); }
.log li.empty { color: #5f544c; font-family: inherit; font-style: italic; }

.legend-row { display: flex; gap: 12px; align-items: center; padding: 6px 0; }
.legend-art { width: 46px; flex: none; line-height: 0; }
.legend-row b { display: block; font-size: 13px; }
.legend-row span { display: block; font-size: 12px; color: var(--ink-dim); line-height: 1.35; }

/* ---- rules overlay ------------------------------------------------------- */
.overlay {
  position: fixed; inset: 0; z-index: 20;
  background: rgba(8,6,5,.78);
  display: grid; place-items: center; padding: 20px;
  overflow-y: auto;
}
.overlay[hidden] { display: none; }
.sheet {
  position: relative; max-width: 620px; width: 100%;
  background: var(--bg-soft); border: 1px solid var(--line);
  border-radius: 16px; padding: 26px 30px 30px;
  max-height: 88vh; overflow-y: auto;
}
.sheet h2 { margin: 0 0 6px; color: var(--gold); font-size: 20px; }
.sheet h3 {
  margin: 22px 0 6px; font-size: 12px; letter-spacing: .12em;
  text-transform: uppercase; color: var(--gold);
}
.sheet p, .sheet li { color: #d5c9bc; font-size: 14px; }
.sheet .lede { color: var(--ink); }
.sheet ul, .sheet ol { padding-left: 20px; margin: 6px 0; }
.sheet li { margin: 5px 0; }
.rules-pieces b, .win-list b { color: var(--ink); }
.close {
  position: absolute; top: 12px; right: 14px;
  background: none; border: none; font-size: 26px; line-height: 1;
  color: var(--ink-dim); cursor: pointer;
}
.close:hover { color: var(--ink); }

/* ---- tabs ---------------------------------------------------------------- */
.tabs { display: flex; gap: 4px; margin-right: auto; margin-left: 18px; }
.tab {
  background: none; border: 1px solid transparent; border-radius: 8px;
  padding: 7px 14px; cursor: pointer; color: var(--ink-dim);
}
.tab:hover { color: var(--ink); background: #241f1c; }
.tab.on { color: var(--gold); border-color: var(--line); background: var(--bg-soft); }

/* ---- games screen -------------------------------------------------------- */
.games {
  display: flex; flex-direction: column; gap: 16px;
  max-width: 560px; margin: 0 auto; padding: 24px 20px;
}
.gate p { color: var(--ink-dim); font-size: 14px; margin: 0 0 14px; }
.note { font-size: 13px; color: var(--gold); margin: 10px 0 0; }
.muted { font-size: 12px; color: var(--ink-dim); margin-top: 6px; }

.account b { display: block; font-size: 14px; }
.account span { display: block; font-size: 12px; color: var(--ink-dim); margin-bottom: 12px; }

.game-list { list-style: none; margin: 0; padding: 0; }
.game-list li.empty { color: #5f544c; font-style: italic; font-size: 13px; }
.game-row {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 6px; border-bottom: 1px solid var(--line); cursor: pointer;
}
.game-row:last-child { border-bottom: none; }
.game-row:hover { background: #241f1c; }
.game-row .who { font-weight: 600; flex: 1; }
.game-row .state { font-size: 12px; color: var(--ink-dim); }
.game-row.yours .state { color: var(--gold); font-weight: 600; }
.game-row .when { font-size: 11px; color: #5f544c; min-width: 58px; text-align: right; }
.game-row .x {
  background: none; border: none; color: #5f544c; cursor: pointer;
  font-size: 16px; padding: 2px 6px; border-radius: 6px;
}
.game-row .x:hover { color: var(--red-soft); }
.game-row .x.armed { font-size: 11px; color: var(--red-soft); }

.dot-red, .dot-blue {
  width: 12px; height: 12px; border-radius: 50%; flex: none; display: inline-block;
}
.dot-red { background: var(--red); }
.dot-blue { background: var(--blue); }

/* ---- online panel + chat ------------------------------------------------- */
.vs { display: flex; align-items: center; gap: 8px; font-size: 13px; padding: 3px 0; }
#online-actions { flex-wrap: wrap; margin-top: 12px; }
#online-actions button { flex: 1 1 auto; min-width: 120px; }

.chat { max-height: 210px; overflow-y: auto; margin-bottom: 10px; }
.chat .empty { color: #5f544c; font-style: italic; font-size: 13px; margin: 0; }
.msg { padding: 5px 0; font-size: 13px; }
.msg b { color: var(--ink-dim); font-weight: 600; margin-right: 6px; font-size: 12px; }
.msg.me b { color: var(--gold); }
.msg span { color: #d5c9bc; overflow-wrap: anywhere; }
.chat-form { display: flex; gap: 6px; }
.chat-form input {
  flex: 1; min-width: 0; padding: 7px 9px; border-radius: 7px;
  background: #100d0b; border: 1px solid var(--line); color: var(--ink);
}

/* ---- narrow screens ------------------------------------------------------ */
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; gap: 20px; padding: 16px; }
  .panel { max-width: 520px; width: 100%; margin: 0 auto; }
}
@media (max-width: 560px) {
  .topbar { flex-wrap: wrap; gap: 8px; }
  .tabs { margin-left: 0; order: 3; width: 100%; }
  .tab { flex: 1; }
}
@media (max-width: 420px) {
  .topbar { padding: 12px 14px; }
  .topbar h1 { font-size: 16px; }
  .board { grid-template-columns: repeat(3, 82px); grid-template-rows: repeat(4, 82px); padding: 9px; }
  .piece { width: 70px; height: 70px; }
  .plabel { font-size: 8px; }
}
