:root {
  --bg: #070a14;
  --bg-2: #0d1224;
  --panel: rgba(20, 26, 48, 0.72);
  --line: rgba(120, 140, 200, 0.18);
  --fg: #e8ecf8;
  --muted: #8b96b8;
  --cyan: #22d3ee;
  --pink: #f472b6;
  --lime: #a3e635;
  --amber: #fbbf24;
  --red: #f87171;
  --t1: #4ade80;
  --t2: #38bdf8;
  --t3: #f472b6;
  --mono: 'JetBrains Mono', ui-monospace, Consolas, monospace;
  --kr: 'Noto Sans KR', system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--kr);
  overflow: hidden;
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  background:
    radial-gradient(900px 600px at 15% -10%, rgba(34, 211, 238, 0.16), transparent 60%),
    radial-gradient(800px 600px at 90% 110%, rgba(244, 114, 182, 0.14), transparent 60%),
    linear-gradient(180deg, #070a14, #0a0f20 60%, #070a14);
  pointer-events: none;
  z-index: 0;
}

#app { position: relative; z-index: 1; height: 100%; }

.screen { display: none; height: 100%; overflow: auto; }
.screen.active { display: block; }
.hidden { display: none !important; }

button, input { font-family: inherit; }

/* ---------------- 로비 ---------------- */
.lobby-inner {
  max-width: 1040px;
  margin: 0 auto;
  padding: 40px 24px 32px;
  min-height: 100%;
  display: flex;
  flex-direction: column;
  gap: 26px;
}

.brand { text-align: center; }
.brand h1 {
  margin: 0;
  font-family: var(--mono);
  font-size: clamp(38px, 7vw, 68px);
  font-weight: 800;
  letter-spacing: -2px;
  line-height: 1;
}
.brand-t { color: var(--cyan); text-shadow: 0 0 28px rgba(34, 211, 238, 0.55); }
.brand-x { color: var(--pink); text-shadow: 0 0 28px rgba(244, 114, 182, 0.5); }
.tagline { color: var(--muted); margin: 12px 0 0; font-size: 15px; }

.lobby-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
  align-items: start;
}

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 22px;
  backdrop-filter: blur(10px);
}

.field { display: block; margin-bottom: 18px; }
.field span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 7px; letter-spacing: 1px; }
.field input,
.join-row input {
  width: 100%;
  background: #060912;
  border: 1px solid var(--line);
  color: var(--fg);
  border-radius: 11px;
  padding: 12px 14px;
  font-size: 16px;
  outline: none;
  transition: border-color .15s;
}
.field input:focus, .join-row input:focus { border-color: var(--cyan); }

.mode-buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 11px; }

.btn {
  border: 1px solid var(--line);
  background: #121a33;
  color: var(--fg);
  border-radius: 12px;
  padding: 13px 16px;
  cursor: pointer;
  text-align: left;
  transition: transform .12s, box-shadow .18s, border-color .18s, background .18s;
}
.btn:hover { transform: translateY(-2px); border-color: rgba(160,180,255,.45); }
.btn:active { transform: translateY(0); }
.btn strong { display: block; font-size: 15px; }
.btn small { display: block; color: var(--muted); font-size: 11.5px; margin-top: 3px; }

