:root {
  color-scheme: light;
  --ink: #2b2018;
  --muted: #6c5a46;
  --paper: #fff7e8;
  --panel: #f5e6cb;
  --green: #13784a;
  --red: #a72d28;
  --blue: #0c6d94;
  --gold: #c58a34;
  --wood: #6b3f1f;
  --dark-wood: #2d1b10;
  --line: rgba(74, 50, 27, 0.2);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    linear-gradient(180deg, rgba(37, 20, 8, 0.1), rgba(37, 20, 8, 0.18)),
    url("../assets/fond-parchemin-gaulois.png") center top / cover fixed,
    var(--paper);
}

button,
input,
select {
  font: inherit;
}

button,
.button-link {
  border: 2px solid rgba(45, 27, 16, 0.48);
  border-radius: 8px;
  color: var(--ink);
  background:
    linear-gradient(180deg, rgba(255, 250, 240, 0.95), rgba(232, 196, 136, 0.86));
  min-height: 44px;
  padding: 0 14px;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  box-shadow: 0 4px 0 rgba(45, 27, 16, 0.18);
}

button:disabled,
.is-disabled {
  opacity: 0.45;
  pointer-events: none;
}

.app-header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 18px 18px 10px;
  max-width: 1040px;
  margin: 0 auto;
  text-shadow: 0 2px 0 rgba(255, 247, 232, 0.55);
}

.app-logo {
  width: 74px;
  height: 74px;
  flex: 0 0 auto;
  border-radius: 18px;
  object-fit: cover;
  box-shadow: 0 10px 22px rgba(43, 32, 24, 0.18);
}

.eyebrow {
  margin: 0 0 2px;
  color: #2f6f35;
  font-size: 0.8rem;
  font-weight: 900;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(1.45rem, 6vw, 2.6rem);
  line-height: 1.02;
  font-family: Georgia, "Times New Roman", serif;
  font-weight: 900;
}

h2 {
  font-size: 1.15rem;
}

.icon-button {
  width: 44px;
  padding: 0;
  border-radius: 50%;
  background: var(--green);
  color: white;
  font-size: 1.5rem;
}

.app-shell {
  width: min(1040px, 100%);
  margin: 0 auto;
  padding: 4px 14px 28px;
}

.tabs {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  justify-content: center;
  align-items: center;
  gap: clamp(8px, 4vw, 22px);
  width: min(430px, 100%);
  margin: 50px auto 6px;
  padding: 0;
  overflow: visible;
  position: relative;
  z-index: 5;
}

.tab {
  min-height: clamp(82px, 19vw, 112px);
  padding: 0;
  border: 0;
  background: transparent;
  box-shadow: none;
  overflow: visible;
  aspect-ratio: 1.85 / 1;
  transform: translateY(0) scale(0.98);
  transition: transform 160ms ease, filter 160ms ease;
}

.tab.is-active {
  background: transparent;
  filter: drop-shadow(0 8px 0 rgba(19, 120, 74, 0.22)) drop-shadow(0 10px 16px rgba(43, 32, 24, 0.25));
  transform: translateY(-2px) scale(1.02);
}

.tab img {
  display: block;
  width: 100%;
  max-width: none;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
  transform: scale(1.18);
  transform-origin: center;
}

.tab:not(.is-active) img {
  filter: saturate(0.82) brightness(0.88);
}

.view {
  display: none;
  margin-top: -100px;
  position: relative;
  z-index: 0;
}

.view.is-active {
  display: block;
}

#galleryView.is-active {
  transform: translateY(-40px);
}

#createView {
  gap: 14px;
}

#createView.is-active {
  display: grid;
}

.card-form,
.preview-panel {
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}

.card-form {
  display: grid;
  gap: 14px;
  width: min(560px, 100%);
  margin: 0 auto;
  padding: 4px 4px 14px;
  position: relative;
  overflow: hidden;
}

.step-meter {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  position: relative;
  z-index: 1;
  overflow: visible;
  transform: translateY(50px);
}

.step-meter span {
  height: 42px;
  border: 0;
  background: url("../assets/icone-epee.png") center / contain no-repeat;
  filter: saturate(0.25) sepia(0.1) opacity(0.42);
}

