/* ===== RESET & BASE ===== */
html {
  font-size: 1.25vw;
}
@media (min-width: 1200px) {
  html {
    font-size: 15px;
  }
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  scrollbar-color: #f89c1c #0000;
  scrollbar-width: thin;
}

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  background: #0f172a;
  color: #e0e0e0;
  line-height: 1.5;
}

main:not(:has(#opt-twitch:checked)) .require-twitch {
  display: none;
}
main:not(:has(#opt-show-chat-proposals:checked)) .guess-row:not(.player-guess) {
  display: none;
}

/* ===== HEADER ===== */
#app-header {
  height: 6rem;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

#logo {
  font-size: 2.4rem;
  font-weight: bold;
  color: #f89c1c;
}

/* ===== LAYOUT 3 COLONNES ===== */
#app {
  position: relative;
  height: calc(100vh - 6rem); /* 100vh - header */
  width: 80rem;
  overflow: hidden;
  transform: translateX(calc(50vw - 40rem));
}

/* Colonnes (3 colonnes de même taille) */
.col {
  position: absolute;
  height: 100%;
  width: 26rem;
  overflow: hidden;
  transform-origin: left center;
  transition:
    transform 0.8s ease-in-out,
    left 0.8s ease-in-out;
  transform: scaleX(0);
}

/* Positions fixes pour chaque colonne */
.col-1, #app[data-page="game"] .col-2 {
  left: 0.5rem;
}
.col-2, .col-3, #app[data-page="score"] .col-4, #app[data-page="error"] .col-error {
  left: 27rem;
}
.col-4, .col-5, #app[data-page="home"] .col-3, #app[data-page="game"] .col-6, .col-error {
  left: 53.5rem;
}
.col-6 {
  left: 80rem;
}

/* Visibilité des colonnes par page */
#app[data-page="home"] .col-1,
#app[data-page="home"] .col-2,
#app[data-page="home"] .col-5,
#app[data-page="game"] .col-2,
#app[data-page="game"] .col-3,
#app[data-page="game"] .col-6,
#app[data-page="score"] .col-1,
#app[data-page="score"] .col-4,
#app[data-page="score"] .col-5 ,
#app[data-page="error"] .col-1,
#app[data-page="error"] .col-error,
#app[data-page="error"] .col-5 {
  transform: scaleX(1);
}

/* ===== COLONNE 1 : PARAMÈTRES ===== */
.col-1 {
  display: flex;
  flex-direction: column;
}

.settings {
  display: flex;
  flex-direction: column;
  gap: 0.625rem; /* 10px en rem */
}

.settings h2 {
  color: #f89c1c;
  margin-bottom: 0.3125rem; /* 5px en rem */
}

.twitch-options,
.game-options {
  display: flex;
  flex-direction: column;
  gap: 0.3125rem; /* 5px en rem */
  padding: 0.3125rem; /* 5px en rem */
  border-radius: 0.375rem; /* 6px en rem */
}

/* ===== ÉLÉMENTS DE FORMULAIRE ===== */
input[type="text"],
input[type="number"],
select {
  background: #1a233a;
  border: 0.0625rem solid #2a3a5a; /* 1px en rem */
  color: #e0e0e0;
  padding: 0.3125rem; /* 5px en rem */
  border-radius: 0.375rem; /* 6px en rem */
  font-size: 1rem;
  transition: all 0.2s;
  width: 100%;
}

input[type="text"]:focus,
input[type="number"]:focus,
select:focus {
  border-color: #ff9500;
  box-shadow: 0 0 0 0.125rem rgba(255, 149, 0, 0.2); /* 2px en rem */
  outline: none;
}

input[type="checkbox"] {
  appearance: none; /* Désactive le style natif */
  width: 1.5rem;
  height: 1.5rem;
  background: #2a3a5a; /* Bleu moyen */
  border-radius: 0.4rem;
  cursor: pointer;
  transition: background 0.2s;
  vertical-align: middle;
}

input[type="checkbox"]:checked {
  background: #ff9500; /* Orange */
  position: relative;
}

input[type="checkbox"]:checked::after {
  content: "✓";
  position: absolute;
  color: white;
  font-size: 12px;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -55%);
}

/* Boutons */
button {
  background: #ff9500;
  border: none;
  color: #0f172a;
  padding: 0.5rem 1rem;
  border-radius: 0.6rem;
  font-weight: bold;
  cursor: pointer;
  transition: all 0.2s;
  font-size: 1rem;
}

button:hover {
  background: #e68a00;
  transform: scale(1.02);
}

