:root {
  --primary: #007bff;
  --primary-hover: #0056b3;
  --primary-soft: #e7f2ff;
  --bg: #f4f6f8;
  --panel: #ffffff;
  --chat-bg: #f8f9fa;
  --text: #333333;
  --muted: #5f6b7a;
  --border: #dee2e6;
  --bubble-other: #e9ecef;
  --success: #28a745;
  --danger: #dc3545;
  --radius: 12px;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.12);
  font-synthesis-weight: none;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Noto Sans KR", -apple-system, BlinkMacSystemFont, "Malgun Gothic", sans-serif;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
button, input, textarea { font: inherit; color: inherit; }
::selection { background: rgba(0, 123, 255, 0.2); }

/* ---------------- shared ---------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 0;
  border-radius: 8px;
  padding: 12px 20px;
  font-weight: 700;
  background: var(--primary);
  color: #fff;
  cursor: pointer;
  transition: background 0.2s ease, transform 0.1s ease, opacity 0.2s ease;
}
.btn:hover { background: var(--primary-hover); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.55; cursor: progress; }

.btn-ghost {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 7px 12px;
  font-size: 14px;
  color: var(--text);
  cursor: pointer;
  transition: background 0.2s ease;
  white-space: nowrap;
}
.btn-ghost:hover { background: var(--bg); }

.field { display: grid; gap: 7px; }
.field label { font-size: 13px; font-weight: 500; color: #555; }

.input {
  width: 100%;
  padding: 12px 15px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.input::placeholder { color: #adb5bd; }
.input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.12);
}

.error-text {
  min-height: 20px;
  margin: 0;
  font-size: 13px;
  color: var(--danger);
}

.muted { color: var(--muted); }

.brand {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  font-weight: 700;
  font-size: 20px;
  letter-spacing: -0.02em;
  color: #1c2b3a;
}
.brand-logo { width: 32px; height: 32px; display: block; }
.brand-sub {
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
  letter-spacing: 0.02em;
  transform: translateY(2px);
}

.live-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 0 3px rgba(40, 167, 69, 0.15);
  flex: none;
}

/* ---------------- lobby ---------------- */

.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(255, 255, 255, 0.92);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(8px);
}
.site-header-inner {
  max-width: 1120px;
  margin: 0 auto;
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.header-status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--muted);
}
.header-status strong { color: var(--primary); font-size: 14px; }

.page { max-width: 1120px; margin: 0 auto; padding: 0 24px; }

.hero {
  display: grid;
  grid-template-columns: 1.05fr 1fr;
  gap: 56px;
  align-items: center;
  padding: 64px 0 56px;
}

.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 500;
  color: var(--primary);
  background: var(--primary-soft);
  border-radius: 999px;
  padding: 5px 12px;
}
.eyebrow::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--primary);
}

.hero h1 {
  margin: 18px 0 14px;
  font-size: clamp(32px, 4.2vw, 48px);
  line-height: 1.22;
  letter-spacing: -0.035em;
  color: #1c2b3a;
}
.hero h1 span { color: var(--primary); }

.hero-copy > p {
  margin: 0 0 26px;
  max-width: 48ch;
  font-size: 15.5px;
  color: #667085;
}

.hero-form { display: flex; gap: 10px; max-width: 460px; }
.hero-form .input { flex: 1; }
.hero-form .btn { padding-inline: 22px; white-space: nowrap; }
.hint { margin: 10px 0 0; font-size: 13px; color: var(--muted); }

