:root {
  --bg: #05080d;
  --panel: #0a111a;
  --line: #16324a;
  --fg: #c9e7ff;
  --dim: #5f7f99;
  --accent: #35e0ff;
  --accent2: #ff4fd8;
  --ok: #3dff9e;
  --bad: #ff5d5d;
  --font: "Nanum Gothic Coding", "D2Coding", ui-monospace, Menlo, Consolas, monospace;
  color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; background: var(--bg); color: var(--fg); font-family: var(--font); }

.app {
  height: 100dvh;
  display: grid;
  grid-template-rows: auto 1fr auto auto;
  max-width: 1100px;
  margin: 0 auto;
  transition: max-width .2s ease;
  padding: env(safe-area-inset-top, 0px) 12px env(safe-area-inset-bottom, 0px);
}

.bar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 4px; border-bottom: 1px solid var(--line);
}
.logo {
  font-weight: 700; font-size: 22px; letter-spacing: 4px; color: var(--accent);
  text-shadow: 0 0 8px rgba(53, 224, 255, .6), 0 0 2px var(--accent2);
}
.sub { margin-left: 10px; font-size: 11px; color: var(--dim); letter-spacing: 2px; }
.status { font-size: 12px; color: var(--dim); display: flex; align-items: center; gap: 6px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--dim); }
.dot.on { background: var(--ok); box-shadow: 0 0 6px var(--ok); }
.dot.off { background: var(--bad); }

.main {
  min-height: 0; margin: 10px 0;
  display: grid; grid-template-columns: minmax(0, 1fr) 290px; gap: 12px;
}
.main:has(.side[hidden]) { grid-template-columns: minmax(0, 1fr); }

/* ── 게시판 / 채팅 ───────────────────────── */
.bar-right { display: flex; align-items: center; gap: 8px; }
.drawer-btn {
  position: relative; font: inherit; font-size: 12px; color: var(--fg); background: #0d1824;
  border: 1px solid var(--line); border-radius: 4px; padding: 4px 10px; cursor: pointer;
}
.drawer-btn:hover, .drawer-btn:focus-visible { border-color: var(--accent); color: var(--accent); outline: none; }
.badge {
  position: absolute; top: -6px; right: -6px; min-width: 16px; height: 16px; padding: 0 4px;
  border-radius: 8px; background: var(--accent2); color: #05080d; font-size: 10px; font-weight: 700;
  line-height: 16px; text-align: center;
}
.board, .chat {
  display: flex; flex-direction: column; min-height: 0; padding: 0; overflow: hidden;
  /* 좁은 화면: 서랍 */
  position: fixed; top: calc(env(safe-area-inset-top, 0px) + 54px); bottom: 12px; z-index: 40;
  width: min(360px, calc(100vw - 24px));
  box-shadow: 0 12px 40px rgba(0, 0, 0, .6);
  visibility: hidden; opacity: 0; transition: opacity .18s ease, transform .18s ease, visibility 0s .18s;
}
.board { left: 12px; transform: translateX(-12px); }
.chat { right: 12px; transform: translateX(12px); }
body[data-drawer="board"] .board, body[data-drawer="chat"] .chat {
  visibility: visible; opacity: 1; transform: none; transition: opacity .18s ease, transform .18s ease;
}
.cpanel-head {
  display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--line);
}
.cpanel-head h2 { margin: 0; font-size: 14px; letter-spacing: 1px; color: var(--accent); }
.cmeta { font-size: 11px; color: var(--dim); font-variant-numeric: tabular-nums; }
.cpanel-head .cmeta { margin-right: auto; }
.cbtn {
  font: inherit; font-size: 12px; color: var(--fg); background: #0d1824; border: 1px solid var(--line);
  border-radius: 4px; padding: 4px 10px; cursor: pointer;
}
.cbtn:hover:not(:disabled), .cbtn:focus-visible { border-color: var(--accent); color: var(--accent); outline: none; }
.cbtn:disabled { opacity: .45; cursor: not-allowed; }
.cbtn.danger { color: var(--bad); }
.cbtn.danger:hover { border-color: var(--bad); color: var(--bad); }
.cclose { font: inherit; font-size: 12px; color: var(--dim); background: none; border: 0; cursor: pointer; padding: 2px 4px; }
.cclose:hover, .cclose:focus-visible { color: var(--accent); outline: none; }
.clink { font: inherit; font-size: 12px; color: var(--dim); background: none; border: 0; padding: 0; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }
.clink:hover, .clink:focus-visible { color: var(--accent); outline: none; }
.cbody { flex: 1; min-height: 0; overflow-y: auto; }
.cname { font-weight: 700; }            /* .who 는 HUD 이름 칸이 쓴다 */
.cnote { margin: 0; padding: 0 12px; max-height: 0; overflow: hidden; font-size: 12px; color: var(--accent2); transition: max-height .2s ease, padding .2s ease; }
.cnote.show { max-height: 60px; padding: 8px 12px; border-top: 1px solid var(--line); }

