/* =========================================================
   IMPOSSIBLE TOWER LIST — chat.css  (v2)
   Chat card sits in the empty space to the RIGHT of the list.
   The list + header shift left to make room.

   >= 1024px : chat card docked on the right
   <  1024px : chat hidden, opens with the "Chat" button
   ========================================================= */

:root {
  --chat-w: 320px;
  --chat-gap: 16px;
  --chat-space: calc(var(--chat-w) + var(--chat-gap) * 2);
}

@media (min-width: 1024px) and (max-width: 1179px) { :root { --chat-w: 280px; } }
@media (min-width: 1180px) and (max-width: 1439px) { :root { --chat-w: 300px; } }

/* ---------------- Panel (base = slide-in on small screens) ---------------- */

.chat-panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 130;
  width: min(100vw, 380px);
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg-1);
  border-left: 1px solid var(--border);
  box-shadow: -24px 0 60px rgba(0, 0, 0, 0.45);
  transform: translateX(100%);
  visibility: hidden;
  transition: transform 320ms cubic-bezier(0.22, 1, 0.36, 1),
              visibility 0s linear 320ms;
}

.chat-panel.open {
  transform: translateX(0);
  visibility: visible;
  transition: transform 320ms cubic-bezier(0.22, 1, 0.36, 1),
              visibility 0s linear 0s;
}

/* ---------------- Header ---------------- */

.chat-head {
  height: 58px;
  flex-shrink: 0;
  padding: 0 16px 0 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--border);
}

.chat-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex: 1;
  min-width: 0;
}

.chat-title h2 {
  font-size: 16px;
  font-weight: 800;
  letter-spacing: -0.01em;
  color: var(--text);
  white-space: nowrap;
}

.chat-online {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: var(--bg-1);
  border: 1px solid var(--border);
  padding: 5px 11px;
  border-radius: 100px;
  font-size: 12px;
  white-space: nowrap;
}

.chat-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-muted);
  transition: background 200ms ease, box-shadow 200ms ease;
}

.chat-dot.on {
  background: var(--tier-verified);
  box-shadow: 0 0 8px rgba(74, 222, 128, 0.6);
}

.chat-dot.off {
  background: var(--tier-unverified);
  box-shadow: 0 0 8px rgba(248, 113, 113, 0.5);
}

.chat-online-num {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 13px;
  color: var(--accent);
}

.chat-online-label {
  color: var(--text-muted);
  font-weight: 500;
}

.chat-close {
  display: none;
  width: 34px;
  height: 34px;
  flex-shrink: 0;
  place-items: center;
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: 100px;
  color: var(--text-dim);
  cursor: pointer;
  transition: color 180ms ease, border-color 180ms ease, background 180ms ease;
}

.chat-close:hover {
  color: var(--text);
  border-color: var(--border-hover);
  background: var(--bg-3);
}

.chat-close svg { width: 16px; height: 16px; }

/* ---------------- Messages ---------------- */

.chat-body {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.chat-messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 10px 0 12px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.chat-messages::-webkit-scrollbar { width: 6px; }
.chat-messages::-webkit-scrollbar-track { background: transparent; }
.chat-messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 6px; }

.chat-msg {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  column-gap: 10px;
  padding: 6px 16px 6px 13px;
  border-left: 3px solid transparent;
  transition: background 180ms ease;
  animation: chatIn 260ms cubic-bezier(0.22, 1, 0.36, 1) both;
}

.chat-msg.no-anim { animation: none; }

@keyframes chatIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.chat-msg:hover { background: var(--bg-hover); }

.chat-msg.mine {
  border-left-color: var(--accent);
  background: rgba(255, 107, 74, 0.05);
}

.chat-msg.mine:hover { background: rgba(255, 107, 74, 0.09); }

.chat-msg.cont { padding-top: 0; padding-bottom: 2px; }

