/* ============================================================
   Crescendo — "Music Stand Top-Down"
   Wood-grain practice room, chalkboard counters, manuscript cards.
   ============================================================ */

:root {
  --wood-1: #5a4233;
  --wood-2: #4a3629;
  --wood-3: #3b2f2f;
  --accent: #c4953a;      /* brass */
  --ink: #2c2323;
  --ivory: #f7f0d9;       /* manuscript paper */
  --ivory-old: #efe2b4;   /* yellow patina */
  --chalk-green: #2f5d43;
  --chalk-green-deep: #245038;
  --chalk: #f3efe2;
  --panel-radius: 16px;
  --tabbar-h: 64px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  /* warm wood grain via layered gradients */
  background:
    repeating-linear-gradient(
      90deg,
      rgba(0,0,0,0.06) 0 3px,
      rgba(255,255,255,0.02) 3px 7px,
      rgba(0,0,0,0) 7px 60px
    ),
    repeating-linear-gradient(
      0deg,
      rgba(0,0,0,0.05) 0 1px,
      rgba(0,0,0,0) 1px 90px,
      rgba(0,0,0,0.03) 90px 91px,
      rgba(0,0,0,0) 91px 190px
    ),
    radial-gradient(circle at 20% 10%, rgba(255,255,255,0.08), transparent 40%),
    radial-gradient(circle at 80% 90%, rgba(0,0,0,0.25), transparent 50%),
    linear-gradient(160deg, var(--wood-1), var(--wood-2) 55%, var(--wood-3));
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

.sr-only {
  position: absolute; width: 1px; height: 1px;
  clip: rect(0 0 0 0); overflow: hidden; white-space: nowrap;
}

#app {
  max-width: 560px;
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
  padding: calc(env(safe-area-inset-top) + 16px) 16px
           calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 16px);
}

.tab-pane[hidden] { display: none; }
.hidden { display: none !important; }

/* ---------- Headers ---------- */
.pane-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 4px 2px 14px; }

.logo {
  font-family: "Segoe Print", "Bradley Hand", "Marker Felt", "Comic Sans MS", cursive;
  font-size: 2rem;
  color: var(--ivory);
  text-shadow: 0 2px 3px rgba(0,0,0,0.45);
  letter-spacing: 0.5px;
}

.pane-title {
  font-family: "Segoe Print", "Bradley Hand", "Comic Sans MS", cursive;
  font-size: 1.6rem;
  color: var(--ivory);
  text-shadow: 0 2px 3px rgba(0,0,0,0.45);
}

.tagline {
  font-size: 0.72rem;
  color: rgba(247,240,217,0.75);
  letter-spacing: 1px;
  text-transform: uppercase;
  margin-top: -6px;
  margin-left: 6px;
}

.section-title {
  font-family: "Segoe Print", "Bradley Hand", "Comic Sans MS", cursive;
  font-size: 1.05rem;
  color: var(--ivory);
  margin: 18px 4px 10px;
  text-shadow: 0 1px 2px rgba(0,0,0,0.4);
}

/* ---------- Buttons ---------- */
.btn {
  border: none;
  cursor: pointer;
  border-radius: 12px;
  font-family: inherit;
  font-weight: 600;
  font-size: 1rem;
  padding: 14px 20px;
  transition: transform 0.08s ease, box-shadow 0.15s ease, filter 0.15s ease;
  touch-action: manipulation;
}
.btn:active { transform: scale(0.97); }

