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

:root {
  --bg: #F8F7F5;
  --surface: #FFFFFF;
  --text: #1A1A1A;
  --muted: #6B6B6B;
  --border: #E8E5E0;
  --accent: #007AFF;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-xl: 16px;
}

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Helvetica Neue', sans-serif;
  color: var(--text);
  user-select: none;
  -webkit-user-select: none;
  display: flex;
  flex-direction: column;
  height: 100dvh;
}

/* ── App Bar ─────────────────────────────────────────────────────────────── */
.appbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 48px 24px 8px;
  background: var(--bg);
  flex-shrink: 0;
}
.appbar-title { font-size: 17px; font-weight: 600; letter-spacing: -0.3px; }
.export-btn {
  font-size: 15px; font-weight: 600; color: var(--accent);
  background: none; border: none; cursor: pointer; padding: 4px 0;
}

/* ── Orientation ─────────────────────────────────────────────────────────── */
.orient-row {
  display: flex;
  justify-content: center;
  gap: 8px;
  padding: 2px 24px 6px;
  flex-shrink: 0;
}
.orient-btn {
  display: flex; align-items: center; gap: 5px;
  padding: 6px 14px; border-radius: var(--radius-md);
  border: none; font-size: 12px; font-weight: 500;
  cursor: pointer; transition: all 0.2s;
}
.orient-btn.active   { background: var(--text); color: #fff; }
.orient-btn.inactive { background: #EEECEA; color: var(--muted); }

/* ── Canvas ──────────────────────────────────────────────────────────────── */
.canvas-wrap {
  flex: 1;
  min-height: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 6px 16px;
  overflow: hidden;
}
.canvas-shadow {
  position: relative;
  border-radius: var(--radius-xl);
  box-shadow: 0 8px 32px rgba(0,0,0,0.16);
  transition: all 0.3s ease;
  flex-shrink: 0;
}
#bgCanvas {
  display: block;
  border-radius: var(--radius-xl);
  pointer-events: none;
}
.canvas {
  position: absolute; inset: 0;
  border-radius: var(--radius-xl);
  overflow: hidden;
  touch-action: none;
}

/* ── Bottom Panel ────────────────────────────────────────────────────────── */
.bottom-panel {
  flex-shrink: 0;
  background: var(--bg);
  padding: 6px 0 20px;
  display: flex;
  flex-direction: column;
  gap: 0;
}

.bottom-row {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 6px 16px;
  overflow-x: auto;
  scrollbar-width: none;
}
.bottom-row::-webkit-scrollbar { display: none; }

.row-divider {
  height: 1px;
  background: var(--border);
  margin: 0 16px;
  opacity: 0.6;
}

/* ── Mat Chips ───────────────────────────────────────────────────────────── */
.mat-chip {
  display: flex; align-items: center; gap: 5px;
  padding: 0 11px; height: 34px;
  border-radius: var(--radius-md);
  font-size: 11px; font-weight: 600;
  cursor: pointer;
  border: 2px solid transparent;
  transition: all 0.2s;
  white-space: nowrap;
  flex-shrink: 0;
}
.mat-chip.selected { border-color: var(--text); }
.mat-dot { width: 7px; height: 7px; border-radius: 50%; }

/* ── Color Row ───────────────────────────────────────────────────────────── */
.color-label {
  font-size: 11px; color: var(--muted);
  font-weight: 500; white-space: nowrap; flex-shrink: 0;
}
.color-dot {
  width: 22px; height: 22px; border-radius: 50%;
  cursor: pointer; border: 2px solid transparent;
  transition: all 0.15s; flex-shrink: 0;
}
.color-dot.active { border-color: var(--text); transform: scale(1.15); }
.color-custom {
  width: 22px; height: 22px; border-radius: 50%;
  border: 1.5px dashed #bbb;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; position: relative; flex-shrink: 0;
  font-size: 13px; color: #bbb; line-height: 1;
}
.color-custom input[type=color] {
  position: absolute; inset: 0; opacity: 0;
  cursor: pointer; width: 100%; height: 100%; border-radius: 50%;
}

/* ── Tools Row ───────────────────────────────────────────────────────────── */
.tools-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 16px;
  overflow-x: auto;
  scrollbar-width: none;
}
.tools-row::-webkit-scrollbar { display: none; }

