/* style.css — interface sobre : blanc / gris / noir + un accent discret. */
:root {
  --accent: #2563eb;
  /* accent discret (bleu) */
  --accent-soft: #dbeafe;
  --accent-faint: #eff6ff;
  --black-cell: #1f2937;
  /* gris très foncé (cases noires) */
  --border: #e5e7eb;
  --panel-bg: #fafafa;
  --text: #111827;
  --text-muted: #6b7280;
  --cell: 32px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  /* jamais de scrollbar de page (bande grise) : les zones scroilent en interne */
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text);
  background: #fff;
}

.app {
  display: flex;
  height: 100vh;
  height: 100dvh;
}

/* ---- panneau latéral ---- */
.panel {
  background: var(--bg-alt);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  box-shadow: 2px 0 8px rgba(0,0,0,0.02);
  z-index: 100;
  width: 320px;
  flex-shrink: 0;
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* mobile: panel hidden by default */
@media (max-width: 768px) {
  .panel {
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    transform: translateX(-100%);
    box-shadow: 10px 0 20px rgba(0,0,0,0.1);
  }

  .panel.open {
    transform: translateX(0);
  }
}

.panel-body {
  flex: 1;
  overflow-y: auto;
  padding-bottom: 20px;
}

.panel h1 {
  font-size: 20px;
  margin: 0 0 2px;
}

.panel .sub {
  color: var(--text-muted);
  font-size: 12px;
  margin: 0 0 18px;
}

/* ---- blocs de contenu ---- */
.block {
  margin: 16px;
  padding: 16px;
  background: var(--bg);
  border-radius: 12px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.03);
  border: 1px solid var(--border);
  margin-bottom: 0;
}
.block + .block {
  margin-top: 16px;
}

.block h2 {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-muted);
  margin: 0 0 8px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 4px;
}

.row {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 8px;
}

.row label {
  font-size: 13px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  flex: 1;
}

input[type="number"],
input[type="text"] {
  width: 100%;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
  background: #fff;
}

textarea {
  width: 100%;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  background: #fff;
  resize: vertical;
  font-family: inherit;
}

input[type="text"] {
  text-transform: uppercase;
  letter-spacing: .05em;
}

input:focus {
  outline: 2px solid var(--accent-soft);
  border-color: var(--accent);
}

.btn {
  display: block;
  width: 100%;
  padding: 8px 10px;
  margin-bottom: 7px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
}

.btn:hover {
  background: var(--accent-faint);
}

.btn:active {
  background: var(--accent-soft);
}

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

.btn-primary:hover {
  background: #1d4ed8;
}

.opt {
  display: block;
  font-size: 13px;
  margin: 6px 0;
  cursor: pointer;
}

.opt input {
  vertical-align: middle;
}

.stat {
  font-size: 14px;
  margin-top: 6px;
}

.stat .hint {
  font-size: 12px;
  color: var(--text-muted);
}

.stat .ok {
  color: #15803d;
}

.stat .bad {
  color: #b91c1c;
}

.status {
  font-size: 12px;
  color: var(--text-muted);
  min-height: 16px;
  margin-top: 4px;
}

.help-note {
  font-size: 11.5px;
  color: var(--text-muted);
  line-height: 1.5;
  margin: 6px 0 0;
}

.help ul {
  margin: 0;
  padding-left: 16px;
  font-size: 12.5px;
  color: var(--text-muted);
  line-height: 1.7;
}

.help li {
  margin: 1px 0;
}

.help .note {
  font-size: 11.5px;
  color: var(--text-muted);
  margin-top: 8px;
}

/* ---- grille ---- */
.grid-area {
  flex: 1;
  position: relative;
  overflow: hidden;
  min-width: 0;
}

#gridView {
  position: absolute;
  inset: 0;
  overflow: hidden;
}

.grid {
  display: grid;
  gap: 1px;
  width: max-content;
  /* épouse les colonnes — sinon le fond gris remplit tout le parent (bande grise) */
  background: var(--border);
  border: 1px solid var(--border);
  outline: none;
  user-select: none;
  transform-origin: 0 0;
}

