:root {
  color-scheme: dark;
  --bg: #000000;
  --surface: #0a0a0a;
  --border: #3a3a3a;
  --fg: #ffffff;
  --fg-dim: #9a9a9a;
  --fg-disabled: #4a4a4a;
}

* {
  box-sizing: border-box;
}

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--fg);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}

/* Piège connu : un attribut [hidden] et une règle d'auteur `.classe {
   display: flex }` ont la même spécificité (0,1,0) ; sans ce !important,
   la règle .screen ci-dessous gagnerait et [hidden] serait neutralisé en
   silence (tous les écrans resteraient visibles superposés, sans erreur
   JS). Toujours poser cette règle tôt, avant toute règle `display` sur une
   classe togglable dynamiquement. Voir connaissances/lessons.md. */
[hidden] {
  display: none !important;
}

#app {
  position: relative;
  height: 100vh;
  width: 100vw;
  overflow: hidden;
}

.screen {
  height: 100%;
  width: 100%;
  display: flex;
  flex-direction: column;
}

.screen-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
}

.screen-header h2 {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 600;
}

.screen-inner {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.title-inner {
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 32px;
}

.title-inner h1 {
  font-size: 2.2rem;
  letter-spacing: 0.04em;
  margin: 0;
}

.menu-buttons {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  max-width: 320px;
}

.placeholder-text {
  color: var(--fg-dim);
}

/* --- Écran de jeu --- */

#screen-game {
  display: flex;
  flex-direction: row;
}

#game-area {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

#game-canvas {
  background: var(--surface);
  border: 2px solid var(--border);
  display: block;
  max-width: 100%;
  max-height: 100%;
}

#sidebar {
  flex: 0 0 320px;
  width: 320px;
  background: var(--surface);
  border-left: 1px solid var(--border);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  overflow-y: auto;
}

#hud {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

#hud-money {
  font-size: 1.4rem;
  font-weight: 700;
}

#hud-title {
  color: var(--fg-dim);
}

#actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.gear-btn {
  position: absolute;
  top: 16px;
  right: 16px;
  z-index: 30;
}

/* --- Boutons & icônes --- */

button {
  font: inherit;
  color: var(--fg);
  background: transparent;
  border: 1px solid var(--fg);
  border-radius: 0;
  padding: 10px 14px;
  cursor: pointer;
  text-align: left;
}

button:hover:not(:disabled) {
  background: var(--surface);
}

button:disabled {
  color: var(--fg-disabled);
  border-color: var(--fg-disabled);
  cursor: not-allowed;
}

button.primary {
  background: var(--fg);
  color: #000000;
}

button.primary:hover:not(:disabled) {
  background: var(--fg-dim);
}

.icon-btn {
  border: none;
  background: transparent;
  padding: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 0;
}

.icon-btn:hover:not(:disabled) {
  background: var(--surface);
}

.icon-btn svg {
  width: 24px;
  height: 24px;
  stroke: var(--fg);
  fill: none;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon-btn:disabled svg {
  stroke: var(--fg-disabled);
}

/* --- Sauvegardes --- */

#saves-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.save-slot {
  display: flex;
  align-items: center;
  gap: 12px;
  border: 1px solid var(--border);
  padding: 10px 12px;
}

.save-slot-name {
  flex: 1 1 auto;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.save-slot-name.empty {
  color: var(--fg-dim);
}

.save-slot-actions {
  display: flex;
  gap: 4px;
}

#saves-file-controls {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  max-width: 420px;
}

#saves-import-label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.85rem;
  color: var(--fg-dim);
}

/* --- Contrôles --- */

#keybinding-fieldset {
  display: flex;
  flex-direction: column;
  gap: 8px;
  border: 1px solid var(--border);
  padding: 16px;
  max-width: 320px;
}

#keybinding-fieldset label {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* --- Notifications (overlay global, visible sur tous les écrans) --- */

#global-notifications {
  position: fixed;
  right: 16px;
  bottom: 16px;
  display: flex;
  flex-direction: column-reverse;
  gap: 6px;
  font-size: 0.85rem;
  z-index: 40;
  max-width: 280px;
}

.notification {
  padding: 6px 10px;
  background: var(--surface);
  border: 1px solid var(--fg);
  animation: fade-in 150ms ease-out;
}

.notification.warn {
  border-width: 2px;
}

@keyframes fade-in {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* --- Contrôles tactiles --- */

#touch-controls {
  position: fixed;
  inset: auto 0 0 0;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  padding: 20px;
  pointer-events: none;
  z-index: 20;
}

.joystick-base {
  width: 100px;
  height: 100px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.06);
  border: 2px solid rgba(255, 255, 255, 0.4);
  position: relative;
  touch-action: none;
  pointer-events: auto;
}

.joystick-knob {
  width: 44px;
  height: 44px;
  margin: -22px 0 0 -22px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.85);
  position: absolute;
  top: 50%;
  left: 50%;
  transition: transform 60ms linear;
}

.touch-action-btn {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.15);
  border: 2px solid rgba(255, 255, 255, 0.85);
  color: #fff;
  font-size: 1.4rem;
  touch-action: none;
  pointer-events: auto;
}
