* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  -webkit-text-size-adjust: 100%;
  touch-action: manipulation;
}

body {
  font-family: -apple-system, system-ui, 'PingFang SC', 'SF Pro Text',
    'Helvetica Neue', 'Hiragino Sans GB', 'Microsoft YaHei',
    'Noto Sans CJK SC', 'Segoe UI', Roboto, Arial,
    'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  background-image: linear-gradient(0deg, #eee 1px, transparent 0),
    linear-gradient(90deg, #eee 1px, transparent 0);
  background-size: 30px 30px;
  color: #333;
  min-height: 100vh; /* fallback for older engines */
  min-height: 100dvh;
  overflow: hidden;
}

/* 主题变量（可按需微调） */
:root {
  --panel-accent: #0ea5e9;
  --panel-accent-weak: rgba(14, 165, 233, 0.08);
  --panel-accent-weak-2: rgba(14, 165, 233, 0.06);
  --focus-ring: rgba(14, 165, 233, 0.45);
}

body.has-maximized-card {
  overflow: hidden;
}

body.is-mobile {
  overflow-y: auto;
}

#board {
  position: relative;
  width: 100vw;
  height: 100vh; /* fallback */
  height: 100dvh;
  overflow: hidden;
}

body.is-mobile #board {
  height: auto;
  min-height: 100vh; /* fallback */
  min-height: 100dvh;
}

.card {
  position: absolute;
  width: 220px;
  border-radius: 12px;
  box-shadow: 0 16px 35px rgba(0, 0, 0, 0.2);
  background: #fff;
  border: 1px solid rgba(0, 0, 0, 0.08);
  overflow: hidden;
  opacity: 0;
  transform-origin: center;
  transition: transform 0.35s ease, opacity 0.35s ease, left 0.35s ease,
    top 0.35s ease, width 0.35s ease, height 0.35s ease,
    border-radius 0.35s ease;
}

.card.dragging {
  transition: none;
  box-shadow: 0 22px 45px rgba(0, 0, 0, 0.35);
  will-change: transform, left, top;
}

.card.maximized {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  border-radius: 0;
  box-shadow: 0 28px 60px rgba(0, 0, 0, 0.4);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.7);
  cursor: grab;
  user-select: none;
  touch-action: pan-y;
}

.card-header.dragging {
  cursor: grabbing;
}

.window-controls {
  display: flex;
  align-items: center;
  gap: 6px;
}

.window-controls .control {
  position: relative;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 1px solid rgba(0, 0, 0, 0.08);
  background: #ccc;
  cursor: pointer;
  outline: none;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.window-controls .control.close {
  background: #ff5f57;
  border-color: #e0443e;
}

.window-controls .control.minimize {
  background: #febb2e;
  border-color: #dea123;
}

.window-controls .control.maximize {
  background: #28c840;
  border-color: #1aab2c;
}

.window-controls .control::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  opacity: 0;
  transition: opacity 0.2s ease;
}

.card-header:hover .window-controls .control::after {
  opacity: 0.8;
}

.window-controls .control.close::after {
  content: '×';
  width: auto;
  height: auto;
  background: none;
  font-size: 10px;
  line-height: 1;
  font-weight: 700;
  color: rgba(0, 0, 0, 0.7);
}

.window-controls .control.minimize::after {
  width: 6px;
  height: 2px;
  background: rgba(0, 0, 0, 0.6);
}

.window-controls .control.maximize::after {
  width: 6px;
  height: 6px;
  background: linear-gradient(
    45deg,
    rgba(0, 0, 0, 0.6) 0%,
    rgba(0, 0, 0, 0.6) 45%,
    transparent 45%,
    transparent 55%,
    rgba(0, 0, 0, 0.6) 55%,
    rgba(0, 0, 0, 0.6) 100%
  );
}

.card-title {
  font-size: 13px;
  font-weight: 600;
  color: rgba(0, 0, 0, 0.55);
  padding-left: 10px;
  flex: 1;
}

.card-body {
  padding: 16px;
  font-size: 16px;
  line-height: 1.6;
  font-weight: 500;
  letter-spacing: 0.2px;
  color: rgba(0, 0, 0, 0.72);
  word-break: break-word;
  overflow-wrap: anywhere;
  white-space: normal;
}

.card.maximized {
  display: flex;
  flex-direction: column;
}

