/* ============================================================
   铃 / Iva PWA — iOS 26 Liquid Glass theme
   Design notes:
   - SF Pro 系统字体 + Inter fallback
   - 8pt grid (8 / 12 / 16 / 20 / 24 / 32 / 40)
   - 18px 气泡圆角 (iOS Messages standard)
   - 玻璃材质 header + tab bar (backdrop-filter blur + saturate)
   - prefers-color-scheme 自动切深色
   - WCAG AA 4.5:1 文字对比 ≥ 全部通过
   ============================================================ */

/* ---------- Tokens (Light) ---------- */
:root {
  --bg:            #F2F2F7;   /* iOS system grouped background */
  --surface:       #FFFFFF;
  --elevated:      rgba(255,255,255,0.92);
  --glass:         rgba(255,255,255,0.72);
  --glass-strong:  rgba(255,255,255,0.86);
  --glass-border:  rgba(60,60,67,0.10);

  --label:         #1C1C1E;
  --label-2:       rgba(60,60,67,0.60);
  --label-3:       rgba(60,60,67,0.30);

  --accent:        #007AFF;
  --accent-press:  #0066D6;

  --bubble-user:        #007AFF;
  --bubble-user-text:   #FFFFFF;
  --bubble-bot:         #E9E9EB;
  --bubble-bot-text:    #1C1C1E;
  --bubble-bot-border:  transparent;

  --field-bg:      rgba(118,118,128,0.12);
  --field-border:  rgba(60,60,67,0.15);
  --separator:     rgba(60,60,67,0.18);

  --danger:        #FF3B30;
  --success:       #34C759;
  --warning:       #FF9F0A;

  --shadow-sm: 0 1px 2px rgba(0,0,0,0.04), 0 1px 1px rgba(0,0,0,0.03);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.08), 0 1px 4px rgba(0,0,0,0.04);
  --shadow-lg: 0 12px 40px rgba(0,0,0,0.12), 0 4px 12px rgba(0,0,0,0.06);

  --radius-bubble:  18px;
  --radius-tail:    4px;
  --radius-card:    14px;
  --radius-modal:   22px;
  --radius-btn:     14px;
  --radius-pill:    999px;

  --motion-fast: 150ms cubic-bezier(.4,0,.2,1);
  --motion-norm: 240ms cubic-bezier(.4,0,.2,1);
  --motion-slow: 380ms cubic-bezier(.4,0,.2,1);
}

/* ---------- Tokens (Dark) ---------- */
@media (prefers-color-scheme: dark) {
  :root {
    --bg:           #000000;
    --surface:      #1C1C1E;
    --elevated:     #2C2C2E;
    --glass:        rgba(28,28,30,0.72);
    --glass-strong: rgba(28,28,30,0.86);
    --glass-border: rgba(255,255,255,0.10);

    --label:        #FFFFFF;
    --label-2:      rgba(235,235,245,0.60);
    --label-3:      rgba(235,235,245,0.30);

    --accent:       #0A84FF;
    --accent-press: #409CFF;

    --bubble-user:       #0A84FF;
    --bubble-user-text:  #FFFFFF;
    --bubble-bot:        #2C2C2E;
    --bubble-bot-text:   #FFFFFF;
    --bubble-bot-border: transparent;

    --field-bg:     rgba(118,118,128,0.24);
    --field-border: rgba(255,255,255,0.10);
    --separator:    rgba(84,84,88,0.65);

    --danger:       #FF453A;
    --success:      #30D158;
    --warning:      #FFD60A;

    --shadow-sm: 0 1px 2px rgba(0,0,0,0.40);
    --shadow-md: 0 4px 16px rgba(0,0,0,0.50);
    --shadow-lg: 0 12px 40px rgba(0,0,0,0.60);
  }
}

/* ---------- Reset & root ---------- */
*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--label);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