#btn-new-game {
  padding: 0.5rem;
  font-size: 3rem;
  background: #ff9f18;
  width: 25.4rem;
  margin: 0.3rem;
}

/* ===== COLONNE 2 : JEU ===== */
.col-2 {
  display: flex;
  flex-direction: column;
}

.game {
  display: flex;
  flex-direction: column;
  height: 100%;
  gap: 1rem;
}

.game-grid {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  overflow-y: auto;
  width: 26rem;
  margin: 0;
}

#grid-history {
  display: flex;
  flex-direction: column-reverse;
  gap: 0.2rem; /* 5px en rem */
  overflow-y: auto;
  scrollbar-width: none;
  max-height: calc(100vh - 20rem);
}

#grid-input {
  display: flex;
  justify-content: center;
  gap: 0.2rem; /* 5px en rem */
  min-height: 2.4rem; /* 30px en rem */
}

.letter-box {
  width: 2.8125rem; /* 45px en rem */
  height: 2.8125rem; /* 45px en rem */
  border: 0.125rem solid #444; /* 2px en rem */
  border-radius: 0.375rem; /* 6px en rem */
  display: flex;
  justify-content: center;
  align-items: center;
  font-weight: bold;
  font-size: 1.3rem;
  background: #333;
  color: #e0e0e0;
  user-select: none;
  transition: all 0.2s;
}

.letter-box.filled {
  background: #444;
}

.letter-box.correct {
  background: #f89c1c;
  border-color: #f89c1c;
  color: white;
}

.letter-box.misplaced {
  background: #ffb347;
  border-color: #ffb347;
  color: black;
}

.letter-box.absent {
  background: #3a3a3c;
  border-color: #555;
  color: #787c7e;
}

/* Clavier virtuel */
#keyboard {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  margin: auto 0 1.5rem 0;
}

.keyboard-row {
  display: flex;
  justify-content: center;
  gap: 0.2rem;
}

.key {
  width: 2.4rem;
  height: 3.5rem;
  border: none;
  border-radius: 0.3rem;
  background: #333;
  color: #e0e0e0;
  font-weight: bold;
  cursor: pointer;
  font-size: 1.5rem;
  display: flex;
  justify-content: center;
  align-items: center;
  transition: all 0.2s;
}

.key[data-key="Backspace"] {
  background-color: #933;
  width: 5rem;
}
.key[data-key="Enter"] {
  background-color: #393;
  width: 5rem;
}

.key:hover {
  filter: brightness(1.1);
  transform: scale(1.05);
}

.key[data-state="absent"] {
  background-color: #222;
  color: #666;
}
.key[data-state="placed"] {
  background-color: #e0e0e0;
  color: #333;
}
.key[data-state="present"] {
  box-shadow: inset 0 0 0 0.2rem currentColor;
}

.guess-row {
  display: flex;
  justify-content: center;
  gap: 0.2rem;
}

/* ===== COLONNE 3 : TCHAT ===== */
.col-3 {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#tchat-column {
  height: 100%;
  display: flex;
  flex-direction: column;
  gap: 0.3125rem; /* 5px en rem */
  overflow-y: auto;
}

.chat-message {
  padding: 0.3125rem; /* 5px en rem */
  border-radius: 0.375rem; /* 6px en rem */
  background: #2d2d2d;
  display: flex;
  flex-direction: column;
  gap: 0.1875rem; /* 3px en rem */
}

.chat-message.valid {
  border-left: 0.1875rem solid #f89c1c; /* 3px en rem */
}

.chat-message.error {
  border-left: 0.1875rem solid #e53935; /* 3px en rem */
}

.pseudo {
  font-weight: bold;
  color: #f89c1c;
}

.word-grid {
  display: flex;
  gap: 0.1875rem; /* 3px en rem */
}

.error-message {
  color: #e53935;
  font-size: 0.5625rem; /* 9px en rem */
}

/* ===== VISIBILITÉ DES BOUTONS ===== */
#app[data-page="game"] #btn-new-game,
#app[data-page="game"] .game-options,
#app[data-page="home"] #btn-abandon {
  display: none;
}

/* Ligne de proposition actuelle */
.grid-input {
  display: flex;
  justify-content: center;
  gap: 0.2rem;
  margin-bottom: 1rem;
}

/* Historique des propositions */
.grid-history {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-height: 30rem;
  overflow-y: auto;
}

/* Case de lettre (style de base) */
.letter-cell {
  position: relative;
  width: 2.4rem;
  height: 2.4rem;
  border-radius: 0.4rem;
  display: flex;
  justify-content: center;
  font-weight: bold;
  font-size: 1.5rem;
  color: #e0e0e0;
  user-select: none;
  transition: all 0.2s;
}

