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

:root {
  --bg: #05070f;
  --panel: rgba(13, 18, 34, 0.92);
  --panel-border: rgba(90, 130, 255, 0.18);
  --text: #e4ebff;
  --text-dim: #99a7cf;
  --topbar-h: 66px;
  --accent: #5a82ff;
  --m0: #68e07f;
  --m3: #ffe14d;
  --m4: #ffb300;
  --m5: #ff7a00;
  --m6: #ff3b30;
  --m7: #ff2d78;
}

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, sans-serif;
}

/* ---------- Topbar ---------- */
#topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 22px;
  padding: 8px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--panel-border);
  backdrop-filter: blur(8px);
  flex-wrap: wrap;
}

#brand { display: flex; align-items: center; gap: 10px; }
#brand .logo { font-size: 28px; }
#brand h1 { font-size: 18px; letter-spacing: 1px; }
#brand .sub { font-size: 12px; color: var(--text-dim); }

#stats { display: flex; gap: 18px; }
.stat { display: flex; flex-direction: column; align-items: center; min-width: 62px; }
.stat-val { font-size: 18px; font-weight: 700; color: #fff; font-variant-numeric: tabular-nums; }
.stat-lab { font-size: 10px; color: var(--text-dim); text-transform: uppercase; letter-spacing: .5px; }

#controls {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-left: auto;
  font-size: 12px;
  color: var(--text-dim);
}
#controls label { display: flex; align-items: center; gap: 6px; white-space: nowrap; }
#controls select {
  background: #101830;
  color: var(--text);
  border: 1px solid var(--panel-border);
  border-radius: 6px;
  padding: 3px 6px;
  font-size: 12px;
}
#controls input[type=range] { width: 90px; accent-color: var(--accent); }
#controls .chk { cursor: pointer; user-select: none; }
#mag-val { color: #fff; font-weight: 700; min-width: 20px; text-align: right; }

#live { display: flex; align-items: center; gap: 6px; font-size: 11px; color: var(--text-dim); }
.dot { width: 9px; height: 9px; border-radius: 50%; background: #666; }
.dot.ok { background: #3ddc84; box-shadow: 0 0 8px #3ddc84; animation: pulse 2s infinite; }
.dot.err { background: #ff3b30; box-shadow: 0 0 8px #ff3b30; }
@keyframes pulse { 50% { opacity: .4; } }

/* ---------- Layout ---------- */
main { height: 100%; }
#globe { position: absolute; inset: 0; }

#panel {
  position: fixed;
  top: calc(var(--topbar-h) + 12px);
  left: 12px;
  bottom: 12px;
  width: 320px;
  z-index: 15;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

#panel section {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  padding: 12px;
  backdrop-filter: blur(8px);
}

#panel h2 { font-size: 13px; margin-bottom: 8px; letter-spacing: .5px; }
#panel h2 small { color: var(--text-dim); font-weight: 400; }

/* ---------- Histogram ---------- */
#histogram {
  display: flex;
  align-items: flex-end;
  gap: 2px;
  height: 90px;
}
.bar {
  flex: 1;
  min-height: 2px;
  background: var(--accent);
  border-radius: 2px 2px 0 0;
  cursor: pointer;
  position: relative;
  opacity: .85;
  transition: opacity .15s;
}
.bar:hover, .bar.sel { opacity: 1; outline: 1px solid #fff; }
.bar .tip {
  display: none;
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  background: #000d;
  border: 1px solid var(--panel-border);
  border-radius: 6px;
  padding: 5px 8px;
  font-size: 12px;
  white-space: nowrap;
  z-index: 5;
  pointer-events: none;
}
.bar:hover .tip { display: block; }

#day-banner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: rgba(90,130,255,.15);
  border: 1px solid var(--accent);
  border-radius: 8px;
  padding: 5px 8px;
  font-size: 12px;
  margin-bottom: 8px;
}
#day-banner.hidden { display: none; }
#day-reset {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  font-size: 12px;
}

.legend { display: flex; gap: 11px; margin-top: 8px; font-size: 11px; color: var(--text-dim); flex-wrap: wrap; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 3px; }

/* ---------- List ---------- */
#list-box { flex: 1; min-height: 0; display: flex; flex-direction: column; }
#quake-list {
  list-style: none;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}
#quake-list li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 6px;
  border-bottom: 1px solid rgba(255,255,255,.05);
  cursor: pointer;
  border-radius: 6px;
}
#quake-list li:hover { background: rgba(90,130,255,.12); }
#quake-list li.new { animation: flash 2.5s; }
@keyframes flash { 0% { background: rgba(255,59,48,.4); } 100% { background: transparent; } }

