@font-face {
  font-family: "Nunito";
  src: url("fonts/Nunito-Variable.ttf") format("truetype");
  font-weight: 200 900;
  font-style: normal;
  font-display: swap;
}

:root {
  --bg: #17202b;
  --bg-elev: #1d2836;
  --text: #ffffff;
  --muted: #8b95a1;
  --line: #c8d0d8;
  --green: #8fc31f;
  --yellow: #f0c418;
  --yellow-sheet: #d4a20c;
  --orange: #e08a1e;
  --red: #d8322e;
  --blackout: #3a4150;
  --card: #ffffff;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bot: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); }
body {
  font-family: "Nunito", "Varela Round", system-ui, sans-serif;
  min-height: 100dvh;
  overflow: hidden;
}
button, input, select { font-family: inherit; }
button { cursor: pointer; border: 0; background: none; color: inherit; }
.hidden { display: none !important; }

.app {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  padding-top: var(--safe-top);
  max-width: 480px;
  margin: 0 auto;
  position: relative;
}

.topbar {
  display: grid;
  grid-template-columns: 64px 1fr 72px;
  align-items: center;
  padding: 8px 16px 4px;
}
.score-btn {
  position: relative;
  width: 56px;
  height: 52px;
  padding: 0;
}
.avatar {
  display: block;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  overflow: hidden;
  box-shadow: 0 0 0 2px #f0c418;
}
.avatar-svg { width: 44px; height: 44px; display: block; }
.score-badge {
  position: absolute;
  left: 26px;
  top: 26px;
  min-width: 28px;
  height: 28px;
  padding: 0 5px;
  border-radius: 50%;
  background: var(--yellow);
  color: #17202b;
  font-weight: 800;
  font-size: 11px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 0 0 2px var(--bg);
}
.app-title {
  margin: 0;
  text-align: center;
  font-size: 18px;
  font-weight: 800;
  letter-spacing: -0.02em;
}
.top-actions { display: flex; justify-content: flex-end; gap: 2px; }
.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: #e8edf2;
}

.section-tabs {
  display: flex;
  gap: 18px;
  padding: 6px 20px 10px;
  overflow: auto;
}
.section-tab {
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 0 0 6px;
  border-bottom: 3px solid transparent;
  white-space: nowrap;
}
.section-tab.is-active {
  color: #fff;
  border-bottom-color: #fff;
}

.main {
  flex: 1;
  overflow: auto;
  padding: 0 16px 12px;
  padding-bottom: calc(88px + var(--safe-bot));
}
.month-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 6px 2px 12px;
}
.month-title-row { display: flex; align-items: center; gap: 10px; min-width: 0; }
.month-name {
  margin: 0;
  font-size: 28px;
  font-weight: 900;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}
.year-pill {
  background: #2a3544;
  color: #fff;
  border-radius: 999px;
  padding: 4px 10px 4px 12px;
  font-weight: 800;
  font-size: 13px;
  box-shadow: inset 0 0 0 1px #3b4656;
}
.month-nav { display: flex; gap: 4px; }
.nav-arrow {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  font-size: 26px;
  line-height: 1;
  display: grid;
  place-items: center;
  color: #d5dbe1;
}

.weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  text-align: center;
  color: var(--muted);
  font-weight: 800;
  font-size: 13px;
  margin-bottom: 8px;
}

.month-wrap { position: relative; padding: 5px; }
.month-outline {
  position: absolute;
  left: 5px;
  top: 5px;
  overflow: visible;
  pointer-events: none;
  z-index: 1;
}
.month-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 3px;
  position: relative;
  z-index: 2;
}
.day-spacer { aspect-ratio: 1; }
.day {
  aspect-ratio: 1;
  border-radius: 5px;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 16px;
  position: relative;
  color: #e8edf2;
}
.day.future {
  color: #5c6673;
  font-weight: 700;
}
.day.open {
  box-shadow: inset 0 0 0 2px #c5cdd6;
  color: #f4f7fa;
}
.day.today:not(.logged) {
  box-shadow: inset 0 0 0 2.5px #ffffff;
  color: #fff;
}
.day.logged {
  color: transparent;
}
.day.logged .fill {
  position: absolute;
  inset: 0;
  border-radius: 5px;
  display: grid;
  place-items: center;
}
.day .lock {
  width: 18px;
  height: 18px;
  color: #fff;
  filter: drop-shadow(0 1px 1px rgba(0,0,0,.2));
}
.day[data-level="0"] .fill { background: var(--green); }
.day[data-level="1"] .fill { background: var(--yellow); }
.day[data-level="3"] .fill { background: var(--orange); }
.day[data-level="6"] .fill { background: var(--red); }
.day[data-level="bo"] .fill { background: var(--blackout); }

