:root {
  --bg: #12081f;
  --ink: #fff;
  --ink-dim: #c9b8e8;
  --panel: #1e1033;
  --panel-edge: #0a0414;
  --accent: #ffd93b;
  --danger: #ef3b4f;
  --go: #2ee06a;
  --font: 'Press Start 2P', ui-monospace, monospace;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  overscroll-behavior: none;
}

#vortex {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}
#vortex.shake { animation: shake 0.45s steps(9); }
@keyframes shake {
  0%, 100% { transform: translate(0, 0); }
  20% { transform: translate(-6px, 3px); }
  40% { transform: translate(6px, -3px); }
  60% { transform: translate(-3px, -6px); }
  80% { transform: translate(3px, 6px); }
}

/* Pixel-art buttons: stepped borders made from box-shadows */
.pixbtn {
  font: inherit;
  font-size: 11px;
  color: var(--ink);
  background: var(--panel);
  border: 0;
  padding: 10px 12px;
  cursor: pointer;
  box-shadow:
    0 -3px 0 0 var(--panel-edge), 0 3px 0 0 var(--panel-edge),
    -3px 0 0 0 var(--panel-edge), 3px 0 0 0 var(--panel-edge),
    inset -3px -3px 0 0 rgba(0,0,0,.35), inset 3px 3px 0 0 rgba(255,255,255,.18);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.pixbtn:active { transform: translateY(2px); }
.pixbtn.wide { width: 100%; margin-top: 10px; }
.pixbtn.danger { background: var(--danger); }
.pixbtn.go { background: var(--go); color: #08240f; }

#hud {
  position: fixed;
  top: calc(var(--safe-t) + 10px);
  left: 16px;
  right: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  pointer-events: none;
  z-index: 3;
}
#hud > * { pointer-events: auto; }
.logo {
  font-size: 12px;
  letter-spacing: 2px;
  text-shadow: 2px 2px 0 #000;
  opacity: .85;
}
.icon-btn { font-size: 16px; padding: 6px 8px; font-family: system-ui, sans-serif; }

#install-tip {
  position: fixed;
  top: calc(var(--safe-t) + 52px);
  left: 16px;
  right: 16px;
  z-index: 3;
  background: rgba(10, 4, 20, .85);
  border: 3px solid #000;
  font-size: 9px;
  line-height: 1.6;
  padding: 8px 36px 8px 10px;
}
#install-tip .x {
  position: absolute; right: 4px; top: 2px;
  background: none; border: 0; color: var(--ink); font-size: 20px; cursor: pointer;
}

/* ----- Celebration overlay ----- */
#celebrate {
  position: fixed;
  left: 0; right: 0;
  top: calc(var(--safe-t) + 70px);
  text-align: center;
  pointer-events: none;
  z-index: 2;
  visibility: hidden;
}
#celebrate.show { visibility: visible; }
#celebrate > div { opacity: 0; }
#celebrate.show > div { animation: pop 2.6s cubic-bezier(.2, 1.6, .4, 1) both; }
#celebrate.show .c-count  { animation-delay: .12s; }
#celebrate.show .c-combo  { animation-delay: .28s; }
#celebrate.show .c-praise { animation-delay: .45s; }