.card.maximized .card-title {
  display: none;
}

.card.maximized .card-body {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  text-align: center;
  padding: clamp(32px, min(10vw, 10vh), 128px);
  padding-top: clamp(72px, min(14vw, 14vh), 192px);
  font-size: clamp(48px, min(18vw, 18vh), 200px);
  line-height: 1.05;
}

@media (max-width: 768px) {
  .card {
    width: 180px;
    border-radius: 10px;
  }

  .card-body {
    padding: 14px;
    font-size: 14px;
  }

  .card-title {
    font-size: 12px;
  }
}

/* 减少动态效果以照顾 prefers-reduced-motion 用户 */
@media (prefers-reduced-motion: reduce) {
  .card {
    transition: none !important;
  }
}

/* 右下角隐蔽入口（浮动按钮） */
.fab {
  position: fixed;
  right: 16px;
  bottom: calc(16px + env(safe-area-inset-bottom, 0));
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: none;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  font-size: 22px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
  z-index: 1000002; /* 高于卡片全屏层级 */
  opacity: 0.45;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

/* 打开面板时隐藏悬浮按钮，避免遮挡 */
body.panel-open .fab {
  display: none;
}

.fab:focus-visible,
.fab:active {
  outline: none;
  opacity: 0.9;
  transform: scale(0.98);
}

body.is-mobile .fab {
  width: 56px;
  height: 56px;
  font-size: 24px;
}

/* 管理面板与遮罩 */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  -webkit-backdrop-filter: blur(6px) saturate(1.06);
  backdrop-filter: blur(6px) saturate(1.06);
  display: none;
  z-index: 1000001;
}

.overlay.active {
  display: block;
}

#managePanel {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  background: #fff;
  border-radius: 12px 12px 0 0;
  max-height: 85vh;
  height: auto;
  display: flex;
  flex-direction: column;
  transform: translateY(100%);
  transition: transform 0.3s ease;
}

.overlay.active #managePanel {
  transform: translateY(0);
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.06);
  background:
    linear-gradient(180deg, var(--panel-accent-weak), transparent),
    linear-gradient(90deg, var(--panel-accent-weak-2), transparent);
  -webkit-backdrop-filter: saturate(1.06) blur(4px);
  backdrop-filter: saturate(1.06) blur(4px);
}

.panel-header .panel-controls {
  display: inline-flex;
  gap: 8px;
}

.panel-title {
  font-weight: 600;
  font-size: 16px;
  color: rgba(0, 0, 0, 0.75);
  letter-spacing: 0.2px;
  flex: 1 1 auto;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.panel-close {
  border: none;
  background: transparent;
  font-size: 22px;
  line-height: 1;
  color: rgba(0, 0, 0, 0.6);
}

.panel-body {
  padding: 12px 14px 20px 14px;
  padding-bottom: calc(20px + env(safe-area-inset-bottom, 0));
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  flex: 1 1 auto;
  min-height: 0;
}

/* 面板尺寸模式（min/max） */
#managePanel.panel-compact {
  max-height: 56vh;
}

#managePanel.panel-full {
  border-radius: 0;
  height: 100dvh;
  max-height: 100dvh;
}

.panel-desc {
  font-size: 13px;
  color: rgba(0, 0, 0, 0.55);
  margin-bottom: -15px;
  line-height: 1.6;
  letter-spacing: 0.2px;
}

#managePanel .field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 10px;
}

#managePanel .field label {
  font-size: 13px;
  color: rgba(0, 0, 0, 0.62);
}

#managePanel input[type='text'] {
  width: 100%;
  height: 44px; /* iOS 不触发缩放 */
  border: 1px solid rgba(0, 0, 0, 0.1);
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 16px;
}

#managePanel input::placeholder,
#managePanel textarea::placeholder {
  color: rgba(0, 0, 0, 0.38);
}

#managePanel input:focus-visible,
#managePanel textarea:focus-visible {
  outline: none;
  border-color: var(--panel-accent);
  box-shadow: 0 0 0 3px var(--focus-ring);
}

#managePanel .hstack {
  display: flex;
  align-items: center;
  gap: 8px;
}

#managePanel .hstack input {
  flex: 1;
}

.upload-status {
  margin-top: 6px;
  font-size: 12px;
  color: rgba(0, 0, 0, 0.55);
}