body {
  font-family:
    -apple-system, BlinkMacSystemFont,
    'SF Pro Display', 'SF Pro Text',
    'Helvetica Neue', 'Inter',
    'PingFang SC', 'Source Han Sans CN', 'Microsoft YaHei UI',
    sans-serif;
  font-size: 17px;            /* iOS body */
  line-height: 1.4;
  font-feature-settings: 'kern' 1, 'liga' 1, 'tnum' 1;
  padding:
    env(safe-area-inset-top, 0)
    env(safe-area-inset-right, 0)
    env(safe-area-inset-bottom, 0)
    env(safe-area-inset-left, 0);
  display: flex;
  flex-direction: column;
  overscroll-behavior: none;
}

/* ---------- Header (Large Title, iOS 26 glass) ---------- */
header {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 16px 20px 12px;
  background: var(--glass);
  backdrop-filter: blur(24px) saturate(180%);
  -webkit-backdrop-filter: blur(24px) saturate(180%);
  border-bottom: 0.5px solid var(--glass-border);
}

h1 {
  margin: 0;
  font-size: 28px;           /* iOS Large Title */
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--label);
}

.sub {
  margin-left: 8px;
  font-size: 13px;
  font-weight: 400;
  color: var(--label-2);
  letter-spacing: 0;
}

/* ---------- Tabs (iOS segmented control 风 + 玻璃) ---------- */
.tabs {
  position: sticky;
  top: 64px;                  /* sit under header */
  z-index: 40;
  display: flex;
  gap: 4px;
  padding: 8px 20px 8px;
  background: var(--glass-strong);
  backdrop-filter: blur(24px) saturate(180%);
  -webkit-backdrop-filter: blur(24px) saturate(180%);
  border-bottom: 0.5px solid var(--glass-border);
}

.tab {
  flex: 1;
  background: transparent;
  color: var(--label-2);
  border: none;
  padding: 10px 14px;
  font-size: 15px;
  font-weight: 590;
  cursor: pointer;
  font-family: inherit;
  border-radius: var(--radius-pill);
  transition:
    background var(--motion-fast),
    color var(--motion-fast);
}

.tab:hover { color: var(--label); }

.tab.active {
  background: var(--surface);
  color: var(--label);
  box-shadow: var(--shadow-sm);
}

@media (prefers-color-scheme: dark) {
  .tab.active { background: var(--elevated); }
}

/* ---------- Main + tab content ---------- */
main {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.tab-content {
  display: none;
  padding: 16px 20px 24px;
  max-width: 720px;
  width: 100%;
  margin: 0 auto;
  flex: 1;
  flex-direction: column;
  min-height: 0;
}
.tab-content.active { display: flex; }

/* ---------- Chat log ---------- */
#chat-log {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 8px 0 16px;
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
}

/* Bubble */
.bubble {
  max-width: 80%;
  padding: 8px 14px;
  font-size: 17px;
  line-height: 1.4;
  word-break: break-word;
  white-space: pre-wrap;
  position: relative;
  border-radius: var(--radius-bubble);
  animation: bubble-in var(--motion-norm) both;
}