.preview-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.preview-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}
.preview-head h3 { margin: 0; font-size: 16px; font-weight: 700; color: #1c2b3a; }
.preview-head .count { font-size: 12.5px; color: var(--muted); }
.preview-badge {
  font-size: 11px;
  font-weight: 700;
  color: var(--primary);
  background: var(--primary-soft);
  border-radius: 999px;
  padding: 3px 10px;
}
.preview-body {
  background: var(--chat-bg);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 250px;
}
.preview-msg { display: flex; flex-direction: column; max-width: 78%; }
.preview-msg.other { align-self: flex-start; }
.preview-msg.mine { align-self: flex-end; align-items: flex-end; }
.preview-msg .bubble {
  padding: 9px 13px;
  border-radius: 16px;
  font-size: 13.5px;
  line-height: 1.45;
  background: var(--bubble-other);
  color: var(--text);
  border-top-left-radius: 4px;
}
.preview-msg.mine .bubble {
  background: var(--primary);
  color: #fff;
  border-top-left-radius: 16px;
  border-top-right-radius: 4px;
}
.preview-msg .info { font-size: 11px; color: var(--muted); margin-top: 4px; display: flex; gap: 6px; }
.preview-msg.mine .info { flex-direction: row-reverse; }
.preview-system {
  align-self: center;
  font-size: 11.5px;
  color: var(--muted);
  background: rgba(0, 0, 0, 0.05);
  border-radius: 999px;
  padding: 6px 14px;
}
.preview-input {
  display: flex;
  gap: 8px;
  padding: 12px 14px;
  border-top: 1px solid var(--border);
  background: #fff;
}
.preview-input span {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 9px 15px;
  font-size: 13px;
  color: #adb5bd;
  white-space: nowrap;
  overflow: hidden;
}
.preview-input em {
  font-style: normal;
  background: var(--primary);
  color: #fff;
  border-radius: 24px;
  padding: 9px 17px;
  font-size: 13px;
  font-weight: 700;
}

.rooms-section { padding-bottom: 28px; }
.section-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 18px;
  padding: 24px 0 16px;
  border-top: 1px solid var(--border);
}
.section-head h2 { margin: 0 0 4px; font-size: 21px; letter-spacing: -0.02em; color: #1c2b3a; }
.section-head p { margin: 0; font-size: 13.5px; color: var(--muted); }
.stats { display: flex; gap: 8px; flex-wrap: wrap; }
.stat {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 13px;
  font-size: 13px;
  color: var(--muted);
}
.stat strong { color: var(--primary); font-size: 14.5px; margin-right: 2px; }

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.create-card { padding: 20px; margin-bottom: 18px; }
.create-card h2 { margin: 0 0 4px; font-size: 17px; color: #1c2b3a; }
.create-card > p { margin: 0 0 15px; font-size: 13px; color: var(--muted); }
.create-form {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 12px;
  align-items: end;
}
.create-form .btn { height: 46px; }
.create-card .error-text { margin-top: 6px; }

.room-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 12px;
  padding-bottom: 30px;
}
.room-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 16px 18px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color 0.2s ease, box-shadow 0.2s ease, transform 0.15s ease;
}
.room-card:hover {
  border-color: var(--primary);
  box-shadow: 0 6px 18px rgba(0, 123, 255, 0.12);
  transform: translateY(-1px);
}
.room-card .room-name {
  font-size: 15.5px;
  font-weight: 700;
  color: #1c2b3a;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.room-card .room-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 12.5px;
  color: var(--muted);
}
.room-status.live { color: var(--success); font-weight: 700; }
.tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 500;
  background: #fff;
  border: 1px solid var(--border);
  color: var(--muted);
}
.tag.locked { color: #b8860b; border-color: #ffe8a3; background: #fff8e1; }

.empty-rooms {
  grid-column: 1 / -1;
  text-align: center;
  padding: 50px 20px;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  background: #fff;
  color: var(--muted);
  font-size: 14px;
}

.site-footer {
  border-top: 1px solid var(--border);
  background: #fff;
  padding: 22px 0 28px;
  color: #adb5bd;
  font-size: 12.5px;
  text-align: center;
}

/* ---------------- room ---------------- */

body.room-page {
  height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: var(--bg);
}

.chat-container {
  width: 100%;
  height: 100dvh;
  background: var(--panel);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

@media (min-width: 768px) {
  .chat-container {
    height: 95vh;
    max-width: 1200px;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
  }
}

.chat-header {
  flex: none;
  padding: 14px 20px;
  background: #fff;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
}
.header-left { min-width: 0; }
.header-left h1 {
  margin: 0 0 3px;
  font-size: 18px;
  font-weight: 700;
  color: #1c2b3a;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.user-count {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  color: var(--muted);
}
.user-count strong { color: var(--text); }
.conn-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #adb5bd;
  flex: none;
}
.conn-dot.online { background: var(--success); }
.conn-dot.offline { background: var(--danger); }

.header-right { display: flex; align-items: center; gap: 7px; flex: none; }
.header-right .btn-icon { padding: 7px 10px; }

.chat-wrapper {
  display: flex;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.chat-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: var(--chat-bg);
}

.messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  scrollbar-width: thin;
  scrollbar-color: #ced4da transparent;
  overscroll-behavior: contain;
}
.messages::-webkit-scrollbar { width: 8px; }
.messages::-webkit-scrollbar-thumb { background: #ced4da; border-radius: 8px; }

.message {
  max-width: 75%;
  display: flex;
  flex-direction: column;
  margin-bottom: 12px;
}
.message.other { align-self: flex-start; align-items: flex-start; }
.message.mine { align-self: flex-end; align-items: flex-end; }

.msg-bubble {
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 15px;
  line-height: 1.45;
  word-break: break-word;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}
.message.other .msg-bubble {
  background: var(--bubble-other);
  color: var(--text);
  border-top-left-radius: 4px;
}
.message.mine .msg-bubble {
  background: var(--primary);
  color: #fff;
  border-top-right-radius: 4px;
}
.msg-bubble a { color: inherit; text-decoration: underline; text-underline-offset: 2px; }
.message.other .msg-bubble a { color: var(--primary); }

.msg-info {
  display: flex;
  gap: 6px;
  align-items: center;
  margin-top: 4px;
  font-size: 11px;
  color: var(--muted);
}
.message.mine .msg-info { flex-direction: row-reverse; }
.msg-info .msg-name { font-weight: 500; color: #6c757d; }

.message.system {
  align-self: center;
  align-items: center;
  max-width: 90%;
  background: rgba(0, 0, 0, 0.05);
  border-radius: 16px;
  padding: 7px 16px;
  margin-bottom: 12px;
  font-size: 12.5px;
  color: var(--muted);
  text-align: center;
}

.date-divider {
  align-self: center;
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  margin: 6px 0 14px;
  font-size: 11.5px;
  color: #adb5bd;
}
.date-divider::before,
.date-divider::after { content: ""; height: 1px; flex: 1; background: var(--border); }

.typing {
  flex: none;
  min-height: 20px;
  padding: 0 22px 4px;
  font-size: 12px;
  color: var(--muted);
  background: var(--chat-bg);
}

.chat-input-area {
  flex: none;
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 14px 20px;
  background: #fff;
  border-top: 1px solid var(--border);
}
.chat-input-area textarea {
  flex: 1;
  resize: none;
  min-height: 46px;
  max-height: 132px;
  padding: 11px 18px;
  border: 1px solid var(--border);
  border-radius: 24px;
  font-size: 15px;
  line-height: 1.45;
  outline: none;
  transition: border-color 0.2s ease;
}
.chat-input-area textarea:focus { border-color: var(--primary); }
.chat-input-area textarea::placeholder { color: #adb5bd; }
.chat-input-area .count { font-size: 11px; color: #adb5bd; padding-bottom: 14px; min-width: 38px; text-align: right; }
.chat-input-area .count.warn { color: var(--danger); }
.btn-send {
  height: 46px;
  padding: 0 22px;
  border: 0;
  border-radius: 24px;
  background: var(--primary);
  color: #fff;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.2s ease, opacity 0.2s ease;
}
.btn-send:hover { background: var(--primary-hover); }
.btn-send:disabled { opacity: 0.45; cursor: not-allowed; }

.user-sidebar {
  width: 260px;
  flex: none;
  background: #fff;
  border-left: 1px solid var(--border);
  display: none;
  flex-direction: column;
  min-height: 0;
}
.user-sidebar.open { display: flex; }

@media (min-width: 768px) {
  .user-sidebar { display: flex; }
}

.sidebar-header { padding: 15px 16px; border-bottom: 1px solid var(--border); }
.sidebar-header h3 {
  margin: 0;
  font-size: 14.5px;
  font-weight: 700;
  color: #1c2b3a;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.sidebar-header h3 span {
  font-size: 11.5px;
  font-weight: 500;
  color: var(--primary);
  background: var(--primary-soft);
  border-radius: 999px;
  padding: 1px 8px;
}

.user-list {
  flex: 1;
  overflow-y: auto;
  list-style: none;
  margin: 0;
  padding: 8px;
}
.user-item {
  display: flex;
  align-items: center;
  padding: 9px 12px;
  border-radius: 8px;
  transition: background 0.2s ease;
}
.user-item:hover { background: #f1f3f5; }
.user-item.me { background: #e7f5ff; }
.user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: #e9ecef;
  color: #495057;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
  margin-right: 11px;
  flex-shrink: 0;
}
.user-name {
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.user-status {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--success);
  margin-left: auto;
  flex-shrink: 0;
}

/* ---------------- modal / toast ---------------- */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(20, 30, 40, 0.45);
  backdrop-filter: blur(3px);
}
.modal {
  width: min(410px, 100%);
  padding: 26px;
  background: #fff;
  border-radius: var(--radius);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.22);
  display: grid;
  gap: 14px;
}
.modal h2 { margin: 0; font-size: 21px; color: #1c2b3a; letter-spacing: -0.02em; }
.modal .sub { margin: -8px 0 0; font-size: 13px; color: var(--muted); }
.locked-note {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12.5px;
  color: #8a6d1a;
  background: #fff8e1;
  border: 1px solid #ffe8a3;
  border-radius: 8px;
  padding: 8px 12px;
}
.modal .btn { width: 100%; margin-top: 2px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 90px;
  transform: translateX(-50%);
  z-index: 60;
  background: rgba(33, 37, 41, 0.94);
  color: #fff;
  font-size: 13px;
  font-weight: 500;
  padding: 10px 18px;
  border-radius: 999px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.28);
  animation: toast-in 0.2s ease;
}
.toast.ok { background: rgba(25, 135, 84, 0.95); }
@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, 8px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

/* ---------------- 404 ---------------- */

.notfound-page {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.notfound-card {
  width: min(420px, 100%);
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 46px 36px;
  text-align: center;
}
.notfound-card h1 {
  margin: 0;
  font-size: 64px;
  line-height: 1;
  letter-spacing: -0.05em;
  color: var(--primary);
}
.notfound-card p { margin: 12px 0 24px; color: var(--muted); font-size: 14px; }

/* ---------------- responsive ---------------- */

@media (max-width: 900px) {
  .hero { grid-template-columns: 1fr; gap: 32px; padding: 42px 0 38px; }
  .preview-card { display: none; }
  .create-form { grid-template-columns: 1fr; }
  .create-form .btn { width: 100%; }
}

@media (max-width: 767px) {
  .page { padding: 0 16px; }
  .site-header-inner { padding: 12px 16px; }
  .header-status { font-size: 12px; }
  .hero h1 { font-size: 32px; }
  .hero-form { flex-direction: column; }
  .hero-form .btn { width: 100%; }
  .section-head { flex-direction: column; align-items: flex-start; gap: 10px; }
  .chat-header { padding: 11px 14px; }
  .header-left h1 { font-size: 16px; }
  .header-right { gap: 5px; }
  .header-right .btn-ghost { padding: 6px 9px; font-size: 13px; }
  .messages { padding: 14px; }
  .message { max-width: 86%; }
  .chat-input-area { padding: 10px 12px 14px; }
  .chat-input-area .count { display: none; }
  .user-sidebar {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    z-index: 40;
    width: min(290px, 82vw);
    box-shadow: -16px 0 36px rgba(0, 0, 0, 0.18);
  }
}
