:root {
  --bg-dark: #0a1420;
  --bg-panel: #12202f;
  --bg-panel-light: #17293b;
  --border: #3a5a78;
  --border-light: #5b87ab;
  --ice: #7fd7ff;
  --ice-bright: #cdf3ff;
  --ember: #ff8a3d;
  --ember-dark: #c85a1a;
  --text: #eaf6ff;
  --text-dim: #8fa8bd;
  --success: #6ee7a0;
  --danger: #ff6b6b;
  --font-pixel: "Press Start 2P", "Courier New", monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg-dark);
  color: var(--text);
  font-family: var(--font-pixel);
  font-size: 12px;
  image-rendering: pixelated;
  overflow: hidden;
}

body {
  background-image:
    radial-gradient(circle at 20% 20%, rgba(127, 215, 255, 0.06), transparent 40%),
    radial-gradient(circle at 80% 70%, rgba(255, 138, 61, 0.05), transparent 45%);
}

#app { height: 100%; width: 100%; position: relative; }

.screen {
  display: none;
  height: 100%;
  width: 100%;
  align-items: center;
  justify-content: center;
  flex-direction: column;
}
.screen.active { display: flex; }

.pixel-title {
  font-size: 28px;
  letter-spacing: 4px;
  color: var(--ice-bright);
  text-shadow: 3px 3px 0 var(--ember-dark), -1px -1px 0 var(--border);
  margin: 0 0 8px;
}

/* Loading screen */
.loading-box { text-align: center; }
.loading-text { color: var(--text-dim); font-size: 11px; }
.dots::after {
  content: "";
  animation: dots 1.4s steps(4, end) infinite;
}
@keyframes dots {
  0% { content: ""; }
  25% { content: "."; }
  50% { content: ".."; }
  75% { content: "..."; }
  100% { content: ""; }
}

/* Panels */
.panel {
  background: var(--bg-panel);
  border: 4px solid var(--border);
  box-shadow:
    0 0 0 4px var(--bg-dark),
    0 0 0 8px var(--border-light),
    8px 8px 0 rgba(0,0,0,0.4);
  padding: 28px 32px;
  image-rendering: pixelated;
}

.auth-panel {
  width: 360px;
  max-width: 90vw;
  text-align: center;
}
.subtitle {
  color: var(--text-dim);
  font-size: 9px;
  line-height: 1.6;
  margin: 0 0 20px;
}

.tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 18px;
  border-bottom: 2px solid var(--border);
}
.tab-btn {
  flex: 1;
  background: var(--bg-panel-light);
  color: var(--text-dim);
  border: 2px solid var(--border);
  border-bottom: none;
  font-family: var(--font-pixel);
  font-size: 9px;
  padding: 10px 4px;
  cursor: pointer;
}
.tab-btn.active {
  background: var(--bg-dark);
  color: var(--ice-bright);
  border-color: var(--border-light);
}

.auth-form { display: none; flex-direction: column; gap: 14px; text-align: left; }
.auth-form.active { display: flex; }

.auth-form label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 9px;
  color: var(--text-dim);
}

.auth-form input, .auth-form select {
  font-family: var(--font-pixel);
  font-size: 10px;
  background: var(--bg-dark);
  border: 2px solid var(--border);
  color: var(--text);
  padding: 10px 8px;
  outline: none;
}
.auth-form input:focus, .auth-form select:focus {
  border-color: var(--ice);
}

.form-error {
  color: var(--danger);
  font-size: 9px;
  min-height: 12px;
  margin: 0;
  line-height: 1.5;
}

.btn-pixel {
  font-family: var(--font-pixel);
  font-size: 10px;
  color: var(--bg-dark);
  background: var(--ice);
  border: none;
  box-shadow: 0 4px 0 var(--border-light), 0 4px 0 4px rgba(0,0,0,0.3);
  padding: 12px 16px;
  cursor: pointer;
  margin-top: 4px;
}
.btn-pixel:hover { background: var(--ice-bright); }
.btn-pixel:active { box-shadow: 0 1px 0 var(--border-light); transform: translateY(3px); }
.btn-pixel:disabled {
  background: var(--border);
  color: var(--text-dim);
  cursor: not-allowed;
  box-shadow: 0 4px 0 #24384a;
}
.btn-pixel.small { font-size: 8px; padding: 8px 10px; margin-top: 0; }
.btn-pixel.danger { background: var(--danger); box-shadow: 0 4px 0 #9c3b3b; }
.btn-pixel.danger:hover { background: #ff8f8f; }

.link-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  font-family: var(--font-pixel);
  font-size: 8px;
  text-decoration: underline;
  cursor: pointer;
  margin-top: 6px;
}
.link-btn:hover { color: var(--ice); }

/* Mobile block message inside dialog handles this now */

/* Game screen */
#screen-game { align-items: stretch; justify-content: flex-start; }
.hud {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: linear-gradient(180deg, var(--bg-panel-light), var(--bg-panel));
  border-bottom: 4px solid var(--border);
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.35);
  padding: 14px 20px;
  flex-wrap: wrap;
  gap: 10px;
  position: relative;
  z-index: 5;
}
.hud-resources { display: flex; gap: 14px; }
.resource {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--ice-bright);
  background: var(--bg-dark);
  border: 2px solid var(--border);
  padding: 7px 11px;
}
.icon { width: 14px; height: 14px; display: inline-block; image-rendering: pixelated; }
.icon-coin { background: var(--ember); border: 2px solid var(--ember-dark); border-radius: 50%; }
.icon-gem { background: var(--ice); border: 2px solid var(--border-light); transform: rotate(45deg); }