.stats {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin: 22px 4px 8px;
}
.stat { display: flex; align-items: center; gap: 8px; min-width: 0; }
.stat-icon { flex: 0 0 auto; display: grid; place-items: center; }
.stat-text { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; }
.stat-text strong { font-size: 15px; font-weight: 800; }
.stat-text span { font-size: 12px; color: #d5dbe3; font-weight: 700; }
.info-dot {
  display: inline-grid;
  place-items: center;
  width: 14px;
  height: 14px;
  margin-left: 2px;
  border-radius: 50%;
  background: #5b6572;
  color: #fff;
  font-size: 9px;
  font-weight: 800;
  vertical-align: 1px;
}

.year-toolbar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin: 4px 0 14px;
}
.year-heading { margin: 0; font-size: 28px; font-weight: 900; }
.year-card {
  background: var(--card);
  color: #17202b;
  border-radius: 22px;
  padding: 14px 12px 12px;
  box-shadow: 0 8px 30px rgba(0,0,0,.18);
}
.year-card-title {
  margin: 0 0 10px;
  text-align: center;
  font-size: 18px;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}
.mini-months {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px 6px;
}
.mini-month { cursor: pointer; }
.mini-label {
  text-align: center;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.04em;
  margin-bottom: 3px;
  color: #3b4552;
}
.mini-wrap { position: relative; width: 76px; margin: 0 auto; }
.mini-outline {
  position: absolute;
  inset: 0;
  overflow: visible;
  pointer-events: none;
}
.mini-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 0;
}
.mini-spacer { aspect-ratio: 1; }
.mini-day { aspect-ratio: 1; border-radius: 1px; background: transparent; }
.mini-day[data-level="0"] { background: var(--green); }
.mini-day[data-level="1"] { background: var(--yellow); }
.mini-day[data-level="3"] { background: var(--orange); }
.mini-day[data-level="6"] { background: var(--red); }
.mini-day[data-level="bo"] { background: var(--blackout); }

.legend {
  list-style: none;
  padding: 10px 4px 4px;
  margin: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px 8px;
}
.legend li {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 800;
  font-size: 12px;
}
.swatch {
  width: 18px;
  height: 18px;
  border-radius: 3px;
  display: inline-block;
}
.swatch-0 { background: var(--green); }
.swatch-1 { background: var(--yellow); }
.swatch-3 { background: var(--orange); }
.swatch-6 { background: var(--red); }
.swatch-bo { background: var(--blackout); }
.share-btn {
  display: block;
  width: min(240px, 100%);
  margin: 10px auto 2px;
  background: var(--bg);
  color: #fff;
  font-weight: 800;
  font-size: 15px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  border-radius: 999px;
  padding: 11px 18px;
}