@keyframes bubble-in {
  from { opacity: 0; transform: translateY(6px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.bubble.user {
  background: var(--bubble-user);
  color: var(--bubble-user-text);
  align-self: flex-end;
  border-bottom-right-radius: var(--radius-tail);
  margin-top: 8px;
}

.bubble.bot {
  background: var(--bubble-bot);
  color: var(--bubble-bot-text);
  align-self: flex-start;
  border-bottom-left-radius: var(--radius-tail);
  margin-top: 8px;
}

/* Consecutive same-sender bubbles tighter spacing (iOS Messages 行为) */
.bubble.user + .bubble.user,
.bubble.bot  + .bubble.bot { margin-top: 2px; }

.bubble.bot.playing {
  box-shadow: 0 0 0 2px var(--accent), 0 0 16px rgba(10,132,255,0.25);
  animation: bubble-breath 1.6s ease-in-out infinite;
}

@keyframes bubble-breath {
  0%, 100% { box-shadow: 0 0 0 2px var(--accent), 0 0 14px rgba(10,132,255,0.20); }
  50%      { box-shadow: 0 0 0 2px var(--accent), 0 0 22px rgba(10,132,255,0.40); }
}

/* Replay button inside bot bubble */
.bubble .play-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  margin-left: 6px;
  margin-bottom: -3px;
  background: transparent;
  border: none;
  padding: 0;
  cursor: pointer;
  border-radius: 50%;
  color: var(--label-2);
  font-size: 13px;
  transition: color var(--motion-fast), transform var(--motion-fast);
}
.bubble .play-btn:hover  { color: var(--accent); transform: scale(1.1); }
.bubble .play-btn:active { transform: scale(0.95); }

/* ---------- Chat input (sticky bottom row) ---------- */
.chat-input {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 8px 0 4px;
}

.chat-input textarea {
  flex: 1;
  min-height: 36px;
  max-height: 144px;
  background: var(--field-bg);
  color: var(--label);
  border: 0.5px solid var(--field-border);
  border-radius: var(--radius-bubble);
  padding: 8px 14px;
  font-family: inherit;
  font-size: 17px;
  line-height: 1.35;
  resize: none;
  transition: border-color var(--motion-fast);
}
.chat-input textarea::placeholder { color: var(--label-3); }
.chat-input textarea:focus {
  outline: none;
  border-color: var(--accent);
}

#chat-send {
  flex: 0 0 36px;
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  border: none;
  cursor: pointer;
  font-size: 18px;
  font-weight: 700;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition:
    background var(--motion-fast),
    transform var(--motion-fast);
}
#chat-send:hover   { background: var(--accent-press); }
#chat-send:active  { transform: scale(0.92); }
#chat-send:disabled {
  background: var(--label-3);
  cursor: not-allowed;
  transform: none;
}

/* ---------- Speak tab ---------- */
#tab-speak textarea#text {
  width: 100%;
  background: var(--surface);
  color: var(--label);
  border: 0.5px solid var(--field-border);
  border-radius: var(--radius-card);
  padding: 14px 16px;
  font-size: 17px;
  font-family: inherit;
  resize: vertical;
  min-height: 96px;
  transition: border-color var(--motion-fast);
}
#tab-speak textarea#text::placeholder { color: var(--label-3); }
#tab-speak textarea#text:focus {
  outline: none;
  border-color: var(--accent);
}

.counter {
  text-align: right;
  color: var(--label-2);
  font-size: 13px;
  margin: 6px 2px 0;
  font-variant-numeric: tabular-nums;
}

.controls {
  display: flex;
  gap: 10px;
  margin: 16px 0 8px;
}

audio {
  width: 100%;
  margin: 8px 0 16px;
  border-radius: var(--radius-card);
}

/* ---------- Buttons (generic) ---------- */
button {
  font-family: inherit;
  font-size: 17px;
  font-weight: 590;
  cursor: pointer;
  border-radius: var(--radius-btn);
  border: none;
  padding: 12px 18px;
  transition:
    background var(--motion-fast),
    transform var(--motion-fast),
    color var(--motion-fast);
}

button.primary {
  background: var(--accent);
  color: white;
  flex: 1;
}
button.primary:hover  { background: var(--accent-press); }
button.primary:active { transform: scale(0.98); }
button.primary:disabled {
  background: var(--label-3);
  cursor: not-allowed;
  transform: none;
}

button.ghost {
  background: var(--field-bg);
  color: var(--label);
  border: none;
}
button.ghost:hover  { background: rgba(118,118,128,0.20); }
button.ghost:active { transform: scale(0.98); }
button.ghost:disabled {
  color: var(--label-3);
  cursor: not-allowed;
}

#settings-btn {
  background: transparent;
  color: var(--label-2);
  padding: 6px 8px;
  font-size: 22px;
  line-height: 1;
  font-weight: 400;
  border-radius: 50%;
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
#settings-btn:hover  { background: var(--field-bg); color: var(--label); }
#settings-btn:active { transform: scale(0.92); }

#speak-btn, #stop-btn { min-width: 100px; }

