:root {
  --primary: #4a5d4a;
  --primary-soft: #5d725d;
  --secondary: #e8dcc4;
  --accent: #c76b4a;
  --ink: #3b443b;
  --muted: #8a927f;
  --sand: #cfc4ab;
  --sand-dark: #b6ab90;
  --slate: #4a5d4a;
  --jade: #7a9a7a;
  --rose: #c76b4a;
  --clay: #a8684a;
  --paper: #f4eee0;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overscroll-behavior: none;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--sand);
  background-image:
    repeating-linear-gradient(0deg,
      rgba(255,255,255,0.06) 0px, rgba(255,255,255,0.06) 2px,
      transparent 2px, transparent 10px),
    radial-gradient(circle at 18% 82%, rgba(255,255,255,0.18), transparent 32%),
    radial-gradient(circle at 80% 18%, rgba(90,100,80,0.12), transparent 40%),
    linear-gradient(180deg, #cfc4ab, #c6bb9f);
  color: var(--ink);
  min-height: 100%;
  -webkit-font-smoothing: antialiased;
}

#app {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
}

/* ---------- shishi-odoshi fountain ---------- */
#shishi {
  flex: 0 0 auto;
  height: 58px;
  padding: 6px calc(14px + env(safe-area-inset-left)) 2px calc(14px + env(safe-area-inset-left));
  padding-top: calc(6px + env(safe-area-inset-top));
  display: flex;
  align-items: flex-start;
  gap: 12px;
}
.fountain { position: relative; width: 52px; height: 34px; flex: 0 0 auto; }
.bamboo {
  position: absolute; left: 6px; top: 2px; width: 7px; height: 22px;
  background: linear-gradient(90deg, #6e7a55, #7e8a63, #68734f);
  border-radius: 3px;
  transform: rotate(-18deg); transform-origin: 6px 22px;
  box-shadow: inset 0 0 2px rgba(0,0,0,0.25);
}
.bamboo::after {
  content: ""; position: absolute; right: -3px; top: 4px; width: 7px; height: 15px;
  background: linear-gradient(90deg, #7e8a63, #6e7a55);
  border-radius: 3px; transform: rotate(-38deg);
}
.pool {
  position: absolute; left: 0; bottom: 0; width: 24px; height: 9px;
  background: radial-gradient(circle at 50% 35%, #9fb0c0, #76899b);
  border-radius: 50%;
  box-shadow: inset 0 2px 3px rgba(20,30,40,0.35);
}
.drip { position: absolute; left: 16px; top: 4px; width: 4px; height: 4px; border-radius: 50%;
  background: rgba(200,220,235,0.85); animation: drip 2.4s ease-in infinite; }
@keyframes drip {
  0% { opacity: 0; transform: translateY(0) scale(1); }
  15% { opacity: 1; }
  100% { opacity: 0; transform: translateY(22px) scale(0.6); }
}
#app-title {
  margin: 0; font-size: 1.3rem; letter-spacing: 3px; text-transform: lowercase;
  color: var(--primary); font-weight: 600; line-height: 1;
  font-family: "Segoe Print", "Bradley Hand", "Comic Sans MS", cursive;
  text-shadow: 0 1px 0 rgba(255,255,255,0.4);
}

/* ---------- main viewport ---------- */
#viewport {
  flex: 1 1 auto;
  position: relative;
  overflow: hidden;
  padding-bottom: 84px;
}
.page {
  position: absolute; inset: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 10px calc(14px + env(safe-area-inset-right)) 24px calc(14px + env(safe-area-inset-left));
  scrollbar-width: none;
}
.page::-webkit-scrollbar { display: none; }
.page { display: none; }
.page.active { display: block; }

.page-heading {
  font-family: "Segoe Print", "Bradley Hand", "Comic Sans MS", cursive;
  color: var(--primary); font-weight: 600; font-size: 1.05rem; letter-spacing: 1px;
  margin: 6px 0 12px;
}

/* ---------- today bowls ---------- */
.today-top { display: flex; gap: 18px; justify-content: center; margin: 6px 0 18px; }
.bowl-wrap { display: flex; flex-direction: column; align-items: center; }
.bowl {
  width: 92px; height: 44px;
  background: radial-gradient(ellipse at 50% 30%, #8a5a3a, #6d4528 60%, #55331d);
  border-radius: 46% 46% 44% 44%;
  position: relative;
  box-shadow: 0 8px 12px rgba(40,25,10,0.35), inset 0 4px 8px rgba(255,200,140,0.28), inset 0 -6px 10px rgba(0,0,0,0.35);
}
.bowl-week { background: radial-gradient(ellipse at 50% 30%, #96613e, #76492a 60%, #5b361e); }
.pebbles { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; gap: 3px; padding-top: 6px; }
.pebble {
  width: 16px; height: 13px; border-radius: 48% 52% 52% 48%;
  background: radial-gradient(circle at 32% 28%, #f5ead4, #c9b896 60%, #8f7f63);
  box-shadow: inset 0 1px 2px rgba(255,255,255,0.7), 0 2px 3px rgba(0,0,0,0.3);
}
.tag {
  margin-top: 8px; padding: 5px 12px;
  background: var(--paper);
  color: var(--primary);
  border: 1px solid rgba(90,93,70,0.4);
  border-radius: 3px;
  font-family: "Segoe Print", "Bradley Hand", cursive;
  font-size: 0.85rem; white-space: nowrap;
  box-shadow: 0 3px 0 rgba(90,70,40,0.15);
  position: relative;
}
.tag::before {
  content: ""; position: absolute; left: 8px; right: 8px; top: -6px; height: 6px;
  background: repeating-linear-gradient(0deg, transparent 0 2px, rgba(74,93,74,0.5) 2px 4px);
}

/* ---------- moment stones ---------- */
.moment-list { display: flex; flex-direction: column; gap: 12px; }
.moment {
  position: relative;
  border-radius: 50% 46% 46% 50%;
  background: radial-gradient(circle at 30% 24%, #f0e8d4, #ddd2b6 55%, #c3b795);
  padding: 14px 14px 14px 18px;
  color: var(--ink);
  box-shadow: 0 5px 8px rgba(40,35,20,0.3), inset 0 2px 4px rgba(255,255,255,0.6);
  border: 0;
  overflow: hidden;
  user-select: none;
  cursor: pointer;
}
.moment .rim {
  position: absolute; left: 6px; top: 14%; bottom: 14%; width: 4px; border-radius: 4px;
}
.moment.mind .rim { background: var(--slate); }
.moment.body .rim { background: var(--jade); }
.moment.soul .rim { background: var(--rose); }

.moment .m-top { display: flex; align-items: center; gap: 10px; }
.moment .etch {
  flex: 0 0 auto; width: 30px; height: 30px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 1rem; color: rgba(255,255,255,0.9);
  background: var(--etch-bg, var(--slate));
  box-shadow: inset 0 1px 2px rgba(255,255,255,0.4), 0 2px 3px rgba(0,0,0,0.25);
}
.moment.mind .etch { background: var(--slate); }
.moment.body .etch { background: var(--jade); }
.moment.soul .etch { background: var(--rose); }

.moment .m-name {
  font-family: "Segoe Print", "Bradley Hand", "Comic Sans MS", cursive;
  font-size: 1.05rem; color: var(--primary); font-weight: 600; line-height: 1.15;
}
.moment .m-meta {
  margin-top: 6px; display: flex; flex-wrap: wrap; gap: 6px 10px;
  font-size: 0.8rem; color: var(--muted);
}
.moment .m-meta span .num { font-weight: 600; color: var(--ink); }
.moment .m-feel { margin-top: 6px; font-size: 0.9rem; color: #555c4a; font-style: italic; }

.group-date {
  font-family: "Segoe Print", "Bradley Hand", cursive;
  color: var(--primary); font-size: 0.9rem; margin: 16px 4px 8px; letter-spacing: 1px;
  text-transform: capitalize;
}

/* empty states */
.empty-state { text-align: center; padding: 40px 10px; color: var(--muted); }
.empty-stones { display: flex; justify-content: center; gap: 8px; margin-bottom: 16px; }
.empty-stones i {
  display: block; border-radius: 50%;
  background: radial-gradient(circle at 32% 28%, #e6dcbe, #cfc4a0);
  box-shadow: inset 0 2px 3px rgba(255,255,255,0.6), 0 4px 6px rgba(40,35,20,0.25);
}
.empty-stones .e1 { width: 26px; height: 22px; }
.empty-stones .e2 { width: 20px; height: 17px; margin-top: 14px; }
.empty-stones .e3 { width: 24px; height: 20px; margin-top: 6px; }
.empty-lone { width: 34px; height: 28px; margin: 0 auto 16px; border-radius: 50%;
  background: radial-gradient(circle at 32% 28%, #e6dcbe, #cfc4a0);
  box-shadow: inset 0 2px 3px rgba(255,255,255,0.6), 0 4px 6px rgba(40,35,20,0.25); }
.empty-rake {
  width: 130px; height: 6px; margin: -6px auto 18px;
  background: repeating-linear-gradient(90deg, rgba(90,80,60,0.25) 0 2px, transparent 2px 16px);
  border-radius: 3px;
}
.empty-msg { font-family: "Segoe Print", "Bradley Hand", cursive; font-size: 0.95rem; }
.empty-msg .sub { display: block; margin-top: 4px; font-size: 0.8rem; font-family: inherit; color: var(--muted); }

/* ---------- logbook bar ---------- */
.logbook-bar { position: sticky; top: 0; z-index: 3; padding: 2px 0 6px;
  background: linear-gradient(180deg, #cfc4ab 60%, rgba(207,196,171,0)); }
#search {
  width: 100%; padding: 11px 14px; border-radius: 20px; border: 1px solid rgba(90,93,70,0.35);
  background: rgba(255,255,255,0.45); font-size: 0.95rem; color: var(--ink); outline: none;
}
#search:focus { border-color: var(--primary); background: rgba(255,255,255,0.7); }
.filter-chips { display: flex; gap: 8px; margin-top: 8px; overflow-x: auto; scrollbar-width: none; }
.filter-chips::-webkit-scrollbar { display: none; }
.chip {
  border: 1px solid rgba(90,93,70,0.4); background: rgba(255,255,255,0.3);
  color: var(--ink); border-radius: 20px; padding: 6px 14px; font-size: 0.85rem; cursor: pointer; white-space: nowrap;
}
.chip.active { background: var(--primary); color: var(--paper); border-color: var(--primary); }

/* ---------- categories ---------- */
.cat-list { display: flex; flex-direction: column; gap: 18px; padding-top: 8px; }
.cat-stone {
  border: 0; cursor: pointer; padding: 22px 20px; color: var(--ink); width: 100%;
  border-radius: 44% 48% 48% 44%;
  box-shadow: 0 8px 12px rgba(40,35,20,0.3), inset 0 3px 5px rgba(255,255,255,0.5);
  display: flex; align-items: center; gap: 16px;
}
.cat-stone.mind { background: radial-gradient(circle at 32% 24%, #7d8f7a, var(--slate) 62%, #3a4a3a); }
.cat-stone.body { background: radial-gradient(circle at 32% 24%, #a6c2a0, var(--jade) 62%, #5f7a5f); }
.cat-stone.soul { background: radial-gradient(circle at 32% 24%, #e39a75, var(--rose) 62%, #a8583a); }
.cat-stone .cat-etch {
  width: 52px; height: 52px; flex: 0 0 auto; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.5rem; color: rgba(255,255,255,0.92);
  background: rgba(255,255,255,0.18);
  box-shadow: inset 0 2px 4px rgba(255,255,255,0.35), 0 3px 5px rgba(0,0,0,0.2);
}
.cat-stone .cat-txt { text-align: left; }
.cat-stone .cat-name { font-family: "Segoe Print", "Bradley Hand", cursive; font-size: 1.2rem; color: #fff; font-weight: 600; }
.cat-stone .cat-count { color: rgba(255,255,255,0.85); font-size: 0.9rem; margin-top: 2px; }
.cat-stone .cat-count.pale { color: rgba(255,255,255,0.5); }

/* ---------- capture form ---------- */
.field-label { display: block; font-size: 0.82rem; letter-spacing: 1px; text-transform: lowercase;
  color: var(--primary); margin: 16px 2px 7px; font-weight: 600; }
.field-label .subtle { color: var(--muted); text-transform: none; letter-spacing: 0; }
.stone-input {
  width: 100%; padding: 13px 16px; font-size: 1rem; color: var(--ink);
  background: rgba(255,255,255,0.5); border: 1px solid rgba(90,93,70,0.35);
  border-radius: 24px; outline: none; -webkit-appearance: none;
}
.stone-input:focus { border-color: var(--primary); background: rgba(255,255,255,0.75); }
.area { border-radius: 18px; resize: none; font-family: inherit; }
.stone-input.invalid { border-color: var(--accent); animation: shake 0.35s; }
@keyframes shake { 0%,100%{transform:translateX(0)} 20%,60%{transform:translateX(-6px)} 40%,80%{transform:translateX(6px)} }

.crack-msg { display: none; margin: 6px 4px 0; color: var(--accent); font-size: 0.8rem; font-family: "Segoe Print", cursive; }
.crack-msg.show { display: block; }

.cat-picker { display: flex; gap: 10px; }
.stone-cat {
  flex: 1; border: 0; cursor: pointer; padding: 16px 6px 14px;
  border-radius: 46% 44% 44% 46%;
  color: #fff; display: flex; flex-direction: column; align-items: center; gap: 6px;
  font-size: 0.85rem; font-family: "Segoe Print", cursive;
  box-shadow: 0 5px 8px rgba(40,35,20,0.3), inset 0 2px 4px rgba(255,255,255,0.4);
  background: var(--slate); opacity: 0.85;
}
.stone-cat .etched { font-size: 1.2rem; }
.stone-cat[data-cat="Body"] { background: var(--jade); }
.stone-cat[data-cat="Soul"] { background: var(--rose); }
.stone-cat.selected { opacity: 1; transform: scale(1.05); box-shadow: 0 7px 12px rgba(0,0,0,0.4), inset 0 3px 6px rgba(255,255,255,0.5); }

.stepper { display: flex; align-items: center; gap: 12px; }
.step-btn {
  width: 44px; height: 44px; border-radius: 50%; border: 0; cursor: pointer;
  font-size: 1.4rem; color: var(--primary); background: rgba(255,255,255,0.5);
  box-shadow: 0 4px 6px rgba(40,35,20,0.25), inset 0 2px 3px rgba(255,255,255,0.6);
}
.step-btn:active { transform: translateY(2px); }
.step-input { flex: 1; text-align: center; }

.submit-stone {
  width: 100%; margin-top: 22px; padding: 18px; border: 0; cursor: pointer;
  border-radius: 48% 46% 46% 48%;
  font-size: 1.05rem; letter-spacing: 2px;
  color: #fff; font-family: "Segoe Print", cursive;
  background: radial-gradient(circle at 50% 30%, #5d725d, var(--primary) 65%, #3a4a3a);
  box-shadow: 0 10px 14px rgba(40,35,20,0.35), inset 0 3px 5px rgba(255,255,255,0.35);
  transition: transform 0.08s, box-shadow 0.08s;
}
.submit-stone:active { transform: translateY(4px) scale(0.99); box-shadow: 0 3px 6px rgba(40,35,20,0.3), inset 0 4px 6px rgba(0,0,0,0.25); }
.cancel-btn { display: none; width: 100%; margin-top: 10px; padding: 12px; border: 0; cursor: pointer;
  background: transparent; color: var(--muted); font-size: 0.9rem; text-decoration: underline dotted; }
.cancel-btn.show { display: block; }

/* ---------- quick add ---------- */
.quick-add {
  position: fixed; right: calc(16px + env(safe-area-inset-right)); bottom: calc(104px + env(safe-area-inset-bottom));
  width: 58px; height: 58px; border-radius: 50%; border: 0; cursor: pointer; z-index: 20;
  background: radial-gradient(circle at 32% 26%, #b47b5a, var(--clay) 62%, #7e4c30);
  box-shadow: 0 8px 14px rgba(40,25,10,0.4), inset 0 3px 5px rgba(255,255,255,0.4);
  display: flex; align-items: center; justify-content: center;
}
.quick-add .q-pebble { position: absolute; border-radius: 50%; background: radial-gradient(circle at 32% 28%, #f5ead4, #cdbd9a 60%, #96876c);
  box-shadow: inset 0 1px 2px rgba(255,255,255,0.7); }
.q1 { width: 20px; height: 16px; transform: translateY(6px); }
.q2 { width: 16px; height: 13px; transform: translate(-8px,-4px) rotate(12deg); }
.q3 { width: 14px; height: 12px; transform: translate(9px,-6px) rotate(-14deg); }
.quick-add:active { transform: scale(0.94); }

/* ---------- tab bar ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  padding: 14px 10px calc(10px + env(safe-area-inset-bottom));
  display: flex; justify-content: space-around; align-items: flex-end;
  background: linear-gradient(180deg, rgba(0,0,0,0) 0, rgba(60,50,30,0.08) 18px, rgba(60,50,30,0.22) 30px);
}
.tabbar::before {
  content: ""; position: absolute; left: 10px; right: 10px; top: 16px; height: 5px;
  background: linear-gradient(180deg, #9c7b53, #7a5c38);
  border-radius: 3px;
  box-shadow: 0 6px 10px rgba(40,25,10,0.3);
}
.tab {
  position: relative; z-index: 1; background: none; border: 0; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 0; min-width: 56px;
}
.tab-stone {
  display: block; width: 40px; height: 34px; border-radius: 46% 50% 50% 46%;
  box-shadow: 0 4px 6px rgba(0,0,0,0.28), inset 0 2px 3px rgba(255,255,255,0.35);
}
.today-s { background: radial-gradient(circle at 32% 26%, #7d8f7a, var(--slate) 62%, #3a4a3a); }
.log-s { background: radial-gradient(circle at 32% 26%, #a6c2a0, var(--jade) 62%, #5f7a5f); }
.cat-s { background: radial-gradient(circle at 32% 26%, #e39a75, var(--rose) 62%, #a8583a); }
.cap-s { background: radial-gradient(circle at 32% 26%, #b47b5a, var(--clay) 62%, #7e4c30); }
.tab-label { font-size: 0.72rem; color: rgba(59,68,59,0.85); font-family: "Segoe Print", cursive; }
.tab.active .tab-label { color: var(--ink); font-weight: 600; }
.tab.active .tab-stone {
  transform: scale(1.1);
  box-shadow: 0 7px 10px rgba(0,0,0,0.35), inset 0 3px 5px rgba(255,255,255,0.5), 0 0 12px rgba(255,255,255,0.45);
}
.tab.active .tab-stone::after {
  content: ""; position: absolute; top: 8%; left: 18%; width: 20%; height: 26%;
  background: rgba(255,255,255,0.85); border-radius: 50%;
  filter: blur(1px);
}

/* ---------- modal ---------- */
.modal {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(40,35,20,0.45);
  display: flex; align-items: center; justify-content: center; padding: 24px;
}
.modal[hidden] { display: none; }
.modal-card {
  background: var(--paper); border-radius: 20px; padding: 26px 22px; width: 100%; max-width: 320px;
  text-align: center; box-shadow: 0 18px 30px rgba(20,15,5,0.4);
}
.modal-stone { width: 44px; height: 38px; margin: 0 auto 14px; border-radius: 50%;
  background: radial-gradient(circle at 32% 28%, #d9b7a2, var(--accent) 62%, #a8583a);
  box-shadow: inset 0 2px 3px rgba(255,255,255,0.4); }
.modal-card h3 { margin: 0 0 8px; font-family: "Segoe Print", cursive; color: var(--ink); }
.modal-card p { margin: 0 0 18px; font-size: 0.9rem; color: var(--muted); }
.modal-actions { display: flex; gap: 10px; }
.modal-btn { flex: 1; padding: 12px; border-radius: 24px; border: 0; cursor: pointer; font-size: 0.9rem; font-family: "Segoe Print", cursive; }
.modal-btn.ghost { background: rgba(74,93,74,0.15); color: var(--primary); }
.modal-btn.danger { background: var(--accent); color: #fff; }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(120px + env(safe-area-inset-bottom)); z-index: 60;
  background: rgba(59,68,59,0.92); color: var(--paper); padding: 10px 18px;
  border-radius: 24px; font-size: 0.85rem; font-family: "Segoe Print", cursive;
  box-shadow: 0 8px 16px rgba(0,0,0,0.3); white-space: nowrap;
  transition: opacity 0.3s, transform 0.3s;
}
.toast[hidden] { opacity: 0; transform: translateX(-50%) translateY(10px); pointer-events: none; }