.cell {
  width: var(--cell);
  height: var(--cell);
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: calc(var(--cell) * 0.59);
  font-weight: 600;
  text-transform: uppercase;
  cursor: pointer;
  position: relative;
  padding: 5%;
}

.cell.black {
  background: var(--black-cell);
}

/* mot invalide (slot complet absent du dictionnaire) : bordure rouge */
.cell.invalid {
  box-shadow: inset 0 0 0 2px #dc2626;
}

.cell.filled.user {
  color: var(--accent);
}

/* lettres tapées : accent discret */
.cell.filled:not(.user) {
  color: var(--text);
}

/* lettres du solveur : noir */

/* case verrouillée : overlay semi-transparent à rayures jaunes diagonales (45°) */
.cell.locked::after {
  content: "";
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(45deg,
      rgba(250, 204, 21, 0.40) 0px,
      rgba(250, 204, 21, 0.40) 5px,
      rgba(250, 204, 21, 0) 5px,
      rgba(250, 204, 21, 0) 10px);
  pointer-events: none;
}

/* suggestion courante (prévisualisation, mode Tab) : bleu clair + italique */
.cell.preview {
  color: #60a5fa;
  font-style: italic;
  font-weight: 500;
}

.cell.cursor {
  outline: 3px solid var(--accent);
  outline-offset: -2px;
  z-index: 5;
  box-shadow: inset 0 0 0 2px rgba(255,255,255,0.8);
  position: relative;
}
.grid:focus .cell.cursor {
  outline-color: var(--accent);
}

.cell.cursor.cursor-h::before {
  content: '';
  position: absolute;
  top: 50%;
  right: -6px;
  transform: translateY(-50%);
  border-top: 6px solid transparent;
  border-bottom: 6px solid transparent;
  border-left: 6px solid var(--accent);
  z-index: 6;
}
.cell.cursor.cursor-v::before {
  content: '';
  position: absolute;
  bottom: -6px;
  left: 50%;
  transform: translateX(-50%);
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
  border-top: 6px solid var(--accent);
  z-index: 6;
}

.cell.selected {
  background: var(--accent-faint);
}

.cell.selected.black {
  background: #4b5563;
}

.cell .letter {
  line-height: 1;
}

/* ---- définitions dans la case noire (mots fléchés) ---- */
.cell.black.has-def {
  background: var(--black-cell);
  position: relative;
  overflow: visible;
  z-index: 5;
}

/* 0 definition : emoji */
.cell.black.no-def {
  display: flex;
  align-items: center;
  justify-content: center;
}

.cell.black.no-def .f-emoji {
  font-size: calc(var(--cell) * 0.45);
  pointer-events: none;
}

/* Flèche indicatrice : part du BORD de la case noire (ou de la zone), pointe vers le mot. */
.cell.black .f-arrow {
  position: absolute;
  color: #222;
  font-weight: 700;
  line-height: 1;
  z-index: 2;
  font-size: calc(var(--cell) * 0.30);
  pointer-events: none;
}

.cell.black .f-arrow-h {
  /* mot à droite : flèche au bord droit, vers l'extérieur */
  left: 100%;
  margin-left: 2px;
  top: 50%;
  transform: translateY(-50%) translateX(-30%);
}

.cell.black .f-arrow-v {
  /* mot en dessous : flèche au bord bas, vers l'extérieur */
  top: 100%;
  margin-top: 2px;
  left: 50%;
  transform: translateX(-50%) translateY(-30%);
}

/* Texte de base */
.cell.black .f-text {
  background: transparent;
  border: none;
  outline: none;
  font-family: inherit;
  color: #e5e7eb;
  font-size: calc(var(--cell) * 0.16);
  line-height: 1.05;
  word-break: break-word;
  overflow: hidden;
  text-transform: none;
  font-weight: 400;
  z-index: 1;
  text-align: center;
  width: 100%;
}

.cell.black .f-text:empty::before {
  content: attr(data-placeholder);
  color: rgba(255, 255, 255, 0.3);
  pointer-events: none;
}