.step-meter span.is-active {
  filter: drop-shadow(0 5px 5px rgba(45, 27, 16, 0.28));
}

.form-step {
  display: none;
  gap: 12px;
  position: relative;
  z-index: 1;
  transform: translateY(50px);
}

.form-step.is-active {
  display: grid;
}

.form-step h2 {
  color: #235f34;
  font-size: 1.3rem;
  font-family: Georgia, "Times New Roman", serif;
  text-align: center;
  text-transform: uppercase;
  text-shadow: 0 2px 0 rgba(255, 247, 232, 0.65);
}

label {
  display: grid;
  gap: 6px;
  font-weight: 800;
}

label span {
  font-size: 0.88rem;
  color: #4b2f1b;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  text-align: center;
}

input,
select {
  width: 100%;
  min-height: 46px;
  border: 2px solid rgba(45, 27, 16, 0.3);
  border-radius: 8px;
  padding: 0 12px;
  background: rgba(255, 250, 240, 0.94);
  color: var(--ink);
  box-shadow: inset 0 2px 5px rgba(45, 27, 16, 0.08);
}

input[type="file"] {
  padding: 10px;
}

label:has(select[name="mood"][hidden]) {
  display: none;
}

.gender-choice {
  display: grid;
  gap: 8px;
  grid-template-columns: 1fr 1fr;
  margin: 0;
  padding: 0;
  border: 0;
}

.gender-choice legend {
  grid-column: 1 / -1;
  margin-bottom: 6px;
  font-size: 0.88rem;
  font-weight: 800;
  color: #4b2f1b;
  text-transform: uppercase;
  text-align: center;
}

.job-grid,
.photo-choice-grid {
  display: grid;
  gap: 8px;
}

.job-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  column-gap: 58px;
  row-gap: 18px;
  max-height: min(54vh, 560px);
  overflow: auto;
  padding-right: 2px;
}

.job-card {
  min-height: 132px;
  gap: 0;
  padding: 0 4px 4px;
  border: 0;
  background: transparent;
  box-shadow: none;
  overflow: visible;
  transition: transform 160ms ease, filter 160ms ease;
}

.choice-card,
.photo-choice {
  position: relative;
  display: grid;
  align-items: center;
  justify-items: center;
  min-height: 86px;
  padding: 10px 8px;
  border: 2px solid rgba(45, 27, 16, 0.28);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255, 250, 240, 0.9), rgba(230, 195, 129, 0.72));
  text-align: center;
  box-shadow: 0 5px 0 rgba(45, 27, 16, 0.12);
}

.choice-card.job-card {
  border: 0;
  background: transparent;
  box-shadow: none;
}

.choice-card input,
.photo-choice input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  min-height: 0;
  opacity: 0;
  cursor: pointer;
}

.choice-icon {
  display: grid;
  place-items: center;
  width: 62px;
  height: 34px;
  border: 0;
  color: transparent;
  background: url("../assets/icone-epee.png") center / contain no-repeat;
  font-size: 0;
  line-height: 1;
  filter: drop-shadow(0 3px 3px rgba(45, 27, 16, 0.22));
}

.job-icon {
  display: block;
  width: min(88px, 100%);
  height: min(88px, 100%);
  aspect-ratio: 1 / 1;
  border: 0;
  border-radius: 0;
  object-fit: cover;
  object-position: center 38%;
  filter: drop-shadow(0 7px 7px rgba(45, 27, 16, 0.3));
  pointer-events: none;
  transition: transform 160ms ease, filter 160ms ease;
}

.job-card strong {
  margin-top: -5px;
  padding: 0;
  background: transparent;
  box-shadow: none;
  text-shadow: 0 2px 0 rgba(255, 247, 232, 0.72);
  transition: color 160ms ease, text-shadow 160ms ease, transform 160ms ease;
}

.gender-card {
  min-height: 142px;
  overflow: hidden;
  border: 0;
  background: transparent;
  box-shadow: none;
}

.gender-card .choice-icon {
  width: 94px;
  height: 94px;
  background-size: cover;
  border-radius: 50%;
}

.gender-card strong {
  transform: translateY(-10px);
}

.gender-male .choice-icon {
  background-image: url("../assets/icone-gaulois.png");
}

.gender-female .choice-icon {
  background-image: url("../assets/icone-gauloise.png");
}

