/* =============================================================================
   Викинг-путешественник — оформление страниц и игрового HUD
   Аудитория 6–12 лет: крупные элементы, высокий контраст, минимум текста.
   Страницы: / (лендинг), /login, /play, /leaderboard.
   ============================================================================= */

:root {
  --sky-1: #8ec5ff;
  --sky-2: #4a90d9;
  --sea: #1b4f86;
  --wood-1: #8b5a2b;
  --wood-2: #5d3a17;
  --gold: #ffcc4d;
  --gold-dark: #e0a800;
  --grass: #4caf50;
  --ink: #1d2733;
  --paper: #fdf8ee;
  --danger: #d94b4b;
  --ok: #38a169;
  --radius: 18px;
  --shadow: 0 8px 24px rgba(12, 30, 54, 0.28);
  --hud-bg: rgba(19, 35, 58, 0.78);
  --font: "Trebuchet MS", "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  font-family: var(--font);
  color: var(--ink);
  background: linear-gradient(180deg, var(--sky-1), var(--sky-2));
  -webkit-tap-highlight-color: transparent;
}

body.theme-play { overflow: hidden; overscroll-behavior: none; }

a { color: #14487a; }

/* --- Общие элементы ------------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 14px 26px;
  border: none;
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 20px;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.18);
  transition: transform 0.08s ease, filter 0.15s ease;
}

.btn:active { transform: translateY(2px); box-shadow: 0 2px 0 rgba(0, 0, 0, 0.18); }
.btn-primary { background: linear-gradient(180deg, var(--gold), var(--gold-dark)); color: #432c00; }
.btn-secondary { background: var(--paper); color: var(--ink); }
.btn-ghost { background: rgba(255, 255, 255, 0.25); color: #fff; }
.btn-xl { padding: 20px 54px; font-size: 28px; }
.btn:disabled { filter: grayscale(0.6); opacity: 0.7; cursor: progress; }
.is-hidden { display: none !important; }

.page {
  max-width: 720px;
  margin: 0 auto;
  padding: 24px 18px 60px;
}

.page-title { font-size: 32px; text-align: center; margin: 18px 0 8px; color: #fff; text-shadow: 0 3px 0 rgba(0, 0, 0, 0.25); }

/* --- Лендинг -------------------------------------------------------------- */

.landing { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.landing-hero {
  width: 100%;
  background: var(--paper);
  border-radius: 26px;
  box-shadow: var(--shadow);
  padding: 28px 22px 32px;
  text-align: center;
  border: 4px solid rgba(255, 255, 255, 0.6);
}
.viking-badge { font-size: 76px; line-height: 1; }
.landing-hero h1 { font-size: 36px; margin: 6px 0 10px; }
.tagline { font-size: 18px; color: #45566b; margin: 0 auto 22px; max-width: 460px; }
.landing-actions { display: flex; flex-direction: column; gap: 12px; align-items: stretch; }
.facts { list-style: none; display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; padding: 0; margin: 22px 0 0; }
.facts li { background: #eef4ff; border-radius: 999px; padding: 8px 14px; font-size: 14px; color: #33506f; }

/* --- Вход и регистрация --------------------------------------------------- */

.auth {
  background: var(--paper);
  border-radius: 24px;
  box-shadow: var(--shadow);
  margin: 24px auto;
}
.auth .page-title { color: var(--ink); text-shadow: none; }
.auth-hint { text-align: center; color: #4a5b70; margin-top: 0; }
.tabs { display: flex; gap: 8px; margin: 18px 0 12px; }
.tab {
  flex: 1;
  padding: 12px 10px;
  border-radius: 14px 14px 0 0;
  border: none;
  background: #e6ecf5;
  font-family: inherit;
  font-size: 16px;
  font-weight: 700;
  color: #43556b;
  cursor: pointer;
  text-align: center;
  text-decoration: none;
}
.tab.is-active { background: var(--gold); color: #432c00; }
.auth-form { display: flex; flex-direction: column; gap: 14px; }
.auth-form label { display: flex; flex-direction: column; gap: 6px; font-weight: 700; font-size: 16px; }
.auth-form input {
  font-family: inherit;
  font-size: 20px;
  padding: 14px 16px;
  border-radius: 14px;
  border: 3px solid #d3dcea;
  background: #fff;
}
.auth-form input:focus { outline: none; border-color: var(--sky-2); }
.auth-form small { font-weight: 400; color: #6b7c92; font-size: 13px; }
.auth-error {
  margin-top: 16px;
  background: #ffe6e6;
  border: 3px solid var(--danger);
  color: #7a1f1f;
  border-radius: 14px;
  padding: 12px 16px;
  font-weight: 700;
}
.auth-foot { text-align: center; margin-top: 22px; }

/* --- Игровой экран -------------------------------------------------------- */

.game-root { position: fixed; inset: 0; overflow: hidden; background: var(--sea); }
#game-canvas { display: block; width: 100%; height: 100%; touch-action: none; }

.hud-top {
  position: absolute;
  top: 0; left: 0; right: 0;
  display: flex;
  gap: 8px;
  align-items: center;
  padding: max(10px, env(safe-area-inset-top)) 12px 10px;
  pointer-events: none;
}
.hud-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--hud-bg);
  color: #fff;
  border-radius: 999px;
  padding: 8px 16px;
  font-size: 20px;
  font-weight: 700;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.3);
  backdrop-filter: blur(4px);
}
.hud-coins { color: var(--gold); }
.hud-icon { font-size: 22px; }
.hud-nick { max-width: 34vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hud-icon-btn {
  pointer-events: auto;
  margin-left: auto;
  width: 48px; height: 48px;
  border-radius: 50%;
  border: none;
  background: var(--hud-bg);
  color: #fff;
  font-size: 22px;
  cursor: pointer;
}

.hud-actions {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.hud-action {
  width: 56px; height: 56px;
  border-radius: 50%;
  border: none;
  background: var(--hud-bg);
  color: #fff;
  font-size: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  cursor: pointer;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.3);
}
.hud-action.is-on { background: linear-gradient(180deg, #7ee08a, #38a169); }
.hud-action.is-off { background: var(--hud-bg); opacity: 0.75; }

.joystick-zone {
  position: absolute;
  left: 0; bottom: 0;
  width: 55%;
  height: 45%;
  touch-action: none;
}
.joystick-base {
  position: absolute;
  left: 34px;
  bottom: 34px;
  width: 148px;
  height: 148px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.18);
  border: 4px solid rgba(255, 255, 255, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
}
.joystick-knob {
  width: 68px;
  height: 68px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.85);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
}

.action-buttons {
  position: absolute;
  right: 24px;
  bottom: 40px;
  display: flex;
  gap: 14px;
}
.action-btn {
  width: 96px; height: 96px;
  border-radius: 50%;
  border: 5px solid rgba(255, 255, 255, 0.55);
  background: radial-gradient(circle at 35% 30%, #ffe07a, #e0a800);
  font-size: 44px;
  cursor: pointer;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35);
}
.action-btn:active { transform: scale(0.94); }

.toast-area {
  position: absolute;
  top: 76px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  pointer-events: none;
  width: min(92vw, 460px);
}
.toast {
  background: var(--hud-bg);
  color: #fff;
  padding: 10px 18px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 16px;
  animation: toast-in 0.2s ease-out;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.3);
}
.toast.is-good { background: rgba(56, 161, 105, 0.92); }
.toast.is-warn { background: rgba(217, 121, 75, 0.94); }
.toast.is-bad { background: rgba(217, 75, 75, 0.94); }

@keyframes toast-in { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: none; } }

.overlay {
  position: absolute;
  inset: 0;
  background: rgba(11, 26, 45, 0.82);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 20;
}
.overlay.is-hidden { display: none; }
.overlay-card {
  background: var(--paper);
  border-radius: 22px;
  padding: 26px 24px;
  text-align: center;
  max-width: 420px;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 14px;
  align-items: center;
  box-shadow: var(--shadow);
}
.spinner {
  width: 52px; height: 52px;
  border-radius: 50%;
  border: 6px solid #d8e2ef;
  border-top-color: var(--sky-2);
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.progress { width: 100%; height: 14px; background: #dde6f2; border-radius: 999px; overflow: hidden; }
.progress.is-hidden { display: none; }
.progress-bar { height: 100%; width: 0%; background: linear-gradient(90deg, var(--gold), var(--grass)); transition: width 0.2s ease; }

/* --- Рейтинг -------------------------------------------------------------- */

.leaderboard { background: var(--paper); border-radius: 24px; margin: 24px auto 60px; box-shadow: var(--shadow); }
.leaderboard .page-title { color: var(--ink); text-shadow: none; }
.lb-tabs { display: flex; gap: 8px; margin-bottom: 14px; }
.lb-my-rank { text-align: center; font-size: 18px; }
.lb-table { width: 100%; border-collapse: collapse; background: #fff; border-radius: 16px; overflow: hidden; }
.lb-table th, .lb-table td { padding: 12px 10px; text-align: left; font-size: 17px; border-bottom: 1px solid #eef1f6; }
.lb-table th { background: #eaf1fb; font-size: 15px; color: #3d5876; }
.lb-rank { font-weight: 700; color: var(--gold-dark); }
.lb-nick { font-weight: 700; }
.lb-updated { text-align: center; color: #66788f; font-size: 14px; margin-top: 16px; }

/* --- Мобильные уточнения -------------------------------------------------- */

@media (max-width: 520px) {
  .hud-chip { font-size: 17px; padding: 7px 12px; }
  .hud-nick { display: none; }
  .action-btn { width: 84px; height: 84px; font-size: 38px; }
  .joystick-base { left: 22px; bottom: 26px; width: 132px; height: 132px; }
  .landing-hero h1 { font-size: 30px; }
}

@media (min-width: 900px) {
  /* На большом экране джойстик не мешает: управление WASD/стрелками. */
  .joystick-zone { opacity: 0.9; }
}
