:root {
  --bg: #1a1a2e;
  --card: #16213e;
  --text: #f8f9fa;
  --muted: #a8b0c0;
  --accent: #ffc857;
  --accent-2: #ff6b6b;
  --ok: #4ecdc4;
  --btn: #ffc857;
  --btn-text: #1a1a2e;
  --danger: #ff6b6b;
  --radius: 20px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans TC", sans-serif;
  user-select: none;
}

body { min-height: 100dvh; }

#app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: 12px 16px calc(16px + var(--safe-bottom));
}

.top { text-align: center; padding: 8px 0 12px; }
.top h1 { margin: 0; font-size: 1.6rem; letter-spacing: 0.02em; }
.sub { margin: 6px 0 0; color: var(--muted); font-size: 0.95rem; }

.screen { flex: 1; display: flex; flex-direction: column; gap: 14px; }

.foot { text-align: center; color: var(--muted); font-size: 0.75rem; padding-top: 10px; }

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.25);
}

/* ─── Preview ─── */
.preview-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 3 / 4;
  border-radius: 16px;
  overflow: hidden;
  background: #0b1020;
  display: flex;
  align-items: center;
  justify-content: center;
}

.preview-wrap img,
.preview-wrap video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.placeholder { color: var(--muted); text-align: center; padding: 20px; font-size: 1.1rem; line-height: 1.5; }
.hint { text-align: center; font-size: 1.15rem; margin: 0; }
.hint strong { color: var(--accent); }

/* ─── Vision Result ─── */
.vision-result {
  text-align: center;
  font-size: 1.05rem;
  color: var(--ok);
  margin: 10px 0 0;
  padding: 8px 12px;
  background: rgba(78, 205, 196, 0.1);
  border-radius: 12px;
}

.vision-tag {
  text-align: center;
  font-size: 0.9rem;
  color: var(--muted);
  margin: 8px 0 0;
}

/* ─── Buttons ─── */
.btn-col { display: flex; flex-direction: column; gap: 12px; }
.btn-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

button.big {
  appearance: none;
  border: none;
  border-radius: 18px;
  min-height: 72px;
  padding: 16px 18px;
  font-size: 1.35rem;
  font-weight: 800;
  background: var(--btn);
  color: var(--btn-text);
  cursor: pointer;
  box-shadow: 0 6px 0 rgba(0,0,0,0.2);
  transition: transform 0.05s ease, filter 0.15s ease;
}