.choice-card strong,
.photo-choice strong {
  min-width: 0;
  font-size: 0.82rem;
  line-height: 1.12;
}

.choice-card:has(input:checked),
.photo-choice:focus-within,
.photo-choice.has-file {
  border-color: #146d40;
  background:
    linear-gradient(180deg, rgba(231, 255, 224, 0.94), rgba(108, 160, 75, 0.28));
  box-shadow:
    inset 0 0 0 2px rgba(19, 120, 74, 0.28),
    0 5px 0 rgba(45, 27, 16, 0.14);
}

.choice-card.job-card:has(input:checked) {
  border: 0;
  background: transparent;
  box-shadow: none;
  transform: translateY(-3px);
}

.choice-card.job-card:has(input:checked) .job-icon {
  transform: scale(1.12);
  filter:
    drop-shadow(0 8px 7px rgba(45, 27, 16, 0.32))
    drop-shadow(0 0 8px rgba(255, 244, 150, 1))
    drop-shadow(0 0 16px rgba(255, 196, 42, 0.95))
    drop-shadow(0 0 26px rgba(19, 120, 74, 0.95));
}

.choice-card.job-card:has(input:checked) strong {
  color: #0f6a3e;
  transform: scale(1.08);
  text-shadow:
    0 2px 0 rgba(255, 247, 232, 0.95),
    0 0 9px rgba(255, 210, 90, 0.95);
}

.photo-choice-grid {
  grid-template-columns: 1fr;
}

.trait-choice {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  border: 0;
}

.trait-choice legend {
  margin-bottom: 8px;
  font-size: 0.88rem;
  font-weight: 800;
  color: #4b2f1b;
  text-transform: uppercase;
  text-align: center;
}

.trait-choice small {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 900;
}

.trait-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  max-height: min(48vh, 380px);
  overflow: auto;
  padding-right: 2px;
}

.trait-grid label {
  position: relative;
  min-height: 42px;
  padding: 0;
}

.trait-group-title {
  grid-column: 1 / -1;
  margin-top: 2px;
  color: #4b2f1b;
  font-size: 0.78rem;
  font-weight: 900;
  text-align: center;
  text-transform: uppercase;
}

.trait-grid input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  min-height: 0;
  opacity: 0;
  cursor: pointer;
}

.trait-grid span {
  display: grid;
  place-items: center;
  height: 100%;
  min-height: 42px;
  padding: 8px 6px;
  border: 2px solid rgba(45, 27, 16, 0.24);
  border-radius: 8px;
  background: rgba(255, 250, 240, 0.82);
  color: #4b2f1b;
  font-size: 0.82rem;
  font-weight: 900;
  text-align: center;
  transition: transform 140ms ease, background 140ms ease, border-color 140ms ease;
}

.trait-grid input:checked + span {
  border-color: rgba(19, 120, 74, 0.62);
  background: rgba(19, 120, 74, 0.16);
  color: #125a38;
  transform: translateY(-1px);
}

.trait-grid input:disabled + span {
  opacity: 0.45;
}

.trait-hint {
  margin: 0;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 800;
  text-align: center;
}

.photo-choice {
  min-height: 82px;
  padding: 0;
  border: 0;
  background: transparent;
  box-shadow: none;
  overflow: visible;
  transition: transform 160ms ease, filter 160ms ease;
}

.photo-choice .choice-icon,
.photo-choice strong {
  display: none;
}

.photo-choice-button {
  display: block;
  width: 75%;
  height: auto;
  pointer-events: none;
  filter: drop-shadow(0 6px 6px rgba(45, 27, 16, 0.28));
}

.photo-choice:focus-within,
.photo-choice.has-file {
  border: 0;
  background: transparent;
  box-shadow: none;
  transform: translateY(-2px);
}

.photo-choice:focus-within .photo-choice-button,
.photo-choice.has-file .photo-choice-button {
  filter:
    drop-shadow(0 6px 6px rgba(45, 27, 16, 0.28))
    drop-shadow(0 0 12px rgba(255, 210, 90, 0.8));
}