/* 1 definition : centré */
.cell.black.has-def-single {
  display: flex;
  align-items: center;
  justify-content: center;
}

.cell.black.has-def-single .f-text {
  width: 100%;
}

.cell.black.has-def-single .f-text-h {}

.cell.black.has-def-single .f-text-v {}

/* 2 definitions : layout flex split */
.cell.black.has-def-split {
  display: flex;
  flex-direction: column;
}

.cell.black.has-def-split .def-zone {
  flex: 1;
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.cell.black.has-def-split .def-zone-h::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 10%;
  width: 80%;
  height: 1px;
  background: rgba(255, 255, 255, 0.4);
}

.cell.black.has-def-split .f-text {
  width: 100%;
  padding: 1px 2px;
}

.cell.black.has-def-split .f-text-h {}

.cell.black.has-def-split .f-text-v {}

.cell.black.has-def-split .f-arrow-h {
  top: 25%;
}

.cell.black:hover {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
  z-index: 10;
}

/* ---- panneau : en-tête (bouton repli, mobile) ---- */
.panel-head {}

.panel-title {}

.panel-toggle {
  display: none;
}

/* ---- clavier virtuel (caché sur desktop, affiché en mobile) ---- */
.keyboard {
  display: none;
}

.panel-toggle {
  display: none;
}

/* hamburger caché sur desktop */

/* ============================================================ */
/*  MOBILE (écrans étroits)                                     */
/* ============================================================ */
@media (max-width: 899.98px) {
  .app {
    flex-direction: column;
    padding-top: env(safe-area-inset-top, 0px);
    padding-left: env(safe-area-inset-left, 0px);
    padding-right: env(safe-area-inset-right, 0px);
  }

  /* panneau : bande horizontale en haut, repliable */
  .panel {
    width: 100%;
    flex: 0 0 auto;
    max-height: 40vh;
    overflow-y: auto;
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding: 8px 12px;
    -webkit-overflow-scrolling: touch;
  }

  .panel-head {
    display: flex;
    align-items: center;
    gap: 10px;
  }

  .panel-title {
    flex: 1 1 auto;
    min-width: 0;
  }

  .panel-title h1 {
    font-size: 18px;
    margin: 0 0 2px;
  }

  .panel-title .sub {
    margin: 0;
  }

  .panel-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 40px;
    width: 40px;
    height: 40px;
    font-size: 22px;
    line-height: 1;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #fff;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }

  /* état replié : seule la barre d'en-tête reste visible */
  .app.panel-collapsed .panel {
    max-height: 56px;
    overflow: hidden;
  }

  .app.panel-collapsed .panel-body {
    display: none;
  }

  /* la grille prend tout l'espace restant */
  .grid-area {
    flex: 1 1 auto;
    min-height: 0;
  }

  #gridView {
    touch-action: none;
  }

  /* clavier virtuel en bas */
  .keyboard {
    display: block;
    flex: 0 0 auto;
    background: #f3f4f6;
    border-top: 1px solid var(--border);
    padding: 6px 6px 6px;
    padding-bottom: calc(6px + env(safe-area-inset-bottom, 0px));
    user-select: none;
    -webkit-user-select: none;
  }

  .kb-row {
    display: flex;
    gap: 4px;
    margin-bottom: 4px;
  }

  .kb-row:last-child {
    margin-bottom: 0;
  }

  .kb-key {
    flex: 1 1 0;
    min-width: 0;
    min-height: 40px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: #fff;
    color: var(--text);
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
  }

  .kb-key:active {
    background: var(--accent-soft);
  }

  .kb-key.kb-wide {
    flex: 1.6 1 0;
  }

  .kb-special .kb-key {
    font-size: 15px;
  }
}

/* aide « clavier » uniquement sur écran tactile */
.kb-hint {
  display: none;
}

@media (pointer: coarse) {
  .kb-hint {
    display: block;
    text-align: center;
    font-size: 11px;
    color: var(--text-muted);
    margin: 0 0 6px;
  }

  #gridView {
    touch-action: none;
  }
}