:root {
  --felt-dark: #17332a;
  --felt: #1f4438;
  --ivory: #efe3c8;
  --ivory-dim: #ddcda6;
  --umber: #6b4a2d;
  --umber-dark: #4a3220;
  --amber: #d9a441;
  --amber-dark: #b5822b;
  --ink: #23180f;
  --ok: #6fae6f;
  --bad: #c0654f;

  --font-display: "Fraunces", "Georgia", serif;
  --font-ui: "Space Grotesk", "Helvetica Neue", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: radial-gradient(ellipse at top, var(--felt) 0%, var(--felt-dark) 70%);
  color: var(--ivory);
  font-family: var(--font-ui);
  -webkit-tap-highlight-color: transparent;
}

.app {
  max-width: 760px;
  margin: 0 auto;
  padding: 32px 20px 60px;
  display: flex;
  flex-direction: column;
  gap: 28px;
}

.app-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid rgba(239, 227, 200, 0.18);
  padding-bottom: 18px;
}

.app-header h1 {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 30px;
  margin: 0;
  letter-spacing: 0.2px;
}

.timer {
  font-family: var(--font-ui);
  font-weight: 700;
  font-size: 22px;
  font-variant-numeric: tabular-nums;
  color: var(--amber);
  min-width: 64px;
  text-align: center;
  padding: 8px 16px;
  border-radius: 999px;
  background: rgba(217, 164, 65, 0.12);
  border: 1px solid rgba(217, 164, 65, 0.3);
  transition: color 0.3s ease, background 0.3s ease, border-color 0.3s ease;
}

.timer.urgent {
  color: var(--bad);
  background: rgba(192, 101, 79, 0.14);
  border-color: rgba(192, 101, 79, 0.4);
}

.progress-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.progress-dots {
  display: flex;
  gap: 10px;
}

.dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid rgba(239, 227, 200, 0.3);
  background: transparent;
  transition: all 0.2s ease;
}

.dot.done {
  background: var(--amber);
  border-color: var(--amber);
}

.dot.current {
  border-color: var(--amber);
  box-shadow: 0 0 0 4px rgba(217, 164, 65, 0.2);
  transform: scale(1.15);
}

.score-badge {
  font-size: 14px;
  color: var(--ivory-dim);
}

.score-badge strong {
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 700;
  color: var(--amber);
  margin-left: 6px;
}

.player-bar {
  display: flex;
  align-items: center;
  gap: 10px;
}

.player-bar label {
  font-size: 14px;
  color: var(--ivory-dim);
}

.player-bar input {
  flex: 1;
  max-width: 240px;
  padding: 10px 14px;
  font-family: var(--font-ui);
  font-size: 15px;
  background: rgba(239, 227, 200, 0.1);
  color: var(--ivory);
  border: 1px solid rgba(239, 227, 200, 0.3);
  border-radius: 8px;
}

.player-bar input:focus {
  outline: 2px solid var(--amber);
  outline-offset: 1px;
  background: rgba(239, 227, 200, 0.16);
}

.player-bar input::placeholder {
  color: rgba(239, 227, 200, 0.45);
}

.scores-link {
  background: none;
  border: none;
  padding: 0;
  font: inherit;
  color: var(--amber);
  font-size: 14px;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
}

.scores-link:hover {
  text-decoration: underline;
}

/* --- Fenêtre modale des scores --- */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 1000;
}

.modal-overlay[hidden] {
  display: none;
}

