/* ============================================================
   PIXELHABIT — pixel art design system
   ============================================================ */
:root {
  --bg: #0b0c17;
  --bg-2: #11132a;
  --panel: #171a35;
  --panel-2: #1e2244;
  --line: #2c3160;
  --line-hi: #454c8f;

  --ink: #e8ecff;
  --ink-dim: #9aa2d4;
  --ink-mute: #6b74a8;

  --green: #41f6a0;
  --green-d: #17a86a;
  --pink: #ff6b9d;
  --yellow: #ffd166;
  --blue: #41a6f6;
  --purple: #a97bff;
  --red: #ff5d5d;

  --shadow: 4px 4px 0 #05060d;
  --shadow-sm: 3px 3px 0 #05060d;

  --pixel: 'Press Start 2P', monospace;
  --ui: 'Silkscreen', 'Press Start 2P', monospace;
  --body: 'VT323', monospace;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--body);
  font-size: 20px;
  line-height: 1.35;
  -webkit-font-smoothing: none;
  image-rendering: pixelated;
}

body {
  min-height: 100vh;
  background-image:
    radial-gradient(circle at 15% -10%, rgba(65, 166, 246, 0.16), transparent 45%),
    radial-gradient(circle at 85% 0%, rgba(255, 107, 157, 0.14), transparent 42%),
    radial-gradient(circle at 50% 110%, rgba(65, 246, 160, 0.10), transparent 55%),
    linear-gradient(180deg, #0b0c17 0%, #0e1022 45%, #0a0b15 100%);
  background-attachment: fixed;
  overflow-x: hidden;
}

/* subtle 8px grid overlay */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.022) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.022) 1px, transparent 1px);
  background-size: 32px 32px;
}

