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

:root {
  --ink: #4a2f15;
  --wood-1: #b06a35;
  --wood-2: #8a4f24;
  --wood-border: #5e3416;
  --cream: #fff7e6;
  --panel-border: #7a4a22;
}

html, body {
  width: 100%; height: 100%; overflow: hidden;
  font-family: 'Fredoka', 'Segoe UI', system-ui, sans-serif;
  background: #0e1726;
}

#renderCanvas { width: 100%; height: 100%; display: block; outline: none; touch-action: none; }

.hidden { display: none !important; }

/* ---------------- Boutons cartoon ---------------- */
.btn {
  font-family: inherit; font-weight: 700; color: #fff; cursor: pointer;
  border: none; border-radius: 16px; padding: 12px 24px; font-size: 18px;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.28);
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.45),
    inset 0 -5px 0 rgba(0, 0, 0, 0.22),
    0 5px 0 rgba(0, 0, 0, 0.22),
    0 9px 14px rgba(0, 0, 0, 0.25);
  transition: transform 0.06s ease, box-shadow 0.06s ease, filter 0.12s ease;
}
.btn:hover { filter: brightness(1.06); }
.btn:active {
  transform: translateY(4px);
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.4), inset 0 -2px 0 rgba(0, 0, 0, 0.22), 0 1px 0 rgba(0, 0, 0, 0.22);
}
.btn:disabled { filter: grayscale(0.5) brightness(0.8); cursor: not-allowed; }
.btn-green { background: linear-gradient(#7ed957, #46b035); }
.btn-gold  { background: linear-gradient(#ffd35a, #f0a929); color: #5a3d00; text-shadow: 0 1px 0 rgba(255, 255, 255, 0.45); }
.btn-wood  {
  background: linear-gradient(var(--wood-1), var(--wood-2));
  border: 3px solid var(--wood-border); color: #ffeccc;
}
.btn-xl { font-size: 30px; padding: 18px 64px; border-radius: 22px; letter-spacing: 0.5px; }

/* ---------------- Page d'accueil ---------------- */
#home {
  position: absolute; inset: 0; z-index: 20;
  display: flex; align-items: center; justify-content: center;
  background:
    radial-gradient(120% 80% at 50% -10%, #d6f0ff 0%, #9fd0f4 45%, #6fb4e8 100%);
}
.home-card { text-align: center; padding: 20px; }
.game-title {
  font-size: 84px; font-weight: 700; color: #fff;
  text-shadow: 0 4px 0 #2f6aa6, 0 8px 16px rgba(0, 0, 0, 0.3);
  letter-spacing: 1px;
}
.game-tagline { font-size: 22px; color: #1f4e78; margin: 8px 0 34px; font-weight: 600; }
.home-row { display: flex; gap: 16px; justify-content: center; margin-top: 22px; }

#auth-box { display: flex; flex-direction: column; align-items: center; gap: 12px; margin: 10px auto 6px; }
#auth-box input {
  width: 280px; max-width: 80vw; font-family: inherit; font-size: 18px; font-weight: 600;
  padding: 12px 16px; border-radius: 14px; border: 3px solid var(--panel-border);
  background: #fff7e6; color: var(--ink); outline: none;
}
#auth-box input::placeholder { color: #b09a7a; }
#auth-msg { color: #c0392b; font-weight: 700; min-height: 20px; font-size: 14px; }

#resume-box { display: flex; flex-direction: column; align-items: center; gap: 14px; margin: 10px auto 6px; }
#welcome-msg { font-size: 18px; font-weight: 700; color: #1f4e78; }

#defeat-msg {
  background: rgba(192, 57, 43, 0.92); color: #fff; font-weight: 700; font-size: 16px;
  border-radius: 14px; padding: 12px 18px; margin-bottom: 18px; max-width: 420px;
}

/* ---------------- Modales ---------------- */
.modal {
  position: absolute; inset: 0; z-index: 30;
  display: flex; align-items: center; justify-content: center;
  background: rgba(10, 20, 35, 0.55);
}
.modal-card {
  background: var(--cream); border: 4px solid var(--panel-border); border-radius: 22px;
  padding: 26px 30px; min-width: 320px; color: var(--ink);
  box-shadow: 0 8px 0 rgba(0, 0, 0, 0.2), 0 16px 30px rgba(0, 0, 0, 0.35);
}
.modal-card h2 { margin-bottom: 16px; font-size: 26px; }
.modal-card .field { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin: 12px 0; font-size: 17px; }
.modal-card .field.check { justify-content: flex-start; gap: 10px; }
.help-list { line-height: 1.9; font-size: 15px; margin-bottom: 18px; padding-left: 4px; list-style: none; }
.help-list li { margin: 4px 0; }
.modal-close { margin-top: 10px; }

.sep { border: none; border-top: 2px dashed var(--panel-border); opacity: 0.4; margin: 14px 0; }
.admin-title { font-weight: 700; margin-bottom: 8px; }
#admin-box .btn { width: 100%; margin-bottom: 8px; }
.btn-red { background: linear-gradient(#e2685b, #b8392c); }

/* ---------------- UI de jeu ---------------- */
#ui { position: absolute; inset: 0; pointer-events: none; z-index: 10; }

#topbar {
  position: absolute; top: 14px; left: 14px; right: 14px;
  display: flex; align-items: center; gap: 18px; flex-wrap: wrap;
}
.icon-btn {
  pointer-events: auto;
  width: 44px; height: 44px; font-size: 22px; line-height: 1;
  border: 3px solid var(--wood-border); border-radius: 14px; cursor: pointer;
  background: linear-gradient(var(--wood-1), var(--wood-2));
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.25), 0 4px 0 rgba(0, 0, 0, 0.22), 0 7px 11px rgba(0, 0, 0, 0.2);
}
.icon-btn:active { transform: translateY(3px); box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.2); }

#resbar { display: flex; gap: 10px; flex-wrap: wrap; }
.res-pill {
  pointer-events: auto;
  display: flex; align-items: center; gap: 8px;
  background: linear-gradient(var(--wood-1), var(--wood-2));
  border: 3px solid var(--wood-border); border-radius: 14px;
  padding: 6px 14px; color: #ffeccc; font-weight: 700; font-size: 19px;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.3);
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.25), 0 4px 0 rgba(0, 0, 0, 0.22), 0 7px 11px rgba(0, 0, 0, 0.2);
}
.res-pill .ic { font-size: 20px; }
.res-pill.workers { background: linear-gradient(#5b86c4, #3a5e93); border-color: #28406a; }
.res-pill.city { background: linear-gradient(#8a6bd0, #5d3fa0); border-color: #3d2870; }
.res-pill.soldiers { background: linear-gradient(#c45b5b, #933a3a); border-color: #6a2828; }

/* Panneau de sélection (cartoon) */
.panel {
  pointer-events: auto;
  position: absolute; left: 16px; bottom: 16px; width: 268px;
  background: var(--cream); border: 4px solid var(--panel-border); border-radius: 18px;
  padding: 14px; color: var(--ink); font-weight: 600;
  box-shadow: 0 6px 0 rgba(0, 0, 0, 0.18), 0 12px 20px rgba(0, 0, 0, 0.3);
}
.sel-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 8px; }
.sel-head b { font-size: 20px; }
.sel-head span { opacity: 0.6; font-size: 12px; }

/* Barre de croissance (style pilule) */
.growth {
  height: 18px; border-radius: 999px; background: #e2ebf5;
  border: 3px solid #5b6b80; overflow: hidden; margin-bottom: 10px;
  box-shadow: inset 0 2px 3px rgba(0, 0, 0, 0.22);
}
#sel-growth-bar {
  height: 100%; width: 0%; border-radius: 999px;
  background: linear-gradient(#9be36a, #46b035);
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.5);
  transition: width 0.25s ease;
}

#actions .btn { width: 100%; margin-top: 8px; font-size: 15px; padding: 10px 14px; }
#actions .info { font-size: 14px; opacity: 0.85; padding: 4px 0; }
#action-msg { color: #c0392b; font-size: 13px; min-height: 16px; margin-top: 6px; }

.attack-box { margin-top: 8px; font-size: 13px; }
.attack-box input[type=range] { width: 100%; margin-top: 6px; accent-color: #d4843a; }

#attack-banner {
  pointer-events: auto;
  position: absolute; top: 68px; left: 50%; transform: translateX(-50%);
  display: flex; align-items: center; gap: 12px;
  background: rgba(178, 45, 45, 0.94); color: #fff; font-weight: 700;
  border: 3px solid #6a2020; border-radius: 14px; padding: 8px 10px 8px 16px;
  box-shadow: 0 6px 14px rgba(0, 0, 0, 0.35);
}
#attack-banner .btn { padding: 6px 14px; font-size: 13px; }

.incoming-army {
  border: 2px solid #c0392b; border-radius: 10px; padding: 6px 8px; margin: 6px 0;
  font-size: 12px; background: rgba(192, 57, 43, 0.08);
}
.incoming-army input[type=range] { width: 100%; margin: 4px 0; accent-color: #c0392b; }
.incoming-army .btn { width: 100%; font-size: 12px; padding: 6px 10px; }

/* Flèches indiquant la direction des villes possédées hors écran */
#city-arrows { position: absolute; inset: 0; pointer-events: none; }
.city-arrow {
  position: absolute; pointer-events: auto; cursor: pointer;
  width: 40px; height: 40px; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(#ffd35a, #f0a929); border: 3px solid #8a5a00; border-radius: 50%;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.35);
  font-size: 18px; color: #5a3d00;
}
.city-arrow::after { content: '▲'; }

/* ---------------- Compact sur mobile / petits écrans ---------------- */
@media (max-width: 820px), (pointer: coarse) {
  #topbar { top: 8px; left: 8px; right: 8px; gap: 8px; }
  .icon-btn { width: 36px; height: 36px; font-size: 18px; border-radius: 11px; }
  #attack-banner { top: 56px; font-size: 13px; padding: 6px 8px 6px 12px; }
  .res-pill { padding: 3px 9px; font-size: 14px; border-width: 2px; border-radius: 11px; gap: 5px; }
  .res-pill .ic { font-size: 14px; }
  .panel { width: 200px; left: 8px; bottom: 8px; padding: 10px; border-width: 3px; border-radius: 14px; }
  .sel-head b { font-size: 16px; }
  #actions .btn { font-size: 12px; padding: 7px 10px; margin-top: 6px; }
  #actions .info { font-size: 12px; }
  #action-msg { font-size: 11px; }
  .growth { height: 14px; }
  .game-title { font-size: 52px; }
  .game-tagline { font-size: 16px; }
  .btn { padding: 10px 18px; font-size: 16px; }
  .btn-xl { font-size: 24px; padding: 14px 40px; }
  .modal-card { min-width: 0; width: 88vw; max-width: 360px; padding: 18px 20px; }
  #toast { font-size: 13px; padding: 8px 14px; }
}

/* Toast */
#toast {
  pointer-events: none;
  position: absolute; top: 70px; left: 50%; transform: translateX(-50%);
  background: rgba(40, 20, 10, 0.92); color: #ffd9a8;
  border: 3px solid var(--wood-border); border-radius: 14px;
  padding: 10px 18px; font-weight: 600; font-size: 15px;
  box-shadow: 0 6px 14px rgba(0, 0, 0, 0.35);
}
