/* 형세 체스 — 형세 장기·형세 대국(바둑·오목)과 같은 디자인 */
:root {
  --bg: #15171b;
  --bg2: #1c1f25;
  --panel: #20242b;
  --line: #2f343d;
  --text: #ece8df;
  --muted: #9a9a93;
  --accent: #d9a441;
  --accent-ink: #1b1508;
  --jade: #5fb59a;
  --red: #e0675a;
  --white: #f1ead8;    /* 백 */
  --black: #2b2826;    /* 흑 */
  --radius: 12px;
  --serif: 'Noto Serif KR', serif;
  --sans: 'Noto Sans KR', system-ui, -apple-system, 'Apple SD Gothic Neo', sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font-family: var(--sans); font-size: 15px; }
body { min-height: 100vh; background:
  radial-gradient(1200px 600px at 80% -10%, rgba(217,164,65,.08), transparent 60%),
  radial-gradient(900px 500px at -10% 110%, rgba(63,134,214,.07), transparent 60%), var(--bg); }
button, input, select { font: inherit; color: inherit; }
.hidden { display: none !important; }
.muted { color: var(--muted); }

/* 상단 */
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 20px; padding-top: max(12px, env(safe-area-inset-top)); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 10; background: rgba(21,23,27,.9); backdrop-filter: blur(8px); }
.brand { display: flex; align-items: center; gap: 10px; cursor: pointer; min-width: 0; }
.brand-mark { display: grid; place-items: center; width: 34px; height: 34px; flex: none; border-radius: 9px; background: #ecd3a3; }
.brand-mark .pc { width: 28px; height: 28px; }
.pc { display: block; }
.brand-name { font-family: var(--serif); font-weight: 800; font-size: 19px; letter-spacing: .02em; white-space: nowrap; }
.top-right { display: flex; align-items: center; gap: 12px; }
.nick { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.nick input { width: 110px; padding: 6px 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg2); }

/* 공통 */
.view { max-width: 1280px; margin: 0 auto; padding: 24px 20px 40px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.btn { border: 1px solid var(--line); background: var(--bg2); padding: 9px 16px; border-radius: 10px; cursor: pointer;
  transition: background .15s, border-color .15s, transform .05s; white-space: nowrap; }
.btn:hover:not(:disabled) { border-color: #4a515d; background: #262a32; }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 700; }
.btn.primary:hover:not(:disabled) { background: #e6b354; }
.btn.danger { color: var(--red); }
.btn.exit { background: rgba(224,103,90,.16); border-color: rgba(224,103,90,.6); color: #f3b3a9; font-weight: 700; }
.btn.exit:hover:not(:disabled) { background: rgba(224,103,90,.28); border-color: #e0675a; color: #fff; }
.btn.ghost { background: transparent; }
.btn.small { padding: 6px 12px; font-size: 13px; }
.btn.tiny { padding: 3px 10px; font-size: 13px; border-radius: 8px; }
.btn.big { padding: 12px 28px; font-size: 16px; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 10px; gap: 8px; }
.section-head h2, .section-head h3 { margin: 0; font-size: 15px; font-weight: 700; }
.eyebrow { font-size: 12px; color: var(--muted); letter-spacing: .04em; }
.eyebrow b { color: var(--accent); font-family: ui-monospace, monospace; }
.side-chip { display: inline-grid; place-items: center; width: 24px; height: 24px; flex: none; border-radius: 6px; }
.side-chip.c0 { background: #6b5a40; }
.side-chip.c1 { background: #d9c7a3; }
.side-chip .pc { width: 20px; height: 20px; }
.side-chip.small { width: 18px; height: 18px; border-radius: 4px; }
.side-chip.small .pc { width: 15px; height: 15px; }

/* 로비 */
.lobby-hero { padding: 26px 0 26px; }
.lobby-hero h1 { font-family: var(--serif); font-size: clamp(30px, 5vw, 46px); line-height: 1.2; margin: 0 0 12px; }
.lobby-hero h1 em { font-style: normal; color: var(--accent); }
.lobby-hero p { color: var(--muted); margin: 0 0 22px; max-width: 600px; line-height: 1.6; }
.create { display: flex; gap: 10px; max-width: 520px; }
.create input { flex: 1; min-width: 0; padding: 11px 14px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg2); }
.room-list ul { list-style: none; padding: 0; margin: 0; display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.room { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.room .rname { font-weight: 700; margin-bottom: 4px; }
.room .rmeta { font-size: 13px; color: var(--muted); }
.pill { display: inline-block; white-space: nowrap; vertical-align: 1px; font-size: 11px; padding: 2px 8px; border-radius: 99px; margin-right: 6px; border: 1px solid var(--line); }
.pill.st-waiting { color: var(--jade); border-color: rgba(95,181,154,.5); }
.pill.st-playing, .pill.st-ended { color: var(--accent); border-color: rgba(217,164,65,.5); }
.empty { color: var(--muted); padding: 20px 0; }
.rules-card { margin-top: 26px; }
.rules-card h3 { margin: 0 0 8px; font-size: 15px; }
.rules-card ul { margin: 0; padding-left: 20px; color: var(--muted); font-size: 14px; line-height: 1.8; }
.rules-card b { color: var(--text); }

/* AI */
.ai-panel { margin: 0 0 26px; border-color: rgba(95,181,154,.45); }
.ai-head { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.ai-head h2 { margin: 0 0 2px; font-size: 18px; font-family: var(--serif); }
.ai-head .muted { font-size: 13px; }
.ai-icon { flex: none; width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center; font-weight: 800; font-size: 15px;
  background: rgba(95,181,154,.18); color: var(--jade); border: 1px solid rgba(95,181,154,.5); }
.ai-opts { display: flex; flex-wrap: wrap; gap: 12px 18px; align-items: flex-end; }
.ai-field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.ai-field select { padding: 8px 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg2); color: var(--text); min-width: 120px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--bg2); }
.seg button { border: 0; background: transparent; padding: 8px 14px; cursor: pointer; font-size: 14px; color: var(--text); }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { background: var(--jade); color: #0d241d; font-weight: 700; }
.ai-desc { font-size: 13px; margin: 12px 0; line-height: 1.5; }

/* 대기실 */
.waiting { display: grid; grid-template-columns: 1fr 340px; gap: 16px; }
.wait-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; margin-bottom: 18px; }
.wait-head h2 { margin: 2px 0 0; font-family: var(--serif); font-size: 24px; }
.seats { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 18px; }
.seat { border: 1px dashed var(--line); border-radius: var(--radius); padding: 16px 18px; min-height: 88px; display: flex; flex-direction: column; justify-content: center; gap: 6px; }
.seat.filled { border-style: solid; background: var(--bg2); }
.seat .sname { font-size: 18px; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.seat .stag { font-size: 12px; color: var(--muted); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--jade); display: inline-block; flex: none; }
.dot.off { background: #666; }
.crown { font-size: 11px; color: var(--accent); border: 1px solid rgba(217,164,65,.5); border-radius: 6px; padding: 1px 6px; }
.me-tag { font-size: 11px; color: var(--jade); border: 1px solid rgba(95,181,154,.5); border-radius: 6px; padding: 0 5px; }
.settings { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 20px; }
.settings label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.settings select { padding: 8px 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg2); color: var(--text); }
.wait-actions { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.hint { color: var(--muted); font-size: 13px; text-align: right; margin: 10px 0 0; min-height: 1em; }

/* 채팅 */
.chat-panel { display: flex; flex-direction: column; min-height: 260px; }
.waiting .chat-panel { height: 560px; }
.chat-log { flex: 1; overflow-y: auto; font-size: 13px; line-height: 1.55; padding-right: 4px; min-height: 120px; }
.chat-log .sys { color: var(--muted); font-size: 12px; }
.chat-log .from { color: var(--accent); font-weight: 700; margin-right: 6px; }
.chat-log .from.me { color: var(--jade); }
.chat-form { display: flex; gap: 8px; margin-top: 10px; }
.chat-form input { flex: 1; min-width: 0; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg2); }

/* 대국 */
.game { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 18px; align-items: start; }
.board-col { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.scorebar { display: grid; grid-template-columns: 1fr minmax(160px, 1.3fr) 1fr; gap: 12px; align-items: stretch; }
.pcard { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; display: flex; flex-direction: column; gap: 4px; transition: border-color .2s, box-shadow .2s; min-width: 0; }
.pcard.turn { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.pcard .prow { display: flex; align-items: center; gap: 8px; min-width: 0; }
.pcard .pname { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pcard .pmeta { display: flex; justify-content: space-between; align-items: baseline; flex-wrap: wrap; gap: 2px 8px; font-size: 12px; color: var(--muted); }
.pcard .caps { display: flex; flex-wrap: wrap; align-items: center; min-height: 18px; }
.caps .pc { width: 17px; height: 17px; margin-right: -4px; }
.caps .adv { margin-left: 8px; font-size: 12px; font-weight: 700; color: var(--muted); }
.clock { font-variant-numeric: tabular-nums; font-weight: 700; font-size: 16px; color: var(--text); }
.clock.byo { color: var(--accent); }
.clock.low { color: var(--red); }
.clock.paused { color: var(--muted); }
.gauge { display: flex; flex-direction: column; justify-content: center; gap: 8px; }
.gauge-bar { position: relative; height: 22px; border-radius: 99px; overflow: hidden; background: linear-gradient(90deg, #0d0c0b, var(--black)); border: 1px solid #4a4f58; }
.gauge-w { position: absolute; inset: 0 auto 0 0; width: 50%; background: linear-gradient(90deg, #cfc4ac, var(--white)); transition: width .6s cubic-bezier(.2,.8,.2,1); }
.gauge-mid { position: absolute; left: 50%; top: -2px; bottom: -2px; width: 2px; background: var(--accent); opacity: .8; }
.gauge-text { display: flex; justify-content: space-between; flex-wrap: wrap; row-gap: 2px; font-size: 13px; font-variant-numeric: tabular-nums; }
.gauge-text .t-w { color: var(--white); font-weight: 700; }
.gauge-text .t-b { color: #a9a39a; font-weight: 700; }
.gauge-text .lead { font-weight: 700; color: var(--accent); text-align: center; order: 3; flex-basis: 100%; line-height: 1.35; }
.board-wrap { position: relative; width: 100%; max-width: min(100%, calc(100vh - 250px)); min-width: 280px; margin: 0 auto; aspect-ratio: 1 / 1; }
#board { width: 100%; height: 100%; display: block; border-radius: 8px; box-shadow: 0 18px 40px rgba(0,0,0,.45); touch-action: manipulation; user-select: none; -webkit-user-select: none; -webkit-tap-highlight-color: transparent; }
.controls { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: center; }
.controls .sep { width: 1px; height: 22px; background: var(--line); margin: 0 4px; }
.toggle { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); cursor: pointer; user-select: none; }
.toggle input { accent-color: var(--accent); }
.review-bar { display: flex; align-items: center; justify-content: center; gap: 6px; font-size: 13px; background: rgba(217,164,65,.1); border: 1px solid rgba(217,164,65,.35); border-radius: 10px; padding: 6px; flex-wrap: wrap; }
.review-bar span { min-width: 140px; text-align: center; color: var(--accent); }
.offline-bar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 10px 12px; border-radius: 10px; font-size: 13px; line-height: 1.5;
  background: rgba(224,103,90,.12); border: 1px solid rgba(224,103,90,.45); color: #f1c3bc; }
.offline-bar span { flex: 1; min-width: 200px; }
.promo-pop { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); z-index: 7; background: rgba(20,22,26,.96); border: 1px solid var(--accent); border-radius: 14px; padding: 12px 14px; box-shadow: 0 14px 40px rgba(0,0,0,.6); text-align: center; }
.promo-pop .ptitle { font-size: 13px; color: var(--muted); margin-bottom: 8px; }
.promo-pop .pchoices { display: flex; gap: 8px; }
.promo-pop button { width: 64px; height: 64px; border-radius: 12px; border: 1px solid var(--line); background: #ecd3a3; cursor: pointer; display: grid; place-items: center; padding: 4px; }
.promo-pop button:hover { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }
.promo-pop button .pc { width: 52px; height: 52px; }
.promo-pop button span { display: none; }
.undo-pop { position: absolute; left: 50%; top: 14px; transform: translateX(-50%); background: rgba(20,22,26,.95); border: 1px solid var(--accent); border-radius: 12px; padding: 12px 16px; display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; align-items: center; box-shadow: 0 10px 30px rgba(0,0,0,.5); z-index: 5; max-width: calc(100% - 20px); }
/* 체크! 캐슬링 승진 */
.call-pop { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); z-index: 6; pointer-events: none;
  font: 900 clamp(34px, 9vw, 64px)/1 var(--serif); color: #fff; padding: 14px 30px; border-radius: 18px;
  background: rgba(150,30,24,.88); box-shadow: 0 12px 40px rgba(0,0,0,.5); animation: call 1.4s ease-out forwards; letter-spacing: .1em; }
.call-pop.w { background: rgba(241,234,216,.94); color: #1c1a17; }
.call-pop.soft { background: rgba(30,32,38,.9); font-size: clamp(26px, 6vw, 44px); }
@keyframes call { 0% { transform: translate(-50%, -50%) scale(.6); opacity: 0; } 15% { transform: translate(-50%, -50%) scale(1.08); opacity: 1; }
  25% { transform: translate(-50%, -50%) scale(1); } 75% { opacity: 1; } 100% { opacity: 0; } }
.result-pop { position: absolute; inset: 0; z-index: 8; display: flex; align-items: center; justify-content: center; padding: 12px; background: rgba(8,10,14,.45); border-radius: 8px; animation: rp-fade .25s ease-out; }
.rp-card { position: relative; width: min(330px, 100%); text-align: center; background: rgba(24,27,33,.97); border: 1px solid var(--accent); border-radius: 16px; padding: 20px 18px 16px; box-shadow: 0 18px 50px rgba(0,0,0,.6); animation: rp-pop .3s cubic-bezier(.2,1.4,.4,1); }
.result-pop.win .rp-card { border-color: var(--jade); }
.result-pop.lose .rp-card { border-color: var(--red); }
.rp-x { position: absolute; top: 6px; right: 6px; width: 36px; height: 36px; border: 0; border-radius: 10px; background: transparent; color: var(--muted); font-size: 18px; cursor: pointer; }
.rp-icon { font-size: 40px; line-height: 1; margin-bottom: 6px; }
.rp-head { font-size: 24px; font-weight: 800; color: var(--accent); }
.result-pop.win .rp-head { color: var(--jade); }
.result-pop.lose .rp-head { color: var(--red); }
.rp-why { margin-top: 8px; font-size: 16px; font-weight: 600; }
.rp-text { margin-top: 4px; font-size: 13px; color: var(--muted); }
.rp-actions { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin-top: 14px; }
@keyframes rp-fade { from { opacity: 0; } }
@keyframes rp-pop { from { transform: scale(.85); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .result-pop, .rp-card, .call-pop { animation: none; } .call-pop { opacity: 0; } }

.side { display: flex; flex-direction: column; gap: 14px; }
#graph { width: 100%; height: 150px; display: block; cursor: crosshair; }
.graph-legend { display: flex; justify-content: space-between; gap: 6px; font-size: 11px; color: var(--muted); margin-top: 6px; }
.engine-tag { font-size: 11px; color: var(--muted); }
.last-eval { margin-top: 10px; font-size: 13px; padding: 8px 10px; border-radius: 8px; background: var(--bg2); min-height: 20px; line-height: 1.5; }
.last-eval .good { color: var(--jade); font-weight: 700; }
.last-eval .bad { color: var(--red); font-weight: 700; }
.last-eval .meh { color: var(--accent); font-weight: 700; }
.move-list { list-style: none; margin: 0; padding: 0; max-height: 210px; overflow-y: auto; font-size: 13px; display: grid; grid-template-columns: 26px 1fr 1fr; gap: 2px 4px; align-items: center; }
.move-list li.mn { color: var(--muted); font-size: 11px; justify-content: flex-end; padding: 3px 2px 3px 0; cursor: default; background: none; }
.move-list li { display: flex; gap: 6px; align-items: center; padding: 3px 6px; border-radius: 6px; cursor: pointer; font-variant-numeric: tabular-nums; }
.move-list li:hover { background: var(--bg2); }
.move-list li.cur { background: rgba(217,164,65,.15); }
.move-list .n { color: var(--muted); min-width: 22px; text-align: right; font-size: 11px; }
.move-list .q { margin-left: auto; font-size: 11px; }
.q-good { color: var(--jade); } .q-bad { color: var(--red); } .q-meh { color: var(--accent); }
.game-info .info-actions { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
#gameMeta { font-size: 13px; line-height: 1.6; }
.side .chat-panel { height: 240px; }

.conn-bar { position: sticky; top: 0; z-index: 30; background: #7a2e25; color: #fff; text-align: center; font-size: 13px; padding: 8px 12px; }

.ask-dlg { width: min(380px, calc(100vw - 32px)); padding: 20px; border-radius: 16px; border: 1px solid var(--line); background: var(--panel); color: var(--text); }
.ask-dlg::backdrop { background: rgba(0,0,0,.6); }
.ask-dlg h3 { margin: 0 0 8px; font-size: 18px; }
.ask-dlg p { margin: 0 0 16px; color: var(--muted); line-height: 1.55; font-size: 14px; }
.ask-actions { display: flex; justify-content: flex-end; gap: 8px; }

@media (max-width: 980px) {
  .game { grid-template-columns: 1fr; }
  .waiting { grid-template-columns: 1fr; }
  .waiting .chat-panel { height: 300px; }
  .board-wrap { max-width: 100%; }
}
@media (max-width: 640px) {
  .view { padding: 14px 10px 30px; }
  .top { padding: 10px 12px; gap: 8px; }
  .top-right { gap: 6px; }
  .nick span { display: none; }
  .nick input { width: 84px; padding: 6px 8px; }
  .brand-name { font-size: 17px; }
  .settings { grid-template-columns: 1fr 1fr; }
  .scorebar { grid-template-columns: 1fr 1fr; gap: 8px; }
  .gauge { grid-column: 1 / -1; order: -1; }
  .create { flex-direction: column; }
  .clock { font-size: 14px; }
  .seats { grid-template-columns: 1fr; }
  .controls .btn { padding: 10px 14px; }
  .seg button { padding: 8px 11px; font-size: 13px; }
  #aiStart { width: 100%; }
  .wait-actions .btn.big { padding: 12px 20px; }
}
.waiting > *, .game > * { min-width: 0; }