.hud-user { display: flex; align-items: center; gap: 12px; }
.hud-pseudo { color: var(--text-dim); font-size: 9px; }
.streak-badge {
  font-size: 8px;
  color: var(--ember);
  border: 2px solid var(--ember-dark);
  padding: 4px 6px;
}
.streak-badge:empty { display: none; }

.per-sec { font-size: 8px; color: var(--text-dim); margin-left: 2px; }

.toggle-btn {
  font-family: var(--font-pixel);
  font-size: 8px;
  background: var(--bg-panel-light);
  color: var(--ice);
  border: 2px solid var(--border-light);
  padding: 7px 8px;
  cursor: pointer;
}
.toggle-btn.off { color: var(--text-dim); border-color: var(--border); opacity: 0.55; }
.toggle-btn.wide { letter-spacing: 0.5px; }
.toggle-btn:not(.off) { box-shadow: inset 0 0 0 1px rgba(127, 215, 255, 0.35); }
.account-note { font-size: 8px; color: var(--text-dim); margin: 8px 0 0; line-height: 1.6; }
.btn-pixel.ember { background: var(--ember); box-shadow: 0 4px 0 var(--ember-dark); }
.btn-pixel.ember:hover { background: #ffa563; }

.game-main {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(300px, 1fr) minmax(320px, 1.2fr) minmax(300px, 1fr);
  gap: 16px;
  padding: 16px;
  min-height: 0;
}

.panel-click {
  position: relative;
  background: #0a1622;
  border: 4px solid var(--border);
  overflow: hidden;
  /* Canvas et overlay sont en position absolue : sans hauteur minimale, le
     panneau s'effondre dès que la grille lui donne une rangée auto. */
  min-height: 320px;
}
#scene-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  cursor: pointer;
  display: block;
}
.click-overlay {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 18px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
  z-index: 2;
}
.click-overlay > * { pointer-events: auto; }
.btn-click {
  font-family: var(--font-pixel);
  font-size: 14px;
  letter-spacing: 2px;
  color: var(--bg-dark);
  background: var(--ember);
  border: none;
  box-shadow: 0 6px 0 var(--ember-dark), 0 6px 0 4px rgba(0,0,0,0.35);
  padding: 18px 34px;
  cursor: pointer;
  user-select: none;
}
.btn-click:hover { background: #ffa563; }
.btn-click:active { box-shadow: 0 2px 0 var(--ember-dark); transform: translateY(4px); }
.click-info {
  color: var(--text);
  font-size: 9px;
  margin: 0;
  background: rgba(10, 22, 34, 0.75);
  padding: 5px 9px;
  border: 2px solid var(--border);
}

.float-layer { position: absolute; inset: 0; pointer-events: none; overflow: hidden; z-index: 3; }
.floating-number {
  position: absolute;
  color: var(--ice-bright);
  font-size: 11px;
  text-shadow: 2px 2px 0 var(--bg-dark);
  animation: floatUp 0.9s ease-out forwards;
  pointer-events: none;
}
@keyframes floatUp {
  0% { opacity: 1; transform: translate(-50%, 0); }
  100% { opacity: 0; transform: translate(-50%, -70px); }
}

.panel-col {
  background: var(--bg-panel);
  border: 4px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 14px 16px;
  border-bottom: 3px solid var(--border);
  background: linear-gradient(180deg, var(--bg-panel-light), var(--bg-panel));
  flex-wrap: wrap;
}
.panel-head h2 {
  font-size: 11px;
  color: var(--ice-bright);
  margin: 0;
  letter-spacing: 1px;
  text-shadow: 2px 2px 0 rgba(0, 0, 0, 0.5);
}

.buy-amount { display: flex; gap: 4px; }
.amount-btn {
  font-family: var(--font-pixel);
  font-size: 8px;
  background: var(--bg-dark);
  color: var(--text-dim);
  border: 2px solid var(--border);
  padding: 6px 7px;
  cursor: pointer;
}
.amount-btn.active { color: var(--bg-dark); background: var(--ice); border-color: var(--ice-bright); }

.list { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.list::-webkit-scrollbar { width: 10px; }
.list::-webkit-scrollbar-track { background: var(--bg-dark); }
.list::-webkit-scrollbar-thumb { background: var(--border); border: 2px solid var(--bg-dark); }

.empty-hint { color: var(--text-dim); font-size: 9px; line-height: 1.9; text-align: center; margin: 12px 0; }

.card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  text-align: left;
  font-family: var(--font-pixel);
  background: var(--bg-panel-light);
  border: 2px solid var(--border);
  border-left: 5px solid var(--border);
  padding: 12px;
  cursor: pointer;
  color: var(--text);
  transition: transform 0.08s steps(2), background 0.12s;
}
.card.affordable { border-left-color: var(--ice); box-shadow: inset 0 0 0 1px rgba(127, 215, 255, 0.12); }
.card.affordable:hover { background: #1d3346; border-color: var(--border-light); transform: translateX(3px); }
.card.affordable:active { transform: translateX(3px) translateY(2px); }
.card.locked { opacity: 0.45; cursor: not-allowed; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.card-name { font-size: 10px; color: var(--ice-bright); line-height: 1.4; }
.card-count { font-size: 12px; color: var(--ember); }
.card-desc { font-size: 8px; color: var(--text-dim); line-height: 1.7; }
.card-foot { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.card-cost { font-size: 9px; color: var(--text); }
.card.locked .card-cost { color: var(--danger); }
.card-rate { font-size: 8px; color: var(--success); }

.upgrade-card { border-left-color: var(--ember-dark); }
.upgrade-card.affordable { border-left-color: var(--ember); }

.card-body { display: flex; gap: 10px; align-items: flex-start; }
.card-icon {
  flex: 0 0 auto;
  width: 28px;
  height: 28px;
  display: block;
  background: var(--bg-dark);
  border: 2px solid var(--border);
  padding: 2px;
}
.pixel-icon { image-rendering: pixelated; display: block; width: 28px; height: 28px; }
.card-text { display: flex; flex-direction: column; gap: 7px; flex: 1; min-width: 0; }
.card.affordable .card-icon { border-color: var(--border-light); }

/* Lutins et récompenses flottantes */
.imp-layer { position: fixed; inset: 0; pointer-events: none; z-index: 60; }
.imp {
  position: absolute;
  width: 60px;
  height: 60px;
  image-rendering: pixelated;
  pointer-events: auto;
  cursor: pointer;
  animation: impIn 0.25s steps(3) both, impBob 1.1s ease-in-out infinite 0.25s;
  filter: drop-shadow(0 0 6px rgba(110, 231, 160, 0.55));
}
.imp:hover { filter: drop-shadow(0 0 10px rgba(255, 217, 160, 0.9)); }
@keyframes impIn { from { opacity: 0; transform: scale(0.4); } to { opacity: 1; transform: scale(1); } }
@keyframes impBob { 0%, 100% { translate: 0 0; } 50% { translate: 0 -8px; } }

.floating-number.imp-reward {
  color: var(--success);
  font-size: 13px;
  animation-duration: 1.2s;
}

/* Modal compte */
.account-box { width: 460px; }
.account-section { margin-bottom: 18px; }
.account-heading {
  font-size: 9px;
  color: var(--ember);
  margin: 0 0 10px;
  letter-spacing: 1px;
}
.stats-grid {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px 12px;
  margin: 0;
  max-height: 210px;
  overflow-y: auto;
}
.stats-grid dt { font-size: 8px; color: var(--text-dim); align-self: center; }
.stats-grid dd { font-size: 9px; color: var(--ice-bright); margin: 0; text-align: right; }
.account-row { display: flex; gap: 8px; }
.account-row input {
  flex: 1;
  font-family: var(--font-pixel);
  font-size: 10px;
  background: var(--bg-dark);
  border: 2px solid var(--border);
  color: var(--text);
  padding: 9px 8px;
  outline: none;
  min-width: 0;
}
.account-row input:focus { border-color: var(--ice); }
.btn-pixel.account { background: var(--bg-panel-light); color: var(--ice); box-shadow: 0 4px 0 var(--border); }
.btn-pixel.account:hover { background: var(--border); color: var(--ice-bright); }

/* 8-bit dialog box */
.dialog-overlay {
  position: fixed;
  inset: 0;
  background: rgba(4, 8, 14, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.dialog-overlay.hidden { display: none; }

.dialog-box {
  background: var(--bg-panel);
  border: 4px solid var(--border);
  box-shadow: 0 0 0 4px var(--bg-dark), 0 0 0 8px var(--border-light);
  width: 420px;
  max-width: 88vw;
  padding: 22px 24px;
}
.dialog-title {
  color: var(--ice-bright);
  font-size: 12px;
  margin: 0 0 14px;
  border-bottom: 2px solid var(--border);
  padding-bottom: 10px;
}
.dialog-text {
  color: var(--text);
  font-size: 10px;
  line-height: 1.9;
  margin: 0 0 18px;
  white-space: pre-line;
}
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; }

@media (max-width: 1100px) {
  .game-main { grid-template-columns: 1fr 1fr; grid-template-rows: 380px 1fr; }
  .panel-click { grid-column: 1 / -1; }
}

@media (max-width: 640px) {
  .auth-panel { padding: 20px; }
  .pixel-title { font-size: 20px; }
  .hud { flex-direction: column; align-items: flex-start; }
  .game-main { grid-template-columns: 1fr; }
  #app { overflow-y: auto; }
  html, body { overflow: auto; }
}