.mag-badge {
  min-width: 40px;
  text-align: center;
  font-weight: 700;
  font-size: 13px;
  color: #000;
  border-radius: 6px;
  padding: 4px 0;
}
.q-info { flex: 1; min-width: 0; }
.q-place { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.q-meta { font-size: 11px; color: var(--text-dim); }

#quake-list::-webkit-scrollbar { width: 6px; }
#quake-list::-webkit-scrollbar-thumb { background: rgba(90,130,255,.3); border-radius: 3px; }

/* ---------- Toasts ---------- */
#toasts {
  position: fixed;
  top: calc(var(--topbar-h) + 14px);
  right: 16px;
  z-index: 40;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: 340px;
}
.toast {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-left: 5px solid var(--accent);
  border-radius: 10px;
  padding: 10px 14px;
  box-shadow: 0 6px 24px #000a;
  animation: slidein .35s ease;
  cursor: pointer;
}
.toast.out { animation: slideout .4s ease forwards; }
@keyframes slidein { from { transform: translateX(110%); } to { transform: translateX(0); } }
@keyframes slideout { to { transform: translateX(110%); opacity: 0; } }
.toast .t-title { font-weight: 700; font-size: 14px; margin-bottom: 3px; }
.toast .t-body { font-size: 13px; color: var(--text-dim); line-height: 1.45; }

/* ---------- Loading ---------- */
#loading {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  color: var(--text-dim);
  transition: opacity .5s;
}
#loading.done { opacity: 0; pointer-events: none; }
.spinner {
  width: 44px; height: 44px;
  border: 3px solid rgba(90,130,255,.2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Globe tooltip ---------- */
.globe-tip {
  background: rgba(0,0,0,.85);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 12px;
  font-family: "Segoe UI", system-ui, sans-serif;
  color: var(--text);
}
.globe-tip b { font-size: 13px; }

/* Tooltip del puntamento manuale (viste con i punti fusi) */
#custom-tip {
  position: fixed;
  z-index: 30;
  display: none;
  pointer-events: none;
  max-width: 320px;
}

/* ---------- Guida / informazioni ---------- */
#btn-info {
  background: #101830;
  color: var(--text);
  border: 1px solid var(--panel-border);
  border-radius: 6px;
  padding: 4px 9px;
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
}
#btn-info:hover { border-color: var(--accent); color: #fff; }

#info {
  position: fixed;
  top: calc(var(--topbar-h) + 12px);
  right: 12px;
  bottom: 12px;
  width: min(560px, calc(100vw - 360px));
  z-index: 25;
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  padding: 22px 26px 26px;
  backdrop-filter: blur(10px);
  box-shadow: 0 10px 40px #000a;
  line-height: 1.6;
  font-size: 14px;
}
#info[hidden] { display: none; }
#info h2 {
  font-size: 15px;
  margin: 20px 0 7px;
  color: #fff;
  letter-spacing: .3px;
}
#info h2:first-of-type { margin-top: 0; }
#info p { margin-bottom: 4px; color: var(--text); }
#info strong { color: #fff; }
#info a { color: var(--accent); }
#info .info-foot {
  margin-top: 22px;
  padding-top: 14px;
  border-top: 1px solid rgba(255,255,255,.08);
  font-size: 12px;
  color: var(--text-dim);
}
#info-close {
  position: sticky;
  top: 0;
  float: right;
  background: rgba(13,18,34,.9);
  color: var(--text-dim);
  border: 1px solid var(--panel-border);
  border-radius: 6px;
  width: 26px; height: 26px;
  font-size: 13px;
  cursor: pointer;
  margin-left: 12px;
}
#info-close:hover { color: #fff; border-color: var(--accent); }

body.info-open #footer { display: none; }   /* la guida ha già i suoi link in fondo */

#info::-webkit-scrollbar { width: 7px; }
#info::-webkit-scrollbar-thumb { background: rgba(90,130,255,.3); border-radius: 4px; }

/* ---------- Footer ---------- */
#footer {
  position: fixed;
  bottom: 10px;
  right: 14px;
  z-index: 15;
  font-size: 11px;
  color: var(--text-dim);
  background: rgba(13, 18, 34, 0.75);
  border: 1px solid var(--panel-border);
  border-radius: 20px;
  padding: 5px 12px;
  backdrop-filter: blur(6px);
}
#footer a { color: var(--accent); text-decoration: none; }
#footer a:hover { text-decoration: underline; }
#app-version { color: #fff; font-weight: 600; }

@media (max-width: 900px) {
  #panel { width: 260px; }
  #brand .sub { display: none; }
  /* Sotto i 900px lo spazio a destra del pannello non basta: la guida
     occupa tutta la larghezza disponibile. Senza questo, su schermi molto
     stretti calc(100vw - 360px) diventa negativa e la larghezza non è valida. */
  #info { left: 12px; width: auto; padding: 18px 20px 22px; }
}
