:root {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface-subtle: #f8fafc;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --text: #0f172a;
  --text-muted: #475569;
  --text-light: #64748b;
  --primary: #0b1957;
  --primary-hover: #1e3a8a;
  --primary-soft: #dbeafe;
  --accent: #0284c7;
  --success: #15803d;
  --success-bg: #dcfce7;
  --warning: #b45309;
  --warning-bg: #fef3c7;
  --danger: #dc2626;
  --danger-bg: #fee2e2;
  --radius-lg: 16px;
  --radius-md: 12px;
  --radius-sm: 8px;
  --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.06), 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-md: 0 4px 16px -2px rgba(15, 23, 42, 0.08), 0 2px 6px -1px rgba(15, 23, 42, 0.04);
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* Header */
.site-header {
  background: linear-gradient(135deg, #060d2e 0%, #0b1957 60%, #1e3a8a 100%);
  color: #ffffff;
  padding: 20px 24px;
  box-shadow: var(--shadow-sm);
}

.header-inner {
  max-width: 1320px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.brand-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: rgba(255, 255, 255, 0.14);
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  margin-bottom: 6px;
}

.site-title {
  margin: 0;
  font-size: clamp(1.2rem, 2.5vw, 1.65rem);
  font-weight: 800;
  line-height: 1.25;
}

.site-subtitle {
  margin: 6px 0 0 0;
  color: #cbd5e1;
  font-size: 0.95rem;
  max-width: 720px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Main Container */
.container {
  max-width: 1320px;
  margin: 24px auto 48px;
  padding: 0 16px;
}

/* Make the 3D Card Column the prominent Highlight */
.main-grid {
  display: grid;
  grid-template-columns: 1.22fr 1fr;
  gap: 24px;
  align-items: start;
}

@media (max-width: 1020px) {
  .main-grid {
    grid-template-columns: 1fr;
  }
}

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  padding: 22px;
}

@media (max-width: 600px) {
  .card {
    padding: 14px;
  }
}

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

.card-title {
  margin: 0;
  font-size: 1.18rem;
  font-weight: 800;
  display: flex;
  align-items: center;
  gap: 8px;
}

.step-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  font-size: 0.85rem;
  font-weight: 700;
  flex-shrink: 0;
}

/* =========================================================
   3D ALTARFALZ CARD STAGE (Highlight + Fullscreen + Drag)
   ========================================================= */
.card-viewer-card.is-fullscreen {
  position: fixed;
  inset: 0;
  z-index: 2000;
  border-radius: 0;
  margin: 0;
  padding: 16px 22px;
  display: flex;
  flex-direction: column;
  background: #0f172a;
  color: #f8fafc;
  border: none;
}

.card-viewer-card.is-fullscreen .card-title {
  color: #ffffff;
}

.card-viewer-card.is-fullscreen .card-controls-bar {
  background: #1e293b;
  border-color: #334155;
}

.card-controls-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 12px;
  background: var(--surface-subtle);
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

