:root {
  --grass: #6ab04c;
  --stone: #7f8c8d;
  --water: #3498db;
  --dark: #2c3e50;
  --accent: #4a9e5c;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", Roboto, sans-serif;
  background: #1e272e;
  color: #ecf0f1;
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.topbar {
  display: flex;
  align-items: baseline;
  gap: 16px;
  padding: 10px 20px;
  background: var(--dark);
  border-bottom: 3px solid var(--accent);
}
.topbar h1 { margin: 0; font-size: 1.4rem; }
.tagline { color: #bdc3c7; font-size: 0.9rem; }
.score-box {
  margin-left: auto;
  display: flex;
  gap: 14px;
  align-items: center;
}
.score-stars {
  font-size: 1.05rem;
  font-weight: 700;
  color: #f1c40f;
}
.score-xp {
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  padding: 4px 12px;
  border-radius: 14px;
  font-size: 0.95rem;
}
.level-btn .btn-stars { font-size: 0.75rem; margin-left: 4px; }

.layout {
  flex: 1;
  display: flex;
  min-height: 0;
}

/* ---- Panneau jeu ---- */
.game-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 16px;
  background: #222f3e;
  border-right: 3px solid var(--dark);
}
.levels {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
  max-width: 480px;
}
.level-btn {
  border: 2px solid var(--dark);
  background: #34495e;
  color: #ecf0f1;
  border-radius: 6px;
  padding: 6px 12px;
  font-weight: 600;
  cursor: pointer;
}
.level-btn:hover { background: #3d566e; }
.level-btn.active {
  background: var(--accent);
  border-color: #7fdbb6;
}
.level-title {
  margin-bottom: 8px;
  font-weight: 700;
  color: #7fdbb6;
  text-align: center;
  max-width: 480px;
}

#game {
  border: 4px solid var(--dark);
  border-radius: 6px;
  overflow: hidden;
  box-shadow: 0 6px 18px rgba(0,0,0,0.4);
}
.status {
  margin-top: 14px;
  padding: 10px 16px;
  background: var(--dark);
  border-radius: 6px;
  font-size: 0.95rem;
  max-width: 480px;
  text-align: center;
}
.status.success { background: #218c5a; }
.status.error { background: #c0392b; }

/* ---- Panneau code ---- */
.code-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: var(--dark);
}
.btn {
  border: none;
  border-radius: 6px;
  padding: 8px 16px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  color: #fff;
}
.btn-run { background: var(--accent); }
.btn-run:hover { background: #3d8a4e; }
.btn-reset { background: #576574; }
.btn-reset:hover { background: #47576a; }
.toggle { margin-left: auto; font-size: 0.9rem; cursor: pointer; }

.blockly { flex: 1; min-height: 0; }

.python-view {
  height: 180px;
  background: #0f1720;
  border-top: 3px solid var(--dark);
  display: flex;
  flex-direction: column;
}
.python-title {
  padding: 6px 12px;
  font-size: 0.8rem;
  color: #7fdbb6;
  background: #16202b;
}
#python-code {
  margin: 0;
  padding: 12px;
  overflow: auto;
  flex: 1;
  color: #a5f3c9;
  font-family: "Consolas", "Courier New", monospace;
  font-size: 0.9rem;
}

/* ---- Espace utilisateur (topbar) ---- */
.user-area {
  display: flex;
  align-items: center;
  gap: 10px;
}
.user-name {
  font-weight: 700;
  color: #ffd479;
  font-size: 0.95rem;
}
.btn-auth {
  background: #f39c12;
}
.btn-auth:hover {
  background: #e08e0b;
}
.btn-block {
  width: 100%;
  margin-top: 4px;
}

/* ---- Modale d'authentification ---- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
.modal {
  position: relative;
  width: 340px;
  max-width: 90vw;
  background: #22303d;
  border: 2px solid var(--accent);
  border-radius: 12px;
  padding: 24px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
}
.modal h2 {
  margin: 0 0 4px;
  font-size: 1.3rem;
}
.modal-sub {
  margin: 0 0 16px;
  font-size: 0.85rem;
  color: #bdc3c7;
}
.modal-close {
  position: absolute;
  top: 8px;
  right: 12px;
  background: none;
  border: none;
  color: #bdc3c7;
  font-size: 1.6rem;
  line-height: 1;
  cursor: pointer;
}
.modal-close:hover {
  color: #fff;
}
.field {
  display: block;
  font-size: 0.85rem;
  color: #cfd8dc;
  margin-bottom: 12px;
}
.field input {
  width: 100%;
  margin-top: 5px;
  padding: 9px 11px;
  border: 1px solid #3a4d5e;
  border-radius: 6px;
  background: #1b2733;
  color: #ecf0f1;
  font-size: 0.95rem;
}
.field input:focus {
  outline: none;
  border-color: var(--accent);
}
.auth-error {
  min-height: 18px;
  margin-bottom: 8px;
  color: #ff7675;
  font-size: 0.85rem;
}
.auth-switch {
  margin-top: 14px;
  text-align: center;
  font-size: 0.85rem;
  color: #bdc3c7;
}
.auth-switch a {
  color: #7fdbb6;
  margin-left: 4px;
  text-decoration: none;
  font-weight: 600;
}
.auth-switch a:hover {
  text-decoration: underline;
}
