:root {
  --bg: #14171c;
  --panel: #1d2128;
  --panel-2: #262b34;
  --line: #333a46;
  --text: #e8ebf0;
  --muted: #95a0b0;
  --accent: #6c8cff;
  --red: #e5484d;
  --green: #30a46c;
  --blue: #3e82f7;
  --yellow: #f5c518;
  --cell: #e9e4d8;
  --cell-alt: #e2dccd;
  --grid: #cfc7b4;
  --wall: #2a2e36;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Pretendard", "Apple SD Gothic Neo", "Noto Sans KR", "Segoe UI", sans-serif;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
button, input { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }

.dot { display: inline-block; width: 12px; height: 12px; border-radius: 50%; }
.dot.r { background: var(--red); } .dot.g { background: var(--green); }
.dot.b { background: var(--blue); } .dot.y { background: var(--yellow); }

.btn {
  border: 1px solid var(--line);
  background: var(--panel-2);
  border-radius: 10px;
  padding: 9px 14px;
  cursor: pointer;
  transition: background .12s, border-color .12s, opacity .12s;
  white-space: nowrap;
}
.btn:hover:not(:disabled) { border-color: #4a5364; background: #2d333e; }
.btn:disabled { opacity: .45; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #0d1020; font-weight: 700; }
.btn.primary:hover:not(:disabled) { background: #84a0ff; border-color: #84a0ff; }
.btn.ghost { background: transparent; }
.btn.small { padding: 6px 10px; font-size: 13.5px; border-radius: 8px; }
.btn.big { padding: 13px 18px; font-size: 16px; }
.btn.wide { width: 100%; }
.btn.active { border-color: var(--accent); color: var(--accent); }
.link { background: none; border: 0; color: var(--muted); text-decoration: underline; cursor: pointer; padding: 6px; }

/* landing */
.landing { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.landing-card {
  width: 100%; max-width: 400px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 18px; padding: 30px 26px; text-align: center;
  display: flex; flex-direction: column; gap: 14px;
}
.logo { display: flex; gap: 8px; justify-content: center; }
.logo .dot { width: 18px; height: 18px; }
.landing h1 { margin: 0; font-size: 30px; letter-spacing: -.02em; }
.tagline { margin: 0 0 6px; color: var(--muted); }
.field { display: flex; flex-direction: column; gap: 6px; text-align: left; }
.field span { font-size: 13px; color: var(--muted); }
input {
  background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 11px 13px; width: 100%; min-width: 0;
}
input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
#landingActions, .invite { display: flex; flex-direction: column; gap: 12px; }
.invite p { margin: 0; }
.or { color: var(--muted); font-size: 13px; }
.join-row { display: flex; gap: 8px; }
#codeInput { text-transform: uppercase; letter-spacing: .3em; text-align: center; font-weight: 700; }
.error { color: #ff8589; min-height: 1.4em; margin: 0; font-size: 14px; }

/* game */
.game { min-height: 100%; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 9px 16px; border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 5px; }
.brand b { margin-left: 6px; }
.topbar-right { display: flex; gap: 6px; align-items: center; }
#roomCode { letter-spacing: .12em; }
.layout {
  flex: 1; display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 16px;
  padding: 16px; max-width: 1320px; width: 100%; margin: 0 auto; align-items: start;
}
.board-wrap { width: 100%; max-width: calc(100vh - 86px); margin: 0 auto; aspect-ratio: 1; }
#board { width: 100%; height: 100%; display: block; touch-action: none; user-select: none; -webkit-user-select: none; }
.panel { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 13px 14px; display: flex; flex-direction: column; gap: 10px; }
.card-title { display: flex; justify-content: space-between; align-items: baseline; font-weight: 700; }
.card-title.sub { font-weight: 600; font-size: 13.5px; color: var(--muted); margin-top: 2px; }
.card p { margin: 0; }
.row { display: flex; gap: 6px; flex-wrap: wrap; }
.row .btn { flex: 1; }

.status-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.status-text { font-weight: 700; font-size: 16px; line-height: 1.35; }
.timer { font-size: 30px; font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1; }
.timer.urgent { color: var(--red); }
.timer-bar { height: 5px; border-radius: 3px; background: var(--panel-2); overflow: hidden; }
.timer-bar i { display: block; height: 100%; width: 100%; background: var(--accent); transform-origin: left; }
.timer-bar.urgent i { background: var(--red); }

.moves { display: flex; flex-wrap: wrap; gap: 4px; min-height: 28px; align-items: center; }
.moves:empty::before { content: "아직 이동이 없습니다"; color: var(--muted); font-size: 13px; }
.mv {
  width: 26px; height: 26px; border-radius: 7px; display: grid; place-items: center;
  font-weight: 800; font-size: 15px; color: #fff;
}
.mv.c0 { background: var(--red); } .mv.c1 { background: var(--green); }
.mv.c2 { background: var(--blue); } .mv.c3 { background: var(--yellow); color: #3a2f00; }
.hint { line-height: 1.45; }

.setting { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
#hostControls { display: flex; flex-direction: column; gap: 10px; }
.seg { display: flex; border: 1px solid var(--line); border-radius: 9px; overflow: hidden; }
.seg button { background: transparent; border: 0; padding: 6px 12px; cursor: pointer; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { background: var(--accent); color: #0d1020; font-weight: 700; }

.players, .bids { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.players li, .bids li {
  display: flex; align-items: center; gap: 8px; padding: 6px 9px; border-radius: 9px; background: var(--panel-2);
}
.players li.me, .bids li.me { outline: 1px solid var(--accent); }
.players li.off { opacity: .45; }
.players .name, .bids .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.players .score { font-weight: 800; font-variant-numeric: tabular-nums; }
.tag { font-size: 11px; padding: 1px 6px; border-radius: 99px; background: #39414f; color: var(--muted); }
.tag.ok { background: rgba(48, 164, 108, .22); color: #5fd39b; }
.bids li.best { background: rgba(108, 140, 255, .16); }
.bids .n { font-weight: 800; }
.ranking { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 4px; }
.ranking li { display: flex; gap: 8px; padding: 6px 9px; border-radius: 9px; background: var(--panel-2); }
.ranking li:first-child { background: rgba(245, 197, 24, .16); font-weight: 700; }
.ranking .name { flex: 1; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: #2f3644; border: 1px solid var(--line); padding: 9px 16px; border-radius: 99px; z-index: 20;
  max-width: calc(100vw - 32px);
}
.conn { position: fixed; top: 0; left: 0; right: 0; background: var(--red); color: #fff; text-align: center; padding: 6px; z-index: 30; font-size: 14px; }

dialog { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 16px; max-width: 520px; padding: 22px 24px; }
dialog::backdrop { background: rgba(0, 0, 0, .6); }
dialog h2 { margin: 0 0 10px; }
dialog ol { padding-left: 20px; margin: 0 0 16px; display: flex; flex-direction: column; gap: 8px; }
dialog form { text-align: right; }

/* board svg */
.cell { fill: var(--cell); }
.cell.alt { fill: var(--cell-alt); }
.gridline { stroke: var(--grid); stroke-width: .25; }
.wall { stroke: var(--wall); stroke-width: 1.5; stroke-linecap: round; }
.center { fill: var(--wall); }
.tgt { opacity: .5; }
.tgt.current { opacity: 1; }
.tgt-ring { fill: none; stroke: #111; stroke-width: .7; stroke-dasharray: 2 1.4; animation: spin 6s linear infinite; transform-box: fill-box; transform-origin: center; }
@keyframes spin { to { transform: rotate(360deg); } }
.robot { cursor: pointer; transition: transform .22s cubic-bezier(.3, .1, .3, 1); }
.robot .body { stroke: #15181d; stroke-width: .7; }
.robot .shine { fill: rgba(255, 255, 255, .45); }
.robot .sel { fill: none; stroke: #fff; stroke-width: 1; opacity: 0; }
.robot.selected .sel { opacity: 1; }
.robot.selected .body { stroke-width: 1; }
.trail { stroke-width: 1.5; stroke-linecap: round; opacity: .5; fill: none; }
.dest { cursor: pointer; opacity: .55; }
.dest:hover { opacity: .95; }
.dest-hit { fill: transparent; }
.startmark { fill: none; stroke-width: .6; stroke-dasharray: 1.2 1; opacity: .8; }

@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; padding: 10px; gap: 10px; }
  .board-wrap { max-width: min(100%, calc(100vh - 150px)); }
  .brand b { display: none; }
  .topbar { padding: 8px 10px; }
  .hint { display: none; }
}
