:root {
  --bg: #f5f7fb;
  --panel: #ffffffcc;
  --line: #d9e1ef;
  --text: #152033;
  --accent: #0f8b8d;
  --accent-2: #f4a261;
  --danger: #c44536;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(circle at 8% 10%, #fff6de 0%, transparent 45%),
    radial-gradient(circle at 90% 90%, #dff8ff 0%, transparent 40%),
    var(--bg);
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--text);
}

.bg-shape {
  position: fixed;
  border-radius: 999px;
  filter: blur(40px);
  opacity: 0.22;
  z-index: 0;
}

.shape-a {
  width: 280px;
  height: 280px;
  background: #ffbe0b;
  top: -80px;
  right: -60px;
}

.shape-b {
  width: 220px;
  height: 220px;
  background: #00a6fb;
  left: -70px;
  bottom: -90px;
}

.app {
  position: relative;
  z-index: 1;
  width: min(960px, 94vw);
  margin: 24px auto;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--panel);
  backdrop-filter: blur(10px);
  box-shadow: 0 18px 45px rgba(8, 35, 62, 0.12);
  overflow: hidden;
  animation: fadeIn 320ms ease-out;
}

.topbar {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 12px;
  align-items: center;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(90deg, #f4f8ff, #fbfff4);
}

h1 {
  margin: 0;
  letter-spacing: 0.8px;
  font-size: 1.2rem;
}

.top-right {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  min-width: 0;
  gap: 6px;
}

.current-user {
  max-width: min(42vw, 260px);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: #33415c;
  font-size: 0.92rem;
  margin-right: 2px;
}

.menu-wrap {
  position: relative;
}

.menu-btn {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  border: 1px solid #c4d0e6;
  background: #fff;
  color: #24344a;
  font-size: 1.05rem;
  line-height: 1;
  padding: 0;
}

.menu-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  min-width: 132px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px;
  border-radius: 10px;
  border: 1px solid #d5dfef;
  background: #fff;
  box-shadow: 0 12px 28px rgba(14, 33, 53, 0.15);
  z-index: 30;
}

.menu-panel[hidden] {
  display: none !important;
}

.menu-panel a,
.menu-panel button {
  width: 100%;
  height: 32px;
  border-radius: 8px;
  border: 1px solid #d6dfed;
  background: #fff;
  color: #233249;
  font-size: 0.86rem;
  display: flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}

.status-dot {
  width: 11px;
  height: 11px;
  border-radius: 999px;
  display: inline-block;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.92);
  flex: 0 0 auto;
}

.status-online {
  background: #16a34a;
}

.status-offline {
  background: #dc2626;
}

.status-connecting {
  background: #f59e0b;
  animation: statusPulse 1.1s ease-in-out infinite;
}

.status {
  font-size: 0.9rem;
  color: #4f5d75;
}

.messages {
  height: 58vh;
  min-height: 360px;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.message {
  border: 1px solid #dfe7f4;
  background: #ffffff;
  border-radius: 12px;
  padding: 10px;
}

.message .meta {
  font-size: 0.8rem;
  color: #57627c;
  margin-bottom: 6px;
}

.message .text {
  white-space: pre-wrap;
  line-height: 1.5;
}

.message img {
  display: block;
  max-width: min(360px, 78vw);
  border-radius: 10px;
  border: 1px solid #d2d9e6;
  cursor: zoom-in;
}

.composer {
  border-top: 1px solid var(--line);
  padding: 12px 16px;
  background: #fbfdff;
}

.composer-actions,
.composer-row {
  display: flex;
  gap: 10px;
  align-items: center;
}

.composer-actions {
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.tip {
  color: #5b667f;
  font-size: 0.88rem;
}

input,
button {
  border-radius: 10px;
  border: 1px solid #cfd8e8;
  height: 38px;
  padding: 0 12px;
  font-size: 0.95rem;
}

input {
  line-height: 1.2;
  -webkit-appearance: none;
  appearance: none;
}

.composer-row input {
  flex: 1;
  min-width: 0;
}

button {
  cursor: pointer;
  background: #fff;
  transition: transform 120ms ease, border-color 120ms ease;
}

button:hover {
  transform: translateY(-1px);
  border-color: #9eb2d1;
}

#sendBtn,
#saveNicknameBtn,
#uploadBtn,
#recordBtn {
  color: #fff;
  border-color: transparent;
}

#sendBtn,
#saveNicknameBtn {
  background: var(--accent);
}

#logoutBtn {
  height: 34px;
}

#uploadBtn {
  background: var(--accent-2);
}

#recordBtn {
  background: #ef476f;
  min-height: 42px;
  padding: 0 14px;
  touch-action: none;
}

#recordBtn.recording {
  background: #d62839;
}

#recordBtn.canceling {
  background: #7f1d1d;
}

.pending-list {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 10px;
}

.pending-item {
  border: 1px dashed #b8c4dc;
  border-radius: 10px;
  padding: 8px;
  background: #f9fbff;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.pending-item img {
  display: block;
  width: 120px;
  height: 90px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid #d2d9e6;
}

.pending-item audio {
  width: 230px;
}

.pending-item button {
  height: 30px;
  font-size: 0.84rem;
}

.system-msg {
  color: var(--danger);
  font-size: 0.9rem;
}

.image-modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
}

.image-modal[hidden] {
  display: none !important;
}

.image-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(10, 16, 28, 0.78);
}

.image-modal-content {
  position: relative;
  z-index: 1;
  width: min(96vw, 1400px);
  height: min(92vh, 940px);
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: stretch;
}

.image-modal-toolbar {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: flex-end;
  position: relative;
  z-index: 2;
}

