/* 紋の間 — interface (reprise de 升の間).
   Même socle que 仮, 千, 篆, 粋, 色, 字 et 升 : le papier domine, hiérarchie par
   l'espacement, aucune couleur qui ne soit fonctionnelle, angles vifs.
   La seule couleur est l'encre du kamon, choisie par la personne ; le vermillon marque le tracé. */

:root {
  --papier: #f6f3ec;
  --encre: #161310;
  --discret: #8b8378;
  --trait: rgba(22, 19, 16, 0.12);
  --fond-panneau: #fbf9f4;
  --shu: #b8372a;
}

* { box-sizing: border-box; margin: 0; padding: 0 }
html, body { height: 100% }

body {
  background: var(--papier);
  color: var(--encre);
  font-family: 'Hiragino Mincho ProN', 'Yu Mincho', 'Songti SC', Georgia, serif;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}

#scene { display: grid; grid-template-columns: 1fr 320px; height: 100vh; overflow: hidden }
#scene > * { min-height: 0; min-width: 0 }

#stage { display: flex; flex-direction: column; align-items: center; justify-content: center; min-width: 0; min-height: 0; padding: 2rem }

/* ---- la feuille ---- */
#feuille-cadre { position: relative; flex: 1 1 auto; width: 100%; min-height: 0; display: flex; align-items: center; justify-content: center }
/* pendant qu'une police arrive (comme 篆の間) */
.attente { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); display: flex; flex-direction: column; align-items: center; gap: 1rem;
  padding: 1.4rem 1.8rem; background: rgba(251, 249, 244, 0.94); border: 1px solid var(--trait); z-index: 2 }
.attente[hidden] { display: none }
.attente-sceau { width: 2.4rem; height: 2.4rem; border: 2px solid var(--shu); animation: attente-tourne 1.6s cubic-bezier(.6,0,.4,1) infinite }
.attente-txt { white-space: pre-line; font-size: 0.82rem; letter-spacing: 0.1em; color: var(--encre); text-align: center; line-height: 1.8 }
@keyframes attente-tourne { 0% { transform: rotate(0deg) } 50% { transform: rotate(90deg); background: rgba(184,55,42,.12) } 100% { transform: rotate(180deg) } }
@media (prefers-reduced-motion: reduce) { .attente-sceau { animation: none } }
select.chargement { animation: pouls 0.9s ease-in-out infinite }
@keyframes pouls { 50% { border-color: var(--shu) } }
#feuille { display: block; border: 1px solid var(--trait) }
.sous-feuille { flex: none; padding-top: 0.9rem; font-size: 0.8rem; letter-spacing: 0.08em; color: var(--encre);
  display: flex; align-items: flex-end; justify-content: center; gap: 1.4rem; flex-wrap: wrap }
/* le kamon presque à taille réelle (1 cm ≈ 38 px à l'écran) : ce qu'on lit encore, ce qui disparaît */
.petits { display: flex; align-items: flex-end; gap: 0.9rem }
.petit { display: flex; flex-direction: column; align-items: center; gap: 0.2rem }
.petit canvas { display: block; width: 38px; height: 38px }
.petit canvas#v2 { width: 76px; height: 76px }
.petit small { font-size: 0.7rem; color: var(--encre) }

/* ---- les modèles : une vignette par kamon ---- */
.modeles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1px; background: var(--trait); border: 1px solid var(--trait); margin-bottom: 0.4rem }
.modeles button { font: inherit; background: var(--fond-panneau); border: 0; padding: 0.45rem 0.2rem 0.35rem; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 0.25rem; color: var(--encre) }
.modeles button:hover { background: var(--papier) }
.modeles canvas { width: 44px; height: 44px; display: block }
.modeles span { font-size: 0.74rem; letter-spacing: 0.05em }
.modeles small { font-size: 0.62rem; color: var(--encre); opacity: 0.75 }
.choix { flex-wrap: wrap }
.sous { border-left: 1px solid var(--trait); padding: 0.3rem 0 0.2rem 0.9rem; margin: 0 0 0.8rem 0.3rem }
.envoi { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1px; background: var(--trait); border: 1px solid var(--trait); margin-top: 0.4rem }
.envoi button { font: inherit; cursor: pointer; background: var(--fond-panneau); color: var(--encre); border: 0; padding: 0.5rem 0.3rem;
  display: flex; flex-direction: column; align-items: center; gap: 0.15rem }
.envoi button > span { font-size: 0.8rem } .envoi button small { font-size: 0.66rem; letter-spacing: 0.05em }
.envoi button:hover { background: var(--encre); color: var(--papier) }

/* ---- le panneau ---- */
#panel { background: var(--fond-panneau); border-left: 1px solid var(--trait);
  overflow-y: auto; padding: 1.4rem 1.2rem 3rem }

.marque { padding-bottom: 1.4rem; border-bottom: 1px solid var(--trait); margin-bottom: 1.2rem }
.marque-ligne { display: flex; align-items: baseline; justify-content: space-between; gap: 0.6rem }
.marque-kanji { font-size: 1.24rem; font-weight: 400; letter-spacing: 0.14em }
.marque-nom { font-size: 0.66rem; letter-spacing: 0.22em; color: var(--discret) }
.langues { display: flex; gap: 0.45rem }
.lang-opt { font: inherit; font-size: 0.68rem; letter-spacing: 0.1em; background: none; border: 0;
  color: var(--discret); cursor: pointer; padding: 0.1rem 0 }
