/* ─── Reset ─────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ─── Base layout ────────────────────────────────────────── */
html, body {
  min-height: 100%;
}

body {
  background-image: url('/garden-assets/green-bg.jpg');
  background-attachment: fixed;
  background-position: center;
  background-repeat: repeat;
  font-family: Georgia, 'Times New Roman', serif;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  padding: 1.5rem 1rem;
  position: relative;
}

/* ─── Decorative background ──────────────────────────────── */
.bg-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
}

.leaf-svg {
  position: absolute;
  opacity: 0.12;
  animation: leafSway ease-in-out infinite alternate;
  transform-origin: 50% 100%;
}

@keyframes leafSway {
  from { transform: rotate(var(--r0)); }
  to   { transform: rotate(var(--r1)); }
}

.firefly {
  position: absolute;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: #bfffb0;
  box-shadow: 0 0 8px 3px #9eff80;
  animation: fireflyFloat ease-in-out infinite alternate;
}

@keyframes fireflyFloat {
  from { transform: translate(0, 0); opacity: 0.2; }
  to   { transform: translate(var(--fx), var(--fy)); opacity: 0.9; }
}

/* ─── Main page ──────────────────────────────────────────── */
.page {
  position: relative;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  width: 100%;
  max-width: 900px;
  padding: 0.5rem 0.5rem 1.5rem;
}

/* ─── Title ──────────────────────────────────────────────── */
h1 {
  text-align: center;
  margin-top:30px;
  margin-bottom:-30px;
}

h1 img {
  width: 100%;
  max-width: 590px;
  height: auto;
}

/* ─── Status image banner ────────────────────────────────── */
.status-img {
  width: 100%;
    max-width: 440px;
  height: auto;
  display: block;
}

/* ─── Status bar (screen-reader only) ───────────────────── */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.status-bar {
  display: flex;
  align-items: center;
  gap: 0.55rem;
}

.status-dot {
  flex-shrink: 0;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #4ade80;
  transition: background 0.3s;
}

.status-dot.playing    { background: #fbbf24; animation: dotPulse 1s ease-in-out infinite; }
.status-dot.recording  { background: #f87171; animation: dotPulse 0.55s ease-in-out infinite; }
.status-dot.uploading  { background: #60a5fa; animation: dotPulse 1.2s ease-in-out infinite; }
.status-dot.error      { background: #f87171; }

@keyframes dotPulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%       { opacity: 0.4; transform: scale(0.65); }
}

#statusText { flex: 1; }

/* Recording wave bars */
.waves {
  display: none;
  align-items: flex-end;
  gap: 2px;
  height: 18px;
  flex-shrink: 0;
}
.waves.visible { display: flex; }

.wave-bar {
  width: 3px;
  background: #f87171;
  border-radius: 2px;
  animation: waveAnim 0.7s ease-in-out infinite alternate;
}
.wave-bar:nth-child(1) { animation-delay: 0s;   }
.wave-bar:nth-child(2) { animation-delay: 0.1s; }
.wave-bar:nth-child(3) { animation-delay: 0.2s; }
.wave-bar:nth-child(4) { animation-delay: 0.1s; }
.wave-bar:nth-child(5) { animation-delay: 0s;   }

@keyframes waveAnim {
  from { height: 3px; }
  to   { height: 16px; }
}

/* Recording timer */
#recTimer {
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
  font-size: 0.8rem;
  display: none;
}
#recTimer.visible   { display: block; }
#recTimer.recording { color: rgba(220, 38, 38, 0.9); }
#recTimer.playing   { color: rgba(160, 110, 10, 0.9); }

/* ─── Character grid ──────────────────────────────────────── */
.char-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.4rem;
  width: 100%;
  align-items: start;
}

/* Each cell is a flex column so the record button slots in directly
   below the portrait without any gap fiddling */
.char-col {
  display: flex;
  flex-direction: column;
}

/* Record button when moved inside a char-col: match column width */
.char-col .record-btn {
  width: 100%;
  max-width: none;
  margin-top: 0.3rem;
}

/* ─── Character buttons ───────────────────────────────────── */
.char-btn {
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  display: block;
  border-radius: 6px;
  transition:
    transform 0.15s cubic-bezier(.34, 1.56, .64, 1),
    filter 0.15s;
}

/* Fade non-active columns (portrait + button slot) when one is selected */
.char-grid:has(.char-btn.active) .char-col:not(:has(.char-btn.active)) {
  opacity: 0.6;
}

.char-btn img {
  width: 100%;
  height: auto;
  display: block;
}

.char-btn:hover:not(:disabled) {
  transform: scale(1.06);
  filter: brightness(1.08) drop-shadow(0 4px 14px rgba(0, 0, 0, 0.45));
}

.char-btn:active:not(:disabled) {
  transform: scale(0.97);
}

.char-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.char-btn.active, .char-btn.active:hover {
  filter: drop-shadow(0 0 12px rgba(255, 210, 80, 0.9)) brightness(1.1);
  transform: scale(1.04);
}

/* ─── Record / Stop button ────────────────────────────────── */
.record-btn {
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  max-width: 320px;
  width: 80%;
  display: block;
  transition:
    transform 0.14s cubic-bezier(.34, 1.56, .64, 1),
    filter 0.15s,
    opacity 0.2s;
}

.record-btn img {
  width: 100%;
  height: auto;
  display: block;
}

.record-btn:hover:not(:disabled) {
  transform: translateY(-3px) scale(1.02);
  filter: brightness(1.06);
}

.record-btn:active:not(:disabled) {
  transform: translateY(0) scale(0.99);
}

.record-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ─── Upload toast notifications ────────────────────────── */
.uploads-list {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 150;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-width: 300px;
  width: calc(100vw - 3rem);
  pointer-events: none;
}

.upload-item {
  background: rgba(10, 30, 16, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 12px;
  padding: 0.6rem 1rem;
  font-size: 0.8rem;
  color: #d4edda;
  display: flex;
  align-items: center;
  gap: 0.55rem;
  animation: toastIn 0.25s cubic-bezier(.34, 1.56, .64, 1);
  transition: border-color 0.3s;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
  pointer-events: auto;
}

@keyframes toastIn {
  from { opacity: 0; transform: translateX(20px) scale(0.95); }
  to   { opacity: 1; transform: translateX(0)    scale(1); }
}

.upload-item .up-status { font-size: 0.82rem; }

.upload-item.uploading { border-color: rgba(96, 165, 250, 0.35); }
.upload-item.done      { border-color: rgba(74, 222, 128, 0.35); }
.upload-item.error     { border-color: rgba(248, 113, 113, 0.35); }

/* ─── Permission overlay ─────────────────────────────────── */
#permOverlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background: rgba(4, 10, 6, 0.88);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

.perm-allow-btn {
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  max-width: 510px;
  width: 90%;
  display: block;
  transition: filter 0.15s, transform 0.14s cubic-bezier(.34, 1.56, .64, 1);
}

.perm-allow-btn img {
  width: 100%;
  height: auto;
  display: block;
}


/* Screen-reader only — visual state is shown via the banner image */
.perm-denied {
  display: none;
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

/* ─── Responsive ──────────────────────────────────────────── */
@media (max-width: 560px) {
  .char-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

img { max-width: 100%; }