.image-modal-btn {
  border: none;
  background: rgba(255, 255, 255, 0.95);
  color: #1d2a3a;
  height: 32px;
  min-width: 42px;
  padding: 0 12px;
}

.image-modal-content img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.35);
  background: #111;
  transform-origin: center center;
  transition: transform 120ms ease;
  cursor: grab;
  user-select: none;
  -webkit-user-drag: none;
}

.image-modal-viewport {
  width: 100%;
  flex: 1;
  min-height: 320px;
  overflow: hidden;
  border-radius: 12px;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #111;
}

.image-modal-viewport.panning img {
  cursor: grabbing;
}

.image-modal-content img {
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 100%;
}

.image-modal-close {
  border: none;
  background: rgba(255, 255, 255, 0.95);
  color: #1d2a3a;
  height: 32px;
  padding: 0 12px;
}

.auth-page,
.admin-page {
  position: relative;
  z-index: 1;
  width: min(960px, 94vw);
  margin: 24px auto;
}

.auth-card,
.admin-card {
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--panel);
  backdrop-filter: blur(10px);
  box-shadow: 0 18px 45px rgba(8, 35, 62, 0.12);
  padding: 16px;
  margin-bottom: 14px;
}

.auth-card {
  width: min(460px, 96vw);
  margin: 10vh auto 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.auth-tip {
  margin: 0;
  color: #4f5d75;
}

.auth-card input,
.admin-card input,
.admin-card select {
  width: 100%;
}

.admin-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.admin-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

.admin-actions a {
  color: #0f8b8d;
  text-decoration: none;
  font-weight: 600;
}

.admin-form-row {
  display: grid;
  grid-template-columns: 1.2fr 1.2fr 1.2fr 0.8fr auto;
  gap: 8px;
  margin-bottom: 10px;
}

.admin-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.admin-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
  border: 1px solid #dfe7f4;
  border-radius: 10px;
  background: #fff;
  padding: 8px;
  word-break: break-all;
}

.admin-row span {
  min-width: 0;
}

.danger-btn {
  background: #c44536;
  color: #fff;
  border-color: transparent;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes statusPulse {
  0% {
    opacity: 0.35;
  }
  50% {
    opacity: 1;
  }
  100% {
    opacity: 0.35;
  }
}

@media (max-width: 900px) {
  .app,
  .auth-page,
  .admin-page {
    width: min(100%, 100vw);
    margin: 0;
    border-radius: 0;
  }

  .app {
    min-height: 100svh;
    min-height: 100dvh;
  }

  .app,
  .auth-card,
  .admin-card {
    box-shadow: none;
    backdrop-filter: none;
  }

  .topbar {
    grid-template-columns: auto 1fr;
    gap: 8px;
    align-items: center;
  }

  .top-right {
    justify-content: flex-end;
    gap: 5px;
  }

  .current-user {
    max-width: min(52vw, 220px);
  }

  .menu-btn {
    width: 32px;
    height: 32px;
  }

  .messages {
    height: auto;
    min-height: 0;
    flex: 1;
    padding: 12px;
  }

  .composer {
    padding: 10px 12px 12px;
    margin-top: auto;
    padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  }

  #recordBtn {
    min-width: 120px;
  }

  .composer-row input {
    height: 40px;
    line-height: 40px;
    font-size: 16px;
  }

  .image-modal-content {
    width: 96vw;
    height: 88vh;
  }

  .image-modal-toolbar {
    flex-wrap: wrap;
    justify-content: flex-end;
  }

  .admin-form-row {
    grid-template-columns: 1fr 1fr;
  }

  .admin-form-row button {
    grid-column: 1 / -1;
  }

  .admin-row {
    flex-wrap: wrap;
    align-items: flex-start;
  }

  .admin-row span {
    flex: 1 1 100%;
  }

  .admin-page {
    padding: 10px;
  }

  .admin-card {
    padding: 12px;
    border-radius: 12px;
  }

  .admin-header {
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 10px;
  }

  .admin-actions {
    width: 100%;
    justify-content: flex-end;
  }
}

@media (max-width: 760px) {
  .topbar {
    grid-template-columns: auto 1fr;
  }

  .admin-form-row {
    grid-template-columns: 1fr;
  }

  .message img {
    max-width: min(100%, 82vw);
  }

  .pending-item {
    width: 100%;
  }

  .pending-item img,
  .pending-item audio {
    width: 100%;
    height: auto;
  }
}

@media (max-width: 640px) {
  .topbar {
    padding: 12px;
  }

  h1 {
    font-size: 1.08rem;
  }

  .top-right {
    gap: 4px;
  }

  .current-user {
    max-width: 42vw;
    font-size: 0.88rem;
    margin-right: 1px;
  }

  .menu-panel {
    min-width: 126px;
    right: -4px;
  }

  .composer-actions {
    gap: 8px;
  }

  #uploadBtn,
  #recordBtn {
    height: 40px;
    font-size: 0.9rem;
  }

  #recordBtn {
    min-width: 128px;
  }

  .composer-row {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }

  #textInput {
    height: 42px;
    line-height: 42px;
    padding: 0 12px;
    font-size: 16px;
  }

  #sendBtn {
    width: 100%;
    height: 40px;
  }

  .image-modal-content {
    width: 100vw;
    height: 100vh;
    border-radius: 0;
  }

  .image-modal-viewport {
    min-height: 240px;
  }

  .admin-header h1 {
    font-size: 1.02rem;
  }

  .admin-actions {
    justify-content: flex-start;
  }

  .admin-actions a,
  .admin-actions button {
    height: 34px;
    font-size: 0.88rem;
  }
}
