:root {
  --bg: #0a0e1a;
  --bg2: #0f1628;
  --bg3: #141c35;
  --neon: #00d4ff;
  --viola: #7c3aed;
  --oro: #f59e0b;
  --successo: #10b981;
  --pericolo: #ef4444;
  --testo: #e2e8f0;
  --soft: #94a3b8;
  --bordo: #1e2d4d;
  --glow: 0 0 12px rgba(0,212,255,0.4);
}

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

body {
  background: var(--bg);
  color: var(--testo);
  font-family: 'Segoe UI', system-ui, sans-serif;
  min-height: 100vh;
  -webkit-text-size-adjust: 100%;
}

.screen { min-height: 100vh; }
.hidden { display: none !important; }

/* ── AUTH FLASH FIX ──────────────────────────────────────────────────────── */
html.is-authed #login-screen { display: none !important; }

/* ── SETUP PROFILO ───────────────────────────────────────────────────────── */
.setup-box {
  display: flex; flex-direction: column; align-items: center;
  min-height: 100vh; padding: 32px 20px; gap: 8px;
}
.setup-form-wrap {
  width: 100%; max-width: 480px;
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--bordo);
  border-radius: 12px;
  padding: 24px;
  margin-top: 8px;
}
.setup-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 16px; }
.setup-field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.setup-field-full { grid-column: 1 / -1; }
.setup-label { font-size: 12px; letter-spacing: 1px; color: var(--soft); text-transform: uppercase; }
.setup-input, .setup-select {
  background: var(--bg3); border: 1px solid var(--bordo); color: var(--testo);
  border-radius: 8px; padding: 10px 12px; font-size: 15px; width: 100%;
  outline: none; transition: border-color 0.2s;
}
.setup-input:focus, .setup-select:focus { border-color: var(--neon); }
.radio-group { display: flex; gap: 20px; padding-top: 4px; }
.radio-opt { display: flex; align-items: center; gap: 8px; cursor: pointer; font-size: 15px; color: var(--testo); }
.radio-opt input { accent-color: var(--neon); width: 16px; height: 16px; cursor: pointer; }
.setup-submit {
  width: 100%; margin-top: 8px;
  background: var(--neon); color: #000;
  border: none; border-radius: 8px;
  padding: 14px; font-size: 15px; font-weight: 700;
  cursor: pointer; letter-spacing: 1px; transition: opacity 0.2s;
}
.setup-submit:hover { opacity: 0.88; }
.setup-submit:disabled { opacity: 0.5; cursor: not-allowed; }
.setup-error { color: var(--pericolo); font-size: 13px; text-align: center; margin-top: 10px; }

