* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
  background: #0f0f13;
  color: #e8e8ee;
}

.app {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 8px 16px;
  border-bottom: 1px solid #2a2a33;
  flex: none;
}

.topbar h1 {
  margin: 0;
  font-size: 1.25rem;
}

.tagline {
  margin: 0;
  color: #8a8a95;
  font-size: 0.8rem;
}

.tabs {
  display: flex;
  gap: 6px;
  margin-left: 12px;
}

.tab {
  background: #1b1b22;
  border: 1px solid #2a2a33;
  color: #b5b5c0;
  padding: 7px 20px;
  border-radius: 8px;
  font-size: 0.9rem;
  cursor: pointer;
}

.tab:hover { background: #24242d; }

.tab.active {
  background: #ffd166;
  border-color: #ffd166;
  color: #1b1b22;
  font-weight: 600;
}

#print-btn { margin-left: auto; }

#preview-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(8, 8, 12, 0.88);
  backdrop-filter: blur(4px);
  touch-action: none;
  cursor: grab;
}

#preview-overlay.open { display: flex; }
#preview-overlay:active { cursor: grabbing; }

#preview-overlay .scene { perspective: 1400px; }

.card3d {
  width: min(78vw, 640px);
  aspect-ratio: 87 / 55;
  position: relative;
  transform-style: preserve-3d;
}

.card3d .face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  border-radius: 3.45% / 5.45%; /* coins 3 mm sur 87 × 55 */
  overflow: hidden;
  background: #fff;
  box-shadow: 0 40px 80px rgba(0, 0, 0, 0.55);
}

.card3d .face img {
  width: 100%;
  height: 100%;
  display: block;
}

.card3d .face::after {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(115deg, rgba(255, 255, 255, 0.22) 0%, rgba(255, 255, 255, 0) 38%);
}

.card3d .face.back { transform: rotateY(180deg); }

.preview-close {
  position: absolute;
  top: 16px;
  right: 20px;
  font-size: 1.1rem;
  padding: 8px 14px;
}

.preview-hint {
  position: absolute;
  bottom: 18px;
  margin: 0;
  color: #9a9aa5;
  font-size: 0.85rem;
}

.editors {
  flex: 1;
  min-height: 0;
  display: flex;
}

.editor {
  display: none;
  flex: 1;
  min-width: 0;
  flex-direction: column;
}

.editor.active { display: flex; }

.stage {
  flex: 1;
  min-height: 0;
  position: relative;
}

.stage canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  cursor: pointer;
  touch-action: none;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 16px;
  padding: 10px 16px;
  border-top: 1px solid #2a2a33;
  flex: none;
}

.controls label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  color: #b5b5c0;
}

.controls input[type=range] {
  width: 150px;
  accent-color: #ffd166;
}

.tip {
  color: #6f6f7a;
  font-size: 0.78rem;
}

button {
  background: #2a2a33;
  color: #e8e8ee;
  border: 1px solid #3a3a45;
  border-radius: 8px;
  padding: 7px 12px;
  font-size: 0.85rem;
  cursor: pointer;
}

button:hover { background: #34343f; }

button.primary {
  background: #ffd166;
  border-color: #ffd166;
  color: #1b1b22;
  font-weight: 600;
  padding: 8px 22px;
}

button.primary:hover { background: #ffdd88; }

@media (max-width: 800px) {
  .tagline { display: none; }
}

#print-area { display: none; }

@page { margin: 10mm; }

@media print {
  body { background: #fff; }
  .app { display: none; }
  #preview-overlay { display: none !important; }

  #print-area { display: block; }

  .print-note {
    font: 9pt sans-serif;
    color: #555;
    margin: 0 0 6mm;
  }

  .print-card {
    width: 87mm;
    height: 55mm;
    border: 0.3mm dashed #999;
    margin: 0 0 8mm;
    page-break-inside: avoid;
  }

  .print-card img {
    display: block;
    width: 87mm;
    height: 55mm;
  }
}