.modal {
  width: 100%;
  max-width: 520px;
  max-height: 85vh;
  overflow-y: auto;
  background: linear-gradient(180deg, var(--felt) 0%, var(--felt-dark) 100%);
  border: 1px solid rgba(239, 227, 200, 0.15);
  border-radius: 16px;
  padding: 22px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.modal-header h2 {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 24px;
  margin: 0;
  color: var(--ivory);
}

.modal-close {
  background: none;
  border: none;
  color: var(--ivory-dim);
  font-size: 28px;
  line-height: 1;
  cursor: pointer;
  padding: 4px 8px;
}

.modal-close:hover {
  color: var(--ivory);
}

.modal-body h3 {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 17px;
  margin: 18px 0 10px;
  color: var(--ivory);
}

.modal-body h3:first-child {
  margin-top: 0;
}

/* --- Page des scores --- */

.app-header .back-link {
  flex: none;
  min-width: unset;
  padding: 10px 16px;
  font-size: 14px;
}

.scores-section {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.scores-section h2 {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 20px;
  margin: 0;
  color: var(--ivory);
}

.empty-note {
  color: var(--ivory-dim);
  font-size: 15px;
  margin: 0;
}

.scores-table {
  width: 100%;
  border-collapse: collapse;
  background: rgba(0, 0, 0, 0.18);
  border-radius: 12px;
  overflow: hidden;
}

.scores-table th,
.scores-table td {
  text-align: left;
  padding: 10px 14px;
  font-size: 14px;
}

.scores-table th {
  color: var(--amber);
  font-family: var(--font-ui);
  font-weight: 700;
  border-bottom: 1px solid rgba(239, 227, 200, 0.2);
}

.scores-table td {
  color: var(--ivory);
  border-bottom: 1px solid rgba(239, 227, 200, 0.08);
}

.scores-table tbody tr:last-child td {
  border-bottom: none;
}

.scores-table tbody tr:nth-child(odd) {
  background: rgba(239, 227, 200, 0.03);
}

@media (max-width: 480px) {
  .scores-table th, .scores-table td { padding: 8px 8px; font-size: 13px; }
}

.board {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.label {
  font-size: 15px;
  color: var(--ivory-dim);
  margin: 6px 0 2px;
}

.tiles-grid {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  gap: 12px;
  padding: 18px;
  background: rgba(0, 0, 0, 0.18);
  border-radius: 14px;
  min-height: 90px;
}

.tile {
  aspect-ratio: 1 / 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(180deg, var(--ivory) 0%, var(--ivory-dim) 100%);
  color: var(--ink);
  border-radius: 9px;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(22px, 6vw, 38px);
  border: 1px solid var(--umber);
  box-shadow: 0 3px 0 var(--umber), 0 6px 10px rgba(0, 0, 0, 0.35);
  cursor: grab;
  user-select: none;
  touch-action: none;
  transition: transform 0.12s ease, box-shadow 0.12s ease, opacity 0.15s ease;
}

.tile:active {
  cursor: grabbing;
}

.tile.used {
  opacity: 0.22;
  cursor: default;
  box-shadow: none;
  pointer-events: none;
}

.tile.empty {
  background: rgba(239, 227, 200, 0.06);
  border: 1px dashed rgba(239, 227, 200, 0.25);
  box-shadow: none;
  cursor: default;
}

.tile.hover-target {
  border-color: var(--amber);
  background: linear-gradient(180deg, #fff4da 0%, #f1dfae 100%);
}

.tile.dragging-origin {
  opacity: 0.15;
}

.tile-ghost {
  position: fixed;
  z-index: 999;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(180deg, var(--ivory) 0%, var(--ivory-dim) 100%);
  color: var(--ink);
  border-radius: 9px;
  font-family: var(--font-display);
  font-weight: 700;
  border: 1px solid var(--umber);
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.45);
  pointer-events: none;
  touch-action: none;
  transform: scale(1.08) rotate(-2deg);
}

.actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.btn {
  flex: 1;
  min-width: 120px;
  padding: 14px 18px;
  font-family: var(--font-ui);
  font-weight: 700;
  font-size: 15px;
  border-radius: 10px;
  border: none;
  cursor: pointer;
  transition: filter 0.15s ease, transform 0.15s ease, box-shadow 0.15s ease;
}

.btn:hover {
  transform: translateY(-1px);
}

.btn:active {
  transform: translateY(1px);
}

.btn-primary {
  background: var(--amber);
  color: var(--ink);
  box-shadow: 0 2px 0 var(--amber-dark);
}
.btn-primary:hover { filter: brightness(1.06); box-shadow: 0 3px 6px rgba(0, 0, 0, 0.25); }
.btn-primary:disabled {
  background: rgba(217, 164, 65, 0.35);
  color: rgba(35, 24, 15, 0.5);
  cursor: not-allowed;
  box-shadow: none;
  transform: none;
}

.btn-secondary {
  background: rgba(239, 227, 200, 0.12);
  color: var(--ivory);
}
.btn-secondary:hover { background: rgba(239, 227, 200, 0.2); }

.btn-outline {
  background: transparent;
  color: var(--ivory-dim);
  border: 1px solid rgba(239, 227, 200, 0.3);
}
.btn-outline:hover { border-color: var(--ivory); color: var(--ivory); }

.final-answer {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 18px;
  background: rgba(217, 164, 65, 0.1);
  border: 1px solid rgba(217, 164, 65, 0.4);
  border-radius: 12px;
}

/* L'attribut HTML `hidden` doit rester prioritaire sur `display: flex` ci-dessus */
.final-answer[hidden] {
  display: none;
}

.final-answer label {
  font-size: 14px;
  color: var(--ivory-dim);
}

.final-answer-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

#final-word-input {
  flex: 1;
  min-width: 160px;
  padding: 14px 16px;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 22px;
  letter-spacing: 1px;
  text-transform: uppercase;
  background: var(--ivory);
  color: var(--ink);
  border: 1px solid var(--umber);
  border-radius: 9px;
}

#final-word-input:focus {
  outline: 2px solid var(--amber);
  outline-offset: 1px;
}

.result {
  min-height: 28px;
  font-size: 16px;
  line-height: 1.5;
  padding: 0 2px;
}

.result.ok { color: var(--ok); }
.result.bad { color: var(--bad); }
.result strong { color: var(--amber); }

.next-round-bar {
  display: flex;
  justify-content: center;
}

.next-round-bar[hidden] {
  display: none;
}

.next-round-bar .btn {
  flex: none;
  min-width: 220px;
}

.recap-panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 22px;
  background: linear-gradient(135deg, rgba(217, 164, 65, 0.14) 0%, rgba(0, 0, 0, 0.18) 100%);
  border: 1px solid rgba(217, 164, 65, 0.35);
  border-radius: 16px;
}

