*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* deux palettes ici, une sombre et une claire, exactement comme le
   sélecteur de thème dans la version Python (THEMES["dark"] / ["light"]) */
:root {
  --bg: #1E1E2E;
  --panel: #2A2A3C;
  --accent: #89B4FA;
  --gold: #E5C890;
  --text: #CDD6F4;
  --muted: #7F849C;
  --btn-hover: #74C7EC;
  --green: #A6E3A1;
  --score-1: #89B4FA;
  --score-2: #F9E2AF;
  --shadow: rgba(0, 0, 0, 0.4);
  --btn-fg: #1E1E2E;
  --font-b: "DM Sans", "Segoe UI", system-ui, sans-serif;
  --radius: 8px;
}

:root[data-theme="light"] {
  --bg: #FAFAF9;
  --panel: #F5F5F4;
  --accent: #7C9CF5;
  --gold: #C9A66B;
  --text: #44403C;
  --muted: #78716C;
  --btn-hover: #6D8AE8;
  --green: #7BAE7F;
  --score-1: #7C9CF5;
  --score-2: #C9A66B;
  --shadow: rgba(68, 64, 60, 0.18);
  --btn-fg: #FFFFFF;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-b);
  line-height: 1.6;
  transition: background-color 0.25s ease, color 0.25s ease;
}

.back-link {
  position: fixed;
  z-index: 10;
  top: 20px;
  left: 20px;
  padding: 0.6rem 1rem;
  color: var(--text);
  background: rgba(127, 132, 156, 0.18);
  border: 1px solid var(--muted);
  border-radius: var(--radius);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-decoration: none;
  transition: background 0.2s ease, transform 0.2s ease;
}

.back-link:hover {
  background: rgba(127, 132, 156, 0.32);
  transform: translateY(-1px);
}

.ext-app {
  display: flex;
  min-height: 100vh;
  min-height: 100dvh;
  align-items: center;
  justify-content: center;
  padding: 6rem 1.5rem 3rem;
}

.screen {
  display: none;
  width: 100%;
  max-width: 760px;
  text-align: center;
}

.screen.is-active {
  display: block;
}

.top-bar {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 0.5rem;
}

.theme-btn {
  padding: 0.5rem 0.9rem;
  color: var(--muted);
  background: var(--panel);
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-family: var(--font-b);
  font-size: 0.75rem;
  font-weight: 700;
}

.title {
  margin-bottom: 0.4rem;
  color: var(--accent);
  font-size: clamp(1.8rem, 5vw, 2.4rem);
  font-weight: 800;
}

.title.small {
  font-size: 1.7rem;
  margin-top: 1rem;
}

.subtitle {
  margin-bottom: 2rem;
  color: var(--muted);
  font-style: italic;
  font-size: 0.95rem;
}

.rules-panel {
  padding: 1.2rem 1.5rem 1.4rem;
  background: var(--panel);
  border-radius: var(--radius);
}

.rules-panel h2 {
  margin-bottom: 0.5rem;
  font-size: 1.05rem;
}

.rules-panel p {
  color: var(--muted);
  font-size: 0.92rem;
}

.btn-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.6rem;
  margin-top: 2.2rem;
}

.select-label {
  margin-bottom: 0.6rem;
  font-size: 0.95rem;
}

.btn {
  width: 100%;
  max-width: 340px;
  padding: 0.8rem 1.5rem;
  color: var(--btn-fg);
  background: var(--accent);
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-family: var(--font-b);
  font-size: 0.88rem;
  font-weight: 700;
  transition: background 0.2s ease, transform 0.15s ease;
}

.btn:hover:not(:disabled) {
  background: var(--btn-hover);
  transform: translateY(-1px);
}

.btn:disabled {
  cursor: not-allowed;
  opacity: 0.4;
  transform: none;
}

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

.btn-gold {
  background: var(--gold);
}

.btn-muted {
  background: var(--muted);
}

.btn-green {
  background: var(--green);
}

.hint {
  margin-top: 1.5rem;
  color: var(--muted);
  font-size: 0.78rem;
}

.exe-link {
  color: var(--accent);
  text-decoration: underline;
}