.lang-opt.actif { color: var(--encre); border-bottom: 1px solid var(--encre) }

.bloc { display: flex; gap: 0.5rem; margin-bottom: 1rem }
.action { flex: 1 1 auto; font: inherit; font-size: 0.8rem; letter-spacing: 0.1em;
  padding: 0.55rem 0.4rem; background: var(--fond-panneau); border: 1px solid var(--trait);
  color: var(--encre); cursor: pointer; transition: background 0.2s, color 0.2s, border-color 0.2s }
.action:hover { background: var(--encre); color: var(--papier); border-color: var(--encre) }
.action.majeure { background: var(--encre); color: var(--papier); border-color: var(--encre) }
.action.majeure:hover { background: var(--shu); border-color: var(--shu) }
.modele { margin-bottom: 1.6rem }

.section { margin-bottom: 1.6rem }
.section-tete { display: flex; align-items: center; gap: 0.55rem; font-weight: 400;
  padding-bottom: 0.45rem; border-bottom: 1px solid var(--encre); margin-bottom: 0.9rem }
.sec-num { background: var(--encre); color: var(--papier); font-size: 0.62rem;
  letter-spacing: 0.06em; padding: 0.1rem 0.42rem; line-height: 1.5 }
.sec-titre { color: var(--encre); font-size: 0.8rem; letter-spacing: 0.22em }

select { width: 100%; font: inherit; font-size: 0.82rem; padding: 0.45rem 0.5rem;
  background: var(--papier); border: 1px solid var(--trait); color: var(--encre); border-radius: 0 }

.note { font-size: 0.8rem; line-height: 1.75; color: var(--encre); margin: 0.2rem 0 0.8rem }
textarea.texte { width: 100%; font: inherit; font-size: 1rem; line-height: 1.6; padding: 0.45rem 0.5rem; resize: vertical;
  background: var(--papier); border: 1px solid var(--trait); color: var(--encre); border-radius: 0 }
.etiquette { font-size: 0.8rem; color: var(--encre); margin: 0.2rem 0 0.35rem }

.choix { display: flex; gap: 0.35rem; margin-bottom: 0.8rem }
.choix button { flex: 1 1 auto; font: inherit; font-size: 0.78rem; padding: 0.4rem 0.2rem;
  background: var(--papier); border: 1px solid var(--trait); color: var(--encre); cursor: pointer }
.choix button.actif { background: var(--encre); color: var(--papier); border-color: var(--encre) }

.choix.choix-col { flex-direction: column }
.case { display: flex; align-items: center; gap: 0.45rem; font-size: 0.82rem; padding: 0.3rem 0;
  color: var(--encre); cursor: pointer }
.case input { accent-color: var(--encre) }

.glissiere { display: grid; grid-template-columns: 1fr auto; gap: 0.1rem 0.5rem; align-items: center;
  margin-bottom: 0.7rem; font-size: 0.82rem; color: var(--encre) }
.glissiere input[type=range] { grid-column: 1 / -1; width: 100%; accent-color: var(--encre) }
.glissiere .val { font-size: 0.8rem; color: var(--encre); font-variant-numeric: tabular-nums }
.glissiere .bouts { grid-column: 1 / -1; display: flex; justify-content: space-between; font-size: 0.74rem; color: var(--encre); opacity: 0.7 }

.dimensions { display: flex; gap: 0.6rem; margin-bottom: 0.8rem }
.dimensions label { flex: 1 1 0; font-size: 0.8rem; display: flex; flex-direction: column; gap: 0.25rem }
.dimensions input { font: inherit; font-size: 0.85rem; padding: 0.35rem 0.4rem; width: 100%;
  background: var(--papier); border: 1px solid var(--trait); color: var(--encre); border-radius: 0 }

.nuancier { display: flex; align-items: center; gap: 0.35rem; margin-bottom: 0.8rem; flex-wrap: wrap }
.nuancier button { width: 1.6rem; height: 1.6rem; border: 1px solid var(--trait); cursor: pointer; padding: 0 }
.nuancier button.actif { outline: 2px solid var(--encre); outline-offset: 2px }
.nuancier input[type=color] { width: 2.2rem; height: 1.7rem; border: 1px solid var(--trait); background: none; padding: 0; cursor: pointer }

.version { font-size: 0.66rem; letter-spacing: 0.12em; color: var(--discret); padding-top: 0.6rem }
.credit { font-size: 0.72rem; padding-top: 0.4rem }
.credit a { color: var(--encre) }
.credit a:hover { color: var(--shu) }

.toast { position: fixed; left: 50%; bottom: 1.6rem; transform: translateX(-50%); z-index: 60;
  background: var(--encre); color: var(--papier); font-size: 0.82rem; letter-spacing: 0.08em; padding: 0.55rem 1rem }

@media (max-width: 820px) {
  /* comme kana, genji, ten, shiki et iki : la feuille reste en haut, le panneau défile dessous */
  #scene { display: block; height: auto; overflow: visible }
  #panel { border-left: 0 }
  #stage { position: sticky; top: 0; z-index: 5; height: 46svh; min-height: 15rem; padding: 0.7rem 1rem;
    background: var(--papier); border-bottom: 1px solid var(--trait) }
  .sous-feuille { padding-top: 0.4rem; font-size: 0.74rem; gap: 0.8rem }
  .petit.deux { display: none } /* trop grand pour l'aperçu collé en haut */
}