.btn-solo:hover  { box-shadow: 0 0 0 1px var(--lime), 0 10px 30px rgba(163,230,53,.18); }
.btn-quick { background: linear-gradient(135deg, #164e63, #1e3a5f); }
.btn-quick:hover { box-shadow: 0 0 0 1px var(--cyan), 0 10px 30px rgba(34,211,238,.25); }
.btn-create:hover { box-shadow: 0 0 0 1px var(--amber), 0 10px 30px rgba(251,191,36,.18); }
.btn-join:hover   { box-shadow: 0 0 0 1px var(--pink), 0 10px 30px rgba(244,114,182,.2); }

.btn-ghost { background: transparent; text-align: center; }
.btn-sm { padding: 7px 12px; font-size: 12px; }
.btn-go { text-align: center; padding: 12px 22px; background: var(--cyan); color: #04222a; font-weight: 700; border-color: transparent; }

.join-row { display: flex; gap: 10px; margin-top: 12px; }
.join-row input {
  font-family: var(--mono);
  font-size: 22px;
  letter-spacing: 8px;
  text-align: center;
  text-transform: uppercase;
  max-width: 190px;
}

.lobby-msg { min-height: 20px; margin: 14px 0 0; font-size: 13px; color: var(--amber); }

.card-help h3 { margin: 0 0 10px; font-size: 13px; color: var(--cyan); letter-spacing: 1.5px; }
.card-help h3 + * { margin-bottom: 20px; }
.keys { list-style: none; margin: 0; padding: 0; display: grid; gap: 7px; }
.keys li { display: flex; align-items: center; gap: 7px; font-size: 13px; color: var(--muted); }
.keys span { margin-left: 4px; }
kbd {
  font-family: var(--mono);
  background: #0a0f1e;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 6px;
  padding: 2px 7px;
  font-size: 11px;
  color: var(--fg);
}
.rules { margin: 0; padding-left: 18px; display: grid; gap: 7px; font-size: 13px; color: var(--muted); line-height: 1.55; }
.rules b { color: var(--fg); }
.c-atk { color: var(--amber) !important; }
.c-block { color: var(--cyan) !important; }
.t1 { color: var(--t1) !important; }
.t2 { color: var(--t2) !important; }
.t3 { color: var(--t3) !important; }

.conn { display: flex; align-items: center; justify-content: center; gap: 8px; color: var(--muted); font-size: 12px; margin-top: auto; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--amber); box-shadow: 0 0 10px currentColor; }
.dot.on { background: var(--lime); }
.dot.off { background: var(--red); }

/* ---------------- 대기실 ---------------- */
.room-inner {
  max-width: 520px;
  margin: 0 auto;
  padding: 70px 24px;
  text-align: center;
}
.room-inner h2 { font-family: var(--mono); font-size: 26px; margin: 0 0 22px; }
.room-code-box {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  margin-bottom: 18px;
}
.room-code-box .label { font-size: 12px; color: var(--muted); }
.room-code-box strong { font-family: var(--mono); font-size: 34px; letter-spacing: 9px; color: var(--amber); }

.room-players { display: grid; gap: 10px; margin-bottom: 22px; }
.player-row {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; padding: 14px 18px;
}
.player-row .pname { font-weight: 700; }
.player-row .pstat { font-size: 12px; color: var(--muted); }
.player-row.ready { border-color: var(--lime); }
.player-row.ready .pstat { color: var(--lime); }
.player-row.empty { opacity: .45; border-style: dashed; }

.room-actions { display: flex; gap: 10px; justify-content: center; }
.room-actions .btn { min-width: 140px; text-align: center; }
.room-actions .btn strong { display: inline; }

/* ---------------- 게임 ---------------- */
#screen-game.active { display: flex; flex-direction: column; align-items: center; padding: 14px 12px; gap: 12px; }

.hud-top { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.hud-chip {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 6px 12px;
  display: flex; gap: 8px; align-items: baseline;
  font-family: var(--mono);
  font-size: 14px;
}
.hud-k { font-size: 9.5px; color: var(--muted); letter-spacing: 1.2px; }

.game-wrap { display: flex; gap: 14px; align-items: flex-start; }

.side { display: flex; flex-direction: column; gap: 12px; width: 148px; }
.box {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px;
}
.box h4 { margin: 0 0 9px; font-size: 10px; letter-spacing: 2px; color: var(--muted); font-family: var(--mono); }
.box canvas { display: block; width: 100%; height: auto; }

.meters { display: grid; gap: 12px; }
.meter-head { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); margin-bottom: 5px; }
.meter-head b { font-family: var(--mono); color: var(--fg); }
.meter-bar { height: 9px; background: #0a0f1e; border-radius: 5px; overflow: hidden; border: 1px solid var(--line); }
.fill { display: block; height: 100%; width: 0; transition: width .2s ease; border-radius: 5px; }
.fill.atk { background: linear-gradient(90deg, var(--amber), var(--red)); box-shadow: 0 0 12px rgba(251,191,36,.6); }
.fill.grb { background: linear-gradient(90deg, #64748b, var(--red)); box-shadow: 0 0 12px rgba(248,113,113,.5); }
.combo-line { font-family: var(--mono); font-size: 12px; color: var(--muted); text-align: center; }
.combo-line b { color: var(--pink); font-size: 16px; }

.board-area { position: relative; }
#board {
  display: block;
  border: 1px solid rgba(120,140,200,.3);
  border-radius: 10px;
  background: rgba(4, 7, 16, .82);
  box-shadow: 0 0 60px rgba(34,211,238,.1), inset 0 0 60px rgba(0,0,0,.6);
}
#board.danger { border-color: var(--red); box-shadow: 0 0 60px rgba(248,113,113,.35); }

.board-overlay {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 10px;
  background: rgba(4,7,16,.86);
  border-radius: 10px;
  font-family: var(--mono);
  text-align: center;
}
.board-overlay .big { font-size: 62px; font-weight: 800; color: var(--cyan); text-shadow: 0 0 30px rgba(34,211,238,.6); }
.board-overlay .small { font-size: 13px; color: var(--muted); font-family: var(--kr); }

.toast-layer { position: absolute; inset: 0; pointer-events: none; overflow: hidden; border-radius: 10px; }
.toast {
  position: absolute;
  left: 50%;
  top: 28%;
  transform: translateX(-50%);
  font-family: var(--mono);
  font-weight: 800;
  font-size: 22px;
  white-space: nowrap;
  animation: toastUp 1s ease-out forwards;
  text-shadow: 0 2px 18px rgba(0,0,0,.9);
}
@keyframes toastUp {
  0% { opacity: 0; transform: translate(-50%, 14px) scale(.85); }
  18% { opacity: 1; transform: translate(-50%, 0) scale(1.06); }
  70% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -46px) scale(1); }
}

.opp canvas { border: 1px solid var(--line); border-radius: 8px; background: rgba(4,7,16,.8); }
.opp-stats { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); margin-top: 6px; font-family: var(--mono); }
.opp-stats b { color: var(--fg); }
.opp.dead { border-color: var(--red); opacity: .75; }

/* ---------------- 단어 독 ---------------- */
.word-dock {
  width: min(760px, 96vw);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px 20px;
  display: grid;
  grid-template-columns: 190px 1fr 100px;
  align-items: center;
  gap: 16px;
  backdrop-filter: blur(10px);
}
.word-dock.flash { animation: dockFlash .4s ease-out; }
@keyframes dockFlash {
  0% { border-color: var(--lime); box-shadow: 0 0 0 0 rgba(163,230,53,.5); }
  100% { border-color: var(--line); box-shadow: 0 0 0 22px rgba(163,230,53,0); }
}
.word-dock.shake { animation: dockShake .25s ease; }
@keyframes dockShake {
  0%,100% { transform: translateX(0); }
  25% { transform: translateX(-7px); }
  75% { transform: translateX(7px); }
}

.word-side { display: flex; align-items: center; gap: 9px; min-width: 0; }
.word-side.right { justify-content: flex-end; }
.tier-badge {
  font-size: 11px; font-weight: 700;
  padding: 3px 9px; border-radius: 999px;
  background: rgba(74,222,128,.15); color: var(--t1);
  border: 1px solid currentColor;
  flex-shrink: 0;
}
.word-meaning { font-size: 16px; font-weight: 700; color: var(--fg); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.streak { font-family: var(--mono); font-size: 12px; color: var(--muted); }
.streak.hot { color: var(--amber); text-shadow: 0 0 12px rgba(251,191,36,.7); }

.word-letters {
  display: flex; justify-content: center; gap: 3px;
  font-family: var(--mono); font-size: clamp(22px, 3.2vw, 34px); font-weight: 700;
}
.word-letters .ch {
  min-width: .62em;
  text-align: center;
  color: #55617f;
  border-bottom: 3px solid rgba(120,140,200,.2);
  padding-bottom: 3px;
  transition: color .1s, border-color .1s;
}
.word-letters .ch.done { color: var(--lime); border-color: var(--lime); }
.word-letters .ch.cur { color: var(--fg); border-color: var(--cyan); animation: caret .9s steps(2) infinite; }
.word-letters .ch.bad { color: var(--red); border-color: var(--red); }
@keyframes caret { 50% { border-color: transparent; } }

/* ---------------- 결과 ---------------- */
.modal {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(4,7,16,.85);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  backdrop-filter: blur(6px);
}
.modal-card {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 30px;
  width: min(520px, 100%);
  max-height: 90vh;
  overflow: auto;
  text-align: center;
}
.modal-card h2 { font-family: var(--mono); font-size: 32px; margin: 0 0 6px; }
.modal-card h2.win { color: var(--lime); text-shadow: 0 0 26px rgba(163,230,53,.5); }
.modal-card h2.lose { color: var(--red); }
.result-sub { color: var(--muted); margin: 0 0 22px; font-size: 14px; }

.result-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 20px; }
.result-grid div {
  background: rgba(10,15,30,.7);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 8px;
}
.result-grid span { display: block; font-size: 10.5px; color: var(--muted); margin-bottom: 5px; }
.result-grid b { font-family: var(--mono); font-size: 20px; }

.missed-box { text-align: left; margin-bottom: 20px; }
.missed-box h4 { font-size: 12px; color: var(--muted); letter-spacing: 1px; margin: 0 0 8px; }
.missed-box ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; max-height: 170px; overflow: auto; }
.missed-box li {
  display: flex; justify-content: space-between; gap: 12px;
  background: rgba(248,113,113,.08);
  border: 1px solid rgba(248,113,113,.25);
  border-radius: 9px; padding: 8px 12px; font-size: 13px;
}
.missed-box li b { font-family: var(--mono); color: var(--red); }
.missed-box li span { color: var(--muted); }

.modal-actions { display: flex; gap: 10px; justify-content: center; }
.modal-actions .btn { min-width: 130px; text-align: center; }

@media (max-width: 900px) {
  .lobby-grid { grid-template-columns: 1fr; }
  .side { width: 108px; }
  .word-dock { grid-template-columns: 1fr; text-align: center; gap: 9px; }
  .word-side, .word-side.right { justify-content: center; }
}
@media (max-width: 620px) {
  .mode-buttons { grid-template-columns: 1fr; }
  .side-left { display: none; }
  .result-grid { grid-template-columns: repeat(2, 1fr); }
}