.chat-avatar {
  width: 34px;
  height: 34px;
  margin-top: 2px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  font-size: 14px;
  font-weight: 800;
  color: var(--bg-0);
  user-select: none;
}

.chat-gutter {
  padding-top: 5px;
  text-align: right;
  font-family: var(--font-mono);
  font-size: 9px;
  color: var(--text-muted);
  opacity: 0;
  transition: opacity 150ms ease;
  user-select: none;
}

.chat-msg:hover .chat-gutter { opacity: 1; }

.chat-msg-main { min-width: 0; }

.chat-msg-head {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 1px;
}

.chat-nick {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: var(--font-mono);
  font-size: 12.5px;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.chat-time {
  flex-shrink: 0;
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-muted);
}

.chat-text {
  font-size: 13.5px;
  line-height: 1.5;
  color: var(--text);
  word-break: break-word;
  overflow-wrap: anywhere;
}

.chat-empty {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 24px 28px;
  text-align: center;
  font-size: 12.5px;
  line-height: 1.55;
  color: var(--text-muted);
  pointer-events: none;
}

.chat-empty[hidden] { display: none; }

.chat-empty svg {
  width: 34px;
  height: 34px;
  margin-bottom: 4px;
  color: var(--border-hover);
}

.chat-empty strong {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-dim);
}

.chat-newmsg {
  position: absolute;
  left: 50%;
  bottom: 12px;
  transform: translateX(-50%);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-3);
  border: 1px solid var(--accent);
  color: var(--accent);
  font-family: var(--font-body);
  font-size: 12px;
  font-weight: 700;
  padding: 7px 14px;
  border-radius: 100px;
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  transition: background 180ms ease, color 180ms ease;
}

.chat-newmsg:hover {
  background: var(--accent);
  color: var(--bg-0);
}

.chat-newmsg[hidden] { display: none; }

/* ---------------- Composer ---------------- */

.chat-composer {
  flex-shrink: 0;
  padding: 12px 14px 12px;
  background: var(--bg-2);
  border-top: 1px solid var(--border);
}

.chat-form {
  display: flex;
  gap: 8px;
  align-items: stretch;
}

.chat-form input {
  flex: 1;
  min-width: 0;
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 11px 14px;
  color: var(--text);
  font-family: var(--font-body);
  font-size: 14px;
  transition: border-color 200ms, box-shadow 200ms;
}

.chat-form input::placeholder { color: var(--text-muted); }

.chat-form input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(255, 107, 74, 0.12);
}

.chat-form input:disabled { opacity: 0.5; cursor: not-allowed; }

.chat-send {
  width: 44px;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  background: var(--accent);
  color: var(--bg-0);
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  transition: transform 180ms ease, background 180ms ease, opacity 180ms ease;
}

.chat-send:hover {
  background: var(--accent-2);
  transform: scale(1.05);
}

.chat-send:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

.chat-send svg { width: 18px; height: 18px; }