.card-controls-group {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.drag-mode-switch {
  display: inline-flex;
  background: #e2e8f0;
  padding: 2px;
  border-radius: 8px;
  gap: 2px;
}

.mode-btn {
  border: none;
  background: transparent;
  padding: 5px 10px;
  border-radius: 6px;
  font-size: 0.78rem;
  font-weight: 700;
  color: #475569;
  cursor: pointer;
  transition: all 0.15s ease;
}

.mode-btn.active {
  background: #ffffff;
  color: var(--primary);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.card-state-pill {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--primary);
  background: var(--primary-soft);
  padding: 4px 10px;
  border-radius: 999px;
  white-space: nowrap;
}

/* Generous 3D Stage Height on Desktop, Mobile & Fullscreen */
.altar-stage {
  position: relative;
  width: 100%;
  height: 640px;
  background: radial-gradient(circle at 50% 45%, #334155 0%, #0f172a 100%);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  perspective: 1600px;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  cursor: grab;
  box-shadow: inset 0 4px 20px rgba(0, 0, 0, 0.35);
}

.altar-stage.is-dragging {
  cursor: grabbing;
}

@media (max-width: 680px) {
  .altar-stage {
    height: 540px;
  }
}

.card-viewer-card.is-fullscreen .altar-stage {
  flex: 1;
  height: auto;
  border-color: #334155;
}

/* 5-second Auto-Open Countdown Banner */
.auto-open-banner {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 20;
  background: rgba(15, 23, 42, 0.85);
  color: #f8fafc;
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
  border: 1px solid rgba(255, 255, 255, 0.18);
  backdrop-filter: blur(6px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.auto-open-bar {
  width: 140px;
  height: 3px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 99px;
  overflow: hidden;
}

.auto-open-progress {
  width: 100%;
  height: 100%;
  background: #38bdf8;
  transform-origin: left center;
  transition: transform 0.1s linear;
}

/* Pan & Zoom Wrapper */
.altar-pan-zoom-layer {
  width: min(390px, 84%);
  display: flex;
  align-items: center;
  justify-content: center;
  perspective: 1600px;
  transform-style: preserve-3d;
  will-change: transform;
}

.card-viewer-card.is-fullscreen .altar-pan-zoom-layer {
  width: min(56vh, 86vw);
}

.altar-card-3d {
  position: relative;
  width: 100%;
  aspect-ratio: 612.283 / 858.898; /* Exact PDF DIN A4 portrait aspect ratio */
  transform-style: preserve-3d;
  transition: transform 0.75s cubic-bezier(0.34, 1.05, 0.64, 1);
}

/* Disable transition while actively dragging with mouse/finger for instant response */
.altar-card-3d.no-transition {
  transition: none !important;
}

/* The 3 horizontal panels of the Altarfalz */
.altar-panel {
  position: absolute;
  left: 0;
  width: 100%;
  transform-style: preserve-3d;
}

.altar-panel-center {
  top: 25%;
  height: 50%;
  box-shadow: 0 22px 48px rgba(0, 0, 0, 0.55);
}

.altar-panel-top {
  top: 0;
  height: 25%;
  transform-origin: bottom center;
  transform: translateZ(1px) rotateX(0deg);
  transition: transform 1.05s cubic-bezier(0.4, 0.0, 0.2, 1);
}

.altar-panel-bottom {
  top: 75%;
  height: 25%;
  transform-origin: top center;
  transform: translateZ(1px) rotateX(0deg);
  transition: transform 1.05s cubic-bezier(0.4, 0.0, 0.2, 1);
}

/* Folded (Closed) state: Top flap folds down (-179deg), Bottom flap folds up (+179deg) onto the front (+Z) */
.altar-card-3d.is-closed .altar-panel-top {
  transform: translateZ(2px) rotateX(-179.4deg);
}

.altar-card-3d.is-closed .altar-panel-bottom {
  transform: translateZ(2px) rotateX(179.4deg);
}

/* Front & Back faces of each panel */
.altar-face {
  position: absolute;
  inset: 0;
  overflow: hidden;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  background: #ffffff;
}

.altar-face img.slice-img {
  position: absolute;
  left: 0;
  width: 100%;
  max-width: none;
  display: block;
  user-select: none;
  -webkit-user-drag: none;
  pointer-events: none;
}

/* Slicing math for Top (0..25%), Center (25..75%), Bottom (75..100%) */
.altar-panel-top .slice-img {
  height: 400%;
  top: 0;
}

.altar-panel-center .slice-img {
  height: 200%;
  top: -50%;
}

.altar-panel-bottom .slice-img {
  height: 400%;
  top: -300%;
}

/* Inside faces (Page 2: Comic & Signature areas) */
.altar-face-inside {
  transform: translateZ(0.6px);
}

/* Outside faces (Page 1: Blue flaps & Hannes living room back) */
.altar-panel-center .altar-face-outside {
  transform: rotateY(180deg) translateZ(0.6px);
}

/* Top flap outside: rotated around X so when folded down (-180deg X) the HiSolutions logo is upright */
.altar-panel-top .altar-face-outside {
  transform: rotateX(180deg) translateZ(0.8px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.22);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.28);
}

/* Bottom flap outside: rotated around Y so when folded up (+180deg X), rotateX(180)*rotateY(180)=rotateZ(180),
   turning the upside-down "Gute Besserung Dein ITM3" on Page 1 automatically right-side up! */
.altar-panel-bottom .altar-face-outside {
  transform: rotateY(180deg) translateZ(0.8px);
  border-top: 1px solid rgba(255, 255, 255, 0.22);
  box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.28);
}

/* Crease lines & shadows inside the card */
.altar-panel-top .altar-face-inside::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 6px;
  background: linear-gradient(to bottom, transparent, rgba(15, 23, 42, 0.14));
  pointer-events: none;
}

.altar-panel-bottom .altar-face-inside::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  height: 6px;
  background: linear-gradient(to top, transparent, rgba(15, 23, 42, 0.14));
  pointer-events: none;
}

