@import url('https://fonts.googleapis.com/css2?family=Nanum+Myeongjo:wght@400;700;800&family=Noto+Serif+KR:wght@300;400;600;700&display=swap');

:root {
  --bg:        #0d0d0d;
  --bg2:       #1a1a1a;
  --panel:     #141414;
  --border:    #333;
  --gold:      #c8922a;
  --glt:       #f0c060;
  --hjw:       #e8e8e8;
  --black-s:   #1a1a1a;
  --white-s:   #f5f5f0;
  --board-bg:  #dcb870;
  --radius:    10px;
  --wood-dark: #1e0c02; --wood-mid: #4a2008; --wood-light: #7a3a10;
  --wood-pale: #a85c28; --hanji: #f5e8c8; --hanji-warm: #d4b87a;
  --shadow:    rgba(0,0,0,.8);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--hjw);
  font-family: 'Noto Serif KR', serif;
  min-height: 100vh;
  overflow: hidden;
}

.screen { display: none; width: 100%; height: 100vh; }
.screen.show { display: flex; flex-direction: column; }

/* ══ 모드 선택 ══ */
#sm {
  align-items: center;
  justify-content: center;
  gap: 1.5rem;
  background: radial-gradient(ellipse at 50% 20%, #1a1a1a 0%, #050505 100%);
}