/* ── DOWNLOAD BANNER ─────────────────────────────────────────────────────── */
.dl-banner {
  display: flex;
  align-items: center;
  gap: 12px;
  background: linear-gradient(90deg, #0a1628, #0f2040);
  border-bottom: 1px solid var(--neon);
  padding: 12px 16px;
}
.dl-banner-icon { font-size: 22px; flex-shrink: 0; }
.dl-banner-text { flex: 1; display: flex; flex-direction: column; gap: 2px; font-size: 13px; }
.dl-banner-text strong { color: var(--neon); font-size: 14px; }
.dl-banner-text span { color: var(--soft); }
.dl-banner-btn {
  background: var(--neon);
  color: #000;
  font-weight: 700;
  font-size: 13px;
  padding: 7px 16px;
  border-radius: 6px;
  text-decoration: none;
  flex-shrink: 0;
  white-space: nowrap;
}
.dl-banner-close {
  background: none;
  border: none;
  color: var(--soft);
  font-size: 16px;
  cursor: pointer;
  padding: 4px 8px;
  flex-shrink: 0;
}

/* ── LOGIN ───────────────────────────────────────────────────────────────── */
.login-box {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; min-height: 100vh;
  gap: 16px; padding: 24px;
}
.system-title { color: var(--neon); font-size: 12px; letter-spacing: 6px; opacity: 0.7; text-align: center; }
.arise-title {
  font-size: 48px; font-weight: 900; letter-spacing: 6px;
  background: linear-gradient(135deg, var(--neon), var(--viola));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
}
.subtitle { color: var(--soft); letter-spacing: 3px; font-size: 13px; margin-bottom: 20px; text-align: center; }

/* ── TOP BAR — mobile: 2 righe ───────────────────────────────────────────── */
.top-bar {
  background: var(--bg2); border-bottom: 1px solid var(--bordo);
  padding: 10px 14px;
  display: grid;
  grid-template-areas:
    "hunter header-right"
    "xp     xp";
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 8px 10px;
}
.hunter-info  { grid-area: hunter;       display: flex; align-items: center; gap: 10px; min-width: 0; }
.xp-bar-wrap  { grid-area: xp;           display: flex; flex-direction: column; gap: 4px; }
.header-right { grid-area: header-right; display: flex; align-items: center; gap: 8px; }

#avatar { width: 36px; height: 36px; border-radius: 50%; border: 2px solid var(--neon); flex-shrink: 0; }
.hunter-name  { font-weight: 700; color: var(--neon); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hunter-level { font-size: 11px; color: var(--soft); }

.xp-bar-bg   { background: var(--bg3); border-radius: 4px; height: 8px; overflow: hidden; border: 1px solid var(--bordo); }
.xp-bar-fill { height: 100%; background: linear-gradient(90deg, var(--neon), var(--viola)); border-radius: 4px; transition: width 0.5s; }
.xp-text     { font-size: 10px; color: var(--soft); }

/* Download button — mobile: solo icona + versione */
.btn-download {
  display: flex; align-items: center; gap: 6px;
  background: none; border: 1px solid var(--neon);
  color: var(--neon); padding: 5px 10px; border-radius: 6px;
  text-decoration: none; transition: all 0.2s;
  box-shadow: 0 0 8px rgba(0,212,255,0.15);
  white-space: nowrap;
}
.btn-download:hover, .btn-download:active { background: rgba(0,212,255,0.12); box-shadow: var(--glow); }
.dl-icon    { font-size: 15px; font-weight: 700; }
.dl-label   { display: none; } /* visibile solo su desktop */
.dl-version { font-size: 10px; color: var(--soft); letter-spacing: 1px; }

.btn-logout {
  background: none; border: 1px solid var(--bordo); color: var(--soft);
  padding: 5px 10px; border-radius: 6px; cursor: pointer; font-size: 12px;
  white-space: nowrap;
}
.btn-logout:hover { border-color: var(--pericolo); color: var(--pericolo); }

/* ── TAB BAR — scroll orizzontale su mobile ──────────────────────────────── */
.tab-bar {
  background: var(--bg2); border-bottom: 1px solid var(--bordo);
  display: flex; padding: 0 6px; gap: 0;
  overflow-x: auto; -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.tab-bar::-webkit-scrollbar { display: none; }
.tab {
  background: none; border: none; color: var(--soft);
  padding: 12px 16px; cursor: pointer; font-size: 13px;
  border-bottom: 2px solid transparent; transition: all 0.2s; flex-shrink: 0;
}
.tab:hover  { color: var(--testo); }
.tab.active { color: var(--neon); border-bottom-color: var(--neon); }

/* ── CONTENT ─────────────────────────────────────────────────────────────── */
.content { padding: 12px; max-width: 1100px; margin: 0 auto; }

/* ── WINDOW ──────────────────────────────────────────────────────────────── */
.window {
  background: var(--bg2); border: 1px solid var(--bordo);
  border-radius: 8px; padding: 14px; margin-bottom: 12px;
}
.window-title { color: var(--neon); font-size: 11px; letter-spacing: 3px; margin-bottom: 12px; opacity: 0.8; }

/* ── STATS GRID — 3 col su mobile ────────────────────────────────────────── */
.stats-grid {
  display: grid; grid-template-columns: repeat(3, 1fr);
  gap: 10px; margin-bottom: 12px;
}
.stat-card {
  background: var(--bg2); border: 1px solid var(--bordo); border-radius: 8px;
  padding: 12px 8px; text-align: center;
}
.stat-label { font-size: 10px; color: var(--soft); letter-spacing: 2px; }
.stat-value { font-size: 22px; font-weight: 800; margin-top: 4px; }
.stat-str   { color: #ef4444; }
.stat-vit   { color: #10b981; }
.stat-agi   { color: var(--neon); }
.stat-intel { color: var(--viola); }
.stat-per   { color: var(--oro); }

/* ── QUEST ───────────────────────────────────────────────────────────────── */
.quest-item { padding: 10px 0; border-bottom: 1px solid var(--bordo); }
.quest-item:last-child { border-bottom: none; }
.quest-check {
  display: inline-block; width: 18px; height: 18px;
  border: 2px solid var(--neon); border-radius: 4px;
  margin-right: 10px; vertical-align: middle;
  text-align: center; line-height: 14px; font-size: 12px;
}
.quest-check.done { background: var(--neon); color: var(--bg); }

/* Intestazione missione con navigazione storico */
.quest-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 10px;
}
.quest-header .quest-title-text { font-weight: 700; font-size: 14px; color: var(--neon); }
.date-nav-sm {
  display: flex; align-items: center; gap: 6px;
}
.date-nav-sm button {
  background: var(--bg3); border: 1px solid var(--bordo); color: var(--soft);
  border-radius: 6px; padding: 2px 8px; font-size: 13px; cursor: pointer;
  transition: border-color 0.2s, color 0.2s;
}
.date-nav-sm button:hover { border-color: var(--neon); color: var(--neon); }
.date-nav-sm span { font-size: 12px; color: var(--soft); min-width: 70px; text-align: center; }

/* ── WORKOUTS ────────────────────────────────────────────────────────────── */
.workout-item { padding: 12px 0; border-bottom: 1px solid var(--bordo); }
.workout-item:last-child { border-bottom: none; }
.workout-header { display: flex; justify-content: space-between; align-items: flex-start; flex-wrap: wrap; gap: 4px; }
.workout-title { font-weight: 600; font-size: 14px; }
.workout-date  { font-size: 12px; color: var(--soft); }
.workout-xp    { color: var(--oro); font-size: 13px; font-weight: 700; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 12px; font-size: 10px; font-weight: 700; margin-left: 6px; }
.badge-forza { background: rgba(124,58,237,0.2); color: var(--viola); border: 1px solid var(--viola); }
.badge-corsa { background: rgba(16,185,129,0.2); color: var(--successo); border: 1px solid var(--successo); }

/* ── NUTRITION ───────────────────────────────────────────────────────────── */
.date-nav {
  display: flex; align-items: center; justify-content: center;
  gap: 16px; margin-bottom: 12px;
}
.date-nav button {
  background: var(--bg2); border: 1px solid var(--bordo);
  color: var(--testo); padding: 8px 18px; border-radius: 6px;
  cursor: pointer; font-size: 16px; touch-action: manipulation;
}
.date-nav span { font-weight: 600; font-size: 15px; }

/* Macro — 2 col su mobile */
.macro-bar-wrap { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 12px; }
.macro-card { background: var(--bg2); border: 1px solid var(--bordo); border-radius: 8px; padding: 12px; text-align: center; }
.macro-name { font-size: 11px; color: var(--soft); }
.macro-val  { font-size: 20px; font-weight: 800; margin-top: 4px; }
.macro-bar  { height: 4px; border-radius: 2px; margin-top: 8px; background: var(--bg3); overflow: hidden; }
.macro-bar-inner { height: 100%; border-radius: 2px; transition: width 0.5s; }

.meal-item { padding: 10px 0; border-bottom: 1px solid var(--bordo); display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.meal-item:last-child { border-bottom: none; }
.meal-left  { min-width: 0; }
.meal-tipo  { font-size: 10px; color: var(--viola); font-weight: 700; letter-spacing: 1px; }
.meal-name  { font-size: 14px; margin-top: 2px; word-break: break-word; }
.meal-grammi{ font-size: 12px; color: var(--soft); }
.meal-kcal  { font-weight: 700; color: var(--neon); white-space: nowrap; padding-top: 2px; }

/* ── PROGRESS ────────────────────────────────────────────────────────────── */
#weight-chart { width: 100%; touch-action: pan-y; }
.hunter-stats-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 8px; }

/* ── BOTTONE ELIMINA PASTO ───────────────────────────────────────────────── */
.btn-delete {
  color: var(--pericolo);
  background: none;
  border: none;
  cursor: pointer;
  font-size: 15px;
  padding: 4px 6px;
  border-radius: 4px;
  line-height: 1;
  opacity: 0.7;
  transition: opacity 0.15s;
  min-width: 30px; min-height: 30px;
  display: flex; align-items: center; justify-content: center;
}
.btn-delete:hover { opacity: 1; background: rgba(239,68,68,0.1); }

/* ── PANNELLI COLLASSABILI ───────────────────────────────────────────────── */
.collapsible-window .window-title {
  cursor: pointer;
  user-select: none;
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0;
  transition: opacity 0.15s;
}
.collapsible-window .window-title:hover { opacity: 1; }
.collapse-arrow { font-size: 10px; opacity: 0.6; transition: transform 0.2s; }

.collapsible-body {
  overflow: hidden;
  max-height: 600px;
  transition: max-height 0.3s ease, opacity 0.25s ease, margin-top 0.2s ease;
  margin-top: 14px;
  opacity: 1;
}
.collapsible-body.collapsed {
  max-height: 0;
  opacity: 0;
  margin-top: 0;
}

/* ── FORM GENERICO ───────────────────────────────────────────────────────── */
.form-field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.form-label { font-size: 11px; letter-spacing: 2px; color: var(--soft); text-transform: uppercase; }
.form-input {
  background: var(--bg3);
  border: 1px solid var(--bordo);
  color: var(--testo);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 14px;
  width: 100%;
  outline: none;
  transition: border-color 0.2s;
  -webkit-appearance: none;
}
.form-input:focus { border-color: var(--neon); box-shadow: 0 0 0 1px rgba(0,212,255,0.2); }

.add-form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.add-form-actions { display: flex; align-items: center; gap: 14px; margin-top: 4px; }

.btn-primary {
  background: var(--neon);
  color: #000;
  font-weight: 700;
  border: none;
  border-radius: 8px;
  padding: 10px 22px;
  font-size: 13px;
  letter-spacing: 1px;
  cursor: pointer;
  transition: opacity 0.15s;
  white-space: nowrap;
  min-height: 40px;
}
.btn-primary:hover { opacity: 0.85; }
.btn-primary:active { opacity: 0.7; }

.form-msg { font-size: 13px; }
.form-msg-ok  { color: var(--successo); }
.form-msg-err { color: var(--pericolo); }

/* ── DROPDOWN CIBI ───────────────────────────────────────────────────────── */
.food-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  left: 0; right: 0;
  background: var(--bg3);
  border: 1px solid var(--neon);
  border-radius: 8px;
  z-index: 100;
  box-shadow: 0 4px 20px rgba(0,212,255,0.15);
  overflow: hidden;
}
.food-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px;
  cursor: pointer;
  border-bottom: 1px solid var(--bordo);
  transition: background 0.12s;
  gap: 8px;
}
.food-item:last-child { border-bottom: none; }
.food-item:hover { background: rgba(0,212,255,0.08); }
.food-item-nome { font-size: 14px; }
.food-item-kcal { font-size: 12px; color: var(--soft); white-space: nowrap; }

/* ── PREVIEW MACRO ───────────────────────────────────────────────────────── */
.meal-preview {
  background: rgba(0,212,255,0.06);
  border: 1px solid rgba(0,212,255,0.25);
  border-radius: 8px;
  padding: 10px 14px;
  margin-bottom: 14px;
}
.preview-name { font-size: 13px; font-weight: 600; color: var(--testo); margin-bottom: 6px; }
.preview-macros { font-size: 13px; color: var(--soft); }

/* ── TOAST ───────────────────────────────────────────────────────────────── */
#toast-container {
  position: fixed; bottom: 20px; right: 16px;
  display: flex; flex-direction: column; gap: 8px;
  z-index: 9999; pointer-events: none;
}
.toast {
  background: var(--bg3); border: 1px solid var(--bordo);
  color: var(--testo); border-radius: 8px;
  padding: 10px 16px; font-size: 13px;
  opacity: 0; transform: translateY(12px);
  transition: opacity 0.25s ease, transform 0.25s ease;
  max-width: 280px; word-break: break-word; pointer-events: auto;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast-ok   { border-color: var(--successo); color: var(--successo); }
.toast-warn { border-color: var(--oro); color: var(--oro); }
.toast-err  { border-color: var(--pericolo); color: var(--pericolo); }

/* ── WORKOUT ITEM ────────────────────────────────────────────────────────── */
.workout-item {
  padding: 12px 0; border-bottom: 1px solid var(--bordo);
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
}
.workout-main { flex: 1; min-width: 0; }

/* ── METRIC ITEM (storico peso) ──────────────────────────────────────────── */
.metric-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 0; border-bottom: 1px solid var(--bordo); font-size: 14px;
}
.metric-item:last-child { border-bottom: none; }
.metric-date { color: var(--soft); font-size: 13px; flex: 1; }
.metric-val  { color: var(--neon); font-weight: 700; }

/* ── EXPORT BUTTONS ──────────────────────────────────────────────────────── */
.export-grid { display: flex; flex-wrap: wrap; gap: 10px; }
.btn-export {
  background: none; border: 1px solid var(--bordo); color: var(--soft);
  padding: 8px 16px; border-radius: 8px; font-size: 13px; cursor: pointer;
  transition: all 0.15s; letter-spacing: 0.5px;
}
.btn-export:hover { border-color: var(--neon); color: var(--neon); background: rgba(0,212,255,0.06); }

/* ── DESKTOP (≥ 640 px) ──────────────────────────────────────────────────── */
@media (min-width: 640px) {
  .arise-title  { font-size: 64px; letter-spacing: 8px; }

  .top-bar {
    grid-template-areas: "hunter xp header-right";
    grid-template-columns: auto 1fr auto;
    padding: 12px 20px;
  }

  .dl-label { display: block; font-weight: 600; font-size: 13px; }
  .dl-version { display: block; }
  .btn-download { padding: 6px 14px; gap: 8px; }
  .btn-logout   { padding: 6px 14px; font-size: 13px; }

  .tab { padding: 14px 20px; font-size: 14px; }
  .tab-bar { padding: 0 20px; }

  .content { padding: 20px; }
  .window   { padding: 16px; margin-bottom: 16px; }

  .stats-grid { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }
  .stat-value { font-size: 28px; }

  .macro-bar-wrap { grid-template-columns: repeat(4, 1fr); }

  .hunter-stats-grid { grid-template-columns: repeat(5, 1fr); }
}
