:root {
  --arsenal-red: #EF0107;
  --arsenal-red-dark: #c50006;
  --arsenal-navy: #023474;
  --gold: #DB0007;
  --ink: #15181f;
  --muted: #6b7280;
  --bg: #f4f6fb;
  --card: #ffffff;
  --line: #e6e9f0;
  --good: #198754;
  --radius: 18px;
  --shadow: 0 4px 18px rgba(20, 24, 31, 0.08);
  --tap: 52px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 17px;
  line-height: 1.4;
}
h1, h2, h3 { margin: 0 0 .4em; }
button { font-family: inherit; cursor: pointer; }

/* ---------- Login ---------- */
.login-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: linear-gradient(160deg, var(--arsenal-red) 0%, var(--arsenal-red-dark) 55%, var(--arsenal-navy) 100%);
  padding: 24px;
}
.login-card {
  background: var(--card);
  border-radius: 28px;
  padding: 34px 28px;
  width: 100%;
  max-width: 360px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .3);
}
.login-logo { margin-bottom: 8px; }
.login-card h1 { color: var(--arsenal-red); font-size: 1.7rem; }
.tagline { color: var(--muted); margin-top: -4px; }
.login-card form { display: flex; flex-direction: column; gap: 14px; margin-top: 18px; }
input, select, textarea {
  font-family: inherit; font-size: 1rem;
  padding: 14px 16px; border: 2px solid var(--line); border-radius: 14px;
  width: 100%; background: #fff; color: var(--ink);
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--arsenal-red); }
.error { color: var(--arsenal-red); font-weight: 600; }

/* ---------- App shell ---------- */
.app-header {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px; padding-top: calc(12px + env(safe-area-inset-top, 0px));
  background: var(--arsenal-red); color: #fff;
  box-shadow: var(--shadow);
}
.app-header h1 { font-size: 1.2rem; margin: 0; flex: 1; }
.icon-btn {
  background: rgba(255,255,255,.18); border: none; color: #fff;
  width: 40px; height: 40px; border-radius: 12px; font-size: 1.2rem;
}
.view { padding: 16px 16px 96px; max-width: 760px; margin: 0 auto; }