.title-stones {
  display: flex;
  gap: .6rem;
  justify-content: center;
  margin-bottom: .8rem;
}
.stone-deco {
  display: inline-block;
  border-radius: 50%;
  box-shadow: inset -3px -3px 6px rgba(0,0,0,.5), inset 2px 2px 4px rgba(255,255,255,.15);
}
.stone-deco.black { width: 22px; height: 22px; background: radial-gradient(circle at 35% 35%, #555, #0a0a0a); }
.stone-deco.white { width: 26px; height: 26px; background: radial-gradient(circle at 35% 35%, #fff, #ccc); }

.title-wrap { text-align: center; }
.title-ko {
  font-family: 'Nanum Myeongjo', serif;
  font-size: 3rem;
  font-weight: 800;
  color: var(--glt);
  letter-spacing: 1rem;
  text-shadow: 0 0 40px rgba(200,146,42,.4);
}
.title-sub { font-size: .8rem; color: var(--hjw); opacity: .5; margin-top: .4rem; }

.mode-cards { display: flex; gap: 1.5rem; }
.mode-card {
  background: var(--panel);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 1.8rem 2.2rem;
  text-align: center;
  cursor: pointer;
  transition: all .2s;
  min-width: 170px;
}
.mode-card:hover { border-color: var(--gold); transform: translateY(-4px); box-shadow: 0 10px 28px rgba(200,146,42,.15); }
.mode-icon  { font-size: 2.4rem; margin-bottom: .6rem; }
.mode-title { font-size: 1.2rem; color: var(--glt); font-weight: 700; margin-bottom: .3rem; }
.mode-desc  { font-size: .82rem; color: var(--hjw); opacity: .75; }
.mode-detail{ font-size: .7rem; color: var(--gold); opacity: .7; margin-top: .2rem; }

.rules-summary {
  background: rgba(255,255,255,.03);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: .8rem 1.2rem;
  max-width: 420px; width: 100%;
}
.rs-title { font-size: .75rem; color: var(--gold); font-weight: 700; margin-bottom: .5rem; text-align: center; letter-spacing: 2px; }
.rs-grid { display: grid; grid-template-columns: 55px 1fr; gap: .2rem .6rem; font-size: .72rem; }
.rs-grid span:nth-child(odd)  { color: var(--glt); font-weight: 700; }
.rs-grid span:nth-child(even) { color: var(--hjw); opacity: .75; }

/* ══ 로비 ══ */
#sl { background: radial-gradient(ellipse at 50% 30%, #1a1a1a, #050505 70%); align-items: center; justify-content: center; padding: 1.5rem; }
.lobby-wrap { background: linear-gradient(160deg, rgba(40,40,40,.95), rgba(10,10,10,.98)); border: 2px solid var(--gold); border-radius: 16px; padding: 1.8rem; max-width: 480px; width: 100%; }
.lobby-header { color: var(--glt); font-size: 1.2rem; letter-spacing: .1em; margin-bottom: 1.2rem; text-align: center; display: block; font-family: 'Nanum Myeongjo', serif; }
.lobby-user { background: rgba(0,0,0,.4); border: 1px solid rgba(255,255,255,.1); border-radius: 10px; padding: .8rem 1rem; margin-bottom: 1rem; text-align: center; }
#lobby-user-name { color: var(--glt); font-size: .95rem; }
.lobby-notice { text-align: center; padding: 1rem 0; color: var(--hanji-warm); font-size: .82rem; }
.lobby-section-title { color: var(--hanji-warm); font-size: .8rem; margin-bottom: .5rem; margin-top: .6rem; }
.lobby-code-row { display: flex; gap: .5rem; margin-bottom: .6rem; }
.lobby-code-input { flex: 1; background: rgba(0,0,0,.4); border: 1px solid var(--wood-pale); color: var(--hanji); padding: .55rem .8rem; border-radius: 8px; font-family: inherit; font-size: .95rem; letter-spacing: .2em; text-align: center; text-transform: uppercase; outline: none; }
.lobby-code-input:focus { border-color: var(--gold); }
.lobby-btn-join { background: linear-gradient(135deg, var(--wood-light), var(--wood-mid)); border: 1px solid var(--wood-pale); color: var(--hanji); padding: .55rem 1rem; border-radius: 8px; cursor: pointer; font-family: inherit; font-size: .82rem; white-space: nowrap; transition: all .2s; }
.lobby-btn-join:hover { border-color: var(--gold); color: var(--glt); }
.lobby-room-list { max-height: 150px; overflow-y: auto; margin-bottom: .8rem; scrollbar-width: thin; scrollbar-color: var(--gold) transparent; }
.room-empty { color: rgba(255,255,255,.3); font-size: .78rem; text-align: center; padding: .6rem 0; }
.room-item { display: flex; align-items: center; justify-content: space-between; background: rgba(0,0,0,.35); border: 1px solid rgba(255,255,255,.08); border-radius: 8px; padding: .5rem .8rem; margin-bottom: .3rem; cursor: pointer; transition: all .2s; }
.room-item:hover:not(.full) { border-color: var(--gold); }
.room-item.full { cursor: not-allowed; opacity: .55; }
.room-name { color: var(--hanji); font-size: .85rem; }
.room-info { color: var(--hanji-warm); font-size: .72rem; opacity: .7; }
.s-wait { font-size: .68rem; padding: 2px 8px; border-radius: 10px; background: rgba(20,90,20,.5); color: #8f8; border: 1px solid #5d5; }
.s-full { font-size: .68rem; padding: 2px 8px; border-radius: 10px; background: rgba(90,20,20,.5); color: #f88; border: 1px solid #d44; }
.lobby-room-name-input { width: 100%; background: rgba(0,0,0,.4); border: 1px solid var(--wood-pale); color: var(--hanji); padding: .55rem .8rem; border-radius: 8px; font-family: inherit; font-size: .88rem; margin-bottom: .6rem; outline: none; }
.lobby-room-name-input:focus { border-color: var(--gold); }
.lobby-btn-create { flex: 1; background: linear-gradient(135deg, #2a2a2a, #111); border: 1px solid #555; color: var(--hanji); padding: .55rem; border-radius: 8px; cursor: pointer; font-family: inherit; font-size: .82rem; transition: all .2s; text-align: center; display: block; width: 100%; margin-bottom: .4rem; }
.lobby-btn-create:hover { border-color: var(--gold); color: var(--glt); }
.lobby-btn-refresh { flex: 1; background: linear-gradient(135deg, var(--wood-light), var(--wood-mid)); border: 1px solid var(--wood-pale); color: var(--hanji); padding: .55rem; border-radius: 8px; cursor: pointer; font-family: inherit; font-size: .82rem; transition: all .2s; text-align: center; display: block; width: 100%; }
.lobby-btn-refresh:hover { border-color: var(--gold); color: var(--glt); }

/* ══ 모달 ══ */
.modal-bg { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.9); z-index: 500; align-items: center; justify-content: center; }
.modal-bg.show { display: flex; }
.modal-box { background: linear-gradient(160deg, #1a1a1a, #0a0a0a); border: 2px solid var(--gold); border-radius: 16px; padding: 1.5rem; min-width: 280px; max-width: 420px; width: 90%; text-align: center; max-height: 90vh; overflow-y: auto; }
.modal-box h2 { font-family: 'Nanum Myeongjo', serif; color: var(--glt); font-size: 1.3rem; margin-bottom: 1rem; }
.diff-btns { display: flex; flex-direction: column; gap: .6rem; margin-bottom: 1rem; }
.diff-btn { display: flex; align-items: center; gap: 1rem; background: var(--bg2); border: 1.5px solid var(--border); border-radius: 10px; padding: .7rem 1rem; cursor: pointer; color: var(--hjw); font-family: inherit; transition: all .2s; text-align: left; }
.diff-btn:hover { border-color: var(--gold); background: rgba(200,146,42,.05); }
.diff-icon { font-size: 1.8rem; }
.diff-name { font-size: .95rem; color: var(--glt); font-weight: 700; }
.diff-desc { font-size: .75rem; opacity: .65; }
.result-box { padding: 2rem; }
.res-icon  { font-size: 3rem; margin-bottom: .5rem; }
.res-title { font-family: 'Nanum Myeongjo', serif; font-size: 1.8rem; color: var(--glt); margin-bottom: .3rem; }
.res-msg   { font-size: .85rem; color: var(--hjw); opacity: .75; margin-bottom: .3rem; }
.res-score { font-size: 1.1rem; color: var(--glt); font-weight: 700; margin-bottom: 1rem; }
.res-btns  { display: flex; gap: .8rem; justify-content: center; flex-wrap: wrap; }

/* 공통 버튼 */
.btn-back { background: linear-gradient(135deg, var(--wood-light), var(--wood-mid)); border: 1px solid var(--wood-pale); color: var(--hanji); border-radius: 8px; padding: .4rem 1.2rem; cursor: pointer; font-size: .82rem; font-family: inherit; margin-top: .5rem; transition: all .2s; }
.btn-back:hover { border-color: var(--gold); color: var(--glt); }
.btn-confirm { background: linear-gradient(135deg, #333, #555); border: 1px solid #888; color: #fff; border-radius: 8px; padding: .6rem 1.6rem; cursor: pointer; font-size: .9rem; font-weight: 700; font-family: inherit; transition: all .15s; margin-top: .5rem; }
.btn-confirm:hover { filter: brightness(1.2); transform: translateY(-1px); }
.btn-copy { background: var(--bg2); border: 1px solid var(--border); border-radius: 6px; padding: .25rem .5rem; cursor: pointer; font-size: .8rem; }

/* ══ 게임 화면 ══ */
#sg { background: radial-gradient(ellipse at 50% 0%, #1a1a1a 0%, #050505 100%); }
.game-header { display: flex; align-items: center; padding: .4rem .8rem; border-bottom: 1px solid var(--border); background: rgba(0,0,0,.5); }
.game-title { flex: 1; text-align: center; font-family: 'Nanum Myeongjo', serif; font-size: 1rem; color: var(--glt); letter-spacing: .4rem; }
.btn-hdr { background: var(--bg2); border: 1px solid var(--border); color: var(--hjw); border-radius: 6px; padding: .3rem .7rem; cursor: pointer; font-size: .78rem; transition: all .15s; }
.btn-hdr:hover { border-color: var(--gold); }

.game-body { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: .4rem; gap: .3rem; overflow: hidden; position: relative; }

.player-bar { display: flex; align-items: center; justify-content: space-between; width: 100%; max-width: 600px; padding: .3rem .5rem; background: rgba(0,0,0,.3); border-radius: 8px; border: 1px solid var(--border); }
.player-info { display: flex; align-items: center; gap: .6rem; }
.player-stone { width: 28px; height: 28px; border-radius: 50%; flex-shrink: 0; }
.black-stone { background: radial-gradient(circle at 35% 35%, #666, #0a0a0a); box-shadow: 0 3px 8px rgba(0,0,0,.6), inset -2px -2px 4px rgba(0,0,0,.5), inset 1px 1px 3px rgba(255,255,255,.2); }
.white-stone { background: radial-gradient(circle at 35% 35%, #fff, #ccc); box-shadow: 0 3px 8px rgba(0,0,0,.4), inset -2px -2px 4px rgba(0,0,0,.1), inset 1px 1px 3px rgba(255,255,255,.8); }
.player-name  { font-size: .85rem; color: var(--hjw); font-weight: 600; }
.player-remain{ font-size: .75rem; color: var(--gold); opacity: .8; }
.turn-indicator { font-size: .75rem; color: var(--gold); padding: .2rem .5rem; border-radius: 12px; transition: all .3s; }
.turn-indicator.active { background: var(--gold); color: #0a0a0a; font-weight: 700; animation: pulse-turn 1.5s ease infinite; }
@keyframes pulse-turn { 0%,100%{box-shadow:0 0 0 rgba(200,146,42,.4)} 50%{box-shadow:0 0 10px rgba(200,146,42,.6)} }

.board-wrap { position: relative; flex-shrink: 0; }
#badukBoard { display: block; border-radius: 4px; box-shadow: 0 8px 32px rgba(0,0,0,.8); }
#aimCanvas  { position: absolute; top: 0; left: 0; pointer-events: none; border-radius: 4px; }

/* 사이드 패널 */
.side-panel { position: absolute; right: 8px; top: 50%; transform: translateY(-50%); width: 150px; display: flex; flex-direction: column; gap: .4rem; }
.turn-badge { background: var(--panel); border: 1.5px solid var(--border); border-radius: 8px; padding: .5rem; text-align: center; font-size: .8rem; color: var(--glt); }
.turn-badge.myturn { border-color: var(--gold); box-shadow: 0 0 12px rgba(200,146,42,.3); }

/* 콤보 디스플레이 */
.combo-display { background: linear-gradient(135deg, #ff6600, #ff2200); border-radius: 8px; padding: .5rem; text-align: center; animation: comboPop .3s cubic-bezier(.34,1.56,.64,1); }
.combo-num   { font-size: 1.8rem; font-weight: 900; color: #fff; line-height: 1; }
.combo-label { font-size: .7rem; color: rgba(255,255,255,.9); font-weight: 700; letter-spacing: .1em; }
@keyframes comboPop { from{transform:scale(.5);opacity:0} to{transform:scale(1);opacity:1} }

.score-board { background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: .5rem .7rem; }
.score-row   { display: flex; align-items: center; gap: .4rem; padding: .15rem 0; }
.score-stone { width: 14px; height: 14px; border-radius: 50%; flex-shrink: 0; }
.black-dot   { background: radial-gradient(circle at 35% 35%, #555, #111); box-shadow: inset -1px -1px 2px rgba(0,0,0,.5); }
.white-dot   { background: radial-gradient(circle at 35% 35%, #fff, #ccc); box-shadow: inset -1px -1px 2px rgba(0,0,0,.2); }
.score-label { font-size: .8rem; color: var(--hjw); flex: 1; }
.score-val   { font-size: .9rem; color: var(--glt); font-weight: 700; }

.power-gauge-wrap { background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: .5rem .7rem; }
.power-label { font-size: .7rem; color: var(--gold); margin-bottom: .3rem; text-align: center; }
.power-track { background: rgba(0,0,0,.4); border-radius: 4px; height: 8px; overflow: hidden; }
.power-fill  { height: 100%; width: 0%; background: linear-gradient(90deg, #4caf50, #ffeb3b, #f44336); border-radius: 4px; transition: width .05s; }

.move-log { flex: 1; max-height: 200px; overflow-y: auto; background: rgba(0,0,0,.2); border: 1px solid var(--border); border-radius: 6px; padding: .3rem .4rem; font-size: .68rem; }
.move-log::-webkit-scrollbar { width: 4px; }
.move-log::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }
.log-entry { padding: 1px 0; border-bottom: 1px solid rgba(255,255,255,.04); color: var(--hjw); opacity: .8; }
.log-entry.out   { color: #ff6644; font-weight: 700; opacity: 1; }
.log-entry.combo { color: #ffaa00; font-weight: 700; opacity: 1; }
.log-entry.win   { color: var(--glt); font-weight: 700; opacity: 1; }
.btn-draw { background: var(--bg2); border: 1px solid var(--border); color: var(--hjw); border-radius: 8px; padding: .5rem; cursor: pointer; font-size: .78rem; transition: all .15s; }
.btn-draw:hover { border-color: var(--gold); color: var(--glt); }

/* 토스트 */
.toast { position: fixed; top: 52px; left: 50%; transform: translateX(-50%) translateY(-8px); background: rgba(5,5,5,.96); border: 1.5px solid var(--gold); color: var(--glt); padding: .4rem 1.3rem; border-radius: 30px; font-size: .8rem; letter-spacing: .07em; z-index: 700; opacity: 0; transition: all .25s; pointer-events: none; white-space: nowrap; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* AI 생각중 */
.ai-thinking { position: fixed; bottom: 12px; left: 50%; transform: translateX(-50%); background: rgba(200,146,42,.85); color: #0a0a0a; border-radius: 16px; padding: .35rem 1rem; font-size: .8rem; font-weight: 700; opacity: 0; transition: opacity .3s; pointer-events: none; z-index: 50; }
.ai-thinking.show { opacity: 1; }

/* 콤보 팝업 */
.combo-pop { position: fixed; left: 50%; top: 35%; transform: translate(-50%,-50%) scale(.5); background: linear-gradient(135deg, #ff6600, #ff2200); color: #fff; border-radius: 16px; padding: .6rem 2rem; font-family: 'Nanum Myeongjo', serif; font-size: 2rem; font-weight: 800; z-index: 200; pointer-events: none; animation: popAnim .5s cubic-bezier(.34,1.56,.64,1) forwards; text-shadow: 0 2px 4px rgba(0,0,0,.3); }
@keyframes popAnim { to{transform:translate(-50%,-50%) scale(1);opacity:1} }
@keyframes fadeIn  { from{opacity:0;transform:translateY(-4px)} to{opacity:1;transform:translateY(0)} }

@media (max-height:700px) { .title-ko{font-size:2.2rem} .mode-card{padding:1.2rem 1.6rem} }
@media (max-width:780px)  { .side-panel{display:none} }
@media (max-width:600px)  { .player-name{font-size:.75rem} .player-stone{width:22px;height:22px} }
@media (pointer:coarse)   { .btn-hdr,.btn-back,.btn-confirm{min-height:44px} }