.font-tab {
  padding: 6px 12px; border-radius: 8px;
  font-size: 12px; font-weight: 600;
  cursor: pointer;
  border: 1.5px solid var(--border);
  background: var(--surface); color: var(--text);
  transition: all 0.2s; white-space: nowrap; flex-shrink: 0;
}
.font-tab.active { background: var(--text); color: #fff; border-color: var(--text); }

.tools-divider {
  width: 1px; height: 28px;
  background: var(--border);
  flex-shrink: 0;
  margin: 0 2px;
}

.tool-btn {
  display: flex; align-items: center; justify-content: center;
  background: none; border: none; cursor: pointer;
  flex-shrink: 0; padding: 0;
}
.tool-icon {
  width: 42px; height: 42px;
  background: var(--surface);
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 1px 6px rgba(0,0,0,0.08);
  color: var(--text);
  transition: transform 0.1s;
}
.tool-btn:active .tool-icon { transform: scale(0.9); }

/* ── Panels ──────────────────────────────────────────────────────────────── */
.panel-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 100;
  display: flex; align-items: flex-end;
  animation: fadeIn 0.2s ease;
}
.panel-sheet {
  width: 100%; background: var(--surface);
  border-radius: 20px 20px 0 0;
  padding: 12px 24px 36px;
  animation: slideUp 0.25s ease;
}
.panel-handle {
  width: 36px; height: 4px;
  background: var(--border); border-radius: 2px;
  margin: 0 auto 16px;
}
.panel-title { font-size: 17px; font-weight: 600; letter-spacing: -0.3px; margin-bottom: 16px; }

.emoji-grid { display: flex; flex-wrap: wrap; gap: 10px; }
.emoji-pick {
  font-size: 34px; cursor: pointer; line-height: 1;
  padding: 4px; border-radius: 8px; transition: transform 0.1s;
}
.emoji-pick:active { transform: scale(0.85); }

.text-field {
  width: 100%; padding: 12px 14px;
  border-radius: 12px; border: 1.5px solid var(--border);
  font-size: 16px; outline: none; margin-bottom: 12px;
  font-family: inherit; background: var(--bg); color: var(--text);
  -webkit-user-select: text; user-select: text;
}
.text-field:focus { border-color: var(--text); }

.add-btn {
  width: 100%; padding: 14px;
  background: var(--text); color: #fff;
  border: none; border-radius: 12px;
  font-size: 16px; font-weight: 600;
  cursor: pointer; font-family: inherit;
  transition: opacity 0.15s;
}
.add-btn:active { opacity: 0.8; }

/* ── Snackbar ────────────────────────────────────────────────────────────── */
.snackbar {
  position: fixed; bottom: 100px; left: 50%;
  transform: translateX(-50%);
  background: var(--text); color: #fff;
  padding: 10px 20px; border-radius: 12px;
  font-size: 13px; font-weight: 500;
  opacity: 0; transition: opacity 0.3s;
  white-space: nowrap; pointer-events: none; z-index: 200;
}
.snackbar.show { opacity: 1; }

/* ── Loading Overlay ─────────────────────────────────────────────────────── */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  z-index: 300;
  display: none;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 16px;
}
.loading-overlay.show { display: flex; }
.loading-spinner {
  width: 44px;
  height: 44px;
  border: 3.5px solid rgba(255,255,255,0.25);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
.loading-text {
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  text-align: center;
  padding: 0 30px;
}
.loading-subtext {
  color: rgba(255,255,255,0.65);
  font-size: 12px;
  text-align: center;
  padding: 0 30px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Canvas Items ────────────────────────────────────────────────────────── */
.c-item {
  position: absolute; touch-action: none;
  cursor: grab; transform-origin: center center;
}
.c-item.selected::after {
  content: '';
  position: absolute; inset: -3px;
  border: 1.5px solid var(--accent);
  border-radius: 4px; pointer-events: none;
}
.c-item:active { cursor: grabbing; }

/* ── Clipping letters ────────────────────────────────────────────────────── */
.clip-word { display: flex; align-items: center; gap: 2px; }
.clip-char {
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 900; line-height: 1;
  padding: 3px 5px; border-radius: 2px;
  box-shadow: 1px 2px 5px rgba(0,0,0,0.28);
  min-width: 26px;
}

/* ── Animations ──────────────────────────────────────────────────────────── */
@keyframes fadeIn  { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
