* {
  box-sizing: border-box;
}

/* 作者樣式的 display 會蓋掉 hidden 屬性預設的 display:none，
   所以這裡明確讓 hidden 優先 */
[hidden] {
  display: none !important;
}

body {
  margin: 0;
  font-family: -apple-system, "PingFang TC", "Microsoft JhengHei", sans-serif;
  background: #0f1220;
  color: #f5f5f7;
  min-height: 100vh;
}

/* ---------- 展示牆 (index.html) ---------- */

.wall-layout {
  display: flex;
  height: 100vh;
}

.qr-panel {
  flex: 0 0 320px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 24px;
  background: #171a2b;
  border-right: 1px solid #2a2e45;
}

.qr-panel #qrcode {
  background: #fff;
  line-height: 0;
  width: 272px;
  max-width: 100%;
}

.qr-panel #qrcode svg {
  display: block;
  width: 100%;
  height: auto;
}

.qr-panel p {
  text-align: center;
  color: #9aa0c3;
  font-size: 14px;
  word-break: break-all;
  max-width: 260px;
}

/* 多欄磚牆排版：欄寬與字級都跟著 --scale 等比縮放，
   JS 會縮小 --scale 直到所有留言塞進畫面。欄寬變小時瀏覽器
   會自動排出更多欄，所以容納量隨著縮放一起增加。 */
.messages-panel {
  --scale: 1;
  flex: 1;
  padding: calc(28px * var(--scale));
  overflow: hidden;
  column-width: calc(300px * var(--scale));
  column-gap: calc(14px * var(--scale));
  column-fill: auto; /* 每欄填滿後才換下一欄，把垂直空間用滿 */
  font-size: calc(22px * var(--scale));
}

/* 留言還少的時候：置中的單欄，不要讓卡片孤零零靠在左邊 */
.messages-panel.is-sparse {
  columns: auto;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}

.messages-panel.is-sparse .message-card {
  width: 100%;
  max-width: calc(760px * var(--scale));
}

.message-card {
  background: linear-gradient(135deg, #2a2e55, #1c1f3a);
  border: 1px solid #3a3f6b;
  border-radius: calc(14px * var(--scale));
  padding: calc(14px * var(--scale)) calc(18px * var(--scale));
  margin-bottom: calc(14px * var(--scale));
  font-size: 1em;
  line-height: 1.45;
  word-break: break-word;
  break-inside: avoid;
}

/* 只有新進的留言會有動畫，避免每次重新縮放時整面閃動 */
.message-card.is-new {
  animation: pop-in 0.45s ease-out;
}

@keyframes pop-in {
  from { opacity: 0; transform: translateY(12px) scale(0.96); }
  60%  { border-color: #7b86ff; }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.msg-count {
  color: #6a6f95;
  font-size: 13px;
  letter-spacing: 0.05em;
}

.empty-hint {
  color: #6a6f95;
  text-align: center;
  margin: auto;
  font-size: 18px;
}

/* ---------- 輸入頁 (input.html) ---------- */

.input-layout {
  max-width: 480px;
  margin: 0 auto;
  padding: 32px 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-height: 100vh;
  justify-content: center;
}

.input-layout h1 {
  font-size: 22px;
  text-align: center;
  margin-bottom: 8px;
}

textarea {
  width: 100%;
  min-height: 120px;
  border-radius: 12px;
  border: 1px solid #3a3f6b;
  background: #171a2b;
  color: #f5f5f7;
  font-size: 18px;
  padding: 14px;
  resize: vertical;
  font-family: inherit;
}

.char-count {
  text-align: right;
  color: #9aa0c3;
  font-size: 13px;
}

button {
  border: none;
  border-radius: 12px;
  padding: 16px;
  font-size: 18px;
  font-weight: 600;
  background: #5865f2;
  color: white;
  cursor: pointer;
}

button:disabled {
  background: #3a3f6b;
  cursor: not-allowed;
}

.status-msg {
  text-align: center;
  min-height: 20px;
  font-size: 14px;
  color: #9aa0c3;
}

/* ---------- 管理頁 (admin.html) ---------- */

.admin-layout {
  max-width: 640px;
  margin: 0 auto;
  padding: 32px 20px 48px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.admin-layout h1 {
  font-size: 22px;
  text-align: center;
}

.admin-layout input[type="email"],
.admin-layout input[type="password"],
.admin-layout input[type="text"],
.admin-layout input:not([type]) {
  border-radius: 10px;
  border: 1px solid #3a3f6b;
  background: #171a2b;
  color: #f5f5f7;
  font-size: 16px;
  padding: 12px;
  font-family: inherit;
  width: 100%;
}

#signin-view {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.admin-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: #9aa0c3;
  font-size: 14px;
}

.admin-bar label {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  white-space: nowrap;
}

#admin-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 60vh;
  overflow-y: auto;
}

.admin-row {
  display: flex;
  align-items: center;
  gap: 12px;
  background: #171a2b;
  border: 1px solid #2a2e45;
  border-radius: 10px;
  padding: 10px 12px;
}

.admin-row-text {
  flex: 1;
  word-break: break-word;
  font-size: 15px;
}

.btn-plain {
  background: none;
  border: 1px solid #3a3f6b;
  color: #9aa0c3;
  font-size: 14px;
  font-weight: 500;
  padding: 8px 14px;
  border-radius: 8px;
  flex: 0 0 auto;
}

.btn-del:hover {
  border-color: #e25555;
  color: #ff8080;
}

.btn-danger {
  background: #7a2230;
}

.btn-danger.is-armed,
.btn-plain.is-armed {
  background: #e25555;
  border-color: #e25555;
  color: #fff;
}

.admin-layout section {
  display: flex;
  flex-direction: column;
  gap: 10px;
  border-top: 1px solid #2a2e45;
  padding-top: 18px;
}

.admin-layout h2 {
  font-size: 15px;
  color: #9aa0c3;
  font-weight: 600;
  margin: 0;
}

.room-create {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.room-create input {
  flex: 1 1 160px;
}

.room-create button {
  flex: 0 0 auto;
  padding: 12px 20px;
  font-size: 16px;
}

.room-card {
  background: #171a2b;
  border: 1px solid #2a2e45;
  border-radius: 12px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.room-head {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 10px;
}

.room-code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 13px;
  color: #9aa0c3;
  background: #0f1220;
  border-radius: 6px;
  padding: 2px 8px;
}

.room-count {
  margin-left: auto;
  font-size: 13px;
  color: #6a6f95;
}

.url-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.url-caption {
  flex: 0 0 68px;
  font-size: 13px;
  color: #6a6f95;
}

.url-row input {
  flex: 1;
  min-width: 0;
  font-size: 13px !important;
  padding: 8px 10px !important;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.url-row button {
  flex: 0 0 auto;
  padding: 8px 12px;
  font-size: 13px;
}

.room-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.room-actions .btn-plain,
.room-actions a.btn-plain {
  text-decoration: none;
  text-align: center;
  display: inline-block;
}

.manual-room {
  margin-top: 4px;
}

.debug-tools {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 6px;
  padding: 12px;
  border: 1px dashed #3a3f6b;
  border-radius: 10px;
  font-size: 13px;
  color: #6a6f95;
}

.debug-label {
  font-weight: 600;
  letter-spacing: 0.05em;
}

.debug-tools label {
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.debug-tools input {
  width: 80px;
  font-size: 14px !important;
  padding: 8px !important;
}

.debug-tools button {
  margin-left: auto;
  padding: 8px 14px;
  font-size: 13px;
}
