:root {
  --bg: #101014;
  --card: #1b1b21;
  --card2: #24242c;
  --line: #2e2e38;
  --text: #f2f2f6;
  --dim: #8e8e99;
  --faint: #55555f;
  --accent: #ff9f0a;
  --accent-dim: #b06e08;
  --green: #32d74b;
  --red: #ff453a;
  --radius: 16px;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f2f2f7;
    --card: #ffffff;
    --card2: #f0f0f4;
    --line: #e3e3e9;
    --text: #1c1c22;
    --dim: #71717c;
    --faint: #b6b6c0;
    --accent: #e08600;
    --accent-dim: #f5c777;
  }
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif;
  font-size: 16px;
  min-height: 100%;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  overscroll-behavior-y: contain;
}
button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; }
input { font: inherit; color: inherit; }

#app { max-width: 480px; margin: 0 auto; padding: 12px 16px calc(50px + env(safe-area-inset-bottom)); }

/* ---------- header ---------- */
.top {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 2px 16px;
}
.top h1 { font-size: 28px; font-weight: 800; letter-spacing: -0.02em; }
.top .sub { color: var(--dim); font-size: 13px; margin-top: 2px; }
.iconbtn {
  width: 40px; height: 40px; border-radius: 12px;
  background: var(--card); border: 1px solid var(--line);
  display: flex; align-items: center; justify-content: center;
  color: var(--dim); font-size: 18px;
}

/* ---------- add button ---------- */
.addwrap { display: flex; gap: 10px; margin-bottom: 22px; }
.addbtn {
  flex: 1; display: flex; align-items: center; justify-content: center; gap: 10px;
  background: var(--accent); color: #17130a;
  border-radius: var(--radius); padding: 16px;
  font-size: 17px; font-weight: 700;
  box-shadow: 0 6px 20px rgba(255, 159, 10, 0.25);
}
.addbtn:active { transform: scale(0.98); }
.addbtn .plus { display: flex; }
.addalt {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 0 18px;
  color: var(--dim); font-weight: 600; font-size: 15px;
}

/* ---------- day cards ---------- */
.monthhdr {
  color: var(--dim); font-size: 13px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.06em; margin: 20px 4px 10px;
}
.daycard {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px 16px; margin-bottom: 10px;
  width: 100%; text-align: left; display: block;
}
.daycard:active { background: var(--card2); }
.daycard .dhead { display: flex; align-items: baseline; gap: 8px; margin-bottom: 8px; }
.daycard .ddate { font-weight: 700; font-size: 16px; }
.daycard .dtype {
  font-size: 12px; font-weight: 800; color: var(--accent);
  border: 1.5px solid var(--accent-dim); border-radius: 7px; padding: 1px 7px;
}
.daycard .dago { margin-left: auto; color: var(--faint); font-size: 13px; }
.daycard .exline {
  display: flex; font-variant-numeric: tabular-nums;
  font-size: 15px; padding: 3px 0; color: var(--text);
}
.daycard .exname { color: var(--dim); }
.daycard .exnums { margin-left: auto; font-weight: 600; }
.daycard .exnums .w { color: var(--accent); margin-right: 10px; }

/* ---------- editor ---------- */
.ebar { display: flex; align-items: center; gap: 10px; padding: 6px 0 18px; }
.ebar .back { font-size: 17px; color: var(--accent); font-weight: 600; padding: 8px 8px 8px 0; }
.ebar .spacer { flex: 1; }
.sync { font-size: 13px; font-weight: 700; min-width: 16px; transition: color 0.2s; }
.sync[data-state="saved"] { color: var(--green); }
.sync[data-state="saving"] { color: var(--faint); }
.sync[data-state="offline"] { color: var(--red); font-size: 11px; }
.live {
  margin-left: auto; font-size: 12px; font-weight: 800; color: var(--green);
  background: rgba(50, 215, 75, 0.12); border-radius: 7px; padding: 3px 8px;
  animation: livepulse 1.6s ease-in-out infinite;
}
@keyframes livepulse { 50% { opacity: 0.55; } }
.ebar input[type="date"] {
  background: var(--card); border: 1px solid var(--line); border-radius: 10px;
  padding: 7px 10px; color: var(--text); font-size: 15px; font-weight: 600;
  -webkit-appearance: none; appearance: none;
}
.typebadge {
  font-size: 15px; font-weight: 800; color: var(--accent);
  border: 1.5px solid var(--accent-dim); border-radius: 9px; padding: 5px 11px;
}

.excard {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px 14px 10px; margin-bottom: 12px;
}
.exhead { display: flex; align-items: center; margin-bottom: 10px; }
.exhead .name { font-size: 17px; font-weight: 700; padding: 2px 0; }
.exhead .name .chev { color: var(--faint); font-size: 13px; margin-left: 5px; }
.prchip {
  margin-left: auto; font-size: 12px; font-weight: 700; color: var(--green);
  background: rgba(50, 215, 75, 0.12); border-radius: 7px; padding: 3px 8px;
}

.controls { display: flex; align-items: stretch; gap: 10px; }