.photo-status {
  margin: 0;
  padding: 10px 12px;
  border: 2px solid rgba(43, 32, 24, 0.18);
  border-radius: 8px;
  color: #2b2018;
  background: rgba(255, 250, 240, 0.92);
  font-size: 1rem;
  line-height: 1.3;
  font-weight: 800;
}

.photo-status.is-ok {
  border-color: rgba(19, 120, 74, 0.45);
  background: rgba(19, 120, 74, 0.12);
  color: #125a38;
}

.photo-status.is-warning {
  border-color: rgba(174, 105, 20, 0.55);
  background: rgba(255, 196, 87, 0.2);
  color: #6d3e0c;
}

.photo-status.is-error {
  border-color: rgba(174, 42, 36, 0.5);
  background: rgba(174, 42, 36, 0.12);
  color: #8b211c;
}

.ai-consent {
  border: 2px solid rgba(19, 120, 74, 0.24);
  border-radius: 8px;
  padding: 10px;
  background: rgba(19, 120, 74, 0.08);
}

.consent {
  grid-template-columns: 24px 1fr;
  align-items: start;
  gap: 9px;
  color: var(--muted);
  font-weight: 700;
}

.consent input {
  width: 20px;
  min-height: 20px;
  margin: 2px 0 0;
}

.primary-button {
  background:
    linear-gradient(180deg, #c9493c, #8f211f);
  color: white;
  border-color: #6f1715;
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.35);
}

.form-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  justify-content: center;
  gap: clamp(8px, 4vw, 18px);
  width: min(430px, 100%);
  margin: -8px auto 0;
  transform: translateY(30px);
}

.form-actions button[hidden] {
  display: none;
}

.form-actions button:only-child {
  grid-column: 1 / -1;
}

.image-action-button {
  min-height: clamp(82px, 19vw, 112px);
  padding: 0;
  border: 0;
  background: transparent;
  box-shadow: none;
  overflow: visible;
  aspect-ratio: 1.85 / 1;
}

.image-action-button img {
  display: block;
  width: 100%;
  max-width: none;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
  transform: scale(1.18);
  transform-origin: center;
}

.image-action-forge img {
  transform: scale(1.08);
}

.image-action-back img {
  transform: translateY(-2px) scale(1.18);
}

.image-action-button:disabled {
  opacity: 0.72;
  filter: grayscale(0.15) saturate(0.85);
}

.preview-panel {
  position: relative;
  padding: 12px;
}

.forge-loader {
  position: absolute;
  inset: 12px;
  z-index: 10;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 12px;
  border-radius: 8px;
  background: rgba(255, 247, 232, 0.96);
  color: var(--ink);
  text-align: center;
  font-size: 1.05rem;
  backdrop-filter: blur(3px);
  box-shadow: inset 0 0 0 2px rgba(197, 138, 52, 0.32);
}

.forge-loader[hidden] {
  display: none;
}

.forge-loader-image {
  width: min(190px, 52vw);
  aspect-ratio: 2 / 3;
  object-fit: cover;
  border-radius: 8px;
  box-shadow: 0 14px 26px rgba(43, 32, 24, 0.26);
  animation: forge-pulse 1.4s ease-in-out infinite;
}

canvas.is-forging {
  opacity: 0.35;
}

@keyframes forge-pulse {
  0%, 100% {
    transform: translateY(0) scale(1);
  }

  50% {
    transform: translateY(-5px) scale(1.03);
  }
}

.reveal-panel {
  transform: translateY(18px) scale(0.96) rotate(-1deg);
  opacity: 0;
  transform-origin: top center;
  filter: drop-shadow(0 28px 36px rgba(43, 32, 24, 0.22));
}

.reveal-panel.is-revealed {
  animation: card-reveal 760ms cubic-bezier(0.16, 1, 0.3, 1) both;
}

.reveal-panel[hidden] {
  display: none;
}

@keyframes card-reveal {
  0% {
    transform: translateY(28px) scale(0.9) rotate(-3deg);
    opacity: 0;
  }

  58% {
    transform: translateY(-6px) scale(1.02) rotate(1deg);
    opacity: 1;
  }

  100% {
    transform: translateY(0) scale(1) rotate(0);
    opacity: 1;
  }
}

canvas {
  width: 100%;
  height: auto;
  display: block;
  border-radius: 8px;
  background: #f9ead1;
}

.actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  margin-top: 10px;
}