.mode-label {
  margin-bottom: 1.5rem;
  color: var(--muted);
  font-style: italic;
  font-size: 0.9rem;
}

.setup-panel {
  padding: 1.4rem 1.5rem;
  background: var(--panel);
  border-radius: var(--radius);
}

.setup-panel h2 {
  margin-bottom: 0.8rem;
  font-size: 1rem;
}

.stepper {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.8rem;
}

.step-btn {
  width: 46px;
  height: 46px;
  color: var(--btn-fg);
  background: var(--accent);
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 1.3rem;
  font-weight: 800;
}

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

.step-value {
  min-width: 3ch;
  font-size: 2rem;
  font-weight: 800;
}

.step-hint {
  margin-top: 0.6rem;
  color: var(--muted);
  font-size: 0.75rem;
  font-style: italic;
}

.game-hdr {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.9rem 1rem;
  background: var(--panel);
  border-radius: var(--radius);
}

.game-hdr-title {
  color: var(--accent);
  font-weight: 800;
  font-size: 1.05rem;
}

.game-hdr-remaining {
  color: var(--muted);
  font-size: 0.85rem;
}

.score-row {
  display: flex;
  align-items: center;
  justify-content: space-around;
  margin-top: 1rem;
}

.score-block {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.score-name {
  font-weight: 700;
  font-size: 0.85rem;
}

.score-value {
  font-size: 2.2rem;
  font-weight: 800;
}

#p1-name,
#p1-score {
  color: var(--score-1);
}

#p2-name,
#p2-score {
  color: var(--score-2);
}

.vs {
  color: var(--muted);
  font-style: italic;
}

.sep {
  margin: 0.9rem 0;
  border: none;
  border-top: 1px solid var(--panel);
}

.turn-indicator {
  margin-bottom: 0.5rem;
  color: var(--muted);
  font-style: italic;
  font-size: 0.88rem;
}

/* flex-wrap plutôt qu'un grid fixe : avec un nombre de cartes variable
   (2 à 20) je voulais que ça se réorganise tout seul sans calculer de colonnes */
.cards-track {
  display: flex;
  flex-wrap: wrap;
  align-content: center;
  justify-content: center;
  gap: 8px;
  min-height: 220px;
  padding: 0.5rem;
}

.card {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 64px;
  height: 96px;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--gold);
  border-radius: 6px;
  box-shadow: 3px 4px 0 var(--shadow);
  font-size: 1.3rem;
  font-weight: 800;
}

.card.is-edge {
  color: var(--btn-fg);
  background: var(--accent);
  border-width: 2px;
}

.card .arrow {
  position: absolute;
  bottom: 6px;
  color: var(--gold);
  font-size: 0.65rem;
}

.take-buttons {
  display: flex;
  justify-content: center;
  gap: 1.5rem;
  margin-top: 0.8rem;
}

.take-buttons .btn {
  width: auto;
  min-width: 190px;
}

.status-line {
  min-height: 1.4em;
  margin-top: 0.6rem;
  color: var(--green);
  font-style: italic;
  font-size: 0.85rem;
}

.result-msg {
  margin: 1rem 0 1.8rem;
  font-size: 1.3rem;
  font-weight: 800;
}

.result-panel {
  padding: 1.2rem 1.5rem 1.4rem;
  background: var(--panel);
  border-radius: var(--radius);
}

.result-panel h2 {
  margin-bottom: 0.8rem;
  font-size: 0.95rem;
}

.result-row {
  display: flex;
  justify-content: center;
  gap: 3rem;
  font-size: 1.1rem;
  font-weight: 800;
}

#result-p1 {
  color: var(--score-1);
}

#result-p2 {
  color: var(--score-2);
}

@media (max-width: 600px) {
  .ext-app {
    padding-top: 5rem;
  }

  .take-buttons {
    flex-direction: column;
    align-items: center;
  }

  .card {
    width: 52px;
    height: 78px;
    font-size: 1.05rem;
  }
}

/* Focus clavier : un contour visible sur tout ce qu'on atteint avec Tab.
   :focus-visible ne s'affiche pas au clic souris, seulement au clavier. */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}
