:root {
  --paper: #FBF3E2; --paper-2: #F4E7CC; --cream: #FFFBF2;
  --ink: #3B2A20; --ink-soft: #8A6A52;
  --jade: #6CC3AE; --jade-d: #2F8F7F; --water: #9EDFD6; --water-d: #58B9B0;
  --lotus: #F7A8C4; --lotus-d: #DD6F98;
  --gold: #E8B545; --gold-l: #FFE08A; --gold-d: #B8861E;
  --mango: #FFC857; --indigo: #2B3A67; --bat: #3C6FB6;
  --wood: #C98E5A; --wood-d: #8E5A32;
  --display: "Baloo 2", "Arial Rounded MT Bold", "Trebuchet MS", sans-serif;
  --body: "Nunito", "Avenir Next", "Segoe UI", sans-serif;
  --grain: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .35 0 0 0 0 .25 0 0 0 0 .15 0 0 0 .09 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

* { box-sizing: border-box; }

body {
  margin: 0;
  color: var(--ink);
  font-family: var(--body);
  background: var(--paper);
  background-image: var(--grain), radial-gradient(circle at 10% 0%, #FDE3EC 0, transparent 40%), radial-gradient(circle at 95% 10%, #DDF3EC 0, transparent 45%);
}

button { font: inherit; color: inherit; }
button:focus-visible { outline: 3px solid var(--bat); outline-offset: 3px; }

.app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.screens {
  flex: 1;
  padding: 1.25rem 1.1rem 6rem;
}

.view {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 0.6rem;
}

.hidden { display: none !important; }

h1 {
  font-family: var(--display);
  font-weight: 800;
  font-size: 1.5rem;
  color: var(--jade-d);
  margin: 0.1rem 0 0.2rem;
}

.label {
  font-family: var(--display);
  font-weight: 700;
  font-size: 0.8rem;
  color: var(--ink-soft);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin: 0;
}

.subtitle {
  color: var(--ink-soft);
  font-weight: 700;
  font-size: 0.85rem;
  line-height: 1.4;
  margin: 0 0 0.5rem;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  margin-bottom: 1rem;
}

.chip {
  font-family: var(--display);
  font-weight: 700;
  font-size: 0.85rem;
  background: var(--cream);
  border-radius: 999px;
  padding: 0.3rem 0.85rem;
  box-shadow: 0 2px 8px rgba(59, 42, 32, 0.12);
}

/* --- Boutons --- */

.btn-primary {
  border: 0;
  border-radius: 999px;
  background: var(--jade-d);
  color: #fff;
  font-family: var(--display);
  font-weight: 800;
  font-size: 1rem;
  padding: 0.75rem 1.6rem;
  cursor: pointer;
  box-shadow: 0 4px 0 #1F6B5E;
  width: 100%;
  max-width: 320px;
}

.btn-primary:active { transform: translateY(2px); box-shadow: 0 2px 0 #1F6B5E; }

.btn-primary:disabled {
  background: #D9CBB0;
  box-shadow: 0 4px 0 #BFAE8C;
  cursor: not-allowed;
}

.btn-text {
  background: none;
  border: none;
  color: var(--ink-soft);
  font-weight: 800;
  font-size: 0.9rem;
  cursor: pointer;
  padding: 0.4rem;
}

.btn-back-top {
  align-self: flex-start;
  color: var(--jade-d);
}

/* --- COLLECTION --- */

.collection-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.6rem;
  width: 100%;
}

.mini-card {
  aspect-ratio: 256 / 372;
  border-radius: 12px;
  padding: 6px;
  background: linear-gradient(140deg, var(--p1), var(--p2) 35%, var(--p3) 65%, var(--p4));
  box-shadow: 0 6px 14px rgba(59, 42, 32, 0.22);
  cursor: pointer;
  border: none;
}

.mini-card-in {
  height: 100%;
  border-radius: 8px;
  background: var(--cream);
  background-image: var(--grain);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 4px;
  overflow: hidden;
}

.mini-card-photo {
  width: 100%;
  flex: 1;
  border-radius: 6px;
  object-fit: cover;
}

.mini-card-vn {
  font-family: var(--display);
  font-weight: 800;
  font-size: 0.7rem;
  color: var(--jade-d);
  line-height: 1.1;
}

.empty-hint {
  color: var(--ink-soft);
  font-weight: 700;
  margin-top: 3rem;
  max-width: 280px;
  line-height: 1.5;
}

/* --- ÉTAPE PHOTO --- */

.photo-drop {
  width: 100%;
  max-width: 300px;
  aspect-ratio: 1 / 1;
  border-radius: 24px;
  border: 3px dashed #E4D5B6;
  background: var(--cream);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  overflow: hidden;
  margin: 0.5rem 0;
}

.photo-drop-hint {
  font-weight: 800;
  color: var(--ink-soft);
  font-size: 1.1rem;
  line-height: 2;
}

#photo-preview {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* --- ÉTAPE MOT --- */

.search-input {
  width: 100%;
  max-width: 320px;
  padding: 0.7rem 1rem;
  border-radius: 999px;
  border: 2px solid #E4D5B6;
  background: var(--cream);
  font: 700 0.9rem var(--body);
  color: var(--ink);
  margin-top: 0.25rem;
}

.search-input:focus { outline: 2px solid var(--jade); }

.theme-filters {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
  justify-content: center;
  margin: 0.5rem 0;
}

.theme-chip {
  border: 2px solid var(--cream);
  background: var(--cream);
  border-radius: 999px;
  padding: 0.3rem 0.8rem;
  font-weight: 800;
  font-size: 0.8rem;
  color: var(--ink-soft);
  cursor: pointer;
}

.theme-chip.active {
  border-color: var(--jade-d);
  color: var(--jade-d);
}

.word-list {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  max-height: 50vh;
  overflow-y: auto;
}

.word-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--cream);
  border: none;
  border-radius: 14px;
  padding: 0.65rem 1rem;
  cursor: pointer;
  text-align: left;
}