.btn-primary {
  background: linear-gradient(180deg, #d8ac55, var(--accent) 45%, #a8781f);
  color: #2a1f14;
  box-shadow: 0 3px 0 #7d5a17, 0 6px 12px rgba(0,0,0,0.35);
  text-shadow: 0 1px 0 rgba(255,255,255,0.35);
}
.btn-primary:active { box-shadow: 0 1px 0 #7d5a17, 0 2px 6px rgba(0,0,0,0.3); }

.btn-ghost {
  background: rgba(247,240,217,0.14);
  color: var(--ivory);
  box-shadow: inset 0 0 0 1px rgba(247,240,217,0.4);
}
.btn-ghost:disabled { opacity: 0.45; cursor: default; }

.btn-big { width: 100%; padding: 18px; font-size: 1.15rem; margin-top: 14px; }
.btn-add { width: 46px; height: 46px; padding: 0; font-size: 1.6rem; border-radius: 50%; }

/* ---------- Chalkboard ---------- */
.chalkboard {
  position: relative;
  background:
    radial-gradient(ellipse at 30% 25%, rgba(255,255,255,0.06), transparent 55%),
    repeating-linear-gradient(0deg, rgba(255,255,255,0.02) 0 1px, transparent 1px 5px),
    linear-gradient(180deg, var(--chalk-green), var(--chalk-green-deep));
  border-radius: 10px;
  box-shadow:
    inset 0 0 40px rgba(0,0,0,0.55),
    inset 0 0 6px rgba(0,0,0,0.5),
    0 5px 0 #23412f,
    0 10px 16px rgba(0,0,0,0.4);
  padding: 26px 18px;
  margin: 6px 4px 8px;
  min-height: 150px;
  overflow: hidden;
}

.board-content { position: relative; z-index: 2; display: flex; flex-direction: column; gap: 20px; }

.counter, .stat {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  text-align: center;
}

.counter-num, .stat-num {
  font-family: "Marker Felt", "Comic Sans MS", "Segoe Print", cursive;
  color: var(--chalk);
  font-size: 2.6rem;
  line-height: 1;
  text-shadow: 0 0 6px rgba(255,255,255,0.25), 0 2px 0 rgba(0,0,0,0.4);
}

.counter-label, .stat-label {
  color: rgba(243,239,226,0.9);
  font-size: 0.72rem;
  letter-spacing: 1.2px;
  text-transform: uppercase;
}

.tally {
  font-size: 2rem;
  line-height: 1;
  color: var(--chalk);
  letter-spacing: 0.2em;
  text-shadow: 0 0 6px rgba(255,255,255,0.25), 0 2px 0 rgba(0,0,0,0.4);
  min-height: 2.2rem;
}

.stats-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px 8px; }
.stat-num { font-size: 2rem; }

/* chalkboard smudge pseudo-graffiti */
.chalk-smudge { position: absolute; border-radius: 50%; z-index: 1; opacity: 0.35; }
.smudge-a { width: 120px; height: 70px; top: -20px; right: -20px;
  background: radial-gradient(circle, rgba(0,0,0,0.35), transparent 70%); filter: blur(6px); }
.smudge-b { width: 90px; height: 90px; bottom: 10px; left: -30px;
  background: radial-gradient(circle, rgba(243,239,226,0.25), transparent 70%); filter: blur(9px); }
.smudge-c { width: 50px; height: 50px; top: 30%; left: 20%;
  background: radial-gradient(circle, rgba(0,0,0,0.3), transparent 70%); filter: blur(4px); }

.chalk-edge { position: absolute; inset: 0; border-radius: 10px;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.08); pointer-events: none; }

/* ---------- Manuscript list & cards ---------- */
.manuscript-list { display: flex; flex-direction: column; gap: 16px; }