.gallery-toolbar {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 18px 0 38px;
}

.gallery-toolbar button {
  min-height: 38px;
}

.admin-panel {
  display: grid;
  gap: 8px;
  margin: 0 0 12px;
  padding: 10px;
  border: 1px solid rgba(43, 32, 24, 0.18);
  border-radius: 8px;
  background: rgba(255, 250, 240, 0.82);
}

.admin-panel[hidden] {
  display: none;
}

.ai-code-field[hidden],
.access-code-panel[hidden] {
  display: none;
}

.access-code-panel form {
  display: grid;
  gap: 8px;
}

.access-code-list {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.access-code-row {
  display: grid;
  grid-template-columns: 1fr auto auto auto;
  align-items: center;
  gap: 8px;
  padding: 8px;
  border: 1px solid rgba(43, 32, 24, 0.16);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.5);
}

.access-code-row button {
  min-height: 34px;
}

.ticket-button {
  border-color: rgba(19, 120, 74, 0.45);
  color: var(--green);
}

.ticket-print-area {
  display: none;
}

.ticket-paper {
  width: 80mm;
  margin: 0;
  padding: 4mm;
  color: #211912;
  background: #fff;
  font-family: Arial, Helvetica, sans-serif;
  text-align: center;
}

.ticket-paper > * {
  box-sizing: border-box;
}

.ticket-brand {
  font-size: 24px;
  font-weight: 900;
  line-height: 1;
  margin: 0 0 2mm;
}

.ticket-brand span:first-child {
  color: #16834c;
}

.ticket-brand span:nth-child(2) {
  color: #d4212d;
}

.ticket-shield {
  width: 26mm;
  height: 26mm;
  margin: 2mm auto;
  border-radius: 7mm;
  object-fit: cover;
  display: block;
}

.ticket-hook {
  font-size: 19px;
  font-weight: 900;
  text-transform: uppercase;
  margin: 2mm 0;
}

.ticket-small {
  font-size: 11px;
  line-height: 1.25;
  margin: 1.5mm 0;
}

.ticket-qr {
  width: 50mm;
  height: 50mm;
  margin: 2mm auto;
  display: block;
}

.ticket-code-label {
  font-size: 12px;
  margin: 3mm 0 1mm;
}

.ticket-code {
  border: 2px solid #211912;
  padding: 2mm;
  margin: 1mm 0 3mm;
  font-size: 25px;
  font-weight: 900;
  letter-spacing: 1px;
}

.ticket-url {
  font-size: 9px;
  overflow-wrap: anywhere;
  margin-top: 2mm;
}

.ticket-cut {
  margin-top: 3mm;
  border-top: 1px dashed #211912;
  padding-top: 2mm;
  font-size: 10px;
}

@media print {
  @page {
    size: 80mm auto;
    margin: 0;
  }

  body.printing-ticket {
    width: 80mm;
    margin: 0;
    padding: 0;
    background: #fff;
  }

  body.printing-ticket > :not(.ticket-print-area) {
    display: none !important;
  }

  body.printing-ticket .ticket-print-area {
    display: block;
  }

  body.printing-ticket .ticket-paper {
    border: 1px dashed #211912;
  }
}

.gallery-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

.gallery-grid:empty::before {
  content: "Aucune carte pour le moment.";
  color: var(--muted);
  font-weight: 800;
}

.gallery-item {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffaf0;
  box-shadow: 0 12px 28px rgba(43, 32, 24, 0.1);
}

.gallery-item img {
  display: block;
  width: 100%;
  aspect-ratio: 17 / 24;
  object-fit: cover;
  background: #ead6b4;
}

.gallery-item div {
  display: grid;
  gap: 8px;
  padding: 10px;
}

.delete-card-button {
  background: var(--red);
  border-color: var(--red);
  color: white;
}

.delete-card-button[hidden] {
  display: none;
}

.gallery-item strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

@media (min-width: 780px) {
  #createView.is-active {
    grid-template-columns: minmax(320px, 390px) 1fr;
    align-items: start;
    gap: 22px;
  }

  .tabs {
    margin-bottom: 2px;
  }

  .card-form {
    width: 100%;
    padding-inline: 0;
  }

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

  .gallery-grid {
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  }
}