.c-name {
  font-size: clamp(22px, 8vw, 44px);
  color: #fff;
  text-shadow: 3px 0 0 #000, -3px 0 0 #000, 0 3px 0 #000, 0 -3px 0 #000,
    4px 4px 0 #ff3dc0, 7px 7px 0 #3d5bff;
}
.c-count {
  margin-top: 6px;
  font-size: clamp(40px, 17vw, 96px);
  color: var(--accent);
  text-shadow: 4px 0 0 #000, -4px 0 0 #000, 0 4px 0 #000, 0 -4px 0 #000,
    6px 6px 0 #ff6a1f, 10px 10px 0 #000;
}
.c-count::before { content: '×'; font-size: .55em; vertical-align: .35em; margin-right: 4px; }
.c-count small, .c-combo small { display: block; font-size: 10px; letter-spacing: 3px; color: #fff; text-shadow: 2px 2px 0 #000; margin-top: 6px; }

.c-combo {
  margin: 16px auto 0;
  display: inline-block;
  padding: 10px 14px 8px;
  font-size: clamp(16px, 6vw, 30px);
  color: #08240f;
  background: var(--go);
  box-shadow: 0 -4px 0 #000, 0 4px 0 #000, -4px 0 0 #000, 4px 0 0 #000, 8px 8px 0 #000;
}
.c-combo .num { font-size: 1.4em; }
.c-combo small { color: #08240f; text-shadow: none; font-size: 8px; }
#celebrate.hot .c-combo { animation-name: pop, rainbowbg; animation-duration: 2.6s, .5s; animation-iteration-count: 1, infinite; animation-timing-function: cubic-bezier(.2,1.6,.4,1), steps(6); }

.c-praise {
  margin-top: 18px;
  font-size: clamp(12px, 4.4vw, 22px);
  color: #fff;
  text-shadow: 3px 3px 0 #000;
}
.c-praise:empty { display: none; }

@keyframes pop {
  0%   { opacity: 0; transform: scale(.2) rotate(-8deg); }
  12%  { opacity: 1; transform: scale(1.15) rotate(3deg); }
  22%  { transform: scale(1) rotate(0); }
  80%  { opacity: 1; transform: scale(1); }
  100% { opacity: 0; transform: scale(.9) translateY(-14px); }
}
@keyframes rainbowbg {
  0% { background: #ff2a4d; } 17% { background: #ffb21f; } 33% { background: #ffe83a; }
  50% { background: #2ee06a; } 67% { background: #29a8ff; } 83% { background: #c03dff; }
}

#empty {
  position: fixed; left: 16px; right: 16px; top: 42%;
  text-align: center; font-size: 12px; line-height: 1.8;
  text-shadow: 2px 2px 0 #000; z-index: 2;
}

#undo {
  position: fixed;
  left: 0; right: 0;
  bottom: calc(var(--safe-b) + 118px);
  text-align: center;
  z-index: 3;
}
#undo .pixbtn { font-size: 9px; padding: 8px 10px; }

/* ----- Habit button bar ----- */
#bar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 3;
  display: flex;
  gap: 14px;
  padding: 18px 16px calc(var(--safe-b) + 26px);
  overflow-x: auto;
  scrollbar-width: none;
  background: linear-gradient(to top, rgba(10,4,20,.85), rgba(10,4,20,0));
  justify-content: safe center;
}
#bar::-webkit-scrollbar { display: none; }

.habit {
  position: relative;
  flex: 0 0 auto;
  width: 76px;
  height: 76px;
  padding: 0;
  border: 0;
  background: #2a1745;
  cursor: pointer;
  box-shadow:
    0 -4px 0 0 #000, 0 4px 0 0 #000, -4px 0 0 0 #000, 4px 0 0 0 #000,
    inset -4px -4px 0 0 rgba(0,0,0,.4), inset 4px 4px 0 0 rgba(255,255,255,.18);
  transition: transform .08s steps(2);
}
.habit canvas { width: 48px; height: 48px; image-rendering: pixelated; display: block; margin: auto; }
.habit.done { background: #4a2a78; box-shadow:
    0 -4px 0 0 var(--accent), 0 4px 0 0 var(--accent), -4px 0 0 0 var(--accent), 4px 0 0 0 var(--accent),
    inset -4px -4px 0 0 rgba(0,0,0,.4), inset 4px 4px 0 0 rgba(255,255,255,.22); }
.habit.bump { animation: bump .35s steps(5); }
@keyframes bump { 0% { transform: scale(.8); } 50% { transform: scale(1.18) translateY(-8px); } 100% { transform: scale(1); } }
.habit .badge {
  position: absolute; right: -8px; top: -10px;
  min-width: 22px; padding: 4px 4px 3px;
  font: 9px var(--font); color: #08240f; background: var(--go);
  box-shadow: 0 -2px 0 #000, 0 2px 0 #000, -2px 0 0 #000, 2px 0 0 #000;
}
.habit .badge:empty { display: none; }
.habit .name {
  position: absolute; left: -6px; right: -6px; bottom: -16px;
  font: 7px var(--font); color: var(--ink-dim); text-align: center;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  text-shadow: 1px 1px 0 #000;
}
.habit.add { font: 28px var(--font); color: var(--ink-dim); background: rgba(42,23,69,.6); }

/* ----- Sheets ----- */
.sheet {
  position: fixed; inset: 0; z-index: 10;
  background: rgba(5, 2, 10, .6);
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet[hidden] { display: none; }
.panel {
  width: 100%;
  max-width: 520px;
  max-height: 88dvh;
  overflow-y: auto;
  background: var(--panel);
  padding: 20px 16px calc(var(--safe-b) + 20px);
  border-top: 4px solid #000;
  box-shadow: inset 0 4px 0 rgba(255,255,255,.12);
  -webkit-user-select: text;
  user-select: text;
}
.panel h2 { font-size: 14px; margin: 0 0 14px; }
.panel h3 { font-size: 10px; color: var(--accent); margin: 18px 0 8px; }
.panel p { font-family: system-ui, sans-serif; font-size: 14px; line-height: 1.45; color: var(--ink-dim); margin: 0 0 8px; }
.panel a { color: var(--accent); }
.panel code { font-size: 12px; color: #fff; }
.row { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 12px; }
.row .pixbtn { flex: 1; }

#habit-list { list-style: none; padding: 0; margin: 0; }
#habit-list li {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 0; border-bottom: 2px solid rgba(0,0,0,.35);
  font-size: 10px;
}
#habit-list li canvas { width: 32px; height: 32px; image-rendering: pixelated; }
#habit-list li .n { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#habit-list li .pixbtn { padding: 6px 8px; font-size: 10px; }

a.pixbtn { text-decoration: none; color: var(--ink); }
#push-code {
  width: 100%; margin-top: 4px;
  font: 10px ui-monospace, monospace; color: var(--ink-dim);
  background: #0f0820; border: 3px solid #000; padding: 8px; resize: none;
}

.toggle {font-family: system-ui, sans-serif; font-size: 14px; display: flex; gap: 8px; align-items: center; }
.toggle input { width: 20px; height: 20px; accent-color: var(--go); }

.field { display: block; font-size: 10px; margin-bottom: 14px; }
.field input {
  display: block; width: 100%; margin-top: 8px;
  font: 14px var(--font); color: var(--ink);
  background: #0f0820; border: 3px solid #000; padding: 10px;
}

#icon-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(56px, 1fr));
  gap: 10px;
}
#icon-grid button {
  background: #2a1745; border: 3px solid #000; padding: 4px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  font: 6px var(--font); color: var(--ink-dim);
}
#icon-grid button canvas { width: 40px; height: 40px; image-rendering: pixelated; }
#icon-grid button[aria-selected="true"] { border-color: var(--accent); background: #4a2a78; color: #fff; }