/* Signature Zone Highlights on Inside Flaps */
.sig-zone-overlay {
  position: absolute;
  left: 5%;
  right: 5%;
  border: 1.5px dashed rgba(2, 132, 199, 0.65);
  background: rgba(224, 242, 254, 0.2);
  border-radius: 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  pointer-events: none;
  transition: opacity 0.3s ease;
  padding: 6px;
}

.sig-zone-top {
  top: 6%;
  bottom: 8%;
}

.sig-zone-bottom {
  top: 8%;
  bottom: 6%;
  justify-content: center;
}

.sig-zone-label {
  font-size: 10px;
  font-weight: 700;
  color: #0369a1;
  background: rgba(255, 255, 255, 0.92);
  padding: 2px 8px;
  border-radius: 999px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.08);
}

.card-live-sig-overlay {
  max-width: 55%;
  max-height: 55%;
  margin-bottom: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.card-live-sig-overlay svg {
  max-width: 100%;
  max-height: 36px;
  width: auto;
  height: auto;
}

.altar-stage-footer {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 10px;
  z-index: 15;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 0.78rem;
  color: #e2e8f0;
  background: rgba(15, 23, 42, 0.72);
  padding: 6px 12px;
  border-radius: 999px;
  backdrop-filter: blur(4px);
}

/* Signers List */
.signers-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.counter-pill {
  background: var(--primary-soft);
  color: var(--primary);
  font-weight: 700;
  font-size: 0.85rem;
  padding: 3px 10px;
  border-radius: 999px;
}

.signers-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  max-height: 200px;
  overflow-y: auto;
  padding: 2px;
}

.signer-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 0.86rem;
  font-weight: 500;
  color: var(--text);
}

.signer-chip.is-me {
  background: var(--success-bg);
  border-color: #86efac;
  color: var(--success);
  font-weight: 700;
}

.signer-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #22c55e;
}

/* Form Elements */
.form-group {
  margin-bottom: 22px;
}

.form-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 0.98rem;
  margin-bottom: 8px;
}

.form-hint {
  font-size: 0.85rem;
  color: var(--text-light);
  margin-top: 6px;
}

.text-input {
  width: 100%;
  padding: 12px 14px;
  font-size: 1rem;
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: #fff;
  color: var(--text);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.text-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(30, 58, 138, 0.15);
}

.alert-box {
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  margin-top: 8px;
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

.alert-warning {
  background: var(--warning-bg);
  color: var(--warning);
  border: 1px solid #fde68a;
}

.alert-error {
  background: var(--danger-bg);
  color: var(--danger);
  border: 1px solid #fecaca;
}

.alert-success {
  background: var(--success-bg);
  color: var(--success);
  border: 1px solid #86efac;
}

/* Drawing Pad & Toolbar */
.pad-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 10px;
  background: var(--surface-subtle);
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.pen-sizes {
  display: flex;
  align-items: center;
  gap: 6px;
}

.pen-size-label {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-right: 4px;
}

.pen-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 6px;
  border: 1px solid var(--border-strong);
  background: #fff;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.12s ease;
}

.pen-btn:hover {
  border-color: var(--primary);
  color: var(--text);
}

.pen-btn.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.pen-dot {
  display: inline-block;
  border-radius: 50%;
  background: currentColor;
}

.pad-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.canvas-wrapper {
  position: relative;
  width: 100%;
  height: 270px;
  background: #ffffff;
  border: 2px solid var(--border-strong);
  border-radius: var(--radius-md);
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  box-shadow: inset 0 2px 4px rgba(15, 23, 42, 0.03);
}

.canvas-wrapper.active-drawing {
  border-color: var(--primary);
}

/* Fullscreen Canvas Mode for Mobile */
.canvas-area-container.fullscreen-mode {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: #ffffff;
  padding: 14px;
  display: flex;
  flex-direction: column;
}

