:root {
  --primary: #1b3a5c;
  --primary-dark: #12273f;
  --accent: #2e9b8a;
  --secondary: #d4a44b;
  --ideas: #f7e68e;
  --active: #27ae60;
  --completed: #6c3483;
  --bench: #2e9b8a;

  --paper: #f6f1e3;
  --paper-line: #cfe0e6;
  --ink: #33404e;
  --ink-soft: #6b7785;
  --hand: 'Comic Sans MS', 'Chalkboard SE', 'Bradley Hand', 'Segoe Print', cursive;
  --sans: 'Comic Sans MS', 'Chalkboard SE', 'Segoe UI', sans-serif;

  --rack-wood-top: #7a5a33;
  --rack-wood: #5b4124;
  --rack-wood-dark: #45301a;

  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background:
    radial-gradient(1200px 500px at 50% -10%, rgba(255,255,255,.06), transparent 60%),
    linear-gradient(160deg, #8a5a33 0%, #6d4423 55%, #543318 100%);
  color: var(--ink);
  font-family: var(--sans);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

.hidden { display: none !important; }

/* ---------- Notebook layout ---------- */
.notebook {
  position: relative;
  height: 100dvh;
  height: 100vh;
  display: flex;
  flex-direction: column;
  background:
    linear-gradient(90deg, rgba(255,255,255,.05) 1px, transparent 1px) 0 0 / 34px 34px,
    linear-gradient(rgba(255,255,255,.05) 1px, transparent 1px) 0 0 / 34px 34px,
    linear-gradient(160deg, #fbf7ec 0%, #f4ecdc 100%);
  box-shadow: inset 0 0 0 6px var(--primary);
  border: 1px solid var(--primary-dark);
  padding-top: var(--safe-t);
}

.notebook-spine {
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 10px;
  background: linear-gradient(90deg, var(--primary-dark), var(--primary) 60%, #2a5580);
  box-shadow: 3px 0 6px rgba(0,0,0,.25);
  z-index: 2;
}

.cover-header {
  padding: 14px 18px 6px 22px;
  background: linear-gradient(180deg, rgba(27,58,92,.06), transparent);
  border-bottom: 1px dashed rgba(27,58,92,.25);
}
.app-title {
  margin: 0;
  font-family: var(--hand);
  font-size: 26px;
  color: var(--primary);
  letter-spacing: .5px;
}
.app-subtitle {
  margin: 2px 0 0;
  font-family: var(--hand);
  font-size: 13px;
  color: var(--ink-soft);
}

/* ---------- Page / content ---------- */
.page {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 14px 16px calc(96px + var(--safe-b));
  position: relative;
  -webkit-overflow-scrolling: touch;
  scroll-padding-bottom: 96px;
}

/* search bar */
.search-wrap {
  position: sticky;
  top: 0;
  z-index: 5;
  padding: 6px 0 10px;
  background: linear-gradient(180deg, rgba(246,241,227,.98), rgba(246,241,227,.9) 70%, transparent);
  margin: 0 -16px;
  padding-left: 16px;
  padding-right: 16px;
}
.search-box {
  position: relative;
}
.search-box input {
  width: 100%;
  padding: 11px 12px 11px 34px;
  border: 1px solid rgba(27,58,92,.25);
  border-radius: 12px;
  background: rgba(255,255,255,.7);
  font-family: var(--hand);
  font-size: 15px;
  color: var(--ink);
}
.search-box::before {
  content: "";
  position: absolute;
  left: 12px; top: 50%;
  width: 11px; height: 11px;
  border: 2px solid var(--ink-soft);
  border-radius: 50%;
  transform: translateY(-60%);
}
.search-box::after {
  content: "";
  position: absolute;
  left: 22px; top: 50%;
  width: 8px; height: 2px;
  background: var(--ink-soft);
  transform: translateY(6px) rotate(45deg);
}

.list-title {
  margin: 14px 2px 8px;
  font-family: var(--hand);
  font-size: 16px;
  color: var(--primary);
}

/* ---------- Experiment note cards ---------- */
.exp-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.exp-item-wrap {
  position: relative;
  border-radius: 12px;
  overflow: hidden;
}
.exp-delete {
  position: absolute;
  top: 0; right: 0; bottom: 0;
  width: 76px;
  background: #c0392b;
  color: #fff;
  border: none;
  font-family: var(--hand);
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 4px;
}
.exp-delete span:first-child { font-size: 20px; }
.exp-item {
  position: relative;
  background:
    linear-gradient(90deg, rgba(123,160,180,.22) 0, rgba(123,160,180,.22) 3px, transparent 3px) 0 0 / 100% 26px,
    rgba(255,255,255,.92);
  border: 1px solid rgba(27,58,92,.15);
  border-radius: 12px;
  padding: 12px 12px 10px 16px;
  box-shadow: 0 2px 0 rgba(0,0,0,.05);
  cursor: pointer;
  transition: transform .18s ease;
  touch-action: pan-y;
}
.exp-item:active { transform: scale(.99); }

.exp-item .row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}
.tube-dot {
  flex: 0 0 auto;
  width: 20px;
  height: 42px;
  margin-top: 2px;
  border: 1.5px solid rgba(27,58,92,.5);
  border-top: none;
  border-radius: 0 0 50% 50% / 0 0 14px 14px;
  position: relative;
  overflow: hidden;
  background: linear-gradient(90deg, rgba(255,255,255,.5), rgba(255,255,255,.9));
}
.tube-dot .dot-liquid {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 70%;
}
.tube-dot.bubbling .dot-liquid::before,
.tube-dot.bubbling .dot-liquid::after {
  content: "";
  position: absolute;
  border-radius: 50%;
  background: rgba(255,255,255,.65);
}
.tube-dot.bubbling .dot-liquid::before { width: 4px; height: 4px; top: 4px; left: 5px; }
.tube-dot.bubbling .dot-liquid::after  { width: 2.5px; height: 2.5px; top: -2px; right: 5px; }

.exp-item .info { flex: 1; min-width: 0; }
.exp-item .exp-title {
  margin: 0;
  font-family: var(--hand);
  font-size: 16px;
  color: var(--ink);
  line-height: 1.3;
  word-break: break-word;
}
.exp-item .exp-meta {
  margin: 6px 0 0;
  font-family: var(--hand);
  font-size: 12px;
  color: var(--ink-soft);
  display: flex;
  align-items: center;
  gap: 6px;
}

/* ---------- Dashboard ---------- */
.dash-intro {
  font-family: var(--hand);
  font-size: 14px;
  color: var(--ink-soft);
  margin: 4px 2px 12px;
}

.counters {
  display: flex;
  gap: 10px;
  justify-content: space-between;
  margin-bottom: 8px;
}
.beaker-sticker {
  flex: 1;
  text-align: center;
  background:
    radial-gradient(circle at 50% 18%, rgba(255,255,255,.9), rgba(255,255,255,.35) 55%),
    linear-gradient(160deg, rgba(255,255,255,.7), rgba(255,255,255,.25));
  border: 1.5px solid rgba(27,58,92,.18);
  border-radius: 14px 14px 18px 18px;
  padding: 12px 6px 8px;
  box-shadow: 2px 3px 0 rgba(0,0,0,.08);
  transform: rotate(-1.2deg);
}
.beaker-sticker:nth-child(2) { transform: rotate(.8deg); }
.beaker-sticker:nth-child(3) { transform: rotate(-.5deg); }
.beaker-sticker .num {
  display: block;
  font-family: var(--hand);
  font-size: 28px;
  font-weight: bold;
  line-height: 1;
}
.beaker-sticker .st-label {
  display: block;
  font-family: var(--hand);
  font-size: 12px;
  color: var(--ink-soft);
  margin-top: 5px;
}
.beaker-sticker.ideas .num { color: #b69a2a; }
.beaker-sticker.active .num { color: #1e8449; }
.beaker-sticker.completed .num { color: var(--completed); }

.quick-action {
  width: 100%;
  margin: 6px 0 16px;
  padding: 14px;
  border: none;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--accent), #21776a);
  color: #fff;
  font-family: var(--hand);
  font-size: 17px;
  font-weight: bold;
  letter-spacing: .3px;
  box-shadow: 0 4px 0 rgba(27,58,92,.3);
  cursor: pointer;
}
.quick-action:active { transform: translateY(2px); box-shadow: 0 2px 0 rgba(27,58,92,.3); }

.dash-section-title {
  margin: 18px 2px 8px;
  font-family: var(--hand);
  font-size: 15px;
  color: var(--primary);
  border-bottom: 1px dashed rgba(27,58,92,.25);
  padding-bottom: 4px;
}

/* ---------- Empty states ---------- */
.empty {
  text-align: center;
  padding: 46px 18px;
}
.empty .empty-tube {
  display: inline-block;
  width: 26px;
  height: 60px;
  border: 2px solid var(--empty, var(--ink-soft));
  border-top: none;
  border-radius: 0 0 60% 60% / 0 0 24px 24px;
  background: linear-gradient(180deg, rgba(255,255,255,.3), var(--empty, rgba(0,0,0,.2)) 130%);
  position: relative;
}
.empty .empty-tube::after {
  content: "";
  position: absolute;
  left: 50%; bottom: 0;
  width: 26px; height: 7px;
  background: var(--empty, var(--ink-soft));
  transform: translateX(-50%);
  border-radius: 0 0 60% 60% / 0 0 24px 24px;
}
.empty p {
  font-family: var(--hand);
  font-size: 16px;
  color: var(--ink-soft);
  margin-top: 18px;
  line-height: 1.5;
}

/* ---------- FAB (beaker) ---------- */
.fab {
  position: fixed;
  right: 18px;
  bottom: calc(86px + var(--safe-b));
  width: 62px; height: 62px;
  border: none;
  border-radius: 50%;
  background: linear-gradient(150deg, #e8f4f0, #cfe9e2);
  box-shadow: 0 5px 0 rgba(27,58,92,.25), 0 10px 18px rgba(0,0,0,.28);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 20;
  transition: transform .15s ease;
}
.fab:active { transform: translateY(3px); box-shadow: 0 2px 0 rgba(27,58,92,.25); }
.fab .fab-text {
  position: absolute;
  bottom: -20px;
  left: 50%;
  transform: translateX(-50%);
  font-family: var(--hand);
  font-size: 12px;
  color: var(--primary);
  font-weight: bold;
  white-space: nowrap;
}
.beaker {
  position: relative;
  width: 26px; height: 24px;
  border: 3px solid var(--accent);
  border-top-width: 2px;
  border-radius: 0 0 10px 10px;
}
.beaker::before, .beaker::after {
  content: "";
  position: absolute;
  top: -5px;
  width: 3px; height: 9px;
  background: var(--accent);
  border-radius: 2px;
}
.beaker::before { left: 0; }
.beaker::after { right: 0; }
.beaker .bubble {
  position: absolute;
  left: 8px; top: -6px;
  width: 6px; height: 6px;
  border-radius: 50%;
  border: 2px solid var(--accent);
}

/* ---------- Bottom test-tube rack ---------- */
.rack {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  height: calc(74px + var(--safe-b));
  padding: 0 8px var(--safe-b);
  display: flex;
  align-items: flex-end;
  justify-content: space-around;
  background: linear-gradient(180deg, var(--rack-wood-top), var(--rack-wood) 40%, var(--rack-wood-dark));
  border-top: 2px solid #2e2012;
  z-index: 30;
  box-shadow: 0 -4px 10px rgba(0,0,0,.35);
}

.tube {
  position: relative;
  width: 26%;
  height: 100%;
  background: transparent;
  border: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.tube-glass {
  position: relative;
  width: 20px;
  height: 38px;
  border: 2px solid rgba(255,255,255,.55);
  border-top: none;
  border-radius: 0 0 50% 50% / 0 0 14px 14px;
  background: linear-gradient(180deg, rgba(255,255,255,.12), rgba(255,255,255,.28));
  overflow: hidden;
  margin-bottom: 2px;
  transition: box-shadow .2s ease;
}
.liquid {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 0%;
  transition: height .25s ease, filter .2s ease;
  border-radius: 0 0 50% 50% / 0 0 14px 14px;
}
.tube.active .liquid { height: 70%; }
.tube.active .liquid-ideas { background: var(--ideas); filter: drop-shadow(0 4px 5px rgba(247,230,142,.6)); }
.tube.active .liquid-active { background: var(--active); filter: drop-shadow(0 4px 5px rgba(39,174,96,.6)); }
.tube.active .liquid-completed { background: var(--completed); filter: drop-shadow(0 4px 5px rgba(108,51,131,.6)); }
.tube.active .liquid-bench { background: var(--bench); filter: drop-shadow(0 4px 5px rgba(46,155,138,.6)); }

.cork {
  width: 14px; height: 8px;
  margin-bottom: 1px;
  background: linear-gradient(180deg, #d9a866, #b9894a);
  border-radius: 3px 3px 0 0;
  border: 1px solid rgba(0,0,0,.2);
  transition: transform .15s ease;
}
.tube-label {
  font-family: var(--hand);
  font-size: 11px;
  color: #f0e3c6;
  margin-top: 2px;
  letter-spacing: .2px;
  text-shadow: 0 1px 2px rgba(0,0,0,.4);
  white-space: nowrap;
}
.tube.active .tube-label { color: #fff; font-weight: bold; }

/* ---------- Bottom sheet form ---------- */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(18,39,63,.55);
  z-index: 40;
}
.sheet {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 50;
  background:
    linear-gradient(rgba(123,160,180,.15) 1px, transparent 1px) 0 0 / 100% 26px,
    #f7f2e4;
  border-radius: 18px 18px 0 0;
  padding: 8px 18px calc(20px + var(--safe-b));
  max-height: 90dvh;
  overflow-y: auto;
  box-shadow: 0 -8px 24px rgba(0,0,0,.4);
  transform: translateY(0);
  transition: transform .25s ease;
}
.sheet.open { transform: translateY(0); }
.sheet.slide { transform: translateY(100%); }
.sheet-handle {
  width: 44px; height: 5px;
  border-radius: 3px;
  background: rgba(27,58,92,.25);
  margin: 4px auto 10px;
}
.sheet h2 {
  margin: 0 0 14px;
  font-family: var(--hand);
  font-size: 20px;
  color: var(--primary);
}
.field { display: block; margin-bottom: 12px; }
.field-label {
  display: block;
  font-family: var(--hand);
  font-size: 13px;
  color: var(--ink-soft);
  margin-bottom: 5px;
}
.field input, .field textarea {
  width: 100%;
  padding: 11px 12px;
  border: 1.5px solid rgba(27,58,92,.25);
  border-radius: 10px;
  background: rgba(255,255,255,.85);
  font-family: var(--hand);
  font-size: 15px;
  color: var(--ink);
}
.field textarea { resize: vertical; min-height: 70px; }
.field input:focus, .field textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(46,155,138,.2);
}
.error {
  display: block;
  color: #c0392b;
  font-family: var(--hand);
  font-size: 12px;
  min-height: 15px;
  margin-top: 3px;
}

.status-picker {
  display: flex;
  gap: 8px;
}
.status-option {
  flex: 1;
  padding: 9px 4px;
  border: 1.5px solid rgba(27,58,92,.25);
  border-radius: 10px;
  background: rgba(255,255,255,.7);
  font-family: var(--hand);
  font-size: 14px;
  color: var(--ink);
  cursor: pointer;
}
.status-option.selected { border-color: var(--accent); background: rgba(46,155,138,.15); }

.sheet-actions {
  display: flex;
  gap: 10px;
  margin-top: 6px;
}
.btn {
  flex: 1;
  padding: 12px;
  border: none;
  border-radius: 10px;
  font-family: var(--hand);
  font-size: 15px;
  font-weight: bold;
  cursor: pointer;
}
.btn-ghost { background: #e4ddd0; color: var(--ink); }
.btn-primary { background: var(--accent); color: #fff; }
.btn-danger { background: #c0392b; color: #fff; }

/* ---------- Confirm dialog ---------- */
.confirm {
  position: fixed;
  left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  z-index: 51;
  width: min(320px, 84vw);
  background:
    linear-gradient(rgba(123,160,180,.15) 1px, transparent 1px) 0 0 / 100% 24px,
    #f7f2e4;
  border-radius: 14px;
  padding: 18px 18px 14px;
  box-shadow: 0 10px 30px rgba(0,0,0,.4);
  text-align: center;
}
.confirm h3 { margin: 0 0 6px; font-family: var(--hand); color: var(--primary); }
.confirm p { margin: 0 0 14px; font-family: var(--hand); font-size: 13px; color: var(--ink-soft); }

@media (min-width: 560px) {
  .notebook { max-width: 480px; margin: 0 auto; border-top: none; border-bottom: none; }
  .rack { max-width: 480px; left: 50%; transform: translateX(-50%); }
  .fab { right: calc(50% - 222px); }
}