:root {
  --bg: #fbf6f8;
  --card: #ffffff;
  --line: #efe3e8;
  --ink: #3b2b33;
  --muted: #9a8790;
  --accent: #ff5f99;
  --accent-soft: #ffe6ef;
  --blue: #2f7bff;
  --danger: #e5484d;
  --ok: #1f9d63;
  --radius: 14px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 'Pretendard', system-ui, sans-serif;
}

[hidden] { display: none !important; }

h1, h2 { margin: 0; font-weight: 800; }
h2 { font-size: 17px; display: flex; align-items: center; gap: 8px; }
code { background: #f4eef1; padding: 1px 6px; border-radius: 6px; font-size: 13px; }

input, select, textarea {
  font: inherit;
  color: inherit;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 7px 10px;
  min-width: 0;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
input[type='color'] { padding: 2px; height: 36px; width: 100%; }
input[type='checkbox'] { accent-color: var(--accent); width: 16px; height: 16px; }
input[type='range'] { accent-color: var(--accent); padding: 0; border: 0; width: 100%; }
textarea { width: 100%; resize: vertical; }

/* ---------- 버튼 ---------- */
.btn {
  font: inherit;
  font-weight: 700;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  padding: 8px 14px;
  border-radius: 10px;
  cursor: pointer;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: transform 0.08s, background 0.15s;
}
.btn:hover { background: #fff5f8; }
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #ff4688; }
.btn.accent { background: var(--accent-soft); border-color: #ffc6d9; color: #c2185b; }
.btn.danger { background: #fff0f0; border-color: #ffc9c9; color: var(--danger); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn.huge { font-size: 22px; padding: 16px 28px; border-radius: 14px; }
.btn-row { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }

/* ---------- 로그인 ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: min(380px, 100%);
  background: #fff;
  border-radius: 20px;
  padding: 28px;
  box-shadow: 0 10px 40px rgba(59, 43, 51, 0.1);
  display: grid;
  gap: 12px;
}
.login-card p { margin: 0; color: var(--muted); }
.error { color: var(--danger) !important; min-height: 1.4em; }

/* ---------- 상단 ---------- */
.top {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 10px 20px;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.brand { font-weight: 800; font-size: 18px; }
.tabs { display: flex; gap: 4px; }
.tabs button {
  font: inherit;
  font-weight: 700;
  border: 0;
  background: transparent;
  padding: 8px 14px;
  border-radius: 10px;
  color: var(--muted);
  cursor: pointer;
}
.tabs button.is-on { background: var(--accent-soft); color: #c2185b; }
.top-right { margin-left: auto; display: flex; gap: 8px; align-items: center; }

.badge {
  font-size: 13px;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 999px;
  background: #f1eef0;
  color: var(--muted);
}
.badge.ok { background: #e3f7ec; color: var(--ok); }
.badge.warn { background: #fff4e0; color: #b26a00; }
.badge.bad { background: #ffeaea; color: var(--danger); }

/* ---------- 레이아웃 ---------- */
.tab { padding: 18px 20px 60px; }
.play-grid { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: 16px; align-items: start; }
.board-grid { display: grid; grid-template-columns: 360px minmax(0, 1fr); gap: 16px; align-items: start; }
.col { display: grid; gap: 16px; min-width: 0; }
.narrow { max-width: 860px; display: grid; gap: 16px; }

@media (max-width: 1100px) {
  .play-grid, .board-grid { grid-template-columns: 1fr; }
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 16px 18px;
  display: grid;
  gap: 12px;
  min-width: 0;
}
.card.danger { border-color: #ffd6d6; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.hint { color: var(--muted); font-size: 13px; font-weight: 500; margin: 0; }
.count {
  background: var(--accent);
  color: #fff;
  font-size: 13px;
  padding: 1px 9px;
  border-radius: 999px;
}

/* ---------- 실행 ---------- */
.run-card { background: linear-gradient(135deg, #fff, #fff4f8); }
.run-row { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; }
.run-side { display: grid; gap: 6px; flex: 1; min-width: 200px; }
.run-status { font-weight: 700; color: var(--muted); }
.run-status.busy { color: #c2185b; }

.switch { display: inline-flex; align-items: center; gap: 8px; font-weight: 700; cursor: pointer; }
.switch input { display: none; }
.switch span {
  width: 42px; height: 24px; border-radius: 999px; background: #e7dde1; position: relative; transition: background 0.2s;
}
.switch span::after {
  content: ''; position: absolute; left: 3px; top: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: left 0.2s;
}
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { left: 21px; }

.inline { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); font-weight: 600; }
.w-num { width: 72px; }
.w-emoji { width: 56px; text-align: center; }
.w-id { width: 170px; }
.mini-ava { width: 26px; height: 26px; border-radius: 50%; object-fit: cover; flex: none; background: #f4eef1; }
.grow { flex: 1; }

/* ---------- 표 ---------- */
.table-wrap { max-height: 460px; overflow: auto; border-radius: 12px; border: 1px solid var(--line); }
.table-wrap.short { max-height: 320px; }
table.list { width: 100%; border-collapse: collapse; font-size: 14px; }
table.list th {
  position: sticky; top: 0; background: #fcf8fa; text-align: left; font-size: 12px; color: var(--muted);
  padding: 8px 10px; border-bottom: 1px solid var(--line); z-index: 1;
}
table.list td { padding: 7px 10px; border-bottom: 1px solid #f6eef2; vertical-align: middle; }
table.list tr:last-child td { border-bottom: 0; }
table.list tr.first td { background: #fff7fa; }
table.list td.num { color: var(--muted); font-size: 12px; width: 32px; }
table.list td.time { color: var(--muted); font-size: 12px; white-space: nowrap; }
table.list td.acts { text-align: right; white-space: nowrap; }
table.list input.nick { width: 100%; max-width: 160px; padding: 4px 8px; }
.nick-cell { display: flex; align-items: center; gap: 6px; }
table.list select.die { padding: 4px 6px; }
.empty-row td { text-align: center; color: var(--muted); padding: 22px; }
.tag {
  display: inline-flex; align-items: center; gap: 4px; padding: 2px 9px; border-radius: 999px;
  background: var(--accent-soft); color: #c2185b; font-weight: 700; font-size: 13px; white-space: nowrap;
}
.tag.src { background: #eef3ff; color: var(--blue); font-weight: 600; font-size: 11px; }
.tag.src.manual { background: #fff4e0; color: #b26a00; }
.skipped summary { cursor: pointer; color: var(--muted); font-weight: 700; font-size: 13px; }
.skipped table { margin-top: 8px; opacity: 0.8; }

/* ---------- 미리보기 ---------- */
.preview {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--line);
}
.preview iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; background: transparent; }
.checker {
  background-color: #3a3340;
  background-image:
    linear-gradient(45deg, #463e4d 25%, transparent 25%), linear-gradient(-45deg, #463e4d 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #463e4d 75%), linear-gradient(-45deg, transparent 75%, #463e4d 75%);
  background-size: 24px 24px;
  background-position: 0 0, 0 12px, 12px -12px, -12px 0;
}
#editorPreview > .jm-stage { position: absolute; left: 0; top: 0; transform-origin: 0 0; }
.local-bg { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0.55; pointer-events: none; z-index: 0; }

/* ---------- 상태 ---------- */
.state-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; }
.state-grid > div { background: #fcf8fa; border-radius: 12px; padding: 10px 12px; display: grid; gap: 2px; }
.state-grid span { font-size: 12px; color: var(--muted); font-weight: 600; }
.state-grid b { font-size: 20px; }
.shield-box { grid-column: 1 / -1; }

.ctrl { display: grid; grid-template-columns: 90px 1fr; gap: 10px; align-items: center; }
.ctrl > label { font-size: 13px; font-weight: 700; color: var(--muted); }
.ctrl input:not(.w-num):not(.w-emoji) { flex: 1; }
.manual { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.manual input[name='nick'] { flex: 1; min-width: 120px; }

/* ---------- 판 편집 ---------- */
.settings { position: sticky; top: 70px; max-height: calc(100vh - 90px); overflow: auto; }
.settings fieldset { border: 0; border-top: 1px solid var(--line); margin: 0; padding: 12px 0 0; display: grid; gap: 10px; }
.settings legend { font-weight: 800; font-size: 14px; padding-right: 8px; }
.settings label { display: grid; gap: 4px; font-size: 13px; font-weight: 600; color: var(--muted); }
.settings label.check, label.check {
  display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 13px; color: var(--ink);
}
.small-gap { margin-top: 4px; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; align-items: end; }
.three { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; align-items: end; }
.four { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.val { color: var(--accent); font-weight: 800; }
.upload { display: grid; gap: 8px; background: #fcf8fa; padding: 10px; border-radius: 12px; }
.save-bar { display: flex; gap: 8px; align-items: center; }
.settings .save-bar {
  position: sticky; top: -16px; background: #fff; z-index: 2; padding: 4px 0 10px; margin-top: -4px;
}
.dirty { color: #c2185b; font-size: 13px; font-weight: 700; }
.board-main { display: grid; gap: 16px; min-width: 0; }
.cell-form { display: grid; grid-template-columns: 2fr 1.4fr 90px 90px; gap: 10px; align-items: end; }
.cell-form label { display: grid; gap: 4px; font-size: 13px; font-weight: 600; color: var(--muted); }
@media (max-width: 700px) { .cell-form { grid-template-columns: 1fr 1fr; } }

/* ---------- 규칙 ---------- */
.rules-table input, .rules-table select { width: 100%; padding: 5px 8px; }
.rules-table td:first-child { width: 90px; }
.rules-table td:nth-child(3) { width: 70px; }


/* ---------- 설정 ---------- */
.copy-row { display: flex; gap: 8px; align-items: center; }
.copy-row input { flex: 1; font-family: ui-monospace, monospace; font-size: 13px; }
.copy-row label { font-size: 13px; font-weight: 700; color: var(--muted); white-space: nowrap; }
.steps { margin: 0; padding-left: 20px; display: grid; gap: 4px; }

/* ---------- 토스트 ---------- */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px);
  background: #2b2026; color: #fff; padding: 10px 18px; border-radius: 12px; font-weight: 700;
  opacity: 0; pointer-events: none; transition: opacity 0.2s, transform 0.2s; z-index: 100; max-width: 90vw;
}
.toast.on { opacity: 1; transform: translate(-50%, 0); }
.toast.bad { background: var(--danger); }
