:root {
  --bg: #f2f2f7;
  --card: #ffffff;
  --text: #1c1c1e;
  --text-2: #8e8e93;
  --sep: rgba(60, 60, 67, 0.12);
  --blue: #007aff;
  --green: #34c759;
  --pink: #ff2d55;
  --orange: #ff9500;
  --koi: #ff6b6b;
  --tab-h: 64px;
  --radius: 18px;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  overscroll-behavior: none;
}

.app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  position: relative;
  background: var(--bg);
}

/* ===== 顶部导航 ===== */
.nav-bar {
  position: sticky;
  top: 0;
  z-index: 20;
  padding: calc(env(safe-area-inset-top) + 14px) 20px 12px;
  background: rgba(242, 242, 247, 0.82);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 0.5px solid var(--sep);
}

.nav-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.5px;
}

.nav-emoji {
  font-size: 26px;
}

.nav-subtitle {
  margin-top: 2px;
  font-size: 13px;
  color: var(--text-2);
}

.sync-pill {
  position: absolute;
  top: calc(env(safe-area-inset-top) + 16px);
  right: 20px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  padding: 5px 11px;
  border-radius: 20px;
  background: rgba(52, 199, 89, 0.14);
  color: #1f8a3d;
}

.sync-pill.off {
  background: rgba(142, 142, 147, 0.16);
  color: var(--text-2);
}

.sync-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--green);
}

.sync-pill.off .sync-dot {
  background: var(--text-2);
}

/* 同步提示气泡 */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tab-h) + env(safe-area-inset-bottom) + 20px);
  transform: translateX(-50%) translateY(10px);
  z-index: 50;
  max-width: 86%;
  background: rgba(28, 28, 30, 0.92);
  color: #fff;
  font-size: 14px;
  padding: 11px 18px;
  border-radius: 22px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s, transform 0.22s;
  text-align: center;
}

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

/* ===== 内容区 ===== */
.content {
  padding: 16px 16px calc(var(--tab-h) + env(safe-area-inset-bottom) + 24px);
}

.page {
  display: flex;
  flex-direction: column;
  gap: 16px;
  animation: fade 0.28s ease;
}

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

.hidden {
  display: none !important;
}

/* ===== 卡片 ===== */
.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.card-title {
  font-size: 18px;
  font-weight: 700;
}