/* Styles dynamiques basés sur data-info */

.letter-cell[data-info="filled"] {
  background: #2a3a5a;
}
.letter-cell[data-info="default"] {
  background: #1a233a;
}

.letter-cell[data-info="correct"] {
  background: #f81c1c;
}

.letter-cell[data-info="misplaced"] {
  color: #333;
  background: #ffb347;
  border-radius: 50%;
}

.error-icon {
  font-size: 3rem;
  color: #ff9500;
}

.error-content h2 {
  color: #ff9500;
}

.error-content p {
  color: #e0e0e0;
  font-size: 1.1rem;
}

.error-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2rem;
}

.twitch-error-message.fade-out {
  opacity: 0;
  transition: opacity 0.5s ease;
}

/* Animation pour les messages */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(-10px); }
  to { opacity: 1; transform: translateY(0); }
}

.tchat-pseudo {
  font-weight: bold;
}
.tchat-guess-word {
  display: flex;
  gap: 0.15rem;
  padding-left: 1rem;
}
.tchat-guess-word .letter-cell{
  width: 2rem;
  height: 2rem;
  font-size: 1.3rem;
}

#btn-save-twitch.error {
  background: #933;
}
#btn-save-twitch.success {
  background: #393;
}

/* Page de victoire */
.col-victory {
  background: #0f172a;
  color: #e0e0e0;
  padding: 2rem;
  text-align: center;
}

.victory-title {
  color: #ff9500;
  font-size: 2.5rem;
  margin-bottom: 1.5rem;
  text-align: center;
}

/* Sections conditionnelles */
.victory-no-twitch,
.victory-twitch {
  margin-bottom: 1.5rem;
  padding: 1rem;
  background: #1a233a;
  border-radius: 0.5rem;
  text-align: center;
}

/* Graphique de progression (visible sans Twitch) */
.progress-graph {
  margin: 1rem auto;
  width: 80%;
  height: 8rem;
}

.progress-bar {
  width: 100%;
  height: 100%;
}

/* Mot à trouver */
.found-word-container {
  font-size: 1.5rem;
  text-align: center;
}

/* Classement Twitch */
.twitch-ranking {
  margin: 1.5rem 0;
  text-align: left;
}

.twitch-ranking table {
  width: 100%;
  border-collapse: collapse;
}

.twitch-ranking th,
.twitch-ranking td {
  padding: 0.5rem;
  text-align: left;
  border-bottom: 1px solid #2a3a5a;
}

.twitch-ranking th {
  color: #ff9500;
}

/* Boutons */
.victory-actions {
  display: flex;
  gap: 1rem;
  justify-content: center;
  margin: 2rem 0;
}

.victory-actions button {
  flex: 1;
  font-size: 1.2rem;
  padding: 0.75rem 0;
  border: none;
  border-radius: 0.5rem;
  font-weight: bold;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.victory-actions button:hover {
  opacity: 0.9;
}

#btn-definition {
  background: #2a3a5a;
  color: #e0e0e0;
  width: 100%;
}
#btn-definition i {
  display: block;
  font-size: 0.9rem;
  font-weight: normal;
  opacity: 0.8;
}

#btn-definition.hidden {
  display: none;
}

/* Définition (masquée par défaut) */
.definition-container {
  margin-top: 1rem;
  padding: 1rem;
  background: #1a233a;
  border-radius: 0.5rem;
  text-align: left;
  max-height: 24rem;
  overflow-y: auto;
}

.definition-container.hidden {
  display: none;
}

/* Gestion des pluriels */
span[data-plural="s"] ~ .plural-s,
span[data-plural="s"] ~ .plural-t {
  display: none;
}

/* Affichage des éléments "sans Twitch" uniquement si Twitch est désactivé */
main:has(#opt-twitch:checked) .require-no-twitch {
  display: none;
}

#definition-text h3 {
  display: inline;
  margin-right: 0.4rem;
  font-size: 1.4rem;
}
span.CatgramDefinition {
  font-style: italic;
}
span.indicateurDefinition {
  opacity: 0.8;
  font-size: 0.8rem;
}
span.numDef {
  color: #ff9500;
}
span.LibelleSynonyme {
  display: block;
  font-weight: bold;
  margin-left: 0.4rem;
}
span.ExempleDefinition {
  font-style: italic;
  font-size: 0.9rem;
}
span[data-score-info] {
  font-weight: bold;
  color: #ff9500;
}

/* TODO : scrollbar */