.recap-panel[hidden] {
  display: none;
}

.recap-panel .recap-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 20px;
  margin: 0;
  color: var(--ivory);
}

.recap-panel .recap-total {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 32px;
  color: var(--amber);
  margin: 0;
}

.recap-panel .recap-total span {
  font-size: 16px;
  font-weight: 500;
  color: var(--ivory-dim);
  margin-left: 8px;
}

.recap-panel .recap-note {
  font-size: 14px;
  color: var(--ivory-dim);
  margin: 0;
}

.recap-panel .recap-note-error {
  color: var(--bad);
}

.possible-words {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 16px 18px;
  background: rgba(0, 0, 0, 0.18);
  border-radius: 12px;
}

.possible-words[hidden] {
  display: none;
}

.possible-words h3 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 17px;
  font-weight: 500;
  color: var(--ivory);
}

.possible-words .length-group {
  display: flex;
  gap: 8px;
  align-items: baseline;
  flex-wrap: wrap;
  font-size: 14px;
}

.possible-words .length-tag {
  flex-shrink: 0;
  color: var(--amber);
  font-weight: 700;
  min-width: 68px;
}

.possible-words .word-list {
  color: var(--ivory-dim);
}

@media (max-width: 420px) {
  .tiles-grid { gap: 5px; padding: 10px; }
  .app-header h1 { font-size: 24px; }
  .progress-bar { justify-content: flex-start; }
  .recap-panel .recap-total { font-size: 26px; }
}