/* ===== 工具入口列表 ===== */
.tool-entries {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.entry {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  text-align: left;
  border: none;
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
  transition: transform 0.08s ease, background 0.15s;
}

.entry:active {
  transform: scale(0.985);
  background: rgba(0, 0, 0, 0.02);
}

.entry-icon {
  flex: 0 0 auto;
  width: 50px;
  height: 50px;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 26px;
}

.entry-icon-vote {
  background: rgba(0, 122, 255, 0.12);
}

.entry-icon-draw {
  background: rgba(255, 45, 85, 0.12);
}

.entry-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.entry-title {
  font-size: 17px;
  font-weight: 700;
}

.entry-desc {
  font-size: 13px;
  color: var(--text-2);
}

.entry-arrow {
  flex: 0 0 auto;
  font-size: 24px;
  color: var(--text-2);
  opacity: 0.55;
}

.back-btn {
  border: none;
  background: none;
  color: var(--blue);
  font-size: 16px;
  font-weight: 500;
  padding: 0 0 12px;
  margin: 0;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
}

.back-btn:active {
  opacity: 0.6;
}

/* ===== 按钮 ===== */
.primary-btn {
  width: 100%;
  border: none;
  background: var(--blue);
  color: #fff;
  font-size: 17px;
  font-weight: 600;
  padding: 13px;
  border-radius: 14px;
  cursor: pointer;
  transition: transform 0.08s ease, opacity 0.15s;
}

.primary-btn:active {
  transform: scale(0.97);
  opacity: 0.85;
}

.btn-row {
  display: flex;
  gap: 10px;
}

.btn-row .primary-btn {
  flex: 1;
}

.secondary-btn {
  flex: 1;
  border: none;
  background: rgba(0, 122, 255, 0.12);
  color: var(--blue);
  font-size: 15px;
  font-weight: 600;
  padding: 13px 10px;
  border-radius: 14px;
  cursor: pointer;
  transition: transform 0.08s ease, opacity 0.15s;
}

.secondary-btn:active {
  transform: scale(0.97);
  opacity: 0.8;
}

/* 未连接群聊时隐藏纯同步按钮 */
.sync-only {
  display: none;
}

body.sync-on .sync-only {
  display: block;
}

.ghost-btn {
  border: none;
  background: rgba(0, 122, 255, 0.1);
  color: var(--blue);
  font-size: 14px;
  font-weight: 600;
  padding: 7px 13px;
  border-radius: 20px;
  cursor: pointer;
}

.ghost-btn:active {
  background: rgba(0, 122, 255, 0.2);
}

.link-btn {
  border: none;
  background: none;
  color: var(--blue);
  font-size: 14px;
  cursor: pointer;
  padding: 4px;
}

.add-option-btn {
  width: 100%;
  border: 1px dashed var(--sep);
  background: none;
  color: var(--text-2);
  font-size: 15px;
  padding: 11px;
  border-radius: 12px;
  cursor: pointer;
  margin-bottom: 12px;
}

.add-option-btn:active {
  background: rgba(0, 0, 0, 0.03);
}

/* ===== 输入框 ===== */
.ios-input {
  width: 100%;
  border: none;
  background: #f2f2f7;
  border-radius: 12px;
  padding: 13px 14px;
  font-size: 16px;
  color: var(--text);
  outline: none;
  margin-bottom: 12px;
}

.ios-input::placeholder {
  color: var(--text-2);
}

/* ===== 投票 ===== */
.vote-options {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 12px;
}

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

.vote-option-row .ios-input {
  margin: 0;
}

.option-del {
  border: none;
  background: rgba(255, 45, 85, 0.12);
  color: var(--pink);
  width: 34px;
  height: 34px;
  border-radius: 50%;
  font-size: 18px;
  cursor: pointer;
  flex: 0 0 auto;
}

.vote-live-question {
  font-size: 17px;
  font-weight: 700;
  margin-bottom: 14px;
}

.vote-live-options {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.vote-bar {
  position: relative;
  background: #f2f2f7;
  border-radius: 12px;
  padding: 12px 14px;
  cursor: pointer;
  overflow: hidden;
  border: 1.5px solid transparent;
  transition: border-color 0.15s;
}

.vote-bar:active {
  border-color: var(--blue);
}

.vote-bar.voted {
  border-color: var(--blue);
}

.vote-bar-fill {
  position: absolute;
  inset: 0 auto 0 0;
  background: rgba(0, 122, 255, 0.16);
  width: 0;
  transition: width 0.5s cubic-bezier(0.22, 1, 0.36, 1);
}

.vote-bar-row {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 16px;
}

.vote-bar-label {
  font-weight: 500;
}

.vote-bar-pct {
  font-variant-numeric: tabular-nums;
  color: var(--text-2);
  font-size: 14px;
}

.vote-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 14px;
  font-size: 14px;
  color: var(--text-2);
}

/* ===== 你画我猜 ===== */
.riddle {
  background: linear-gradient(135deg, #fff5f5, #fff0f6);
  border-radius: 14px;
  padding: 14px;
  margin-bottom: 14px;
}

.riddle-tags {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}

.tag {
  font-size: 12px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 20px;
}

.tag-cat {
  background: rgba(255, 149, 0, 0.16);
  color: #c2670a;
}

.tag-diff {
  background: rgba(52, 199, 89, 0.16);
  color: #1f8a3d;
}

.riddle-word {
  width: 100%;
  border: none;
  background: #fff;
  border-radius: 12px;
  padding: 16px;
  min-height: 60px;
  font-size: 24px;
  font-weight: 800;
  letter-spacing: 2px;
  color: var(--koi);
  cursor: pointer;
  text-align: center;
}

.riddle-word .riddle-hint {
  font-size: 14px;
  font-weight: 500;
  letter-spacing: 0;
  color: var(--text-2);
}

.canvas-wrap {
  border-radius: 14px;
  overflow: hidden;
  background: #fff;
  border: 1px solid var(--sep);
  margin-bottom: 12px;
}

#drawCanvas {
  display: block;
  width: 100%;
  height: auto;
  touch-action: none;
  cursor: crosshair;
  background: #fff;
}

.draw-tools {
  margin-bottom: 14px;
}

.color-row {
  display: flex;
  gap: 10px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.color-dot {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid #fff;
  box-shadow: 0 0 0 1px var(--sep);
  transition: transform 0.1s;
}

.color-dot.active {
  transform: scale(1.18);
  box-shadow: 0 0 0 2px var(--blue);
}

.tool-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.size-control {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-2);
  flex: 1;
  min-width: 130px;
}

.size-control input[type="range"] {
  flex: 1;
  accent-color: var(--blue);
}

.tool-btn {
  border: none;
  background: #f2f2f7;
  color: var(--text);
  font-size: 14px;
  padding: 8px 12px;
  border-radius: 12px;
  cursor: pointer;
}

.tool-btn.active {
  background: rgba(0, 122, 255, 0.14);
  color: var(--blue);
}

.tool-btn:active {
  opacity: 0.7;
}

/* ===== 统计 ===== */
.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.stat-box {
  background: var(--card);
  border-radius: var(--radius);
  padding: 18px 16px;
  text-align: center;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

.stat-num {
  font-size: 34px;
  font-weight: 800;
  letter-spacing: -1px;
  font-variant-numeric: tabular-nums;
}

.stat-label {
  font-size: 13px;
  color: var(--text-2);
  margin-top: 2px;
}

.meter {
  height: 12px;
  background: #f2f2f7;
  border-radius: 8px;
  overflow: hidden;
}

.meter-fill {
  height: 100%;
  width: 0;
  border-radius: 8px;
  background: linear-gradient(90deg, var(--green), var(--blue));
  transition: width 0.6s cubic-bezier(0.22, 1, 0.36, 1);
}

.meter-text {
  margin-top: 10px;
  font-size: 14px;
  color: var(--text-2);
}

.log-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.log-list li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 0;
  border-bottom: 0.5px solid var(--sep);
  font-size: 15px;
}

.log-list li:last-child {
  border-bottom: none;
}

.log-empty {
  color: var(--text-2);
  justify-content: center;
}

.log-time {
  margin-left: auto;
  font-size: 12px;
  color: var(--text-2);
  font-variant-numeric: tabular-nums;
}

/* ===== iOS 底部标签栏 ===== */
.tab-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  max-width: 480px;
  margin: 0 auto;
  height: calc(var(--tab-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  display: flex;
  background: rgba(248, 248, 248, 0.86);
  backdrop-filter: saturate(180%) blur(22px);
  -webkit-backdrop-filter: saturate(180%) blur(22px);
  border-top: 0.5px solid var(--sep);
}

.tab-item {
  flex: 1;
  border: none;
  background: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  cursor: pointer;
  color: var(--text-2);
  padding-top: 8px;
  transition: color 0.15s;
}

.tab-item .tab-icon {
  font-size: 22px;
  filter: grayscale(0.6) opacity(0.7);
  transition: filter 0.15s, transform 0.12s;
}

.tab-item .tab-text {
  font-size: 11px;
  font-weight: 500;
}

.tab-item.active {
  color: var(--blue);
}

.tab-item.active .tab-icon {
  filter: none;
  transform: translateY(-1px);
}

.tab-item:active .tab-icon {
  transform: scale(0.9);
}

/* 暗色模式 */
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --card: #1c1c1e;
    --text: #ffffff;
    --text-2: #98989f;
    --sep: rgba(84, 84, 88, 0.4);
  }
  .nav-bar {
    background: rgba(0, 0, 0, 0.7);
  }
  .ios-input,
  .vote-bar,
  .tool-btn,
  .meter,
  .stat-box .stat-num {
    background: #2c2c2e;
  }
  .stat-box .stat-num {
    background: none;
  }
  .ios-input {
    background: #2c2c2e;
  }
  .vote-bar {
    background: #2c2c2e;
  }
  .riddle {
    background: linear-gradient(135deg, #2a1f22, #2a1f28);
  }
  .riddle-word {
    background: #2c2c2e;
  }
  .tool-btn {
    background: #2c2c2e;
  }
  .meter {
    background: #2c2c2e;
  }
  .tab-bar {
    background: rgba(22, 22, 22, 0.86);
  }
}