.scanlines {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 90;
  background: repeating-linear-gradient(
    180deg,
    rgba(0, 0, 0, 0) 0px,
    rgba(0, 0, 0, 0) 2px,
    rgba(0, 0, 0, 0.16) 3px,
    rgba(0, 0, 0, 0.16) 4px
  );
  opacity: 0.55;
  mix-blend-mode: multiply;
}
.noise {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 91;
  opacity: 0.035;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3'/%3E%3C/filter%3E%3Crect width='120' height='120' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* ---------------- top bar ---------------- */
.topbar {
  position: relative;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 20px;
  flex-wrap: wrap;
  padding: 18px 26px;
  border-bottom: 4px solid var(--line);
  background: linear-gradient(180deg, #14172f 0%, #0d0f1f 100%);
  box-shadow: 0 4px 0 #05060d, inset 0 -2px 0 rgba(255, 255, 255, 0.04);
}

.brand { display: flex; align-items: center; gap: 14px; }
#logoCanvas {
  width: 52px; height: 52px;
  image-rendering: pixelated;
  filter: drop-shadow(3px 3px 0 #05060d);
}
.brand-text h1 {
  font-family: var(--pixel);
  font-size: 17px;
  margin: 0;
  letter-spacing: 1px;
  color: var(--ink);
  text-shadow: 3px 3px 0 #05060d, 0 0 22px rgba(65, 246, 160, 0.35);
}
.brand-text h1 span { color: var(--green); }
.tagline {
  margin: 6px 0 0;
  font-family: var(--ui);
  font-size: 10px;
  letter-spacing: 1.5px;
  color: var(--ink-mute);
  text-transform: uppercase;
}

.player-card {
  flex: 1;
  min-width: 230px;
  max-width: 420px;
  padding: 10px 14px;
  background: var(--panel);
  border: 3px solid var(--line-hi);
  box-shadow: var(--shadow-sm);
}
.player-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-family: var(--ui);
  font-size: 11px;
  letter-spacing: 1px;
  margin-bottom: 8px;
}
.lvl { color: var(--yellow); }
.player-title { color: var(--green); }
.xp-num { color: var(--ink-dim); font-size: 10px; }

.xpbar {
  position: relative;
  height: 14px;
  background: #080a14;
  border: 2px solid var(--line-hi);
  overflow: hidden;
}
.xpfill {
  height: 100%;
  background: repeating-linear-gradient(90deg, var(--green) 0 6px, var(--green-d) 6px 12px);
  transition: width 0.5s steps(12, end);
  box-shadow: 0 0 12px rgba(65, 246, 160, 0.55);
}

.topbar-actions { display: flex; gap: 10px; margin-left: auto; }

/* ---------------- buttons ---------------- */
.btn {
  font-family: var(--ui);
  font-size: 11px;
  letter-spacing: 1px;
  text-transform: uppercase;
  padding: 10px 14px;
  color: var(--ink);
  background: var(--panel-2);
  border: 3px solid var(--line-hi);
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  transition: transform 0.06s steps(2), box-shadow 0.06s steps(2), background 0.15s;
  image-rendering: pixelated;
}
.btn:hover { background: #262b55; }
.btn:active { transform: translate(3px, 3px); box-shadow: 0 0 0 #05060d; }
.btn:focus-visible { outline: 3px dashed var(--yellow); outline-offset: 2px; }

.btn-primary {
  background: var(--green);
  color: #04160d;
  border-color: #9dffd0;
  box-shadow: 3px 3px 0 #0d6b45;
  font-weight: 700;
}
.btn-primary:hover { background: #6bffb8; }

.btn-ghost { background: transparent; }
.btn-danger {
  background: var(--red);
  color: #2a0505;
  border-color: #ff9c9c;
  box-shadow: 3px 3px 0 #7a1414;
}
.btn-mini { padding: 6px 9px; font-size: 9px; border-width: 2px; box-shadow: 2px 2px 0 #05060d; }

/* ---------------- layout ---------------- */
.wrap {
  position: relative;
  z-index: 2;
  max-width: 1240px;
  margin: 0 auto;
  padding: 26px 22px 90px;
  display: grid;
  grid-template-columns: minmax(0, 1.65fr) minmax(0, 1fr);
  gap: 22px;
  align-items: start;
}
.col { display: flex; flex-direction: column; gap: 22px; min-width: 0; }

.panel {
  background: linear-gradient(180deg, var(--panel) 0%, #141733 100%);
  border: 3px solid var(--line);
  box-shadow: var(--shadow), inset 0 0 0 2px rgba(255, 255, 255, 0.028);
  padding: 16px 16px 18px;
  position: relative;
}
/* pixel corner notches */
.panel::before,
.panel::after {
  content: '';
  position: absolute;
  width: 6px; height: 6px;
  background: var(--bg);
}
.panel::before { top: -3px; left: -3px; box-shadow: 0 0 0 3px var(--bg); }
.panel::after { bottom: -3px; right: -3px; box-shadow: 0 0 0 3px var(--bg); }

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding-bottom: 12px;
  margin-bottom: 14px;
  border-bottom: 2px dashed var(--line);
}
.panel-head h2 {
  font-family: var(--ui);
  font-size: 12px;
  letter-spacing: 1.6px;
  margin: 0;
  color: var(--ink);
  display: flex;
  align-items: center;
  gap: 8px;
}
.blink { color: var(--green); animation: blink 1.1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }

.date-chip {
  font-family: var(--ui);
  font-size: 10px;
  letter-spacing: 1px;
  color: var(--yellow);
  border: 2px solid #4a3f14;
  background: #241f0a;
  padding: 5px 9px;
}

/* ---------------- score strip ---------------- */
.score-strip {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-bottom: 16px;
}
.score-item {
  background: #0c0e1d;
  border: 2px solid var(--line);
  padding: 9px 8px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: center;
  justify-content: center;
}
.score-label {
  font-family: var(--ui);
  font-size: 8px;
  letter-spacing: 1px;
  color: var(--ink-mute);
}
.score-val {
  font-family: var(--pixel);
  font-size: 13px;
  color: var(--green);
  text-shadow: 2px 2px 0 #05060d;
}
.score-pixel { padding: 8px 4px; gap: 4px; }
.mood-row { display: flex; align-items: center; gap: 6px; }
#moodSprite { width: 24px; height: 24px; image-rendering: pixelated; }
.mood-word {
  font-family: var(--ui);
  font-size: 9px;
  letter-spacing: .5px;
  color: var(--yellow);
}

/* ---------------- habit rows ---------------- */
.habit-list { display: flex; flex-direction: column; gap: 10px; }

.habit {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) auto auto auto;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: #0e1020;
  border: 2px solid var(--line);
  border-left: 6px solid var(--accent, var(--blue));
  cursor: pointer;
  position: relative;
  transition: background 0.12s, transform 0.06s steps(2);
}
.habit:hover { background: #151833; }
.habit:active { transform: translateY(2px); }
.habit.done {
  background: #0d1c17;
  border-color: var(--green-d);
  border-left-color: var(--green);
}
.habit.done .h-name { color: var(--ink-mute); text-decoration: line-through; text-decoration-thickness: 2px; }

.h-icon {
  width: 40px; height: 40px;
  display: grid;
  place-items: center;
  font-size: 20px;
  background: #05060f;
  border: 2px solid var(--line-hi);
  image-rendering: pixelated;
  filter: saturate(1.2);
}
.habit.done .h-icon { border-color: var(--green); box-shadow: 0 0 14px rgba(65, 246, 160, 0.35); }

.h-main { min-width: 0; }
.h-name {
  font-family: var(--ui);
  font-size: 12px;
  letter-spacing: 0.6px;
  color: var(--ink);
  margin: 0 0 5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.h-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 15px;
  color: var(--ink-mute);
  font-family: var(--body);
  min-width: 0;
}
.h-meta b { color: var(--yellow); font-weight: 400; }
.h-rate { white-space: nowrap; font-size: 14px; }
.h-dots { display: flex; gap: 3px; }
.dot {
  width: 7px; height: 7px;
  background: #1f2444;
  border: 1px solid #2b3160;
}
.dot.on { background: var(--green); border-color: #9dffd0; box-shadow: 0 0 6px rgba(65,246,160,.7); }
.dot.miss { background: #3a1d28; border-color: #5c2b3c; }

.h-streak {
  font-family: var(--ui);
  font-size: 10px;
  color: var(--pink);
  text-align: right;
  min-width: 54px;
}
.h-streak span { display: block; font-size: 8px; color: var(--ink-mute); letter-spacing: 1px; }

.check {
  width: 38px; height: 38px;
  background: #141833;
  border: 3px solid #5a63b8;
  box-shadow: 2px 2px 0 #05060d;
  display: grid;
  place-items: center;
  cursor: pointer;
  padding: 0;
  transition: background 0.1s, transform 0.06s steps(2), border-color 0.12s;
}
.check:hover { border-color: var(--green); background: #1a2440; }
.check:active { transform: translate(2px, 2px); box-shadow: none; }
.check svg { width: 20px; height: 20px; opacity: 0; transform: scale(0.5); transition: opacity .12s, transform .12s steps(3); }
.habit.done .check { background: var(--green); border-color: #d6ffe9; }
.habit.done .check svg { opacity: 1; transform: scale(1); }

.h-edit {
  position: absolute;
  top: 2px; right: 2px;
  font-family: var(--ui);
  font-size: 8px;
  color: var(--ink-mute);
  background: none;
  border: 0;
  cursor: pointer;
  padding: 2px 4px;
  opacity: 0;
  transition: opacity .15s;
}
.habit:hover .h-edit { opacity: 1; }
.h-edit:hover { color: var(--yellow); }

.empty {
  text-align: center;
  padding: 34px 16px;
  color: var(--ink-mute);
  border: 2px dashed var(--line);
  background: #0a0c18;
}
.empty canvas { width: 64px; height: 64px; image-rendering: pixelated; margin-bottom: 12px; animation: float 2.4s steps(4) infinite; }
@keyframes float { 50% { transform: translateY(-8px); } }
.empty p { margin: 0; font-size: 18px; }
.empty b { color: var(--green); }

/* ---------------- heatmap ---------------- */
.heatmap-row { display: flex; gap: 16px; align-items: flex-start; }
.heatmap-wrap { flex: 1; min-width: 0; overflow-x: auto; padding-bottom: 4px; }
.hm-months {
  display: grid;
  grid-auto-flow: column;
  gap: 3px;
  margin-left: 26px;
  margin-bottom: 5px;
  font-family: var(--ui);
  font-size: 8px;
  letter-spacing: .5px;
  color: var(--ink-mute);
}
.hm-months span { white-space: nowrap; overflow: hidden; }
.hm-body { display: flex; gap: 6px; }
.hm-days {
  display: grid;
  grid-template-rows: repeat(7, 1fr);
  gap: 3px;
  width: 22px;
  flex: 0 0 22px;
  font-family: var(--ui);
  font-size: 7px;
  color: var(--ink-mute);
  align-items: center;
}
.hm-days span { line-height: 1; text-align: right; }
.hm-days span:nth-child(1) { grid-row: 1; }
.hm-days span:nth-child(2) { grid-row: 2; }
.hm-days span:nth-child(3) { grid-row: 4; }
.hm-days span:nth-child(4) { grid-row: 6; }
.heatmap {
  display: grid;
  grid-auto-flow: column;
  grid-template-rows: repeat(7, 1fr);
  gap: 3px;
  flex: 1;
  min-width: 0;
}
.hm {
  width: 100%;
  aspect-ratio: 1 / 1;
  background: #14172e;
  border: 1px solid #1e2244;
}
.hm.l1 { background: #12432f; border-color: #1a5c40; }
.hm.l2 { background: #1a7a52; border-color: #23986a; }
.hm.l3 { background: #2ec27e; border-color: #41f6a0; }
.hm.l4 { background: #41f6a0; border-color: #c2ffe0; box-shadow: 0 0 6px rgba(65, 246, 160, .5); }
.hm.off { background: #0c0e1a; border-color: #14172e; }
.hm.today { outline: 2px solid var(--yellow); outline-offset: 1px; }

.hm-side {
  flex: 0 0 152px;
  display: flex;
  flex-direction: column;
  gap: 7px;
}
.hm-side-item {
  background: #0c0e1d;
  border: 2px solid var(--line);
  border-left: 3px solid var(--green-d);
  padding: 6px 9px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.hs-label {
  font-family: var(--ui);
  font-size: 7px;
  letter-spacing: .8px;
  color: var(--ink-mute);
}
.hs-val {
  font-family: var(--ui);
  font-size: 10px;
  color: var(--green);
  letter-spacing: .5px;
}
.legend {
  display: flex; align-items: center; gap: 5px;
  font-family: var(--ui); font-size: 8px; color: var(--ink-mute);
  letter-spacing: 1px;
}
.lg { width: 10px; height: 10px; display: inline-block; border: 1px solid #1e2244; }
.lg0 { background: #14172e; }
.lg1 { background: #12432f; }
.lg2 { background: #1a7a52; }
.lg3 { background: #2ec27e; }
.lg4 { background: #41f6a0; }

/* ---------------- stats grid ---------------- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px;
}
.stat-card {
  background: #0c0e1d;
  border: 2px solid var(--line);
  padding: 10px 10px 12px;
}
.stat-card .sc-top {
  display: flex; align-items: center; gap: 6px;
  font-family: var(--ui); font-size: 9px; letter-spacing: .6px;
  color: var(--ink-dim); margin-bottom: 8px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.stat-card .sc-val { font-family: var(--pixel); font-size: 11px; color: var(--green); text-shadow: 2px 2px 0 #05060d; }
.stat-card .sc-sub { font-size: 14px; color: var(--ink-mute); margin-top: 3px; }
.spark { display: flex; gap: 2px; margin-top: 9px; align-items: flex-end; height: 22px; }
.spark i {
  flex: 1;
  background: #1b2040;
  min-height: 3px;
  display: block;
  border-radius: 0;
}
.spark i.on { background: var(--green); box-shadow: 0 0 6px rgba(65, 246, 160, .6); }
.spark i.sch { background: #2f3663; }

/* ---------------- sage panel ---------------- */
.sage-panel {
  border-color: #3b2f6b;
  background: linear-gradient(180deg, #1b1740 0%, #141733 100%);
  box-shadow: var(--shadow), inset 0 0 40px rgba(169, 123, 255, 0.10);
}
.sage-dot {
  width: 8px; height: 8px; background: var(--purple);
  box-shadow: 0 0 10px var(--purple);
  animation: pulse 1.6s steps(3) infinite;
}
@keyframes pulse { 50% { opacity: .25; } }

.sage-body { display: flex; gap: 12px; align-items: flex-start; }
.sage-sprite-wrap {
  flex: 0 0 64px;
  background: #0a0818;
  border: 2px solid #4a3a8a;
  padding: 6px;
  box-shadow: 3px 3px 0 #05060d;
}
#sageSprite { width: 100%; height: auto; image-rendering: pixelated; animation: sageFloat 3s steps(4) infinite; }
@keyframes sageFloat { 50% { transform: translateY(-4px); } }

.sage-bubble {
  flex: 1;
  background: #0e0a22;
  border: 2px solid #4a3a8a;
  padding: 10px 12px;
  position: relative;
  min-height: 78px;
}
.sage-bubble::before {
  content: '';
  position: absolute;
  left: -8px; top: 16px;
  width: 8px; height: 8px;
  background: #0e0a22;
  border-left: 2px solid #4a3a8a;
  border-bottom: 2px solid #4a3a8a;
  transform: rotate(45deg);
}
.sage-headline {
  font-family: var(--ui);
  font-size: 11px;
  letter-spacing: .8px;
  color: var(--yellow);
  margin: 0 0 7px;
  line-height: 1.5;
  overflow-wrap: break-word;
}
.sage-text { margin: 0; font-size: 17px; color: #c6cbf0; line-height: 1.4; hyphens: none; overflow-wrap: break-word; }

.tips { list-style: none; margin: 14px 0 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.tips li {
  position: relative;
  padding: 8px 10px 8px 26px;
  background: #0e0a22;
  border-left: 4px solid var(--purple);
  font-size: 16px;
  color: #b9bfe8;
  line-height: 1.3;
}
.tips li::before {
  content: '▸';
  position: absolute;
  left: 9px; top: 6px;
  color: var(--purple);
  font-size: 14px;
}
.sage-meta {
  margin-top: 12px;
  padding-top: 2px;
  font-family: var(--ui);
  font-size: 8px;
  letter-spacing: 1px;
  color: var(--ink-mute);
  text-align: right;
}
.sage-meta .ai-badge {
  display: inline-block;
  padding: 3px 6px;
  border: 1px solid var(--green-d);
  color: var(--green);
  background: #08201a;
}
.sage-meta .ai-badge.local { border-color: #5c4a1a; color: var(--yellow); background: #1c1708; }

/* ---------------- chat ---------------- */
.chat-panel { display: flex; flex-direction: column; }
.chat-log {
  flex: 1;
  min-height: 160px;
  max-height: 300px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-right: 6px;
  margin-bottom: 12px;
  scrollbar-width: thin;
  scrollbar-color: var(--line-hi) transparent;
}
.chat-log::-webkit-scrollbar { width: 8px; }
.chat-log::-webkit-scrollbar-thumb { background: var(--line-hi); }

.msg {
  max-width: 90%;
  padding: 8px 10px;
  font-size: 16px;
  line-height: 1.3;
  border: 2px solid var(--line);
  background: #0c0e1d;
  white-space: pre-wrap;
  word-break: break-word;
}
.msg.user {
  align-self: flex-end;
  background: #14243d;
  border-color: #2c5488;
  color: #cfe4ff;
}
.msg.assistant {
  align-self: flex-start;
  background: #150f2b;
  border-color: #4a3a8a;
  color: #cfc9f5;
}
.msg.typing { color: var(--ink-mute); font-family: var(--ui); font-size: 10px; letter-spacing: 1px; }
.msg.typing::after { content: '▋'; animation: blink 1s steps(2) infinite; }

.chat-form { display: flex; gap: 8px; }
.chat-form input {
  flex: 1;
  min-width: 0;
  font-family: var(--body);
  font-size: 17px;
  padding: 9px 11px;
  color: var(--ink);
  background: #080a14;
  border: 2px solid var(--line-hi);
  outline: none;
}
.chat-form input:focus { border-color: var(--purple); box-shadow: 0 0 0 2px rgba(169,123,255,.22); }
.chat-form input::placeholder { color: #4d557f; }
.btn-send { padding: 9px 13px; font-size: 12px; }
.chat-hint {
  font-family: var(--ui);
  font-size: 8px;
  letter-spacing: .8px;
  color: var(--ink-mute);
  margin-top: 8px;
  text-align: center;
}

/* ---------------- badges ---------------- */
.badge-count {
  font-family: var(--ui);
  font-size: 9px;
  letter-spacing: 1px;
  color: var(--yellow);
}
.badge-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}
.badge {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  padding: 9px 4px 7px;
  background: #0b0d1c;
  border: 2px solid var(--line);
  text-align: center;
  position: relative;
  filter: grayscale(1) brightness(.62);
  opacity: .78;
  transition: filter .2s, opacity .2s, border-color .2s;
}
.badge.on {
  filter: none;
  opacity: 1;
  border-color: var(--yellow);
  background: linear-gradient(180deg, #241d08 0%, #141733 100%);
  box-shadow: 0 0 14px rgba(255, 209, 102, .18), inset 0 0 12px rgba(255, 209, 102, .06);
}
.badge canvas { width: 26px; height: 26px; image-rendering: pixelated; }
.badge .b-name {
  font-family: var(--ui);
  font-size: 7px;
  letter-spacing: .3px;
  color: #8d95c4;
  line-height: 1.3;
}
.badge.on .b-name { color: var(--yellow); }

/* ---------------- footer ---------------- */
.site-foot {
  position: relative;
  z-index: 2;
  max-width: 1240px;
  margin: 0 auto;
  padding: 0 22px 40px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  font-family: var(--ui);
  font-size: 8px;
  letter-spacing: 1px;
  color: #565e8c;
}
.site-foot .foot-sep { color: #343a63; }
.site-foot kbd {
  font-family: var(--ui);
  font-size: 8px;
  padding: 2px 5px;
  border: 1px solid var(--line-hi);
  background: #10132b;
  color: var(--ink-dim);
}

/* ---------------- modal ---------------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(4, 5, 12, 0.82);
  backdrop-filter: blur(2px);
  display: grid;
  place-items: center;
  padding: 18px;
  animation: fadeIn .12s steps(3);
}
@keyframes fadeIn { from { opacity: 0; } }
.modal {
  width: 100%;
  max-width: 470px;
  max-height: 92vh;
  overflow-y: auto;
  background: linear-gradient(180deg, #1b1f3d 0%, #141733 100%);
  border: 4px solid var(--line-hi);
  box-shadow: 8px 8px 0 #05060d, inset 0 0 0 2px rgba(255,255,255,.04);
  animation: popIn .14s steps(3);
}
@keyframes popIn { from { transform: scale(.94) translateY(8px); opacity: 0; } }
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 3px solid var(--line);
  background: #10132b;
}
.modal-head h2 { font-family: var(--ui); font-size: 12px; letter-spacing: 1.4px; margin: 0; color: var(--green); }
.modal-body { padding: 16px; display: flex; flex-direction: column; gap: 14px; }

.field { display: flex; flex-direction: column; gap: 7px; }
.field > span {
  font-family: var(--ui);
  font-size: 9px;
  letter-spacing: 1.2px;
  color: var(--ink-dim);
}
.field > span em { color: var(--ink-mute); font-style: normal; }
.field input[type=text] {
  font-family: var(--body);
  font-size: 18px;
  padding: 9px 11px;
  color: var(--ink);
  background: #080a14;
  border: 2px solid var(--line-hi);
  outline: none;
  width: 100%;
}
.field input[type=text]:focus { border-color: var(--green); box-shadow: 0 0 0 2px rgba(65,246,160,.2); }

.icon-picker { display: grid; grid-template-columns: repeat(8, 1fr); gap: 6px; }
.icon-opt {
  aspect-ratio: 1;
  display: grid; place-items: center;
  font-size: 17px;
  background: #080a14;
  border: 2px solid var(--line);
  cursor: pointer;
  padding: 0;
}
.icon-opt:hover { border-color: var(--line-hi); }
.icon-opt.sel { border-color: var(--green); background: #0d2419; box-shadow: 0 0 10px rgba(65,246,160,.35); }

.color-picker { display: flex; gap: 7px; flex-wrap: wrap; }
.color-opt {
  width: 26px; height: 26px;
  border: 3px solid #05060d;
  box-shadow: 2px 2px 0 #05060d;
  cursor: pointer;
  padding: 0;
}
.color-opt.sel { outline: 2px solid #fff; outline-offset: 2px; box-shadow: 0 0 10px rgba(255,255,255,.4); }

.day-picker { display: flex; gap: 5px; flex-wrap: wrap; }
.day-opt {
  font-family: var(--ui);
  font-size: 9px;
  letter-spacing: .5px;
  padding: 7px 8px;
  background: #080a14;
  color: var(--ink-mute);
  border: 2px solid var(--line);
  cursor: pointer;
  min-width: 36px;
}
.day-opt.sel { background: var(--green); color: #04160d; border-color: #d6ffe9; font-weight: 700; }

.modal-actions { display: flex; gap: 9px; justify-content: flex-end; margin-top: 4px; }
.modal-actions .btn-danger { margin-right: auto; }

/* ---------------- toast ---------------- */
.toast {
  position: fixed;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 120;
  font-family: var(--ui);
  font-size: 11px;
  letter-spacing: 1px;
  padding: 11px 18px;
  color: #04160d;
  background: var(--green);
  border: 3px solid #d6ffe9;
  box-shadow: 4px 4px 0 #0d6b45;
  animation: toastIn .16s steps(3);
}
.toast.err { background: var(--red); color: #2a0505; border-color: #ff9c9c; box-shadow: 4px 4px 0 #7a1414; }
@keyframes toastIn { from { transform: translate(-50%, 16px); opacity: 0; } }

/* ---------------- confetti ---------------- */
.confetti {
  position: fixed;
  inset: 0;
  z-index: 110;
  pointer-events: none;
  width: 100%;
  height: 100%;
}

/* ---------------- responsive ---------------- */
@media (max-width: 940px) {
  .wrap { grid-template-columns: 1fr; padding: 18px 14px 70px; }
  .topbar { padding: 14px 16px; gap: 12px; }
  .player-card { order: 3; max-width: none; width: 100%; flex-basis: 100%; }
  .brand-text h1 { font-size: 14px; }
  .topbar-actions { margin-left: auto; }
}
@media (max-width: 560px) {
  body { font-size: 18px; }
  .score-strip { grid-template-columns: repeat(2, 1fr); }
  .habit { grid-template-columns: 36px 1fr auto; gap: 9px; padding: 9px; }
  .h-streak { display: none; }
  .h-icon { width: 34px; height: 34px; font-size: 17px; }
  .check { width: 34px; height: 34px; }
  .icon-picker { grid-template-columns: repeat(6, 1fr); }
  .brand-text h1 { font-size: 12px; }
  .tagline { font-size: 8px; }
  .panel { padding: 12px 11px 14px; }
  .btn { padding: 9px 11px; font-size: 10px; }
  .sage-sprite-wrap { flex: 0 0 52px; padding: 5px; }
  .sage-bubble { padding: 9px 10px; }
  .sage-headline { font-size: 10px; }
  .sage-text { font-size: 16px; }
  .heatmap-row { flex-direction: column; }
  .hm-side { flex: 1 1 auto; width: 100%; flex-direction: row; flex-wrap: wrap; }
  .hm-side-item { flex: 1 1 45%; }
  .badge-grid { grid-template-columns: repeat(4, 1fr); gap: 6px; }
  .badge { padding: 7px 3px 6px; }
  .badge canvas { width: 22px; height: 22px; }
  .badge .b-name { font-size: 6.5px; }
  .site-foot { padding: 0 14px 30px; font-size: 7px; gap: 7px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
  .scanlines { display: none; }
}