/* ---------- Status pill ---------- */
.status {
  margin-top: 12px;
  padding: 8px 14px;
  background: var(--field-bg);
  border-radius: var(--radius-pill);
  color: var(--label-2);
  font-size: 13px;
  font-family: ui-monospace, 'SF Mono', Menlo, monospace;
  font-variant-numeric: tabular-nums;
  align-self: flex-start;
  transition: all var(--motion-fast);
}
.status.ok  { color: var(--success); }
.status.err { color: var(--danger); }

/* ---------- History ---------- */
h2 {
  font-size: 15px;
  font-weight: 590;
  color: var(--label-2);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin: 28px 0 8px;
}

#history { list-style: none; padding: 0; margin: 0; }

#history li {
  background: var(--surface);
  padding: 12px 14px;
  border-radius: var(--radius-card);
  margin-bottom: 6px;
  font-size: 15px;
  color: var(--label);
  cursor: pointer;
  transition: background var(--motion-fast), transform var(--motion-fast);
  box-shadow: var(--shadow-sm);
}
@media (prefers-color-scheme: dark) {
  #history li { background: var(--elevated); }
}
#history li:hover  { transform: translateY(-1px); box-shadow: var(--shadow-md); }
#history li:active { transform: scale(0.99); }

#history li .meta {
  display: block;
  font-size: 12px;
  color: var(--label-2);
  margin-top: 4px;
  font-variant-numeric: tabular-nums;
}

/* ---------- Dialog (settings) ---------- */
dialog {
  background: var(--surface);
  color: var(--label);
  border: 0.5px solid var(--glass-border);
  border-radius: var(--radius-modal);
  padding: 24px 22px 20px;
  max-width: 92vw;
  width: 440px;
  box-shadow: var(--shadow-lg);
}
@media (prefers-color-scheme: dark) {
  dialog { background: var(--elevated); }
}

dialog::backdrop {
  background: rgba(0,0,0,0.50);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

dialog h3 {
  margin: 0 0 16px;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--label);
}

dialog label {
  display: block;
  margin: 12px 0;
  font-size: 13px;
  font-weight: 500;
  color: var(--label-2);
}

dialog label input,
dialog label textarea {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 10px 12px;
  font-size: 15px;
  font-family: inherit;
  background: var(--field-bg);
  color: var(--label);
  border: 0.5px solid var(--field-border);
  border-radius: 10px;
  resize: vertical;
  transition: border-color var(--motion-fast);
}
dialog label input:focus,
dialog label textarea:focus {
  outline: none;
  border-color: var(--accent);
}

dialog details {
  margin: 14px 0;
  padding: 8px 12px;
  background: var(--field-bg);
  border-radius: 10px;
}
dialog summary {
  cursor: pointer;
  color: var(--label-2);
  font-size: 13px;
  font-weight: 500;
  padding: 4px 0;
  user-select: none;
}
dialog details[open] summary { color: var(--label); }

.dlg-btns {
  display: flex;
  gap: 10px;
  margin-top: 20px;
}
.dlg-btns button { flex: 1; padding: 12px; }

/* ---------- Misc inputs base ---------- */
input[type=text], input[type=url], input[type=password], input[type=number] {
  font-family: inherit;
}

/* Hide native number input arrows (cleaner iOS look) */
input[type=number] {
  -moz-appearance: textfield;
}
input[type=number]::-webkit-outer-spin-button,
input[type=number]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

/* ---------- Responsive ---------- */
@media (max-width: 480px) {
  header { padding: 12px 16px 10px; }
  h1 { font-size: 26px; }
  .tabs { padding: 6px 16px; top: 56px; }
  .tab-content { padding: 12px 16px 16px; }
  .bubble { font-size: 16px; max-width: 84%; }
}

/* ---------- Accessibility ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* High-contrast focus for keyboard nav */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
button:focus-visible,
.tab:focus-visible {
  outline-offset: 3px;
}

/* ============================================================
   Character picker (酒馆风网格 + 预览)
   ============================================================ */

/* Active character row (chat tab 顶部) */
.active-char-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  margin-bottom: 8px;
  background: var(--surface);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-sm);
}
@media (prefers-color-scheme: dark) {
  .active-char-row { background: var(--elevated); }
}