.word-item-fr { font-weight: 800; }
.word-item-vn { color: var(--jade-d); font-weight: 800; font-family: var(--display); }

/* --- CARTE (fidèle à la maquette) --- */

.newtag {
  font-family: var(--display);
  font-weight: 800;
  color: var(--jade-d);
  font-size: 1.2rem;
  margin: 0.2rem 0;
}

.card-wrap {
  perspective: 1000px;
  display: flex;
  justify-content: center;
  width: 100%;
}

.card {
  width: 256px;
  height: 372px;
  max-width: 80vw;
  position: relative;
  transform-style: preserve-3d;
  transition: transform 0.7s cubic-bezier(0.3, 1.35, 0.5, 1);
  cursor: pointer;
  --p1: #2F5E78; --p2: #E8A15C; --p3: #4F6FC4; --p4: #F2B8C6; --p5: #3B2A20;
}

.card.flipped { transform: rotateY(180deg); }

.face {
  position: absolute;
  inset: 0;
  border-radius: 20px;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  overflow: hidden;
  padding: 9px;
  background: linear-gradient(140deg, var(--p1), var(--p2) 35%, var(--p3) 65%, var(--p4));
  box-shadow: 0 16px 30px rgba(59, 42, 32, 0.28);
  transition: background 0.6s;
}

.face-in {
  height: 100%;
  border-radius: 13px;
  background: var(--cream);
  display: flex;
  flex-direction: column;
  padding: 10px 12px;
  position: relative;
  gap: 6px;
  background-image: var(--grain);
}

