:root {
  color-scheme: dark;
  --bg: #0b0d12;
  --panel: #151a24;
  --panel-2: #10141c;
  --line: rgba(255, 255, 255, 0.08);
  --text: #e9edf6;
  --muted: #8b95a9;
  --accent: #4f7cff;
  --accent-2: #6f94ff;
  --ok: #3ccf91;
  --warn: #ffb020;
  --bad: #ff5d5d;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: radial-gradient(900px 480px at 50% -10%, rgba(79, 124, 255, 0.16), transparent 60%),
    var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", "PingFang SC",
    "Hiragino Sans GB", sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

input,
textarea,
button {
  font: inherit;
  color: inherit;
}

/* ---------- 入口 ---------- */

.entry {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 28px 20px calc(28px + env(safe-area-inset-bottom));
}

.entry-card {
  width: 100%;
  max-width: 380px;
  padding: 30px 24px 24px;
  border-radius: 20px;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, #161b26, #11151d);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
}

.logo {
  width: 54px;
  height: 54px;
  border-radius: 16px;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 18px;
  color: #fff;
  background: linear-gradient(135deg, #4f7cff, #8a5cff);
  box-shadow: 0 10px 26px rgba(79, 124, 255, 0.35);
}

.entry-card h1 {
  margin: 16px 0 2px;
  font-size: 24px;
  letter-spacing: 0.4px;
}

.entry-card .sub {
  margin: 0 0 22px;
  color: var(--muted);
  font-size: 13px;
}

.field {
  display: block;
  margin-bottom: 14px;
}

.field span {
  display: block;
  margin-bottom: 7px;
  font-size: 12px;
  color: var(--muted);
}

.field input {
  width: 100%;
  padding: 13px 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #0c1017;
  font-size: 16px;
  outline: none;
}

.field input:focus {
  border-color: rgba(79, 124, 255, 0.6);
  box-shadow: 0 0 0 3px rgba(79, 124, 255, 0.13);
}

#roomInput {
  font-family: "SF Mono", "Cascadia Mono", "Consolas", monospace;
  letter-spacing: 5px;
  text-transform: uppercase;
}

.enter-btn {
  width: 100%;
  margin-top: 6px;
  padding: 13px;
  border: 0;
  border-radius: 12px;
  background: linear-gradient(180deg, var(--accent-2), var(--accent));
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 10px 24px rgba(79, 124, 255, 0.32);
}

.enter-btn:disabled {
  opacity: 0.6;
}

.error {
  margin: 12px 0 0;
  padding: 9px 12px;
  border-radius: 9px;
  background: rgba(255, 93, 93, 0.1);
  border: 1px solid rgba(255, 93, 93, 0.3);
  color: #ffb4b4;
  font-size: 13px;
  line-height: 1.5;
}

.tip {
  margin: 18px 0 0;
  color: #6f7a8f;
  font-size: 11px;
  line-height: 1.6;
}

/* ---------- 主界面 ---------- */

.app {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  max-width: 760px;
  margin: 0 auto;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  background: rgba(11, 13, 18, 0.72);
  backdrop-filter: blur(12px);
}

.room-info {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.room-label {
  font-size: 11px;
  color: var(--muted);
}

.room-info b {
  font-family: "SF Mono", "Cascadia Mono", "Consolas", monospace;
  font-size: 15px;
  letter-spacing: 2px;
}

.op-count {
  font-size: 10px;
  color: #6f7a8f;
  white-space: nowrap;
}

.host-state {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
  padding: 5px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.03);
  font-size: 11px;
  color: var(--muted);
}

.host-state .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--ok);
}

.host-state.offline .dot {
  background: var(--bad);
}

.host-state.dnd .dot {
  background: var(--warn);
}

.me {
  display: flex;
  align-items: center;
  gap: 6px;
  max-width: 120px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.04);
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 11px;
  color: #cfd9ef;
  cursor: pointer;
}

.me-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
  flex: none;
}

.me span:last-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dnd-bar {
  padding: 8px 16px;
  font-size: 12px;
  color: #ffd08a;
  background: rgba(255, 176, 32, 0.08);
  border-bottom: 1px solid rgba(255, 176, 32, 0.18);
}

.feed {
  flex: 1;
  overflow-y: auto;
  padding: 16px 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overscroll-behavior: contain;
}

.empty {
  margin: auto;
  text-align: center;
  color: #6f7a8f;
  font-size: 13px;
  line-height: 1.8;
}