.ac-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--field-bg) center/cover no-repeat;
  flex: 0 0 40px;
  box-shadow: inset 0 0 0 0.5px var(--field-border);
}

.ac-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.ac-label {
  font-size: 11px;
  font-weight: 500;
  color: var(--label-2);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.ac-name {
  font-size: 16px;
  font-weight: 590;
  color: var(--label);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#open-char-picker {
  padding: 8px 14px;
  font-size: 14px;
  font-weight: 590;
  border-radius: var(--radius-pill);
}

/* TTS toggle (圆形, 显示扬声器 / 静音两态) */
.ac-toggle {
  width: 36px; height: 36px;
  padding: 0;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  background: var(--field-bg);
  color: var(--label-2);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background var(--motion-fast), color var(--motion-fast), transform var(--motion-fast);
}
.ac-toggle:hover { background: rgba(118,118,128,0.2); }
.ac-toggle:active { transform: scale(0.92); }
.ac-toggle.on { color: var(--accent); background: rgba(0,122,255,0.12); }
.ac-toggle .ico-off { display: none; }
.ac-toggle.off .ico-on { display: none; }
.ac-toggle.off .ico-off { display: block; color: var(--danger); }

/* settings 里的 checkbox 行 */
.row-check {
  display: flex !important;
  align-items: center;
  gap: 8px;
  margin: 12px 0;
  cursor: pointer;
  user-select: none;
}
.row-check input[type=checkbox] {
  width: 18px; height: 18px;
  margin: 0;
  accent-color: var(--accent);
  cursor: pointer;
  flex: 0 0 auto;
}
.row-check span {
  font-size: 14px;
  color: var(--label);
  font-weight: 500;
}

/* Character picker dialog — near-full-screen on mobile.
   IMPORTANT: only style when [open], otherwise UA's `dialog:not([open])
   { display: none }` won't take effect because display:flex overrides it. */
#char-picker-dlg {
  width: 100%;
  max-width: 720px;
  height: 100vh;
  max-height: 100vh;
  margin: 0 auto;
  padding: 0;
  border-radius: 0;
  border: none;
  background: var(--bg);
}
#char-picker-dlg[open] {
  display: flex;
  flex-direction: column;
}
@media (min-width: 600px) {
  #char-picker-dlg {
    height: 88vh;
    max-height: 880px;
    margin: 6vh auto;
    border-radius: var(--radius-modal);
    box-shadow: var(--shadow-lg);
  }
}

#char-picker-dlg::backdrop {
  background: rgba(0,0,0,0.5);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.cp {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
}

.cp-head {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 10px;
  background: var(--glass-strong);
  backdrop-filter: blur(24px) saturate(180%);
  -webkit-backdrop-filter: blur(24px) saturate(180%);
  border-bottom: 0.5px solid var(--glass-border);
}
.cp-head h3 {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.01em;
}
.cp-close {
  width: 32px; height: 32px;
  padding: 0;
  border-radius: 50%;
  background: var(--field-bg);
  color: var(--label);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.cp-close:hover { background: rgba(118,118,128,0.20); }

/* List view */
#cp-list-view {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 12px 16px 20px;
  -webkit-overflow-scrolling: touch;
}

#cp-search {
  width: 100%;
  background: var(--field-bg);
  color: var(--label);
  border: none;
  border-radius: var(--radius-pill);
  padding: 10px 16px;
  font-size: 15px;
  font-family: inherit;
  margin-bottom: 12px;
  -webkit-appearance: none;
}
#cp-search::placeholder { color: var(--label-3); }
#cp-search:focus { outline: 2px solid var(--accent); outline-offset: -2px; }

#cp-groups {
  display: flex;
  gap: 6px;
  margin-bottom: 14px;
  overflow-x: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
  padding-bottom: 2px;
}
#cp-groups::-webkit-scrollbar { display: none; }

