:root {
  --bg: #0f1115;
  --bg2: #151923;
  --panel: #171b25;
  --line: #262c3a;
  --fg: #e6e8ee;
  --dim: #8b93a7;
  --accent: #5eead4;
  --hit: #4ade80;
  --miss: #f87171;
  --todo: #8b93a7;
  --radius: 10px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

/* display 를 따로 준 요소에도 hidden 이 먹게 한다 */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.6 system-ui, "Malgun Gothic", "Apple SD Gothic Neo", sans-serif;
}

button, input, textarea { font: inherit; color: inherit; }

button {
  background: #232938;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 13px;
  cursor: pointer;
}
button:hover { background: #2c3446; }
button.primary { background: var(--accent); color: #06231f; border-color: transparent; font-weight: 700; }
button.primary:hover { filter: brightness(1.08); }
button.ghost { background: transparent; }
button:disabled { opacity: .5; cursor: not-allowed; }

input, textarea {
  background: #10141c;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  width: 100%;
}
input:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
input[type=number] { -moz-appearance: textfield; }

.hint { color: var(--dim); font-size: 12.5px; margin: 6px 0 12px; }
.msg { min-height: 22px; text-align: center; color: var(--miss); }
.msg.ok { color: var(--accent); }
.empty { color: var(--dim); font-size: 13px; text-align: center; padding: 18px 8px; margin: 0; }

/* ── 로비 ── */
.lobby { max-width: 860px; margin: 0 auto; padding: 8vh 20px 60px; }
.lobby h1 { font-size: 30px; margin: 0 0 4px; letter-spacing: -.5px; }
.lobby h1::before { content: "🔎 "; }
.tag { color: var(--dim); margin: 0 0 30px; }
.lobby-cards { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 18px 20px; }
.card h2 { font-size: 16px; margin: 0 0 14px; }
.card button { width: 100%; }
.field { display: block; margin-bottom: 12px; }
.field > span { display: block; font-size: 12.5px; color: var(--dim); margin-bottom: 5px; }
.field em { font-style: normal; opacity: .7; }
.recent { margin-top: 14px; border-top: 1px solid var(--line); padding-top: 12px; font-size: 13px; }
.recent > span { color: var(--dim); }
.recent button { width: auto; margin: 6px 6px 0 0; padding: 4px 10px; font-size: 13px; }
.about { margin-top: 28px; color: var(--dim); font-size: 13.5px; }
.about summary { cursor: pointer; }
.about ul { line-height: 1.9; padding-left: 20px; }
.about b { color: var(--fg); }

/* ── 방: 위쪽 ── */
.room { display: flex; flex-direction: column; height: 100%; }
.top {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) minmax(200px, 340px) auto;
  gap: 16px; align-items: center;
  padding: 10px 16px; border-bottom: 1px solid var(--line); background: var(--bg2);
}
.title-input { background: transparent; border: 1px solid transparent; font-size: 16px; font-weight: 700; padding: 4px 6px; }
.title-input:hover { border-color: var(--line); }
.code-line { display: flex; align-items: center; gap: 8px; padding-left: 6px; }
.code {
  font-family: ui-monospace, Menlo, Consolas, monospace; letter-spacing: 2px;
  font-size: 13px; padding: 2px 9px; background: #10141c;
}
.conn { font-size: 12px; color: var(--dim); }
.conn::before { content: "● "; color: var(--miss); }
.conn[data-state=on]::before { color: var(--hit); }
.conn[data-state=wait]::before { color: #fbbf24; }

.progress { width: 100%; }
.bar { height: 8px; background: #10141c; border: 1px solid var(--line); border-radius: 99px; overflow: hidden; }
.bar > i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .25s; }
.prog-text { display: flex; align-items: center; gap: 4px; font-size: 13px; color: var(--dim); margin-top: 4px; }
.prog-text b { color: var(--fg); font-size: 15px; }
.prog-text input { width: 62px; padding: 2px 6px; text-align: center; }
.top-right { display: flex; align-items: center; gap: 8px; justify-self: end; }
.top-right button { padding: 6px 11px; font-size: 13px; }
.members { display: flex; gap: 5px; margin-right: 4px; }
.members i {
  width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center;
  font-style: normal; font-size: 11px; font-weight: 700; color: #06231f;
}

/* ── 방: 본문 ── */
.cols { display: grid; grid-template-columns: minmax(280px, 380px) 1fr; gap: 12px; padding: 12px; flex: 1; min-height: 0; }
.col { display: flex; flex-direction: column; gap: 12px; min-height: 0; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 13px; display: flex; flex-direction: column; min-height: 0; }
.panel.grow { flex: 1; }
.panel h2 { font-size: 13px; font-weight: 700; color: var(--dim); letter-spacing: .4px; margin: 0 0 10px; text-transform: uppercase; }
.count { background: #10141c; border-radius: 99px; padding: 1px 8px; font-size: 11px; margin-left: 4px; }
.who { text-transform: none; letter-spacing: 0; font-weight: 400; color: var(--accent); float: right; font-size: 11px; }

.row-form { display: flex; gap: 6px; }
.row-form button { flex: none; }

.filters { display: flex; gap: 4px; margin: 9px 0 6px; }
.filters button { padding: 3px 9px; font-size: 12px; background: transparent; color: var(--dim); }
.filters button.on { background: #232938; color: var(--fg); }

.kw-list, .st-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; min-height: 60px; }
.kw-list li {
  display: flex; align-items: center; gap: 8px; padding: 5px 4px;
  border-bottom: 1px solid #1e2431;
}
.kw-list .dot {
  flex: none; width: 15px; height: 15px; border-radius: 50%; border: 2px solid var(--todo);
  background: transparent; padding: 0; cursor: pointer;
}
.kw-list li[data-s=hit] .dot { background: var(--hit); border-color: var(--hit); }
.kw-list li[data-s=miss] .dot { background: var(--miss); border-color: var(--miss); }
.kw-list li[data-s=miss] .txt { text-decoration: line-through; color: var(--dim); }
.kw-list .txt { flex: 1; word-break: break-all; cursor: pointer; }
.kw-list .by { font-size: 11px; opacity: .75; }
.kw-list .x, .st-list .x { flex: none; background: transparent; border: none; color: var(--dim); padding: 2px 5px; }
.kw-list .x:hover, .st-list .x:hover { color: var(--miss); background: transparent; }

.st-list li { display: flex; gap: 8px; align-items: flex-start; padding: 6px 4px; border-bottom: 1px solid #1e2431; }
.st-list li.done .t { text-decoration: line-through; color: var(--dim); }
.st-list .t { flex: 1; word-break: break-word; }
.st-list input[type=checkbox] { width: auto; margin-top: 5px; }
.st-list .by { font-size: 11px; opacity: .75; white-space: nowrap; }

#nt-text { flex: 1; min-height: 90px; resize: none; font-size: 14px; }

.table-wrap { overflow: auto; flex: 1; min-height: 0; }
table.log { width: 100%; border-collapse: collapse; font-size: 14px; }
table.log th { position: sticky; top: 0; background: var(--panel); text-align: left; font-size: 11px; color: var(--dim); font-weight: 700; padding: 4px 6px; border-bottom: 1px solid var(--line); z-index: 1; }
table.log td { padding: 3px 4px; border-bottom: 1px solid #1e2431; vertical-align: top; }
table.log .c-page { width: 68px; }
table.log .c-key { width: 26%; }
table.log .c-by { width: 74px; }
table.log .c-x { width: 30px; }
table.log td input { background: transparent; border-color: transparent; padding: 4px 6px; }
table.log td input:hover { border-color: var(--line); }
table.log tfoot td { padding-top: 8px; }
table.log tfoot input { background: #10141c; border-color: var(--line); }
table.log .by { font-size: 11px; opacity: .8; white-space: nowrap; padding-top: 8px; }
table.log a { color: var(--accent); }
table.log .x { background: transparent; border: none; color: var(--dim); padding: 4px 6px; }
table.log .x:hover { color: var(--miss); }

.ch-list { max-height: 150px; overflow-y: auto; font-size: 13.5px; margin-bottom: 8px; }
.ch-list p { margin: 2px 0; word-break: break-word; }
.ch-list .n { font-weight: 700; margin-right: 5px; }

/* ── 깨진 글자 ── */
dialog {
  background: var(--panel); color: var(--fg); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 22px; width: min(640px, 92vw);
}
dialog::backdrop { background: #000a; }
dialog h2 { margin: 0 0 8px; font-size: 18px; }
.mj-close { float: right; }
.mj-close button { background: transparent; border: none; font-size: 22px; line-height: 1; padding: 0 4px; color: var(--dim); }
#mj-in { height: 96px; resize: vertical; font-family: ui-monospace, Consolas, monospace; }
.mj-out { margin-top: 14px; display: grid; gap: 8px; }
.mj-out .cand { background: #10141c; border: 1px solid var(--line); border-radius: 8px; padding: 9px 11px; }
.mj-out .cand .cs { font-size: 11px; color: var(--dim); display: flex; justify-content: space-between; margin-bottom: 4px; }
.mj-out .cand .r { word-break: break-all; }
.mj-out .cand.best { border-color: var(--accent); }
.mj-out .cand button { margin-top: 6px; padding: 3px 9px; font-size: 12px; }

@media (max-width: 900px) {
  .lobby-cards { grid-template-columns: 1fr; }
  .cols { grid-template-columns: 1fr; overflow-y: auto; }
  .col { min-height: auto; }
  .panel.grow { flex: none; }
  .kw-list, .st-list { max-height: 260px; }
  .top { grid-template-columns: 1fr; gap: 8px; }
  .top-right { justify-self: start; flex-wrap: wrap; }
  .table-wrap { max-height: none; }
}


/* 전체 수 + 세는 단위를 한 줄에. 쪽 번호가 없는 게임이면 단위를 「곳·항목」으로 바꾼다 */
.field-row { display: flex; gap: 10px; align-items: flex-end; }
.field-row .field { flex: 1; }
.field-row .field-narrow { flex: 0 0 5.5rem; }
#rm-unit {
  width: 3.2rem;
  padding: 2px 4px;
  border: 1px solid transparent;
  border-radius: 4px;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
}
#rm-unit:hover, #rm-unit:focus { border-color: rgba(255,255,255,.25); background: rgba(255,255,255,.06); }


/* ───────── 증거 그림 ───────── */
.drop {
  padding: 14px 12px;
  border: 1px dashed rgba(255,255,255,.28);
  border-radius: 8px;
  text-align: center;
  color: #9aa4b2;
  font-size: 13px;
}
.drop.over { border-color: #6ee7b7; background: rgba(110,231,183,.08); color: #d7f5e8; }
.drop p { margin: 0 0 8px; }
.shot-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 8px;
  margin-top: 10px;
}
.shot { margin: 0; }
.shot a { display: block; }
.shot img {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border-radius: 6px;
  background: #11161d;
}
.shot figcaption { margin-top: 4px; }
.shot-head { display: flex; align-items: center; gap: 4px; }
.shot-head i { flex: none; font-style: normal; font-size: 11px; }
.shot-where {
  flex: 1;
  min-width: 0;
  padding: 1px 4px;
  border: 1px solid transparent;
  border-radius: 4px;
  background: transparent;
  color: var(--accent);
  font-size: 11px;
}
.shot-note {
  width: 100%;
  margin-top: 3px;
  padding: 4px 5px;
  border: 1px solid transparent;
  border-radius: 4px;
  background: transparent;
  color: inherit;
  font: inherit;
  font-size: 11px;
  line-height: 1.5;
  resize: vertical;
}
.shot-where:hover, .shot-where:focus,
.shot-note:hover, .shot-note:focus {
  border-color: rgba(255,255,255,.22);
  background: rgba(255,255,255,.06);
}
.shot-note::placeholder { color: #5b6472; }

/* 폰에서는 한 줄에 한 장씩. 증거 그림은 글자를 읽어야 하므로 작으면 소용없다 */
@media (max-width: 600px) {
  .shot-grid { grid-template-columns: 1fr 1fr; }
  .shot img { aspect-ratio: 3 / 2; }
  .shot-note { font-size: 12px; }
}

/* ───────── 좁은 화면: 로그 표를 카드로 ─────────
   폰(375px)에서 5칸을 표로 욱여넣으면 「메모」 칸이 67px 가 돼서 못 쓴다.
   한 줄을 카드 한 장으로 바꾸고 칸마다 이름을 앞에 붙인다. */
@media (max-width: 600px) {
  table.log, table.log tbody, table.log tfoot, table.log tr, table.log td { display: block; width: auto; }
  table.log thead { display: none; }

  table.log tbody tr, table.log tfoot tr {
    margin: 0 0 8px;
    padding: 6px 8px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #10141c;
  }
  table.log td { padding: 2px 0; border: 0; }

  /* 칸 이름을 왼쪽에 고정 폭으로 붙이고 입력칸이 나머지를 다 쓴다 */
  table.log td[data-label]:not([data-label=""]) {
    display: flex;
    align-items: center;
    gap: 8px;
  }
  table.log td[data-label]:not([data-label=""])::before {
    content: attr(data-label);
    flex: 0 0 4.6rem;
    font-size: 11px;
    color: var(--dim);
  }
  table.log td input { width: 100%; background: #0c1017; border-color: var(--line); padding: 7px 8px; font-size: 15px; }
  table.log td a { flex: 1; min-width: 0; overflow-wrap: anywhere; }

  /* 작성자와 지우기는 카드 아래에 한 줄로 */
  table.log .by { display: inline-block; padding: 4px 0 0; }
  table.log tbody td:last-child { display: inline-block; float: right; }
  table.log tbody tr::after { content: ""; display: block; clear: both; }
  table.log tfoot td[colspan] { padding-top: 6px; }
  table.log tfoot button { width: 100%; padding: 9px; }
}


/* ───────── 순서 바꾸기 · 줄 색깔 · 쪽 빠짐 ───────── */
table.log tbody tr { cursor: grab; }
table.log tbody tr.dragging { opacity: .45; }
table.log tbody tr.drop-here { box-shadow: inset 0 2px 0 var(--accent); }
table.log .tint { font-size: 10px; padding: 4px 3px; }
table.log tr.gap td {
  padding: 2px 6px;
  color: #d9a441;
  font-size: 11px;
  background: rgba(217,164,65,.08);
  border-bottom: 1px dashed rgba(217,164,65,.4);
  cursor: default;
}
table.log tr.gap { cursor: default; }

/* 보관 기간 */
.ttl { display: flex; align-items: center; gap: 6px; margin-top: 4px; font-size: 11px; color: var(--dim); }
.ttl select { padding: 1px 4px; font-size: 11px; background: #10141c; color: inherit; border: 1px solid var(--line); border-radius: 4px; }
#rm-left.warn { color: var(--miss); font-weight: 700; }
#tr-list li { display: flex; align-items: center; gap: 8px; justify-content: space-between; }
#tr-list li span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; }

/* 증거 그림: 오른쪽 아래 칸으로 옮김(대화와 자리 바꿈). 그림이 많아도 칸 안에서 스크롤되게 —
   전에는 칸 밖으로 넘쳐 아래 패널 뒤에 숨어 「4장만 올라간다」처럼 보였다 */
#p-shots { max-height: 46vh; }
#p-shots .shot-grid { overflow-y: auto; min-height: 0; flex: 1; padding-right: 2px; }