.tabbar {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: 0;
  width: 100%;
  max-width: 480px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  padding: 6px 8px calc(8px + var(--safe-bot));
  background: linear-gradient(180deg, rgba(23,32,43,0) 0%, var(--bg) 18%, var(--bg) 100%);
  z-index: 5;
}
.tab-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  color: #7f8996;
  font-size: 11px;
  font-weight: 800;
  padding: 6px 0;
}
.tab-item.is-active { color: #fff; }

.sheet {
  position: fixed;
  inset: 0;
  z-index: 20;
  overflow: auto;
  padding: calc(18px + var(--safe-top)) 22px calc(28px + var(--safe-bot));
}
.log-sheet {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  color: #fff;
  background: var(--green);
  transition: background-color .25s ease;
}
.log-sheet[data-level="0"] { background: var(--green); }
.log-sheet[data-level="1"] { background: var(--yellow-sheet); }
.log-sheet[data-level="3"] { background: var(--orange); }
.log-sheet[data-level="6"] { background: var(--red); }
.log-sheet[data-level="bo"] { background: var(--blackout); }

.log-top { width: 100%; }
.note-line {
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: center;
  font-weight: 800;
}
.note-line input {
  flex: 1;
  max-width: 280px;
  background: transparent;
  border: 0;
  color: #fff;
  font-size: 16px;
  font-weight: 800;
  outline: none;
}
.note-line input::placeholder { color: rgba(255,255,255,.88); }

.log-title {
  margin: 28px 8px 8px;
  font-size: 28px;
  font-weight: 900;
  line-height: 1.15;
  max-width: 14ch;
}
.log-stepper {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin: 8px 0 10px;
}
.step-btn { padding: 4px; opacity: .95; }
.log-number {
  font-size: 118px;
  font-weight: 900;
  line-height: 0.9;
  letter-spacing: -0.04em;
  text-shadow: 0 2px 0 rgba(0,0,0,.08);
}

.log-extra {
  width: min(320px, 100%);
  display: grid;
  gap: 12px;
  margin: 8px 0 22px;
}
.spent-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  text-align: left;
  font-weight: 800;
}
.spent-field input {
  background: rgba(255,255,255,.2);
  border: 0;
  border-radius: 12px;
  color: #fff;
  font-size: 18px;
  font-weight: 800;
  padding: 10px 12px;
  outline: none;
  width: 100%;
}
.spent-field input::placeholder { color: rgba(255,255,255,.7); }
.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  text-align: left;
  position: relative;
}
.switch-row strong { display: block; font-size: 16px; }
.switch-row small { display: block; opacity: .85; font-weight: 700; }
.switch-row input {
  position: absolute;
  opacity: 0;
  inset: 0;
  width: 100%;
  height: 100%;
}
.switch {
  width: 48px;
  height: 28px;
  background: rgba(0,0,0,.22);
  border-radius: 999px;
  position: relative;
  flex: 0 0 auto;
}
.switch::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  background: #fff;
  border-radius: 50%;
  transition: transform .18s ease;
}
.switch-row input:checked + .switch { background: #17202b; }
.switch-row input:checked + .switch::after { transform: translateX(20px); }

.save-btn {
  width: min(280px, 100%);
  background: #fff;
  color: #17202b;
  font-weight: 900;
  font-size: 18px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  border-radius: 999px;
  padding: 14px 18px;
}
.save-btn.dark { background: var(--yellow); color: #17202b; }
.cancel-btn, .delete-btn {
  margin-top: 14px;
  font-weight: 800;
  font-size: 16px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: rgba(255,255,255,.95);
}
.delete-btn { margin-top: 18px; opacity: .9; text-decoration: underline; text-underline-offset: 3px; }

.info-sheet, .settings-sheet { background: var(--bg); }
.info-sheet {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}
.info-sheet h2 { margin: 10px 0 8px; font-size: 32px; font-weight: 900; }
.info-sheet p {
  margin: 0 0 12px;
  max-width: 34ch;
  color: #d5dbe3;
  font-weight: 700;
  line-height: 1.45;
  font-size: 16px;
}
.score-formula { font-size: 14px !important; color: #aeb6c0 !important; }
.score-hero {
  position: relative;
  width: 168px;
  height: 168px;
  margin: 24px 0 8px;
}
.score-ring { width: 168px; height: 168px; transform: rotate(-90deg); }
#scoreRingArc { stroke-dasharray: 100; stroke-dashoffset: 0; }
.score-hero-num {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 56px;
  font-weight: 900;
}
.score-mini-avatar {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  box-shadow: 0 0 0 3px var(--yellow);
  overflow: hidden;
  margin-bottom: 6px;
}

.settings-sheet .sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}
.settings-sheet h2 { margin: 0; font-size: 28px; font-weight: 900; }
.text-close { font-weight: 800; color: var(--yellow); }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; font-weight: 800; }
.field input, .field select {
  background: #243140;
  color: #fff;
  border: 0;
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 16px;
  font-weight: 700;
}
.field small { color: var(--muted); font-weight: 700; line-height: 1.35; }
.settings-actions { display: grid; gap: 10px; margin: 12px 0 18px; }
.settings-actions button {
  background: #243140;
  border-radius: 14px;
  padding: 14px;
  font-weight: 800;
  text-align: left;
}
.settings-actions .danger { color: #ff8a84; }
.privacy-note { color: var(--muted); font-weight: 700; line-height: 1.4; }

.modal-back {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.55);
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 24px;
}
.modal {
  background: #243140;
  border-radius: 18px;
  padding: 22px 18px 16px;
  width: min(340px, 100%);
}
.modal p { margin: 0 0 16px; font-weight: 800; font-size: 17px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }
.modal-actions button {
  padding: 10px 14px;
  border-radius: 12px;
  font-weight: 800;
  background: #334155;
}
.modal-actions .danger { background: #d8322e; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(86px + var(--safe-bot));
  transform: translateX(-50%);
  background: #2b3646;
  color: #fff;
  padding: 10px 16px;
  border-radius: 999px;
  font-weight: 800;
  font-size: 13px;
  z-index: 40;
  max-width: 90%;
  text-align: center;
  box-shadow: 0 8px 24px rgba(0,0,0,.25);
}

@media (max-height: 740px) {
  .log-number { font-size: 96px; }
  .log-title { margin-top: 16px; font-size: 24px; }
}