.msg {
  max-width: 88%;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.msg.mine {
  align-self: flex-end;
  align-items: flex-end;
}

.msg-meta {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 11px;
  color: var(--muted);
  padding: 0 2px;
}

.msg-meta .from {
  color: #b9c4d8;
  font-weight: 600;
}

.msg-meta .state {
  padding: 1px 6px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  font-size: 10px;
}

.msg-meta .state.read {
  color: var(--ok);
  border-color: rgba(60, 207, 145, 0.35);
}

.msg-meta .state.shown {
  color: #9ec0ff;
  border-color: rgba(79, 124, 255, 0.35);
}

.msg-meta .state.retracted,
.msg-meta .state.dropped {
  color: #ff9c9c;
  border-color: rgba(255, 93, 93, 0.3);
}

.msg-meta .important-flag {
  color: var(--warn);
  border: 1px solid rgba(255, 176, 32, 0.35);
  border-radius: 999px;
  padding: 1px 6px;
  font-size: 10px;
}

.retract-btn {
  border: 0;
  background: transparent;
  color: #7f8aa0;
  font-size: 10px;
  padding: 0 2px;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.retract-btn:hover {
  color: #ff9c9c;
}

.bubble {
  padding: 11px 14px;
  border-radius: 14px;
  border-top-left-radius: 4px;
  background: #171c26;
  border: 1px solid var(--line);
  font-size: 15px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}

.msg.mine .bubble {
  border-top-left-radius: 14px;
  border-top-right-radius: 4px;
  background: linear-gradient(180deg, #3a63d8, #2f55c2);
  border-color: rgba(255, 255, 255, 0.08);
}

.msg.retracted .bubble {
  opacity: 0.45;
  text-decoration: line-through;
}

/* ---------- 输入区 ---------- */

.composer {
  border-top: 1px solid var(--line);
  background: rgba(13, 16, 23, 0.92);
  backdrop-filter: blur(16px);
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
}

.templates {
  display: flex;
  gap: 7px;
  overflow-x: auto;
  padding: 2px 2px 9px;
  scrollbar-width: none;
}

.templates::-webkit-scrollbar {
  display: none;
}

.chip {
  flex: none;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.04);
  color: #cfd9ef;
  border-radius: 999px;
  padding: 6px 11px;
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
}

.chip:hover {
  background: rgba(255, 255, 255, 0.09);
}

.chip.manage {
  color: var(--muted);
  border-style: dashed;
}

.input-wrap {
  position: relative;
}

textarea {
  width: 100%;
  min-height: 58px;
  max-height: 140px;
  resize: none;
  padding: 11px 13px 22px;
  border-radius: 13px;
  border: 1px solid var(--line);
  background: #0c1017;
  font-size: 15px;
  line-height: 1.5;
  outline: none;
}

textarea:focus {
  border-color: rgba(79, 124, 255, 0.55);
  box-shadow: 0 0 0 3px rgba(79, 124, 255, 0.12);
}

.counter {
  position: absolute;
  right: 12px;
  bottom: 8px;
  font-size: 10px;
  color: #66718a;
  font-variant-numeric: tabular-nums;
}

.send-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 9px;
}

.important {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
}

.important input {
  accent-color: var(--warn);
}

.send-btn {
  margin-left: auto;
  min-width: 108px;
  padding: 11px 22px;
  border: 0;
  border-radius: 11px;
  background: linear-gradient(180deg, var(--accent-2), var(--accent));
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 8px 20px rgba(79, 124, 255, 0.3);
}

.send-btn:disabled {
  opacity: 0.5;
  box-shadow: none;
}

/* ---------- 弹层与提示 ---------- */

.banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 50;
  padding: 9px 16px;
  text-align: center;
  font-size: 12px;
  color: #ffd08a;
  background: rgba(90, 62, 10, 0.95);
  border-bottom: 1px solid rgba(255, 176, 32, 0.3);
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(4, 6, 10, 0.66);
  backdrop-filter: blur(4px);
}

.modal[hidden] {
  display: none;
}

.modal-card {
  width: 100%;
  max-width: 560px;
  max-height: 82dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 18px 18px calc(18px + env(safe-area-inset-bottom));
  border-radius: 20px 20px 0 0;
  background: #141922;
  border: 1px solid var(--line);
}

.modal-head {
  display: flex;
  align-items: center;
  margin-bottom: 6px;
}

.modal-head h2 {
  margin: 0;
  font-size: 16px;
}

.modal-head .icon-btn {
  margin-left: auto;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  font-size: 18px;
  cursor: pointer;
}

.modal-tip {
  margin: 0 0 14px;
  font-size: 11px;
  color: var(--muted);
  line-height: 1.6;
}

.template-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding-right: 4px;
}

.template-row {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px;
  background: rgba(255, 255, 255, 0.02);
}

.template-row .row-head {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 7px;
}

.template-row input {
  flex: 1;
  min-width: 0;
  padding: 7px 9px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #0c1017;
  font-size: 13px;
  outline: none;
}

.template-row textarea {
  min-height: 54px;
  max-height: 110px;
  font-size: 13px;
  padding: 8px 9px 8px;
}

.template-row .delete {
  border: 1px solid rgba(255, 93, 93, 0.3);
  background: rgba(255, 93, 93, 0.08);
  color: #ff9c9c;
  border-radius: 8px;
  padding: 6px 9px;
  font-size: 11px;
  cursor: pointer;
}

.add-template {
  width: 100%;
  margin-top: 12px;
  padding: 11px;
  border-radius: 11px;
  border: 1px dashed var(--line);
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  cursor: pointer;
}

.add-template:hover {
  color: var(--text);
  border-color: rgba(79, 124, 255, 0.4);
}

.template-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.tpl-save,
.tpl-btn {
  flex: 1 1 auto;
  min-width: 110px;
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 13px;
  cursor: pointer;
}

.tpl-save {
  border: 0;
  background: linear-gradient(180deg, var(--accent-2), var(--accent));
  color: #fff;
  font-weight: 600;
}

.tpl-btn {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.04);
  color: #cfd9ef;
}

.template-status {
  min-height: 18px;
  margin: 10px 0 0;
  font-size: 11px;
  color: var(--muted);
}

.modal-head,
.modal-tip,
.add-template,
.template-actions,
.template-status {
  flex: 0 0 auto;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(90px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 60;
  max-width: 86vw;
  padding: 10px 16px;
  border-radius: 10px;
  background: rgba(30, 36, 50, 0.97);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: #e9edf6;
  font-size: 12px;
  line-height: 1.5;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.45);
}

.toast[hidden] {
  display: none;
}

@media (min-width: 640px) {
  .modal {
    align-items: center;
  }

  .modal-card {
    border-radius: 18px;
    padding-bottom: 18px;
  }
}

@media (max-width: 640px) {
  .field input,
  textarea,
  .template-row input {
    font-size: 16px;
  }
}

@media (max-width: 430px) {
  .op-count {
    display: none;
  }
}