button.big:active { transform: translateY(3px); box-shadow: 0 2px 0 rgba(0,0,0,0.2); }
button.big:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }
button.big.secondary { background: #3a4a6b; color: var(--text); }
button.big.ok { background: var(--ok); color: #08332f; }
button.big.danger { background: var(--danger); color: #fff; }
button.big.recording { background: #ff3b3b; color: #fff; animation: pulse 1s infinite; }

@keyframes pulse {
  0%, 100% { filter: brightness(1); }
  50% { filter: brightness(1.15); }
}

.timer { text-align: center; font-size: 2rem; font-weight: 800; color: var(--accent); min-height: 2.4rem; }

/* ─── Badge ─── */
.badge {
  display: inline-block;
  background: rgba(255,200,87,0.15);
  color: var(--accent);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 0.85rem;
}

/* ─── List / Items ─── */
.list { display: flex; flex-direction: column; gap: 6px; max-height: 42vh; overflow-y: auto; -webkit-overflow-scrolling: touch; }

.item {
  display: grid;
  grid-template-columns: 56px 1fr auto auto auto;
  gap: 8px;
  align-items: center;
  background: rgba(255,255,255,0.04);
  border-radius: 14px;
  padding: 8px 10px;
  border: none;
  color: inherit;
  text-align: left;
  width: 100%;
  cursor: pointer;
}

.item img { width: 56px; height: 56px; object-fit: cover; border-radius: 10px; background: #000; }
.item .meta { font-size: 0.85rem; color: var(--muted); }
.item .title { font-weight: 700; margin-bottom: 2px; }

.item-play {
  font-size: 1.3rem;
  cursor: pointer;
  padding: 6px;
  border-radius: 8px;
  transition: background 0.15s;
}

.item-play:active { background: rgba(255,200,87,0.2); }

.item-del {
  font-size: 1rem;
  cursor: pointer;
  padding: 6px;
  border-radius: 8px;
  opacity: 0.4;
  transition: opacity 0.15s;
  background: none;
  border: none;
  color: inherit;
  line-height: 1;
}

.item-del:active { opacity: 1; background: rgba(255, 107, 107, 0.2); }

/* ─── Celebrate ─── */
.celebrate { text-align: center; font-size: 1.6rem; font-weight: 800; color: var(--accent); animation: pop 0.45s ease; }

@keyframes pop {
  0% { transform: scale(0.8); opacity: 0; }
  60% { transform: scale(1.08); opacity: 1; }
  100% { transform: scale(1); }
}

/* ─── Toast ─── */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + var(--safe-bottom));
  transform: translateX(-50%);
  background: rgba(0,0,0,0.85);
  color: #fff;
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 0.95rem;
  z-index: 50;
  max-width: 90vw;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.toast.show { opacity: 1; }

/* ─── Wave ─── */
.wave {
  height: 8px;
  border-radius: 999px;
  background: linear-gradient(90deg, #ff6b6b, #ffc857, #4ecdc4, #ff6b6b);
  background-size: 200% 100%;
  animation: slide 1.2s linear infinite;
}

@keyframes slide {
  from { background-position: 0 0; }
  to { background-position: 200% 0; }
}

.tiny { font-size: 0.8rem; color: var(--muted); text-align: center; margin: 0; }

/* ═══════════════════════════════════════════════════
   MODE CARDS (Home Screen)
   ═══════════════════════════════════════════════════ */
.mode-cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.mode-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  background: var(--card);
  border: 2px solid transparent;
  border-radius: 16px;
  padding: 16px 8px;
  cursor: pointer;
  color: var(--text);
  transition: border-color 0.15s, transform 0.1s;
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}

.mode-card:active { border-color: var(--accent); transform: scale(0.97); }

.mode-emoji { font-size: 2rem; }
.mode-label { font-size: 1rem; font-weight: 700; }
.mode-desc { font-size: 0.7rem; color: var(--muted); text-align: center; }

/* ═══════════════════════════════════════════════════
   FLASHCARD MODE
   ═══════════════════════════════════════════════════ */
.flashcard-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px 16px;
  min-height: 200px;
}

.flashcard-emoji {
  font-size: 5rem;
  margin-bottom: 16px;
  animation: pop 0.5s ease;
}

.flashcard-prompt {
  font-size: 1.4rem;
  font-weight: 800;
  text-align: center;
  color: var(--accent);
  margin: 0;
}

.flashcard-stats {
  display: flex;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
  padding: 8px 0;
}

.stat-badge {
  display: inline-block;
  background: rgba(255,255,255,0.06);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 0.85rem;
}

.flashcard-progress {
  text-align: center;
  font-size: 0.85rem;
  color: var(--muted);
}

/* ═══════════════════════════════════════════════════
   DIARY VIEW
   ═══════════════════════════════════════════════════ */
.diary-day {
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}

.diary-day:last-child { border-bottom: none; margin-bottom: 0; }

.diary-date {
  font-size: 1.05rem;
  font-weight: 700;
  margin-bottom: 6px;
}

.diary-summary {
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 10px;
}

.diary-cats {
  color: var(--accent);
  font-weight: 600;
}

.diary-thumbs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  padding: 4px 0;
}

.diary-thumb {
  flex-shrink: 0;
  width: 72px;
  height: 72px;
  border-radius: 12px;
  overflow: hidden;
  border: 2px solid rgba(255,255,255,0.08);
  cursor: pointer;
  background: none;
  padding: 0;
  transition: border-color 0.15s;
}

.diary-thumb:active { border-color: var(--accent); }

.diary-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* ═══════════════════════════════════════════════════
   FAVOURITES / ITEM STAR
   ═══════════════════════════════════════════════════ */

.item-fav {
  font-size: 1.1rem;
  cursor: pointer;
  padding: 6px;
  border-radius: 8px;
  transition: transform 0.15s;
}

.item-fav:active { transform: scale(1.3); }

.fav-group { margin-bottom: 16px; }

.fav-group-title {
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: 8px;
  color: var(--accent);
}

.fav-cards {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.fav-card {
  display: grid;
  grid-template-columns: 64px 1fr auto;
  gap: 10px;
  align-items: center;
  background: rgba(255,255,255,0.04);
  border-radius: 12px;
  padding: 8px;
  cursor: pointer;
  transition: background 0.15s;
}

.fav-card:active { background: rgba(255,255,255,0.08); }

.fav-card img {
  width: 64px;
  height: 64px;
  object-fit: cover;
  border-radius: 10px;
}

.fav-card-name {
  font-weight: 700;
  font-size: 1rem;
}

.fav-card-sentence {
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 2px;
}