.canvas-area-container.fullscreen-mode .canvas-wrapper {
  flex: 1;
  height: auto;
}

#sigCanvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: crosshair;
  touch-action: none;
}

.canvas-guide-line {
  position: absolute;
  left: 7%;
  right: 7%;
  bottom: 26%;
  border-bottom: 1.5px dashed #cbd5e1;
  pointer-events: none;
}

.canvas-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  color: #94a3b8;
  text-align: center;
  padding: 16px;
  transition: opacity 0.15s ease;
}

.canvas-placeholder.hidden {
  opacity: 0;
}

.canvas-placeholder svg {
  width: 34px;
  height: 34px;
  margin-bottom: 6px;
  opacity: 0.7;
}

/* Auto-Crop Live Preview */
.crop-preview-bar {
  margin-top: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  background: var(--surface-subtle);
  border: 1px dashed var(--border-strong);
}

.crop-preview-info {
  font-size: 0.82rem;
  color: var(--text-muted);
}

.crop-preview-info strong {
  display: block;
  color: var(--text);
  font-size: 0.86rem;
}

.crop-preview-box {
  height: 54px;
  min-width: 130px;
  max-width: 240px;
  padding: 6px 10px;
  background-color: #ffffff;
  background-image: radial-gradient(#e2e8f0 1px, transparent 1px);
  background-size: 8px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.crop-preview-box svg {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.92rem;
  font-weight: 600;
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.15s ease;
  text-decoration: none;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-sm {
  padding: 6px 11px;
  font-size: 0.82rem;
}

.btn-lg {
  width: 100%;
  padding: 14px 20px;
  font-size: 1.05rem;
  font-weight: 700;
}

.btn-primary {
  background: var(--primary);
  color: #ffffff;
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
}

.btn-secondary {
  background: #ffffff;
  color: var(--text);
  border-color: var(--border-strong);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--surface-subtle);
  border-color: #94a3b8;
}

.btn-ghost-light {
  background: rgba(255, 255, 255, 0.12);
  color: #ffffff;
  border: 1px solid rgba(255, 255, 255, 0.22);
}

.btn-ghost-light:hover {
  background: rgba(255, 255, 255, 0.22);
}

.btn-danger {
  background: var(--danger-bg);
  color: var(--danger);
  border-color: #fecaca;
}

.btn-danger:hover:not(:disabled) {
  background: #fecaca;
}

/* Success State Box */
.success-panel {
  text-align: center;
  padding: 24px 16px;
}

.success-icon {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--success-bg);
  color: var(--success);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  margin-bottom: 12px;
}

.saved-svg-showcase {
  max-width: 340px;
  height: 110px;
  margin: 16px auto;
  padding: 14px;
  background: #fff;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
}

.saved-svg-showcase svg {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
}

.success-actions {
  display: flex;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 20px;
}

/* Admin Layout */
.admin-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 14px;
  margin-bottom: 24px;
  padding: 18px 22px;
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

.share-box {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  padding: 8px 12px;
  border-radius: 999px;
  flex: 1;
  min-width: 280px;
}

.share-box code {
  font-size: 0.85rem;
  color: var(--primary);
  word-break: break-all;
  flex: 1;
}

.admin-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 16px;
  margin-top: 16px;
}

.sig-admin-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: #fff;
  padding: 14px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  transition: box-shadow 0.15s ease;
}

.sig-admin-card:hover {
  box-shadow: var(--shadow-md);
}

.sig-admin-preview {
  height: 100px;
  background-color: #ffffff;
  background-image: radial-gradient(#e2e8f0 1px, transparent 1px);
  background-size: 10px 10px;
  border: 1px dashed var(--border-strong);
  border-radius: 8px;
  padding: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 12px;
}

.sig-admin-preview svg {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
}

.sig-admin-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.sig-admin-name {
  font-weight: 700;
  font-size: 0.95rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sig-admin-sub {
  font-size: 0.76rem;
  color: var(--text-light);
  margin-top: 2px;
}

.hidden {
  display: none !important;
}

.site-footer {
  text-align: center;
  padding: 24px 16px;
  color: var(--text-light);
  font-size: 0.84rem;
}

.site-footer a {
  color: var(--text-muted);
  text-decoration: underline;
  cursor: pointer;
}