.rehearsal-card {
  position: relative;
  background:
    repeating-linear-gradient(
      0deg,
      transparent 0 26px,
      rgba(43,62,80,0.30) 26px 27px,
      transparent 27px 54px,
      rgba(43,62,80,0.30) 54px 55px,
      transparent 55px 56px
    ),
    linear-gradient(180deg, var(--ivory), #efe6c8);
  background-color: var(--ivory);
  border-radius: 6px;
  padding: 18px 16px 40px;
  box-shadow: 0 4px 0 #c8b98d, 0 8px 14px rgba(0,0,0,0.28);
  touch-action: pan-y;
  overflow: hidden;
  cursor: pointer;
}

.rehearsal-card.aged {
  background:
    repeating-linear-gradient(
      0deg,
      transparent 0 26px,
      rgba(43,62,80,0.22) 26px 27px,
      transparent 27px 54px,
      rgba(43,62,80,0.22) 54px 55px,
      transparent 55px 56px
    ),
    linear-gradient(180deg, var(--ivory-old), #e4d39c);
  background-color: var(--ivory-old);
  box-shadow: 0 4px 0 #b7a269, 0 8px 14px rgba(0,0,0,0.28);
}

/* curled bottom-right corner for aged cards */
.rehearsal-card.aged::after {
  content: "";
  position: absolute;
  right: 0; bottom: 0;
  width: 26px; height: 26px;
  background: linear-gradient(135deg, rgba(0,0,0,0.16), transparent 55%),
              linear-gradient(225deg, #dcc98c, #c9b06c);
  border-radius: 0 0 0 10px;
  box-shadow: -2px -2px 4px rgba(0,0,0,0.12);
}

/* spring clip pin */
.pin {
  position: absolute;
  top: -6px; left: 50%;
  transform: translateX(-50%);
  width: 34px; height: 18px;
  background: linear-gradient(180deg, #cfcfcf, #9a9a9a);
  border-radius: 4px 4px 3px 3px;
  box-shadow: 0 2px 2px rgba(0,0,0,0.3);
  z-index: 2;
}
.pin::after {
  content: "";
  position: absolute; top: 5px; left: 8px; right: 8px; height: 3px;
  background: linear-gradient(180deg, #b9b9b9, #6d6d6d);
  border-radius: 2px;
}

.card-row {
  position: relative; z-index: 1;
  display: flex; justify-content: space-between; align-items: flex-start; gap: 10px;
}

.card-piece {
  font-family: "Segoe Print", "Bradley Hand", "Comic Sans MS", cursive;
  font-size: 1.25rem;
  color: var(--ink);
  line-height: 1.2;
  word-break: break-word;
}

.card-tempo {
  font-family: "Segoe Print", "Bradley Hand", "Comic Sans MS", cursive;
  color: #5a3f2e;
  font-size: 0.95rem;
  white-space: nowrap;
  margin-top: 2px;
}

.card-meta {
  position: relative; z-index: 1;
  display: flex; justify-content: space-between; align-items: center;
  margin-top: 14px;
  font-size: 0.8rem;
  color: #6b5a3d;
}
.card-date { font-family: inherit; }
.card-instrument { font-style: italic; }

/* swipe reveal action layer */
.rehearsal-card { display: block; }

.card-swipe {
  position: absolute; inset: 0;
  background: linear-gradient(90deg, transparent, #b6492c 68%);
  color: #fff;
  display: flex; align-items: center; justify-content: flex-end;
  padding-right: 20px;
  font-weight: 700;
  border-radius: 6px;
  transform: translateX(100%);
  transition: transform 0.2s ease;
  pointer-events: none;
}
.card-swipe .swipe-hint { font-size: 0.8rem; letter-spacing: 1px; }

.card-btns {
  position: relative; z-index: 1;
  display: flex; gap: 10px; margin-top: 10px;
}
.card-btns .btn { padding: 9px 14px; font-size: 0.85rem; }

/* ---------- Empty states ---------- */
.empty-note {
  text-align: center;
  font-family: "Segoe Print", "Bradley Hand", "Comic Sans MS", cursive;
  font-size: 1.05rem;
  padding: 26px 12px;
  border-radius: 10px;
  margin-top: 8px;
}
.chalk-empty { color: rgba(247,240,217,0.55); }
.manuscript-empty {
  background: rgba(247,240,217,0.9);
  color: #6b5a3d;
  box-shadow: 0 4px 0 #c8b98d;
}

/* ---------- Search ---------- */
.search-wrap { margin: 2px 0 14px; }
.search {
  width: 100%;
  padding: 14px 16px;
  font-size: 1rem;
  border: none;
  border-radius: 12px;
  background: rgba(247,240,217,0.95);
  color: var(--ink);
  box-shadow: inset 0 0 0 2px rgba(196,149,58,0.4), 0 2px 0 rgba(0,0,0,0.3);
}
.search::placeholder { color: #9b8a6a; }
.search:focus { outline: none; box-shadow: inset 0 0 0 2px var(--accent), 0 2px 0 rgba(0,0,0,0.3); }

/* ---------- Forms ---------- */
.edit-panel, .timer-save-wrap {
  background: rgba(247,240,217,0.95);
  border-radius: var(--panel-radius);
  padding: 18px;
  box-shadow: 0 4px 0 #c8b98d, 0 8px 14px rgba(0,0,0,0.28);
  margin-top: 18px;
}
.edit-panel h3, .timer-save-wrap h3 {
  font-family: "Segoe Print", "Bradley Hand", "Comic Sans MS", cursive;
  color: var(--ink);
  margin-bottom: 12px;
}

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field > span { font-size: 0.82rem; font-weight: 600; color: #5a4a30; }
.field > span em { font-weight: 400; color: #8a7957; }
.field input {
  padding: 13px 12px;
  font-size: 1rem;
  border-radius: 10px;
  border: 1px solid #cdbd92;
  background: #fffdf5;
  color: var(--ink);
}
.field input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 2px rgba(196,149,58,0.35); }

.err { color: #b6492c; font-size: 0.78rem; min-height: 0.9em; font-weight: 600; }

.form-actions { display: flex; gap: 10px; margin-top: 6px; }
.form-actions .btn { flex: 1; }

/* ---------- Timer ---------- */
.timer-stage { text-align: center; padding-top: 8px; }

.stopwatch {
  position: relative;
  width: 180px; height: 180px;
  margin: 0 auto 16px;
  border-radius: 50%;
  background:
    radial-gradient(circle at 50% 38%, #fff 0 2%, transparent 2.5%),
    radial-gradient(circle at 50% 50%, #ffffff 0%, #e7e2d4 60%, #cfc7b2 100%);
  box-shadow:
    inset 0 -6px 12px rgba(0,0,0,0.18),
    inset 0 6px 10px rgba(255,255,255,0.9),
    0 6px 0 #a9a191,
    0 12px 20px rgba(0,0,0,0.35);
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
}
.stopwatch::before { /* hour ticks */
  content: ""; position: absolute; inset: 8px;
  border-radius: 50%;
  background: repeating-conic-gradient(from 0deg, rgba(120,120,120,0.5) 0 1deg, transparent 1deg 6deg);
  opacity: 0.5;
}
.watch-face {
  position: relative; z-index: 2;
  width: 140px; height: 140px;
  border-radius: 50%;
  background: #fbfaf4;
  box-shadow: inset 0 2px 6px rgba(0,0,0,0.15);
  display: flex; align-items: center; justify-content: center;
  font-family: "Menlo", "SF Mono", Consolas, monospace;
  font-size: 1.9rem;
  color: var(--ink);
}
.watch-crown {
  position: absolute; top: -6px; right: -10px;
  width: 30px; height: 20px;
  background: linear-gradient(180deg, #b9a985, #8d7c58);
  border-radius: 4px 4px 8px 8px;
  transform: rotate(-12deg);
}
.watch-crown::after {
  content: ""; position: absolute; top: -8px; left: 6px;
  width: 18px; height: 10px;
  background: #b9a985; border-radius: 3px;
}

.timer-idle { color: rgba(247,240,217,0.7); font-size: 0.85rem; margin-bottom: 4px; }
.timer-controls { display: flex; gap: 12px; justify-content: center; }
.timer-controls .btn { flex: 1; max-width: 160px; margin-top: 10px; }

.timer-save-form { margin-top: 10px; }
.timer-save-form .btn { margin-top: 4px; }

/* ---------- Bottom tab bar ---------- */
.tabbar {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: 0;
  width: 100%;
  max-width: 560px;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  display: flex;
  background: linear-gradient(180deg, #2c2323, #1c1616);
  border-top: 3px solid #17100f;
  box-shadow: 0 -6px 14px rgba(0,0,0,0.5);
  z-index: 50;
}

.tab-btn {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  border: none; background: none; cursor: pointer;
  color: #a89a82;   /* desaturated inactive */
  padding: 0;
  font-family: inherit;
  transition: color 0.15s ease, transform 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}

.tab-icon {
  display: block;
  width: 26px; height: 26px;
  filter: grayscale(1) brightness(0.9);
  transform: rotate(0deg);
  transition: transform 0.2s ease, filter 0.2s ease, filter 0.2s ease;
  transform-origin: bottom center;
  will-change: transform;
}

.tab-label { font-size: 0.66rem; letter-spacing: 0.4px; font-weight: 600; }

.tab-btn.active {
  color: var(--accent);
}
.tab-btn.active .tab-icon {
  filter: grayscale(0) brightness(1.15) drop-shadow(0 0 6px rgba(196,149,58,0.8));
  transform: rotate(-12deg) translateY(-3px);
}
.tab-btn.active .tab-label {
  text-shadow: 0 0 8px rgba(196,149,58,0.6);
}

/* inline SVG icons */
.tab-icon svg {
  width: 100%; height: 100%;
  display: block;
  fill: currentColor;
}

/* ---------- Responsive / spacing tweaks ---------- */
@media (max-width: 380px) {
  .counter-num { font-size: 2.2rem; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
}