#messagesInput {
  width: 100%;
  min-height: 180px;
  border: 1px solid rgba(0, 0, 0, 0.1);
  border-radius: 12px;
  padding: 12px;
  font-size: 16px;
  line-height: 1.6;
  resize: vertical;
}

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

.btn {
  appearance: none;
  border: 1px solid rgba(0, 0, 0, 0.15);
  background: #fff;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 500;
  letter-spacing: 0.2px;
}

.btn.sm {
  padding: 6px 10px;
  font-size: 14px;
}

.btn.primary {
  background: #0ea5e9;
  border-color: #0ea5e9;
  color: #fff;
}

.btn.ghost {
  background: transparent;
}

.btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--focus-ring);
}

.share-row {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 10px;
}

#shareLink {
  flex: 1;
  height: 36px;
  border: 1px solid rgba(0, 0, 0, 0.1);
  border-radius: 8px;
  padding: 0 10px;
  font-size: 14px;
}

.panel-tip {
  margin: 15px 0;
  font-size: 12px;
  color: rgba(0, 0, 0, 0.45);
  line-height: 1.6;
  letter-spacing: 0.2px;
}

.desc-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0;
}

/* 分享图预览 */
.img-preview {
  width: 64px;
  height: 64px;
  border-radius: 8px;
  border: 1px solid rgba(0, 0, 0, 0.1);
  overflow: hidden;
  background: #f3f4f6;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

#shareImgPreview {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* 分享引导遮罩层 */
.guide-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: none;
  z-index: 1000003;
}

.guide-overlay.active {
  display: block;
}

.guide-arrow {
  position: absolute;
  top: 10px;
  right: 18px;
  width: 0;
  height: 0;
  border: 18px solid transparent;
  border-bottom-color: #fff;
  transform: rotate(45deg);
}

.guide-text {
  position: absolute;
  top: 56px;
  right: 20px;
  color: #fff;
  font-size: 16px;
  text-align: right;
  max-width: 70vw;
  line-height: 1.4;
}

.guide-close {
  position: absolute;
  bottom: calc(24px + env(safe-area-inset-bottom, 0));
  left: 50%;
  transform: translateX(-50%);
  padding-left: 18px;
  padding-right: 18px;
}

/* 保存成功弹窗 */
.dialog-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: none;
  z-index: 1000004;
}

.dialog-overlay.active {
  display: flex;
  align-items: center;
  justify-content: center;
}

.dialog {
  width: min(86vw, 340px);
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.25);
  padding: 18px 14px 14px 14px;
}

.dialog-message {
  font-size: 16px;
  color: rgba(0, 0, 0, 0.85);
  text-align: center;
  white-space: pre-line;
  line-height: 1.6;
  font-weight: 500;
  letter-spacing: 0.2px;
  word-break: break-word;
}

.dialog-actions {
  margin-top: 12px;
  display: flex;
  gap: 8px;
  justify-content: center;
}

/* 轻提示（Toast） */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(16px + env(safe-area-inset-bottom, 0));
  transform: translateX(-50%) translateY(16px) scale(0.98);
  background: rgba(0, 0, 0, 0.85);
  color: #fff;
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 14px;
  line-height: 1.2;
  opacity: 0;
  transition: opacity 0.25s ease, transform 0.25s ease;
  z-index: 1000006;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0) scale(1);
}

/* 右上角音乐开关 */
.music-toggle {
  position: fixed;
  top: calc(12px + env(safe-area-inset-top, 0));
  right: 12px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  z-index: 1000000; /* 低于面板/遮罩层，避免遮挡 */
  opacity: 0.8;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.music-toggle .icon {
  display: inline-block;
  font-size: 16px;
  line-height: 1;
}

.music-toggle:active,
.music-toggle:focus-visible {
  outline: none;
  opacity: 1;
  transform: scale(0.98);
}

.music-toggle.playing .icon {
  animation: music-rotate 3.6s linear infinite;
}

.music-toggle.muted { opacity: 0.55; }
.music-toggle.muted::after {
  content: '';
  position: absolute;
  width: 22px;
  height: 2px;
  background: rgba(255, 255, 255, 0.9);
  transform: rotate(45deg);
}

@keyframes music-rotate {
  to { transform: rotate(360deg); }
}
