:root {
  --bg: #2f3346;
  --panel: #ffffff;
  --panel-soft: #f5f6fa;
  --line: #e3e6ef;
  --text: #22263a;
  --muted: #7a8099;
  --primary: #4a6fd6;
  --accent: #4a6fd6;
  --radius: 14px;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: Pretendard, -apple-system, 'Apple SD Gothic Neo', sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

#app { display: flex; height: 100vh; height: 100dvh; }

/* ---------- 맵 영역 ---------- */
#stage {
  position: relative;
  flex: 1;
  min-width: 0;
  display: grid;
  place-items: center;
  background: radial-gradient(circle at 50% 40%, #3b4058, #262a3a);
}
#game { display: block; border-radius: 10px; box-shadow: 0 10px 40px rgba(0, 0, 0, 0.35); }

.hud { position: absolute; z-index: 2; pointer-events: none; }
.hud > * { pointer-events: auto; }
.hud-top-left { top: 14px; left: 16px; display: flex; gap: 8px; align-items: center; }
.hud-top-right { top: 14px; right: 16px; }
.hud-bottom { bottom: 14px; left: 50%; transform: translateX(-50%); display: flex; gap: 8px; align-items: center; }

.logo, .me-chip, .hint, .online, .reopen {
  background: rgba(20, 23, 36, 0.78);
  color: #fff;
  backdrop-filter: blur(6px);
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 14px;
}
.logo { font-weight: 700; }
.me-chip:empty { display: none; }
.hint { font-size: 13px; color: #d6d9e6; white-space: nowrap; }
.reopen { border: 0; font-weight: 600; background: var(--primary); }

.online { border-radius: 12px; min-width: 170px; padding: 10px 14px; }
.online-title { font-size: 13px; margin-bottom: 6px; }
.online ul { list-style: none; margin: 0; padding: 0; max-height: 180px; overflow: auto; }
.online li { display: flex; align-items: center; gap: 6px; font-size: 13px; padding: 2px 0; }
.online li { flex-wrap: wrap; }
.online li small { flex-basis: 100%; padding-left: 15px; color: #ffb4a8; font-size: 11px; }
.online li em { margin-left: auto; font-style: normal; color: #aab0c8; font-size: 12px; padding-left: 10px; }

.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 4px; vertical-align: 1px; }

.dpad { position: absolute; left: 16px; bottom: 60px; z-index: 3; display: none; grid-template: repeat(2, 48px) / repeat(3, 48px); gap: 4px; }
.dpad.show { display: grid; }
.dpad button { border: 0; border-radius: 10px; background: rgba(255, 255, 255, 0.85); font-size: 18px; touch-action: none; }
.dpad [data-dir="up"] { grid-column: 2; }
.dpad [data-dir="left"] { grid-column: 1; grid-row: 2; }
.dpad [data-dir="down"] { grid-column: 2; grid-row: 2; }
.dpad [data-dir="right"] { grid-column: 3; grid-row: 2; }

/* ---------- 내 상태 / 내 자리 ---------- */
.status-wrap { position: relative; }
.status-btn, .seat-btn {
  border: 0; border-radius: 999px; padding: 7px 14px; font-size: 14px; font-weight: 600;
  background: rgba(20, 23, 36, 0.78); color: #fff; backdrop-filter: blur(6px);
}
.status-btn.away { background: #d64545; }
.seat-btn { background: #6c7799; }
.seat-btn:disabled { cursor: default; opacity: 0.9; }
.status-menu {
  position: absolute; top: calc(100% + 8px); left: 0; width: 300px; background: #fff; color: var(--text);
  border-radius: 14px; padding: 14px; box-shadow: 0 12px 36px rgba(0, 0, 0, 0.3); display: flex; flex-direction: column; gap: 12px;
}
.status-menu[hidden], .status-extra[hidden] { display: none; }
.status-title { font-weight: 700; font-size: 15px; }
.status-options { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.status-options button { border: 1.5px solid var(--line); background: #fff; border-radius: 10px; padding: 8px; font-size: 13px; font-weight: 600; text-align: left; }
.status-options button.on { border-color: var(--primary); background: #eef2fd; }
.status-extra { display: flex; flex-direction: column; gap: 10px; }
.status-seat { border-top: 1px solid var(--line); padding-top: 10px; }
.link { border: 0; background: none; color: var(--primary); text-decoration: underline; padding: 0; font-size: 12px; }

/* ---------- 방 패널 ---------- */
#panel {
  width: 0;
  overflow: hidden;
  background: var(--panel-soft);
  display: flex;
  flex-direction: column;
  transition: width 0.25s ease;
  border-left: 4px solid var(--accent);
}
#panel.open { width: 420px; }
#panel.open.wide { width: 560px; }
.panel-head {
  display: flex; justify-content: space-between; align-items: flex-start;
  padding: 16px 18px 12px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  min-width: 380px;
}
.panel-head h2 { margin: 0 0 4px; font-size: 19px; }
.panel-people { font-size: 12px; color: var(--muted); }
.panel-body { flex: 1; overflow: auto; padding: 14px; min-width: 380px; display: flex; flex-direction: column; gap: 12px; }

.icon-btn { border: 0; background: var(--panel-soft); width: 32px; height: 32px; border-radius: 50%; }

/* ---------- 공통 UI ---------- */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.card h3 { margin: 0; font-size: 16px; }
.muted { color: var(--muted); margin: 0; font-size: 14px; line-height: 1.5; }
.small { font-size: 12px; }
.empty { text-align: center; color: var(--muted); padding: 30px 0; line-height: 1.7; margin: 0; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.row.end { justify-content: flex-end; }
.stack { display: flex; flex-direction: column; gap: 12px; }

.btn {
  border: 1px solid var(--line); background: #fff; border-radius: 10px;
  padding: 8px 12px; font-size: 14px; font-weight: 600; text-decoration: none; color: var(--text);
  display: inline-flex; align-items: center; gap: 4px; justify-content: center;
}
.btn:hover { background: var(--panel-soft); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.07); }
.btn.ghost { border-color: transparent; color: var(--muted); background: transparent; }
.btn.zoom { background: #2d8cff; border-color: #2d8cff; color: #fff; }
.btn.big { padding: 12px 20px; font-size: 16px; }
.btn.block { width: 100%; padding: 12px; }

input:not([type="checkbox"]):not([type="radio"]), textarea {
  border: 1px solid var(--line); border-radius: 10px; padding: 9px 11px; background: #fff; flex: 1; min-width: 0; width: 100%;
}
.row input:not([type="checkbox"]):not([type="radio"]) { width: auto; }
input:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
textarea { resize: vertical; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 600; }
.check { display: flex; align-items: center; gap: 6px; font-weight: 500; font-size: 14px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 4px; background: var(--panel-soft); border: 1px solid var(--line); border-radius: 999px; padding: 4px 10px; font-size: 13px; font-weight: 500; }
.chip button { border: 0; background: none; padding: 0 0 0 2px; color: var(--muted); }
.chip em { font-style: normal; color: var(--muted); font-size: 12px; }

.tabs { display: flex; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 4px; gap: 4px; }
.tabs button { flex: 1; border: 0; background: none; padding: 9px; border-radius: 9px; font-weight: 600; color: var(--muted); }
.tabs button.on { background: var(--accent); color: #fff; }

.badge { font-size: 12px; font-weight: 700; padding: 3px 9px; border-radius: 999px; white-space: nowrap; }
.badge.open { background: #e5f6ea; color: #23874a; }
.badge.done { background: #eceef4; color: var(--muted); }

/* ---------- 회의실 ---------- */
.video-box {
  aspect-ratio: 16 / 10; background: #1d2030; border-radius: 12px; display: flex; flex-direction: column;
  gap: 10px; align-items: center; justify-content: center; overflow: hidden;
}
.video-box .muted { color: #9aa1bd; }
.video-box.live { aspect-ratio: 4 / 3; }
.video-box iframe { width: 100%; height: 100%; border: 0; }
.tips { margin: 0; padding-left: 18px; font-size: 13px; color: var(--muted); line-height: 1.6; }

/* ---------- 라운지: 채팅 ---------- */
.chat { flex: 1; display: flex; flex-direction: column; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); min-height: 320px; overflow: hidden; }
.chat-list { flex: 1; overflow: auto; padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 82%; align-self: flex-start; }
.msg.mine { align-self: flex-end; text-align: right; }
.msg-meta { font-size: 11px; color: var(--muted); margin-bottom: 3px; }
.msg-text { display: inline-block; background: var(--panel-soft); border-radius: 12px; padding: 8px 12px; font-size: 14px; line-height: 1.45; white-space: pre-wrap; word-break: break-word; text-align: left; }
.msg.mine .msg-text { background: var(--accent); color: #fff; }
.chat-form { display: flex; gap: 6px; padding: 10px; border-top: 1px solid var(--line); }

/* ---------- 라운지: 투표 ---------- */
.poll-head { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; }
.poll-table { width: 100%; border-collapse: separate; border-spacing: 6px; margin: -6px; width: calc(100% + 12px); }
.poll-table th { font-size: 13px; font-weight: 600; text-align: left; white-space: nowrap; }
.poll-table thead th { text-align: center; color: var(--muted); }
.poll-table td { width: 40%; }
.vote {
  width: 100%; min-height: 56px; border: 1.5px solid var(--line); background: #fff; border-radius: 10px;
  padding: 6px 8px; display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.vote b { font-size: 16px; }
.vote .voters { font-size: 11px; color: var(--muted); line-height: 1.3; text-align: center; }
.vote:hover:not(:disabled) { border-color: var(--accent); }
.vote.mine { background: #fff4e6; border-color: var(--accent); }
.vote.best b { color: var(--accent); }
.vote.confirmed { background: var(--accent); border-color: var(--accent); color: #fff; }
.vote.confirmed .voters { color: #fff; }
.vote:disabled { cursor: default; }
.result { background: #fff7ec; border: 1px dashed var(--accent); border-radius: 12px; padding: 12px; display: flex; flex-direction: column; gap: 6px; }

/* ---------- 게시판 ---------- */
.sticker-bar { gap: 8px; position: sticky; top: -14px; z-index: 5; }
.palette { display: flex; gap: 6px; flex-wrap: wrap; }
.palette button { border: 1.5px solid var(--line); background: #fff; width: 42px; height: 42px; border-radius: 10px; font-size: 22px; }
.palette button.on { border-color: var(--accent); background: #eaf6ee; transform: scale(1.08); }

.notes { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px; }
.note-wrap { display: flex; flex-direction: column; gap: 6px; }
.note {
  position: relative; min-height: 170px; padding: 18px 16px 30px; border-radius: 4px;
  box-shadow: 0 6px 14px rgba(40, 40, 60, 0.15); cursor: copy;
}
.note::before { content: '📌'; position: absolute; top: -10px; left: 50%; transform: translateX(-50%); font-size: 18px; }
.note h3 { margin: 0 0 6px; font-size: 16px; }
.note p { margin: 0; font-size: 14px; line-height: 1.5; word-break: break-word; }
.note-meta { position: absolute; bottom: 8px; left: 16px; font-size: 11px; color: rgba(0, 0, 0, 0.45); }
.note-del { position: absolute; top: 6px; right: 6px; border: 0; background: rgba(0, 0, 0, 0.06); width: 24px; height: 24px; border-radius: 50%; font-size: 11px; z-index: 2; }
.note-summary { display: flex; flex-wrap: wrap; gap: 4px; }
.note-summary .chip { font-size: 12px; padding: 3px 8px; }

.sticker {
  position: absolute; transform: translate(-50%, -50%) rotate(var(--r)); border: 0; background: none;
  font-size: 30px; line-height: 1; padding: 0; filter: drop-shadow(0 2px 2px rgba(0, 0, 0, 0.25)); cursor: pointer;
  animation: pop 0.25s ease-out;
}
.sticker.mine { filter: drop-shadow(0 0 0 #fff) drop-shadow(0 2px 3px rgba(0, 0, 0, 0.35)); }
.sticker::after {
  content: attr(data-tip); position: absolute; bottom: 110%; left: 50%; transform: translateX(-50%) rotate(calc(var(--r) * -1));
  background: #22263a; color: #fff; font-size: 11px; white-space: nowrap; padding: 4px 8px; border-radius: 6px;
  opacity: 0; pointer-events: none; transition: opacity 0.15s; font-family: Pretendard, sans-serif;
}
.sticker:hover { z-index: 3; }
.sticker:hover::after { opacity: 1; }
@keyframes pop { from { transform: translate(-50%, -50%) scale(0.2) rotate(var(--r)); } }

.note-color input { display: none; }
.note-color span { display: block; width: 28px; height: 28px; border-radius: 6px; border: 2px solid transparent; cursor: pointer; }
.note-color input:checked + span { border-color: var(--text); }

/* ---------- 로그인 ---------- */
.modal-back { position: fixed; inset: 0; background: rgba(15, 17, 28, 0.6); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal-back[hidden] { display: none; }
.modal { background: #fff; border-radius: 20px; padding: 28px; width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 16px; text-align: center; }
.modal h1 { margin: 0; font-size: 22px; }
.modal .field { text-align: left; }
.modal-emoji { font-size: 44px; }
.colors { display: flex; gap: 8px; flex-wrap: wrap; }
.color-dot { width: 34px; height: 34px; border-radius: 50%; border: 3px solid transparent; }
.color-dot.on { border-color: #fff; box-shadow: 0 0 0 2px var(--text); }

#toast {
  position: fixed; top: 18px; left: 50%; transform: translate(-50%, -80px); background: #22263a; color: #fff;
  padding: 10px 18px; border-radius: 999px; font-size: 14px; z-index: 60; transition: transform 0.25s ease; pointer-events: none;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3); max-width: calc(100vw - 32px); text-align: center;
}
#toast.show { transform: translate(-50%, 0); }

/* ---------- 좁은 화면: 패널을 아래쪽 시트로 ---------- */
@media (max-width: 820px) {
  #app { flex-direction: column; }
  #panel { width: 100% !important; height: 0; border-left: 0; border-top: 4px solid var(--accent); transition: height 0.25s ease; }
  #panel.open { height: 58vh; }
  .panel-head, .panel-body { min-width: 0; }
  .hud-top-right .online { min-width: 0; }
  .online ul { display: none; }
  .hint { display: none; }
  .logo { display: none; }
}
