/* ==========================================================================
   Patate — style « carnet à dessin » : papier quadrillé, traits de crayon,
   écriture à la main et couleurs de surligneur.
   ========================================================================== */

@font-face {
  font-family: "Patrick Hand";
  src: url("../fonts/patrick-hand-latin.woff2") format("woff2");
  font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Patrick Hand";
  src: url("../fonts/patrick-hand-latin-ext.woff2") format("woff2");
  font-display: swap;
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: "Gochi Hand";
  src: url("../fonts/gochi-hand-latin.woff2") format("woff2");
  font-display: swap;
}

:root {
  color-scheme: light;
  --paper: #fffcf2;
  --paper-card: #ffffff;
  --grid: rgba(70, 130, 210, 0.15);
  --margin-line: rgba(232, 85, 100, 0.4);
  --ink: #2c2a35;
  --ink-soft: #6a6476;
  --yellow: #ffe066;
  --pink: #ffa8c9;
  --green: #a6e8a6;
  --blue: #a9d4ff;
  --orange: #ffc078;
  --red: #e5484d;
  --stage-paper: #e8f6ec;           /* fond de la zone de jeu (aussi dans game.js) */
  --stage-frame: #a6e8a6;           /* cadre vert autour de la zone de jeu */
  --hand: "Patrick Hand", "Comic Sans MS", "Chalkboard SE", cursive;
  --title: "Gochi Hand", "Patrick Hand", "Comic Sans MS", cursive;
  /* bords « tracés à la main » */
  --wobble: 255px 15px 225px 15px / 15px 225px 15px 255px;
  --wobble-alt: 15px 255px 15px 225px / 225px 15px 255px 15px;
  --wobble-card: 22px 8px 26px 6px / 8px 24px 6px 22px;
  --shadow: 3px 4px 0 var(--ink);
  --shadow-big: 6px 7px 0 var(--ink);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  background-color: var(--paper);
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 28px 28px;
  color: var(--ink);
  font: 20px/1.45 var(--hand);
  overflow-x: hidden;
}
/* trait rouge de marge, comme sur une feuille de cahier */
body::before {
  content: "";
  position: fixed;
  top: 0; bottom: 0; left: 44px;
  border-left: 2px solid var(--margin-line);
  pointer-events: none;
  z-index: -1;
}

h1, h2, h3 { font-family: var(--title); font-weight: 400; line-height: 1.15; letter-spacing: 0.01em; }
h1 { font-size: 2.6rem; margin: 12px 0; }
h2 { font-size: 1.7rem; margin: 24px 0 10px; }
p { margin: 8px 0; }
a { color: var(--ink); text-decoration-color: var(--pink); text-decoration-thickness: 3px; text-underline-offset: 3px; }
a:hover { text-decoration-color: var(--ink); }
kbd {
  font: 0.8em var(--hand);
  display: inline-block;
  padding: 0 7px;
  border: 1.5px solid var(--ink);
  border-radius: 6px 9px 5px 8px;
  box-shadow: 1px 2px 0 var(--ink);
  background: var(--paper-card);
  line-height: 1.35;
}

.small { font-size: 0.85rem; }
.muted { color: var(--ink-soft); }
.error { color: var(--red); }
.push { margin-left: auto; }