/* ---------- Tab bar ---------- */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: var(--safe-bottom);
}
.tab {
  background: none; border: none; padding: 10px 4px 8px;
  font-size: 1.5rem; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.tab span { font-size: .7rem; font-weight: 600; }
.tab.active { color: var(--arsenal-red); }

/* ---------- Cards & layout ---------- */
.card {
  background: var(--card); border-radius: var(--radius);
  padding: 16px; margin-bottom: 16px; box-shadow: var(--shadow);
}
.card h2 { font-size: 1.05rem; }
.row { display: flex; align-items: center; gap: 10px; }
.spread { justify-content: space-between; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.center { text-align: center; }
.hidden, [hidden] { display: none !important; }

/* ---------- Date nav ---------- */
.datenav { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 14px; }
.datenav .day-label { font-weight: 700; font-size: 1.05rem; text-align: center; flex: 1; }
.datenav button { width: 44px; height: 44px; border-radius: 12px; border: none; background: #fff; box-shadow: var(--shadow); font-size: 1.2rem; }

/* ---------- Pills ---------- */
.pill-grid { display: flex; flex-wrap: wrap; gap: 10px; }
.pill {
  border: 2px solid var(--line); background: #fff; border-radius: 999px;
  padding: 10px 16px; font-size: 1rem; font-weight: 600;
  display: inline-flex; align-items: center; gap: 8px; min-height: var(--tap);
  transition: transform .05s ease;
}
.pill:active { transform: scale(.96); }
.pill .emoji { font-size: 1.3rem; }
.pill.selected { color: #fff; border-color: transparent; }
.pill.done { box-shadow: inset 0 0 0 2px var(--good); }
.pill .check { color: #fff; }

/* ---------- Buttons ---------- */
.btn-primary {
  background: var(--arsenal-red); color: #fff; border: none;
  border-radius: 14px; padding: 14px 18px; font-size: 1rem; font-weight: 700;
  min-height: var(--tap);
}
.btn-primary.big { font-size: 1.1rem; padding: 16px; }
.btn-ghost { background: #fff; color: var(--ink); border: 2px solid var(--line); border-radius: 14px; padding: 12px 16px; font-weight: 600; }
.btn-danger { background: none; border: none; color: var(--arsenal-red); font-weight: 700; }
.btn-row { display: flex; gap: 10px; margin-top: 8px; }
.btn-row > * { flex: 1; }

/* ---------- Steppers ---------- */
.metric { margin: 14px 0; }
.metric label { display: block; font-weight: 600; margin-bottom: 6px; }
.stepper { display: flex; align-items: center; gap: 12px; }
.stepper button { width: 48px; height: 48px; border-radius: 50%; border: none; background: var(--arsenal-red); color: #fff; font-size: 1.6rem; font-weight: 700; }
.stepper .val { font-size: 1.6rem; font-weight: 800; min-width: 70px; text-align: center; }
.stepper input.val.num-input { width: 90px; min-width: 0; border: 2px solid var(--line); border-radius: 12px; height: 48px; background: var(--card); color: inherit; -moz-appearance: textfield; }
.stepper input.val.num-input::-webkit-outer-spin-button,
.stepper input.val.num-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.stepper .unit { color: var(--muted); font-size: .9rem; }
.record-line { color: var(--arsenal-red); font-weight: 700; font-size: .9rem; margin-bottom: 8px; }

/* ---------- Category / metric editor (settings) ---------- */
.cat-edit.archived { opacity: .65; }
.cat-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.cat-head input[type="text"], .cat-head input:not([type]) { height: 44px; }
.metric-edit { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 10px 0; border-top: 1px solid var(--line); }
.metric-edit-name { flex: 1 1 100%; font-weight: 600; }
.metric-edit input, .metric-edit select { height: 40px; }
.metric-edit .mini { display: flex; align-items: center; gap: 6px; font-size: .8rem; color: var(--muted); font-weight: 600; }
.metric-edit .mini input[type="number"] { height: 38px; }

/* ---------- Records (dashboard) ---------- */
.record-row { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.record-row:last-child { border-bottom: none; }
.record-row .emoji { font-size: 1.4rem; }
.record-row .record-val { font-size: 1.3rem; font-weight: 800; color: var(--arsenal-red); }

/* ---------- Logged entries ---------- */
.entry { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.entry:last-child { border-bottom: none; }
.entry .emoji { font-size: 1.4rem; }
.entry .vals { color: var(--muted); font-size: .9rem; }
.entry .vals.note { font-style: italic; }
.badge { display: inline-block; background: var(--bg); border-radius: 999px; padding: 2px 10px; font-size: .8rem; font-weight: 600; }

/* ---------- Stats ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--card); border-radius: var(--radius); padding: 16px; text-align: center; box-shadow: var(--shadow); }
.stat .num { font-size: 2rem; font-weight: 800; color: var(--arsenal-red); }
.stat .lbl { color: var(--muted); font-size: .8rem; font-weight: 600; }

/* Thermometer */
.thermo-wrap { display: flex; align-items: center; gap: 18px; }
.thermo { position: relative; width: 46px; height: 200px; }
.thermo .reward { flex: 1; }
.thermo .reward .pct { font-size: 1.8rem; font-weight: 800; color: var(--arsenal-red); }

/* Heatmap */
.heatmap { overflow-x: auto; padding-bottom: 6px; }
.heat-cell { rx: 2; }

/* Progress bars */
.goal { margin-bottom: 16px; }
.goal .top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.goal .label { font-weight: 700; }
.bar { height: 14px; background: var(--bg); border-radius: 999px; overflow: hidden; margin-top: 6px; }
.bar > span { display: block; height: 100%; background: linear-gradient(90deg, var(--arsenal-red), #ff5a5f); border-radius: 999px; transition: width .5s ease; }
.bar.done > span { background: linear-gradient(90deg, var(--good), #34d399); }

canvas { max-width: 100%; }

/* ---------- Modal ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: grid; place-items: end center; z-index: 40; }
.modal {
  background: var(--card); width: 100%; max-width: 760px;
  border-radius: 24px 24px 0 0; padding: 20px 18px calc(20px + var(--safe-bottom));
  max-height: 92vh; overflow-y: auto; box-shadow: 0 -10px 40px rgba(0,0,0,.25);
}
.modal h2 { display: flex; justify-content: space-between; align-items: center; }
.modal .close { background: none; border: none; font-size: 1.6rem; color: var(--muted); }
.field { margin-bottom: 14px; }
.field label { display: block; font-weight: 600; margin-bottom: 6px; }
.emoji-pick { display: flex; flex-wrap: wrap; gap: 6px; }
.emoji-pick button { font-size: 1.4rem; width: 44px; height: 44px; border-radius: 12px; border: 2px solid var(--line); background: #fff; }
.emoji-pick button.sel { border-color: var(--arsenal-red); background: #fff0f0; }

.empty { text-align: center; color: var(--muted); padding: 30px 10px; }
.empty .big-emoji { font-size: 3rem; display: block; margin-bottom: 8px; }
.toast { position: fixed; left: 50%; bottom: 84px; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 12px 20px; border-radius: 999px; font-weight: 600; z-index: 60; box-shadow: var(--shadow); }

/* ---------- Update banner ---------- */
.update-banner {
  position: fixed; left: 12px; right: 12px;
  bottom: calc(72px + var(--safe-bottom)); z-index: 50;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: var(--arsenal-red); color: #fff;
  padding: 12px 16px; border-radius: 14px; font-weight: 700;
  box-shadow: var(--shadow);
  animation: slide-up .25s ease;
}
.update-banner .btn-refresh {
  flex: none; background: #fff; color: var(--arsenal-red);
  border: none; border-radius: 999px; padding: 8px 18px; font-weight: 800;
}
@keyframes slide-up { from { transform: translateY(140%); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

@media (min-width: 620px) {
  .stat-grid { grid-template-columns: repeat(4, 1fr); }
}
