/* Card studio — the sheet that previews and exports a card.
   Mobile first: a bottom sheet, card on top, controls under the thumb, every
   target ≥44px. From 640px up the same sheet centres as a dialog. */

body.cs-open { overflow: hidden; }

.cs-ov {
  position: fixed;
  inset: 0;
  z-index: 1200;          /* above the pinyin FAB + feedback widget (z:900) */
  background: rgba(var(--shadow-rgb, 31,27,22), .58);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
  overscroll-behavior: contain;
}

.cs-sheet {
  width: 100%;
  max-height: 94vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--paper-raised, #fff);
  color: var(--ink, #1F1B16);
  border: 1px solid var(--hairline, rgba(0,0,0,.12));
  border-bottom: 0;
  border-radius: 20px 20px 0 0;
  padding: 14px 16px calc(18px + env(safe-area-inset-bottom));
  box-shadow: 0 -12px 44px rgba(0, 0, 0, .38);
}

.cs-head {
  display: flex;
  align-items: center;
  gap: 10px;
  position: sticky;
  top: 0;
  background: var(--paper-raised, #fff);
  padding: 2px 0 10px;
  z-index: 2;
}

.cs-title {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cs-x {
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--ink-faded, #6E6253);
  font-size: 1.05rem;
  cursor: pointer;
}

.cs-x:hover { background: rgba(var(--ink-rgb, 31,27,22), .05); }

/* ── the card ─────────────────────────────────────────────────────────────── */
.cs-stage {
  display: flex;
  justify-content: center;
  background: rgba(var(--ink-rgb, 31,27,22), .04);
  border-radius: 14px;
  padding: 10px;
  min-height: 120px;
}

.cs-canvas {
  display: block;
  max-width: 100%;
  max-height: 46vh;
  width: auto;
  height: auto;
  border-radius: 10px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .22);
}

/* ── controls ─────────────────────────────────────────────────────────────── */
.cs-controls { margin-top: 12px; }

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

.cs-lab {
  flex: 0 0 auto;
  font-size: .8rem;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--ink-faded, #6E6253);
}

.cs-chips { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.cs-chip {
  min-height: 44px;
  padding: 0 16px;
  border: 1px solid var(--hairline, rgba(0,0,0,.16));
  border-radius: 22px;
  background: transparent;
  color: inherit;
  font: inherit;
  font-size: .92rem;
  cursor: pointer;
}

.cs-chip.on {
  background: var(--accent, #A8322A);
  border-color: var(--accent, #A8322A);
  color: #fff;
}

.cs-vlabel {
  font-variant-numeric: tabular-nums;
  font-size: .9rem;
  color: var(--ink-faded, #6E6253);
  min-width: 56px;
  text-align: center;
}

.cs-hint {
  margin: 6px 0 0;
  font-size: .82rem;
  color: var(--ink-faded, #6E6253);
}

.cs-note { margin-top: 14px; }

.cs-note .cs-lab { display: block; margin-bottom: 6px; }

.cs-input {
  width: 100%;
  min-height: 46px;
  padding: 10px 12px;
  border: 1px solid var(--hairline, rgba(0,0,0,.18));
  border-radius: 12px;
  background: rgba(var(--ink-rgb, 31,27,22), .03);
  color: inherit;
  font: inherit;
  font-size: 1rem;              /* 16px keeps iOS from zooming the page */
}

.cs-check {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
  min-height: 44px;
  font-size: .92rem;
  cursor: pointer;
}

.cs-check input { width: 20px; height: 20px; }

.cs-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 14px;
}

.cs-btn { min-height: 46px; flex: 1 1 auto; }

.cs-note-line {
  margin: 10px 0 0;
  min-height: 20px;
  font-size: .85rem;
  text-align: center;
  color: var(--ink-faded, #6E6253);
}

/* ── the picker ───────────────────────────────────────────────────────────── */
.cs-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: 12px;
}

.cs-cell {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 8px;
  border: 1px solid var(--hairline, rgba(0,0,0,.14));
  border-radius: 14px;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.cs-cell:hover { border-color: var(--accent, #A8322A); }

.cs-thumb {
  position: relative;
  aspect-ratio: 4 / 5;
  border-radius: 10px;
  overflow: hidden;
  background: rgba(var(--ink-rgb, 31,27,22), .05);
}

.cs-thumb-img { display: block; width: 100%; height: 100%; }

.cs-thumb-fail::after {
  content: '—';
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--ink-whisper, #A89A82);
}

.cs-cell-lab {
  font-size: .86rem;
  line-height: 1.3;
  color: var(--ink-faded, #6E6253);
}

/* ── the ↗ that sits in a panel heading ───────────────────────────────────── */
.dw-panel-head {
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.dw-panel-head h4 { flex: 1 1 auto; min-width: 0; }

.dw-cardbtn {
  flex: 0 0 auto;
  min-width: 44px;
  min-height: 36px;
  padding: 0 10px;
  border: 1px solid var(--hairline, rgba(0,0,0,.16));
  border-radius: 10px;
  background: transparent;
  color: var(--ink-faded, #6E6253);
  font: inherit;
  font-size: .9rem;
  cursor: pointer;
}

.dw-cardbtn:hover,
.dw-cardbtn:focus-visible {
  border-color: var(--accent, #A8322A);
  color: var(--accent, #A8322A);
}

/* ── desktop: the sheet becomes a centred dialog ──────────────────────────── */
@media (min-width: 640px) {
  .cs-ov { align-items: center; padding: 24px; }

  .cs-sheet {
    max-width: 520px;
    border-radius: 18px;
    border-bottom: 1px solid var(--hairline, rgba(0,0,0,.12));
    max-height: 90vh;
    padding: 16px 20px 20px;
    box-shadow: 0 24px 64px rgba(0, 0, 0, .42);
  }

  .cs-picker { max-width: 720px; }

  .cs-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }

  .cs-canvas { max-height: 52vh; }
}

/* ── wide screens: card left, controls right, so Save is never below the fold ── */
@media (min-width: 900px) {
  .cs-sheet:not(.cs-picker) {
    max-width: 900px;
    display: grid;
    grid-template-columns: minmax(0, 1.05fr) minmax(290px, .95fr);
    grid-template-areas:
      "head head"
      "stage controls";
    column-gap: 22px;
    align-items: start;
  }

  .cs-sheet:not(.cs-picker) .cs-head { grid-area: head; }
  .cs-sheet:not(.cs-picker) .cs-stage { grid-area: stage; }

  .cs-sheet:not(.cs-picker) .cs-controls {
    grid-area: controls;
    margin-top: 0;
  }

  .cs-sheet:not(.cs-picker) .cs-canvas { max-height: 66vh; }
}