.chat-hint {
  margin-top: 8px;
  min-height: 15px;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.02em;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-hint b {
  color: var(--text-dim);
  font-weight: 600;
}

.chat-hint.error { color: var(--tier-unverified); }

/* ---------------- Nickname popup ---------------- */

.nick-modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(7, 7, 9, 0.72);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

.nick-modal.open {
  display: flex;
  animation: nickFade 200ms ease both;
}

@keyframes nickFade {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.nick-card {
  width: 100%;
  max-width: 380px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 26px;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.6);
  animation: nickPop 300ms cubic-bezier(0.22, 1, 0.36, 1) both;
}

@keyframes nickPop {
  from { opacity: 0; transform: translateY(12px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.nick-card h3 {
  font-size: 18px;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--text);
}

.nick-sub {
  margin: 6px 0 18px;
  font-size: 13px;
  line-height: 1.55;
  color: var(--text-dim);
}

.nick-card input {
  width: 100%;
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 14px;
  transition: border-color 200ms, box-shadow 200ms;
}

.nick-card input::placeholder {
  color: var(--text-muted);
  font-family: var(--font-body);
}

.nick-card input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(255, 107, 74, 0.12);
}

.nick-card input.invalid {
  border-color: var(--tier-unverified);
  box-shadow: 0 0 0 3px rgba(248, 113, 113, 0.12);
}

.nick-error {
  min-height: 18px;
  margin-top: 8px;
  font-size: 12px;
  color: var(--tier-unverified);
}

.nick-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 14px;
}

.nick-cancel,
.nick-join {
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 700;
  padding: 10px 20px;
  border-radius: 100px;
  cursor: pointer;
  transition: transform 180ms ease, background 180ms ease, border-color 180ms ease, color 180ms ease;
}

.nick-cancel {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
}

.nick-cancel:hover {
  color: var(--text);
  border-color: var(--border-hover);
  background: var(--bg-3);
}

.nick-join {
  background: var(--accent);
  border: 1px solid var(--accent);
  color: var(--bg-0);
}

.nick-join:hover {
  background: var(--accent-2);
  border-color: var(--accent-2);
  transform: scale(1.03);
}

/* ---------------- Small-screen toggle + backdrop ---------------- */

.chat-toggle {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 120;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--accent);
  color: var(--bg-0);
  border: none;
  border-radius: 100px;
  padding: 12px 18px;
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 10px 30px rgba(255, 107, 74, 0.3);
  transition: transform 180ms ease, background 180ms ease;
}

.chat-toggle:hover {
  background: var(--accent-2);
  transform: scale(1.04);
}

.chat-toggle svg { width: 17px; height: 17px; }

.chat-badge {
  display: none;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  background: var(--bg-0);
  color: var(--accent);
  border-radius: 100px;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
}

.chat-badge.show { display: inline-flex; }

body.chat-open .chat-toggle { display: none; }

.chat-backdrop {
  position: fixed;
  inset: 0;
  z-index: 125;
  background: rgba(7, 7, 9, 0.6);
  opacity: 0;
  pointer-events: none;
  transition: opacity 250ms ease;
}

.chat-backdrop.show {
  opacity: 1;
  pointer-events: auto;
}

@media (max-width: 1023px) {
  .chat-close { display: grid; }
}

@media (max-width: 720px) {
  .chat-form input,
  .nick-card input { font-size: 16px; }
  .chat-panel { border-left: none; }
}

/* =========================================================
   DOCKED: chat card in the right margin, list shifted left
   ========================================================= */

@media (min-width: 1024px) {
  body { padding-right: var(--chat-space); }

  /* header stays full width (line across the whole page),
     but its content is centered in the space left of the chat */
  .site-header {
    margin-right: calc(var(--chat-space) * -1);
    padding-right: var(--chat-space);
  }

  .chat-panel {
    top: calc(71px + var(--chat-gap));
    right: var(--chat-gap);
    bottom: var(--chat-gap);
    width: var(--chat-w);
    height: auto;
    transform: none;
    visibility: visible;
    transition: none;
    border: 1px solid var(--border);
    border-radius: 14px;
    overflow: hidden;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
  }

  .chat-toggle,
  .chat-backdrop,
  .chat-close { display: none; }
}

/* Make the list fit next to the chat on medium screens */
@media (min-width: 1024px) and (max-width: 1439px) {
  main { padding-left: 20px; padding-right: 20px; }

  .list-head,
  .row-main { grid-template-columns: 56px 1fr 160px 140px 90px 32px; }
}

@media (min-width: 1024px) and (max-width: 1179px) {
  .list-head,
  .row-main { grid-template-columns: 52px 1fr 150px 90px 32px; }

  .col-creator,
  .row-creator { display: none; }

  .row-detail { grid-template-columns: 1fr; }

  .detail-side {
    padding-left: 0;
    margin-top: 16px;
  }
}