.board-list { list-style: none; margin: 0; padding: 0; }
.board-list li { border-bottom: 1px solid rgba(22, 50, 74, .6); }
.board-list .empty { padding: 18px 12px; font-size: 12px; color: var(--dim); line-height: 1.6; }
.post {
  display: grid; gap: 3px; width: 100%; text-align: left; font: inherit; color: var(--fg);
  background: none; border: 0; padding: 10px 12px; cursor: pointer;
}
.post:hover, .post:focus-visible { background: #0d1824; outline: none; }
.ptitle { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.board-view { display: grid; gap: 8px; padding: 12px; align-content: start; }
.board-view h3 { margin: 0; font-size: 16px; line-height: 1.35; text-wrap: balance; }
.bv-body { white-space: pre-wrap; word-break: break-word; font-size: 13px; line-height: 1.65; padding-top: 6px; border-top: 1px solid var(--line); }
.board-view .cbtn, .board-view .clink { justify-self: start; }
.board-form { display: grid; gap: 6px; padding: 12px; }
.board-form label { font-size: 11px; color: var(--dim); letter-spacing: 1px; }
.board-form input, .board-form textarea, .chat-form input {
  font: inherit; font-size: 13px; color: var(--fg); background: #070d14; border: 1px solid var(--line);
  border-radius: 4px; padding: 6px 8px; resize: vertical;
}
.board-form input:focus, .board-form textarea:focus, .chat-form input:focus { border-color: var(--accent); outline: none; }
.crow { display: flex; align-items: center; gap: 12px; margin-top: 4px; }

.chat-log { flex: 1; min-height: 0; overflow-y: auto; list-style: none; margin: 0; padding: 8px 12px; display: flex; flex-direction: column; gap: 4px; }
.chat-log li { font-size: 13px; line-height: 1.5; word-break: break-word; }
.chat-log time { font-size: 10px; color: var(--dim); margin-right: 6px; font-variant-numeric: tabular-nums; }
.chat-log .cname { margin-right: 6px; }
.chat-log li.mine .msg { color: #fff; }
.chat-form { display: flex; gap: 6px; padding: 8px; border-top: 1px solid var(--line); }
.chat-form input { flex: 1; min-width: 0; }
.chat-form input:disabled { opacity: .6; }

/* 넓은 화면: 게시판 | 게임 | HUD | 채팅 */
@media (min-width: 1500px) {
  .app { max-width: 1840px; }
  .main { grid-template-columns: 290px minmax(0, 1fr) 280px 320px; }
  .main:has(.side[hidden]) { grid-template-columns: 290px minmax(0, 1fr) 320px; }
  .board, .chat {
    position: static; width: auto; visibility: visible; opacity: 1; transform: none;
    box-shadow: none; transition: none;
  }
  .drawer-btn, .cclose { display: none; }
}
.col { display: flex; flex-direction: column; gap: 10px; min-height: 0; min-width: 0; }
.col .screen { flex: 1; }

/* ── 방 카드 ─────────────────────────── */
.room {
  display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 14px; align-items: stretch;
  border: 1px solid var(--line); border-radius: 6px; background: var(--panel); padding: 8px;
}
.room.stale { opacity: .45; filter: grayscale(.6); }
.room-art { width: 384px; aspect-ratio: 16 / 9; max-width: 100%; background: #000; border-radius: 3px; overflow: hidden;
  box-shadow: inset 0 0 0 1px #16324a; }
.room-art img { display: block; width: 100%; height: 100%; image-rendering: pixelated; transition: opacity .25s ease; }
.room-art img.swap { opacity: .35; }
.room-meta { display: flex; flex-direction: column; gap: 6px; min-width: 0; padding: 4px 2px; }
.room-area { font-size: 12px; color: var(--accent); letter-spacing: 1px; }
.room-name { margin: 0; font-size: 20px; line-height: 1.3; text-wrap: balance; }
.room-exits { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 2px; }
.room-exits .lbl { font-size: 11px; color: var(--dim); letter-spacing: 1px; }
.exits { display: flex; flex-wrap: wrap; gap: 4px; }
.exits button { font: inherit; font-size: 12px; color: var(--fg); background: #0d1824; border: 1px solid var(--line);
  border-radius: 4px; padding: 2px 9px; cursor: pointer; }
.exits button:hover, .exits button:focus-visible { border-color: var(--accent); color: var(--accent); outline: none; }
.exits .none { font-size: 12px; color: var(--dim); }
.room-toggle { margin-top: auto; align-self: flex-start; font: inherit; font-size: 11px; color: var(--dim);
  background: none; border: 0; padding: 0; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }
.room-toggle:hover, .room-toggle:focus-visible { color: var(--accent); outline: none; }
.room.collapsed { grid-template-columns: minmax(0, 1fr); }
.room.collapsed .room-art { display: none; }
.room.collapsed .room-meta { flex-direction: row; flex-wrap: wrap; align-items: center; gap: 4px 12px; padding: 0 4px; }
.room.collapsed .room-name { font-size: 15px; }
.room.collapsed .room-toggle { margin: 0 0 0 auto; }
@media (max-height: 860px) { .room-art { width: 288px; } }

.screen {
  position: relative; min-height: 0;
  border: 1px solid var(--line); border-radius: 6px; background: var(--panel);
  overflow: hidden;
}
/* CRT 스캔라인 */
.screen::after {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: repeating-linear-gradient(to bottom, rgba(255,255,255,.025) 0 1px, transparent 1px 3px);
}
.out {
  height: 100%; overflow-y: auto; padding: 12px 14px;
  white-space: pre-wrap; word-break: break-all;
  font-size: 15px; line-height: 1.45;
}
.out .sent { color: var(--dim); }
.out .sys { color: var(--accent2); }

/* ANSI */
.b { font-weight: 700; }
.blink { animation: glow 2.4s ease-in-out infinite; }
@keyframes glow { 50% { opacity: .65; } }
.f0{color:#4a5a6a}.f1{color:#ff5d6c}.f2{color:#3dff9e}.f3{color:#ffd166}
.f4{color:#4d8dff}.f5{color:#ff4fd8}.f6{color:#35e0ff}.f7{color:#c9e7ff}
.b.f0{color:#7d8fa1}.b.f1{color:#ff8a95}.b.f2{color:#8affc4}.b.f3{color:#ffe29a}
.b.f4{color:#8fb6ff}.b.f5{color:#ff8ae6}.b.f6{color:#8cefff}.b.f7{color:#ffffff}
.k0{background:#000}.k1{background:#5a1a22}.k2{background:#11442e}.k3{background:#4d3e12}
.k4{background:#132a5a}.k5{background:#4a1446}.k6{background:#0e4250}.k7{background:#8a9aa8}

/* ── HUD ─────────────────────────────── */
.side { display: flex; flex-direction: column; gap: 10px; min-height: 0; overflow-y: auto; }
.side.stale { opacity: .45; filter: grayscale(.6); }
.panel {
  border: 1px solid var(--line); border-radius: 6px; background: var(--panel);
  padding: 10px 12px;
}
.who { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 8px; font-weight: 700; }
.lv { color: var(--accent); font-size: 12px; letter-spacing: 1px; }
.meter { display: grid; grid-template-columns: 34px 1fr auto; align-items: center; gap: 8px; margin: 5px 0; font-size: 11px; }
.meter label { color: var(--dim); letter-spacing: 1px; }
.meter span { color: var(--fg); font-variant-numeric: tabular-nums; min-width: 52px; text-align: right; }
.track { height: 8px; border-radius: 4px; background: #0f1d2b; overflow: hidden; box-shadow: inset 0 0 0 1px #16324a; }
.fill { height: 100%; width: 0; border-radius: 4px; transition: width .35s ease; }
.hp .fill { background: linear-gradient(90deg, #ff3d5a, #ff7a8a); box-shadow: 0 0 8px rgba(255,61,90,.5); }
.hp.low .fill { animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .45; } }
.sta .fill { background: linear-gradient(90deg, #ffb347, #ffd166); }
.en .fill { background: linear-gradient(90deg, #1fb6ff, #35e0ff); box-shadow: 0 0 8px rgba(53,224,255,.4); }
.xp .fill { background: linear-gradient(90deg, #8a5cff, #ff4fd8); }
.xp.ready span { color: var(--accent2); font-weight: 700; }
.coin { display: flex; justify-content: space-between; margin-top: 8px; font-size: 12px; color: var(--dim); }
.coin b { color: #ffd166; }
.fight { color: var(--bad); font-weight: 700; animation: pulse 1s ease-in-out infinite; }

.maphead { display: flex; justify-content: space-between; gap: 8px; font-size: 12px; margin-bottom: 8px; }
#m-area { color: var(--accent); font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pos { color: var(--dim); white-space: nowrap; }
#map {
  display: block; width: 100%; aspect-ratio: 1; cursor: pointer;
  background: radial-gradient(circle at center, #0c1c2b 0%, #070d14 75%);
  border-radius: 4px; box-shadow: inset 0 0 0 1px #16324a;
}
.mapwrap { position: relative; }
.map-tip {
  position: absolute; z-index: 2; pointer-events: none; white-space: pre; max-width: 220px;
  font-size: 11px; line-height: 1.5; padding: 6px 8px; border-radius: 4px;
  background: rgba(5,8,13,.94); border: 1px solid var(--line); color: var(--fg);
  box-shadow: 0 4px 14px rgba(0,0,0,.5);
}
.here { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 8px; }
.here .ent {
  display: inline-flex; align-items: center; gap: 4px; font: inherit; font-size: 11px;
  color: var(--fg); background: #0d1824; border: 1px solid var(--line); border-radius: 999px;
  padding: 2px 8px 2px 5px; cursor: pointer; max-width: 100%;
}
.here .ent:hover { border-color: var(--accent); }
.here .ent.enemy { border-color: var(--bad); box-shadow: 0 0 6px rgba(255,93,93,.4); }
.here .more { font-size: 11px; color: var(--dim); align-self: center; }
.here-m { display: none; }
.lg-scan { background: var(--ok); border-radius: 50% !important; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 10px; margin-top: 8px; font-size: 11px; color: var(--dim); }
.legend i { display: inline-block; width: 9px; height: 9px; border-radius: 2px; margin-right: 4px; vertical-align: -1px; }
.lg-you { background: var(--accent); border-radius: 50% !important; box-shadow: 0 0 6px var(--accent); }
.lg-exit { box-shadow: inset 0 0 0 2px var(--accent2); }
.lg-stair { background: #6b5cff; }
.lg-door { background: #ffb347; height: 3px !important; }

.quick { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.quick button, .input button {
  font: inherit; font-size: 13px; color: var(--fg); background: #0d1824;
  border: 1px solid var(--line); border-radius: 4px; padding: 6px 10px; cursor: pointer;
}
.quick button:hover, .input button:hover { border-color: var(--accent); color: var(--accent); }
.quick button:active { background: #12263a; }
.pad { display: grid; grid-template-columns: repeat(3, 44px) 8px 44px; grid-template-rows: repeat(3, 30px); gap: 3px; }
.pad button { padding: 0; }
.pad [data-cmd="북"] { grid-area: 1 / 2; }
.pad [data-cmd="서"] { grid-area: 2 / 1; }
.pad .look { grid-area: 2 / 2; color: var(--accent); font-size: 11px; }
.pad [data-cmd="동"] { grid-area: 2 / 3; }
.pad [data-cmd="남"] { grid-area: 3 / 2; }
.pad [data-cmd="위"] { grid-area: 1 / 5; }
.pad [data-cmd="밑"] { grid-area: 3 / 5; }
.cmds { display: flex; flex-wrap: wrap; gap: 6px; flex: 1; }

.input {
  display: flex; align-items: center; gap: 8px; margin: 10px 0 12px;
  border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; background: var(--panel);
}
.input:focus-within { border-color: var(--accent); box-shadow: 0 0 0 1px rgba(53,224,255,.25); }
.caret { color: var(--accent); }
.input input {
  flex: 1; min-width: 0; font: inherit; font-size: 16px; color: var(--fg);
  background: transparent; border: 0; outline: 0;
}
.input input::placeholder { color: var(--dim); }

@media (max-width: 860px) {
  .room { grid-template-columns: minmax(0, 1fr); }
  .room-art { width: 100%; aspect-ratio: 16 / 7; }
  .room-art img { object-fit: cover; object-position: center; }
  .room-meta { flex-direction: row; flex-wrap: wrap; align-items: center; gap: 4px 12px; padding: 0 2px; }
  .room-name { font-size: 16px; }
  .room-toggle { margin: 0 0 0 auto; }
  .main { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); }
  .side { order: -1; flex-direction: row; overflow: visible; }
  .side .vitals { flex: 1; min-width: 0; }
  .side .mappanel { width: 150px; flex: none; padding: 8px; }
  .legend { display: none; }
  .mappanel .here { display: none !important; }
  .here-m:not([hidden]) { display: flex; margin-top: 6px; }
  .here-m .ent { padding: 3px; }
  .maphead { font-size: 11px; margin-bottom: 6px; }
}
@media (max-width: 600px) {
  .drawer-btn { padding: 4px 8px; }
  .panel { padding: 8px 10px; }
  .board, .chat { left: 8px; right: 8px; width: auto; padding: 0; }
  .meter { margin: 3px 0; }
  .side .mappanel { width: 128px; }
  .maphead .pos { display: none; }
  .sub { display: none; }
  .out { font-size: 13px; padding: 10px; }
  .pad { grid-template-columns: repeat(3, 40px) 6px 40px; grid-template-rows: repeat(3, 28px); }
}