/* weight: draggable value */
.weight { display: flex; flex-direction: column; align-items: center; gap: 2px; width: 84px; flex: none; justify-content: center; }
.weight .wval {
  font-size: 28px; font-weight: 800; font-variant-numeric: tabular-nums;
  color: var(--accent); padding: 6px 10px; border-radius: 10px;
  touch-action: none; user-select: none; -webkit-user-select: none;
  transition: transform 0.18s cubic-bezier(0.25, 1.4, 0.5, 1);
}
.weight .wval.dragging { transition: none; background: var(--card2); }
.weight .wval.pop { animation: wpop 0.22s ease-out; }
@keyframes wpop { 40% { transform: scale(1.18); } }
.weight .wlabel { font-size: 11px; color: var(--faint); }
.weight .winput {
  width: 76px; font-size: 24px; font-weight: 800; text-align: center;
  background: var(--card2); border: 1px solid var(--accent); border-radius: 8px;
  color: var(--accent); padding: 2px 0; outline: none;
}

/* sets: chips + active wheel */
.setsrow { display: flex; gap: 7px; margin-left: auto; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.repchip {
  min-width: 36px; height: 36px; border-radius: 11px; padding: 0 6px;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; font-weight: 800; font-variant-numeric: tabular-nums;
  animation: chipin 0.18s ease-out;
}
.repchip.done { background: var(--accent); color: #17130a; }
.repchip.done:active { transform: scale(0.94); }
.repchip.ghost { color: var(--faint); border: 1.5px dashed var(--line); font-weight: 700; }
.repchip.addset { color: var(--dim); background: var(--card2); font-size: 20px; font-weight: 600; }
@keyframes chipin { from { transform: scale(0.6); opacity: 0; } }
.wheel {
  position: relative; width: 50px; height: 114px;
  border-radius: 12px; background: var(--card2);
  overflow: hidden;
  animation: chipin 0.18s ease-out;
  touch-action: pan-y;
  transition: transform 0.2s cubic-bezier(0.25, 1.4, 0.5, 1);
}
.wheel.hdrag { transition: none; }
.wheel.flyout {
  transition: transform 0.12s ease-in, opacity 0.12s ease-in;
  transform: translateX(90px) scale(0.5) !important;
  opacity: 0;
}
.wheel .scroller {
  height: 100%; overflow-y: auto; scroll-snap-type: y mandatory;
  scrollbar-width: none;
}
.wheel .scroller::-webkit-scrollbar { display: none; }
.wheel .pad { height: 38px; }
.wheel .item {
  height: 38px; display: flex; align-items: center; justify-content: center;
  font-size: 19px; font-weight: 700; font-variant-numeric: tabular-nums;
  scroll-snap-align: center; color: var(--faint);
}
.wheel .item.sel { color: var(--accent); font-size: 22px; }
.wheel.untouched .item.sel { color: var(--dim); }
.wheel::before, .wheel::after {
  content: ""; position: absolute; left: 0; right: 0; height: 34px; z-index: 2; pointer-events: none;
}
.wheel::before { top: 0; background: linear-gradient(var(--card2), transparent); }
.wheel::after { bottom: 0; background: linear-gradient(transparent, var(--card2)); }
.wheel .band {
  position: absolute; left: 4px; right: 4px; top: 38px; height: 38px;
  border-radius: 9px; border: 1.5px solid var(--line); pointer-events: none; z-index: 1;
}

.daycard .dnote { color: var(--faint); font-size: 13px; margin-top: 6px; font-style: italic; }

.savebtn {
  width: 100%; background: var(--accent); color: #17130a;
  border-radius: var(--radius); padding: 16px; font-size: 17px; font-weight: 700;
}
.savebtn:disabled { opacity: 0.5; }
.savebtn:active { transform: scale(0.98); }
.delbtn { width: 100%; color: var(--red); font-size: 15px; font-weight: 600; padding: 14px; margin-top: 4px; }

/* ---------- sheet ---------- */
.overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.55); z-index: 10;
  display: flex; align-items: flex-end;
}
.sheet {
  background: var(--card); width: 100%; max-width: 480px; margin: 0 auto;
  border-radius: 20px 20px 0 0; padding: 18px 16px calc(20px + env(safe-area-inset-bottom));
  max-height: 75vh; overflow-y: auto;
}
.sheet h3 { font-size: 17px; margin-bottom: 14px; }
.sheet .opt {
  display: flex; width: 100%; text-align: left; padding: 13px 12px;
  border-radius: 12px; font-size: 16px; font-weight: 600; align-items: center; gap: 8px;
}
.sheet .opt:active { background: var(--card2); }
.sheet .opt .tag { margin-left: auto; color: var(--faint); font-size: 13px; font-weight: 500; }
.sheet .opt.danger { color: var(--red); }
.sheet .opt.newex { color: var(--accent); }
.sheet .divider { height: 1px; background: var(--line); margin: 8px 0; }

/* ---------- key gate ---------- */
.gate { padding-top: 18vh; text-align: center; }
.gate .biglogo { font-size: 52px; margin-bottom: 12px; }
.gate h2 { font-size: 22px; margin-bottom: 8px; }
.gate p { color: var(--dim); font-size: 14px; margin-bottom: 22px; }
.gate input {
  width: 100%; background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 14px; font-size: 16px; text-align: center; color: var(--text); outline: none;
  margin-bottom: 12px;
}
.gate .err { color: var(--red); font-size: 14px; margin-bottom: 10px; }

.banner {
  background: rgba(255, 69, 58, 0.12); color: var(--red);
  border-radius: 12px; padding: 10px 14px; font-size: 14px; font-weight: 600;
  margin-bottom: 14px;
}
.empty { text-align: center; color: var(--dim); padding: 40px 0; font-size: 15px; }
.spin { text-align: center; color: var(--faint); padding: 60px 0; }