/* ---- Boutons --------------------------------------------------------------- */
button, .button, .file-btn {
  font: inherit;
  font-size: 1.05rem;
  color: var(--ink);
  background: var(--paper-card);
  border: 2.5px solid var(--ink);
  border-radius: var(--wobble);
  box-shadow: var(--shadow);
  padding: 5px 16px;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: transform 0.12s ease, box-shadow 0.12s ease, background-color 0.12s ease;
  line-height: 1.3;
}
button:hover, .button:hover, .file-btn:hover { transform: translateY(-2px) rotate(-1.2deg); }
button:active, .button:active, .file-btn:active { transform: translate(2px, 3px); box-shadow: 1px 1px 0 var(--ink); }
button:focus-visible, .button:focus-visible, .file-btn:focus-within,
select:focus-visible, input:focus-visible, a:focus-visible {
  outline: 3px dashed var(--ink);
  outline-offset: 4px;
}
.primary { background: var(--yellow); }
.danger { background: #ffe1e1; color: #a1262b; border-color: #a1262b; box-shadow: 3px 4px 0 #a1262b; }
button.link {
  background: none; border: none; box-shadow: none; padding: 0 4px; border-radius: 0;
  text-decoration: underline wavy var(--pink); text-underline-offset: 4px; font-size: inherit;
}
button.link:hover { transform: none; text-decoration-color: var(--ink); }
.file-btn { position: relative; }
.file-btn.small { font-size: 0.9rem; padding: 3px 12px; }
.file-btn input { position: absolute; opacity: 0; width: 1px; height: 1px; pointer-events: none; }

/* ---- Champs ---------------------------------------------------------------- */
input[type=text], input[type=password], select {
  font: inherit;
  color: var(--ink);
  background: var(--paper-card);
  border: 2.5px solid var(--ink);
  border-radius: var(--wobble-alt);
  padding: 6px 12px;
  min-width: 0;
}
select { cursor: pointer; }
input[type=checkbox] { width: 20px; height: 20px; accent-color: var(--ink); flex: none; }
::placeholder { color: #a7a1b2; }

/* ---- Cartes (feuilles scotchées) ----------------------------------------- */
.card {
  position: relative;
  background: var(--paper-card);
  border: 2.5px solid var(--ink);
  border-radius: var(--wobble-card);
  box-shadow: var(--shadow-big);
  padding: 8px 20px 18px;
  margin: 26px 0;
}
.card::before {             /* bout de scotch */
  content: "";
  position: absolute;
  top: -13px; left: 50%;
  width: 92px; height: 24px;
  transform: translateX(-50%) rotate(-3deg);
  background: rgba(255, 224, 102, 0.75);
}
.card.stack { padding-top: 18px; }
.card h2 { margin: 12px 0 8px; font-size: 1.5rem; }
.status-msg { color: #1f7a3d; min-height: 1.5em; margin: 8px 0 0; }
.status-msg.error { color: var(--red); }

/* ---- Bandeau du haut : nom + état de connexion ---------------------------- */
.topbar {
  display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center;
  padding: 10px 20px 12px 60px;
  background: var(--paper);
  border-bottom: 3px solid var(--ink);
}
.topbar.is-admin { box-shadow: 0 5px 0 var(--green); }
.brand {
  font-family: var(--title);
  font-size: 2rem;
  color: var(--ink);
  text-decoration: none;
  display: inline-flex; align-items: center; gap: 6px;
  transform: rotate(-2deg);
}
.brand-mark { display: block; width: 40px; height: 40px; transform: rotate(-8deg); }
.status {
  display: inline-flex; align-items: center; gap: 8px;
  font-size: 1rem;
  border: 2px dashed var(--ink-soft);
  border-radius: var(--wobble);
  padding: 1px 12px;
  color: var(--ink-soft);
  background: var(--paper-card);
}
.status .dot { width: 10px; height: 10px; border-radius: 50%; border: 2px solid currentColor; }
.status-on { color: var(--ink); border: 2px solid var(--ink); background: var(--green); }
.status-on .dot { background: var(--ink); }
.topbar-actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-left: auto; }
.topbar-actions form { margin: 0; }

/* ---- Jeu : zone de jeu + lanceur à droite ---------------------------------- */
.game {
  --panel-w: 290px;
  --gap: 28px;
  display: grid;
  grid-template-columns: auto var(--panel-w);
  gap: var(--gap);
  justify-content: center;
  align-items: start;
  padding: 22px 16px 28px 60px;
}
.stage {
  position: relative;
  width: min(calc(100vw - var(--panel-w) - var(--gap) - 100px), calc((100dvh - 130px) * 800 / 900), 800px);
  min-width: 280px;
  aspect-ratio: 800 / 900;
  border: 3px solid var(--ink);
  border-radius: 18px 8px 22px 10px / 10px 20px 8px 18px;
  /* cadre vert cerné d'encre, avec l'ombre décalée façon feutre */
  box-shadow: 0 0 0 8px var(--stage-frame), 0 0 0 10.5px var(--ink), 7px 8px 0 10.5px var(--ink);
  background: var(--stage-paper);
  overflow: hidden;
  margin: 11px;                     /* place pour le cadre */
}
#game { width: 100%; height: 100%; display: block; touch-action: none; cursor: crosshair; }
.start {
  position: absolute; inset: 0;
  border: none; border-radius: 0; box-shadow: none;
  background: rgba(232, 246, 236, 0.72);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
}
.start:hover, .start:active { transform: none; box-shadow: none; }
.start:hover .start-title { transform: rotate(2deg) scale(1.04); }
.start[hidden] { display: none; }
.start-title {
  font-family: var(--title);
  font-size: clamp(3rem, 9vw, 5.5rem);
  transform: rotate(-3deg);
  transition: transform 0.15s ease;
  background: linear-gradient(100deg, transparent 3%, var(--yellow) 6%, var(--yellow) 92%, transparent 96%) no-repeat 0 82% / 100% 45%;
  padding: 0 18px;
}
.start-sub { font-size: 1.5rem; }
.start-note { color: var(--ink-soft); font-size: 1rem; }

.launcher {
  position: sticky; top: 16px;
  display: flex; flex-direction: column; gap: 16px;
  background: var(--paper-card);
  border: 2.5px solid var(--ink);
  border-radius: var(--wobble-card);
  box-shadow: var(--shadow-big);
  padding: 22px 20px 18px;
}
.launcher::before {          /* scotch rose */
  content: ""; position: absolute; top: -12px; right: 26px;
  width: 80px; height: 22px; transform: rotate(4deg);
  background: rgba(255, 168, 201, 0.75);
}
.launcher-title { margin: 0; font-size: 2rem; transform: rotate(-1.5deg); }
.field { display: flex; flex-direction: column; gap: 6px; }
.field-label { color: var(--ink-soft); font-size: 1rem; }
.field select { width: 100%; }
.drop {
  font-family: var(--title);
  font-size: 1.6rem;
  background: var(--orange);
  padding: 12px 14px;
  flex-direction: column;
  gap: 2px;
  box-shadow: 4px 5px 0 var(--ink);
}
.drop kbd { font-size: 0.9rem; }
.reset { align-self: flex-start; }
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.switch {
  width: 64px; height: 34px; padding: 0;
  border-radius: 999px 900px 999px 950px;
  background: #eee9f3;
  justify-content: flex-start;
  box-shadow: 2px 3px 0 var(--ink);
  flex: none;
}
.switch .knob {
  width: 22px; height: 22px; margin: 0 4px;
  border-radius: 50% 45% 52% 48%;
  background: var(--paper-card);
  border: 2.5px solid var(--ink);
  transition: transform 0.15s ease;
}
.switch[aria-checked="true"] { background: var(--green); }
.switch[aria-checked="true"] .knob { transform: translateX(26px); background: var(--ink); }
.switch:hover { transform: rotate(-2deg); }
.segmented { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; }
.segmented button {
  font-size: 0.95rem; padding: 2px 0; min-width: 0;
  box-shadow: 2px 2px 0 var(--ink);
}
.segmented button[aria-pressed="true"] { background: var(--pink); transform: rotate(-3deg); }
.launcher-tip {
  margin: 0; padding-top: 12px;
  border-top: 2px dashed #cfc8d8;
  color: var(--ink-soft); font-size: 0.95rem;
}

@media (max-width: 900px) {
  body::before { left: 14px; }
  .topbar { padding-left: 28px; }
  .game { grid-template-columns: 1fr; justify-items: center; padding: 16px 16px 24px 28px; }
  .stage { width: min(100%, calc((100dvh - 130px) * 800 / 900), 800px); min-width: 0; }
  .launcher { position: relative; top: 0; width: min(100%, 520px); }
}

/* ---- Settings ---------------------------------------------------------------- */
.panel { max-width: 880px; margin: 0 auto; padding: 18px 20px 40px 64px; }
.panel.narrow { max-width: 520px; padding-top: 6vh; }
.crumbs { margin: 6px 0 0; color: var(--ink-soft); font-size: 1rem; }
.title-row { display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: center; }
.title-row h1 { margin: 6px 0; }
.steps { margin: 0 0 16px; padding-left: 1.5em; display: grid; gap: 6px; }
.steps li::marker { font-family: var(--title); font-size: 1.2em; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.stack label { display: flex; flex-direction: column; gap: 4px; }
.row { display: flex; gap: 10px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.row input[type=text] { flex: 1; }
.check { display: inline-flex; gap: 10px; align-items: center; cursor: pointer; }
.stack label.check { flex-direction: row; align-items: center; }

.pack-list { list-style: none; padding: 0; display: grid; gap: 14px; }
.pack-list li {
  display: flex; gap: 12px; align-items: center; flex-wrap: wrap;
  background: var(--paper-card);
  border: 2.5px solid var(--ink);
  border-radius: var(--wobble-card);
  box-shadow: var(--shadow);
  padding: 10px 16px;
}
.pack-list li:nth-child(odd) { transform: rotate(-0.4deg); }
.pack-list li:nth-child(even) { transform: rotate(0.4deg); }
.pack-info { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.pack-name { font-family: var(--title); font-size: 1.5rem; text-decoration: none; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; }
.pack-actions { display: flex; gap: 10px; margin-left: auto; }
.tag {
  font-size: 0.85rem;
  color: var(--ink);
  border: 1.5px solid var(--ink);
  border-radius: var(--wobble);
  padding: 0 9px;
  white-space: nowrap;
  background: #f3eff7;
}
.tag-private { background: var(--pink); }
.tag-public { background: var(--green); }

.slots { list-style: none; padding: 0; display: grid; gap: 14px; }
.slot {
  display: flex; gap: 16px; align-items: center;
  background: var(--paper-card);
  border: 2.5px solid var(--ink);
  border-radius: var(--wobble-card);
  box-shadow: var(--shadow);
  padding: 10px 14px;
}
.slot-img {
  position: relative; flex: none; width: 80px; height: 80px;
  border: 2.5px dashed var(--ink-soft);
  border-radius: 50% 46% 52% 48%;
  background: var(--paper);
  display: grid; place-items: center;
}
.slot-img img { width: 86%; height: 86%; object-fit: contain; }
.slot-img.inherited img { opacity: 0.4; filter: grayscale(0.7); }
.slot-num {
  position: absolute; bottom: -6px; right: -6px;
  font-family: var(--title); font-size: 1rem;
  width: 28px; height: 28px; display: grid; place-items: center;
  background: var(--yellow); border: 2px solid var(--ink); border-radius: 50%;
}
.slot-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.slot-body p { margin: 0; }
.label-input { max-width: 280px; }

@media (max-width: 600px) {
  h1 { font-size: 2.1rem; }
  .panel { padding-left: 28px; padding-right: 16px; }
  .pack-actions { margin-left: 0; }
  .slot { align-items: flex-start; }
  .slot-img { width: 64px; height: 64px; }
}

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