.corner {
  position: absolute;
  width: 22px;
  height: 22px;
  background: linear-gradient(135deg, #FFF3C4, var(--gold) 50%, var(--gold-d));
  opacity: 0.95;
}

.corner.tl { top: 0; left: 0; clip-path: polygon(0 0, 100% 0, 0 100%); border-top-left-radius: 13px; }
.corner.br { bottom: 0; right: 0; clip-path: polygon(100% 0, 100% 100%, 0 100%); border-bottom-right-radius: 13px; }

.c-head { display: flex; justify-content: space-between; align-items: baseline; }
.c-name { font-family: var(--display); font-weight: 800; font-size: 20px; line-height: 1.1; }

.stars { display: flex; gap: 2px; }
.star { width: 12px; height: 12px; background: var(--gold); clip-path: polygon(50% 0, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%); }
.star.off { background: #E8DCC2; }

.art {
  height: 176px;
  border-radius: 10px;
  position: relative;
  overflow: hidden;
  background: radial-gradient(circle at 50% 120%, color-mix(in srgb, var(--p4) 70%, #fff) 0 45%, transparent 46%), linear-gradient(170deg, color-mix(in srgb, var(--p1) 30%, #fff), color-mix(in srgb, var(--p3) 25%, #fff));
  transition: background 0.6s;
}

.art img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.holo {
  position: absolute;
  inset: 0;
  border-radius: 20px;
  pointer-events: none;
  mix-blend-mode: color-dodge;
  opacity: 0.55;
  background: linear-gradient(115deg, transparent 20%, color-mix(in srgb, var(--p4) 80%, #fff) 36%, color-mix(in srgb, var(--p3) 60%, #fff) 46%, #FFF6C0 56%, transparent 72%);
  background-size: 260% 260%;
  background-position: var(--hx, 30%) var(--hy, 30%);
}

.vnline { display: flex; align-items: center; gap: 8px; }
.vnline b { font-family: var(--display); font-size: 24px; font-weight: 800; color: var(--jade-d); line-height: 1; }

.speak {
  border: 0;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--gold-l);
  box-shadow: 0 3px 0 var(--gold);
  cursor: pointer;
  display: grid;
  place-items: center;
  padding: 0;
}

.speak:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--gold); }

.kind { font-size: 11px; font-weight: 900; color: var(--ink-soft); }

.swatches {
  margin-top: auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-top: 1.5px dashed #E4D5B6;
  padding-top: 7px;
}

.dots { display: flex; gap: 4px; }
.dots i {
  width: 15px; height: 15px; border-radius: 4px; background: var(--c);
  box-shadow: inset 0 0 0 1.5px rgba(255, 255, 255, 0.6), 0 1px 2px rgba(0, 0, 0, 0.15);
}

.num { font-family: var(--display); font-weight: 800; font-size: 12px; color: var(--ink-soft); }

.back { transform: rotateY(180deg); }
.back .face-in { gap: 8px; padding: 10px; }
.photo { height: 190px; border-radius: 9px; overflow: hidden; background: #ccc; }
.photo img { width: 100%; height: 100%; object-fit: cover; display: block; }

.meta { display: grid; grid-template-columns: 1fr 1fr; gap: 5px; }
.meta div { background: var(--paper-2); border-radius: 8px; padding: 4px 8px; font-size: 11px; font-weight: 800; line-height: 1.25; }
.meta small { display: block; font-size: 9px; color: var(--ink-soft); letter-spacing: 0.4px; text-transform: uppercase; }

.note {
  width: 100%;
  flex: 1;
  min-height: 50px;
  resize: none;
  border: 2px dashed #E4D5B6;
  border-radius: 10px;
  background: transparent;
  font: 700 11.5px/1.4 var(--body);
  color: var(--ink);
  padding: 6px 8px;
}

.hint {
  text-align: center;
  font-size: 12px;
  font-weight: 800;
  color: var(--ink-soft);
  margin: 10px 0 0;
}

.card-actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.3rem;
  width: 100%;
  margin-top: 0.75rem;
}

/* --- NAV --- */

.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 480px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 2rem;
  padding: 0.9rem 0 calc(0.9rem + env(safe-area-inset-bottom, 0px));
  background: linear-gradient(180deg, transparent, var(--paper) 30%);
}

.navbtn {
  border: 0;
  background: var(--cream);
  width: 54px;
  height: 54px;
  border-radius: 20px;
  display: grid;
  place-items: center;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(59, 42, 32, 0.14);
}

.cam {
  border: 0;
  width: 72px;
  height: 72px;
  border-radius: 50%;
  cursor: pointer;
  background: radial-gradient(circle at 35% 30%, #FFF1B8 0, var(--gold) 55%, var(--gold-d));
  box-shadow: 0 0 0 6px var(--cream), 0 10px 20px rgba(184, 134, 30, 0.4);
  display: grid;
  place-items: center;
  transition: transform 0.12s;
}

.cam:active { transform: scale(0.94); }

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