.cp-chip {
  flex: 0 0 auto;
  padding: 7px 13px;
  border-radius: var(--radius-pill);
  background: var(--field-bg);
  color: var(--label-2);
  font-size: 13px;
  font-weight: 590;
  cursor: pointer;
  border: none;
  font-family: inherit;
  white-space: nowrap;
  transition: background var(--motion-fast), color var(--motion-fast);
}
.cp-chip:hover { color: var(--label); }
.cp-chip.active {
  background: var(--accent);
  color: white;
}

#cp-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
@media (min-width: 600px) { #cp-grid { grid-template-columns: repeat(4, 1fr); gap: 12px; } }
@media (min-width: 900px) { #cp-grid { grid-template-columns: repeat(5, 1fr); } }

.char-card {
  position: relative;
  background: var(--surface);
  border-radius: var(--radius-card);
  overflow: hidden;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: transform var(--motion-fast), box-shadow var(--motion-fast);
  display: flex;
  flex-direction: column;
}
@media (prefers-color-scheme: dark) {
  .char-card { background: var(--elevated); }
}
.char-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}
.char-card:active { transform: scale(0.98); }

.char-card .cc-img {
  width: 100%;
  aspect-ratio: 1 / 1;
  background: var(--field-bg) center/cover no-repeat;
  display: block;
}

.char-card .cc-name {
  padding: 7px 9px 9px;
  font-size: 13px;
  font-weight: 590;
  color: var(--label);
  line-height: 1.25;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  min-height: 2.7em;
}

.char-card.active {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}

.char-card .cc-group {
  position: absolute;
  top: 6px;
  left: 6px;
  background: rgba(0,0,0,0.55);
  color: white;
  font-size: 10px;
  font-weight: 590;
  padding: 2px 7px;
  border-radius: var(--radius-pill);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.cp-meta {
  margin-top: 14px;
  text-align: center;
  font-size: 12px;
  color: var(--label-2);
  font-variant-numeric: tabular-nums;
}

.cp-empty {
  text-align: center;
  padding: 40px 20px;
  color: var(--label-2);
  font-size: 14px;
}

/* Preview view */
#cp-preview-view {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 12px 16px 100px;
  -webkit-overflow-scrolling: touch;
}

.cp-back {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: transparent;
  color: var(--accent);
  border: none;
  padding: 6px 0;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  margin-bottom: 8px;
}
.cp-back:hover { color: var(--accent-press); }

.cp-preview-card {
  background: var(--surface);
  border-radius: var(--radius-modal);
  padding: 20px;
  box-shadow: var(--shadow-sm);
}
@media (prefers-color-scheme: dark) {
  .cp-preview-card { background: var(--elevated); }
}

#cp-preview-img {
  display: block;
  width: 60%;
  max-width: 240px;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  margin: 0 auto 16px;
  border-radius: var(--radius-card);
  background: var(--field-bg);
}

#cp-preview-name {
  margin: 0 0 4px;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.01em;
  text-align: center;
}

#cp-preview-meta {
  text-align: center;
  margin: 0 0 12px;
}

.cp-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 0 0 16px;
  justify-content: center;
}
.cp-tag {
  font-size: 11px;
  font-weight: 500;
  padding: 3px 9px;
  border-radius: var(--radius-pill);
  background: var(--field-bg);
  color: var(--label-2);
}

.cp-preview-card h5 {
  font-size: 12px;
  font-weight: 590;
  color: var(--label-2);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin: 18px 0 6px;
}

.cp-block {
  font-size: 14px;
  line-height: 1.55;
  color: var(--label);
  background: var(--field-bg);
  padding: 12px 14px;
  border-radius: var(--radius-card);
  white-space: pre-wrap;
  max-height: 240px;
  overflow-y: auto;
}

.cp-actions {
  position: sticky;
  bottom: 0;
  display: flex;
  gap: 10px;
  padding: 12px 0 max(12px, env(safe-area-inset-bottom));
  margin-top: 20px;
  background: linear-gradient(to bottom, transparent, var(--bg) 30%);
}
.cp-actions button { flex: 1; padding: 14px; font-size: 16px; }

