:root {
  --bg: #fdeef8;
  --surface: #ffffff;
  --surface-soft: rgba(255, 255, 255, 0.82);
  --border: #f3d4ea;
  --primary: #b25fd3;
  --primary-hover: #9a45bd;
  --accent: #ff90c2;
  --danger: #e85a8a;
  --danger-hover: #d23f73;
  --text: #43273f;
  --muted: #9a7fa6;
  --radius: 8px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  min-height: 100vh;
  font-size: 15px;
  background:
    radial-gradient(1200px 600px at 50% -10%, #fff0f9 0%, rgba(255,240,249,0) 60%),
    linear-gradient(180deg, #f6e8fb 0%, #fce3f1 55%, #ffd9ec 100%);
  background-attachment: fixed;
}

/* Ghibli-style floral scene, fixed behind all content */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  background: url("/static/flowers.svg") center bottom / cover no-repeat;
  opacity: .9;
  pointer-events: none;
  z-index: 0;
}

nav, main { position: relative; z-index: 1; }

/* ── nav ── */
nav {
  background: linear-gradient(90deg, #c86fd6 0%, #ff8fc2 100%);
  padding: 0 1.5rem;
  height: 52px;
  display: flex;
  align-items: center;
  box-shadow: 0 2px 10px rgba(178,95,211,.35);
}
.brand {
  color: #fff;
  text-decoration: none;
  font-weight: 700;
  font-size: 1.15rem;
  letter-spacing: -.3px;
  flex: 1;
}
.nav-logout button {
  background: none;
  border: 1px solid rgba(255,255,255,.5);
  border-radius: var(--radius);
  color: #fff;
  font-size: .82rem;
  font-family: inherit;
  padding: .3rem .8rem;
  cursor: pointer;
  transition: background .15s;
}
.nav-logout button:hover { background: rgba(255,255,255,.15); }

/* ── login ── */
.login-wrap {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: calc(100vh - 52px);
}
.login-box {
  background: var(--surface-soft);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 2rem 2.5rem;
  width: 100%;
  max-width: 340px;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  box-shadow: 0 8px 28px rgba(178,95,211,.22);
}
.login-box h1 { font-size: 1.3rem; text-align: center; }
.login-label { font-size: .8rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.login-box input[type="password"] {
  padding: .5rem .75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 1rem;
  font-family: inherit;
  width: 100%;
}
.login-box input[type="password"]:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(178,95,211,.20);
}
.login-box .btn { width: 100%; justify-content: center; text-align: center; padding: .6rem; }
.login-error { color: var(--danger); font-size: .88rem; text-align: center; }

main {
  max-width: 860px;
  margin: 2rem auto;
  padding: 0 1rem;
}

/* ── buttons ── */
.btn {
  display: inline-block;
  padding: .45rem 1.05rem;
  background: linear-gradient(135deg, #b25fd3 0%, #ff8fc2 100%);
  color: #fff;
  border: none;
  border-radius: 999px;
  cursor: pointer;
  font-size: .9rem;
  font-family: inherit;
  text-decoration: none;
  white-space: nowrap;
  box-shadow: 0 2px 8px rgba(178,95,211,.3);
  transition: filter .15s, transform .15s, box-shadow .15s;
}
.btn:hover { filter: brightness(1.06); transform: translateY(-1px); box-shadow: 0 4px 12px rgba(178,95,211,.4); }
.btn-sm { padding: .3rem .8rem; font-size: .82rem; }
.btn-danger { background: linear-gradient(135deg, #e85a8a 0%, #ff9ab0 100%); box-shadow: 0 2px 8px rgba(232,90,138,.3); }
.btn-danger:hover { filter: brightness(1.05); }

/* ── page header ── */
.page-header {
  display: flex;
  align-items: center;
  gap: .75rem;
  margin-bottom: 1.75rem;
  flex-wrap: wrap;
}
.page-header h1 { font-size: 1.4rem; }
.back { color: var(--primary); text-decoration: none; font-size: .9rem; }
.back:hover { text-decoration: underline; }
.section-title { font-size: 1rem; margin-bottom: .75rem; color: var(--muted); font-weight: 600; }

/* ── inline form (header) ── */
.inline-form { display: flex; gap: .5rem; align-items: center; }
.inline-form input,
.title-form input {
  padding: .4rem .75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: .9rem;
  font-family: inherit;
  background: var(--surface);
}
.title-form input { min-width: 200px; font-size: 1rem; }

/* ── set grid ── */
.set-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 1rem;
}
.set-card {
  background: var(--surface-soft);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 1rem 1.1rem;
  display: flex;
  flex-direction: column;
  gap: .65rem;
  box-shadow: 0 4px 16px rgba(178,95,211,.14);
}
.set-card h2 { font-size: .98rem; }
.set-card h2 a { color: var(--text); text-decoration: none; }
.set-card h2 a:hover { color: var(--primary); }
.card-count { font-size: .8rem; color: var(--muted); }
.set-card-actions { display: flex; gap: .5rem; }

.empty-state { color: var(--muted); font-style: italic; margin-top: .5rem; }
.empty-state a { color: var(--primary); }

/* ── card edit blocks ── */
.card-edit-block {
  background: var(--surface-soft);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 1rem 1.25rem 1rem;
  margin-bottom: .85rem;
  box-shadow: 0 4px 16px rgba(178,95,211,.12);
  position: relative;
}
.card-edit-block.new-card { border-color: var(--primary); border-style: dashed; }

.card-num {
  font-size: .75rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .06em;
  margin-bottom: .6rem;
}
.new-label { color: var(--primary); }

.card-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-bottom: .75rem;
}
@media (max-width: 560px) {
  .card-row { grid-template-columns: 1fr; }
}

.field > label:first-child {
  display: block;
  font-size: .75rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .06em;
  margin-bottom: .35rem;
}
.field textarea {
  width: 100%;
  padding: .45rem .65rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: .9rem;
  font-family: inherit;
  resize: vertical;
  background: var(--surface);
}
.field textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(178,95,211,.20);
}

.radio-group {
  display: flex;
  gap: 1rem;
  margin-bottom: .5rem;
  font-size: .88rem;
}
.radio-group label { display: flex; align-items: center; gap: .3rem; cursor: pointer; }

.card-actions { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }

.thumb {
  display: block;
  max-width: 140px;
  max-height: 90px;
  border-radius: 5px;
  margin-bottom: .4rem;
  object-fit: contain;
  border: 1px solid var(--border);
}
.remove-label { font-size: .82rem; display: flex; align-items: center; gap: .3rem; margin-bottom: .4rem; cursor: pointer; }

/* ── study mode ── */
.study-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.5rem;
  margin-top: 1.5rem;
}

.flashcard {
  width: 100%;
  max-width: 640px;
  height: 300px;
  perspective: 1200px;
  cursor: pointer;
  user-select: none;
}
.fc-inner {
  width: 100%;
  height: 100%;
  position: relative;
  transform-style: preserve-3d;
  transition: transform .45s cubic-bezier(.4,0,.2,1);
}
.fc-inner.flipped { transform: rotateY(180deg); }

.fc-front, .fc-back {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  background: rgba(255,255,255,.92);
  border: 2px solid var(--border);
  border-radius: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  font-size: 1.35rem;
  text-align: center;
  overflow: auto;
  box-shadow: 0 8px 28px rgba(178,95,211,.18);
}
.fc-back {
  transform: rotateY(180deg);
  background: linear-gradient(160deg, #fdeaf6 0%, #f3e3fb 100%);
  border-color: var(--primary);
}
.fc-img {
  max-width: 100%;
  max-height: 220px;
  object-fit: contain;
  border-radius: 6px;
}

.study-nav {
  display: flex;
  gap: 1.5rem;
  align-items: center;
  font-size: .95rem;
}
.study-nav button {
  padding: .5rem 1.3rem;
  background: linear-gradient(135deg, #b25fd3 0%, #ff8fc2 100%);
  color: #fff;
  border: none;
  border-radius: 999px;
  cursor: pointer;
  font-size: .9rem;
  font-family: inherit;
  box-shadow: 0 2px 8px rgba(178,95,211,.3);
  transition: filter .15s, box-shadow .15s;
}
.study-nav button:hover:not(:disabled) { filter: brightness(1.06); }
.study-nav button:disabled { background: #e8d6ec; color: var(--muted); cursor: default; box-shadow: none; }
#counter { min-width: 60px; text-align: center; color: var(--muted); }

.flip-hint { color: var(--muted); font-size: .8rem; }

.toggle-side {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .35rem .9rem;
  font-size: .82rem;
  font-family: inherit;
  color: var(--muted);
  cursor: pointer;
  transition: border-color .15s, color .15s;
  white-space: nowrap;
}
.toggle-side:hover { border-color: var(--primary); color: var(--primary); }
.toggle-side[data-state="1"] { border-color: var(--primary); color: var(--primary); }

/* ── guess mode ── */
.guess-card {
  width: 100%;
  max-width: 640px;
  min-height: 200px;
  background: rgba(255,255,255,.9);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  border: 2px solid var(--border);
  border-radius: 18px;
  box-shadow: 0 8px 28px rgba(178,95,211,.18);
  padding: 1.5rem 2rem 2rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
}
.guess-prompt-label {
  font-size: .75rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .06em;
}
.guess-prompt {
  font-size: 1.35rem;
  text-align: center;
  word-break: break-word;
}

.guess-form {
  display: flex;
  gap: .5rem;
  width: 100%;
  max-width: 640px;
}
.guess-form input {
  flex: 1;
  padding: .6rem .85rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 1rem;
  font-family: inherit;
  background: var(--surface);
}
.guess-form input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(178,95,211,.20);
}
.guess-form input:disabled { background: #f3f4f6; color: var(--muted); }

.guess-feedback {
  min-height: 1.4rem;
  font-size: 1.05rem;
  font-weight: 600;
  text-align: center;
}
.guess-feedback.correct { color: #1e7e34; }
.guess-feedback.incorrect { color: var(--danger); }
.guess-feedback .match { font-weight: 400; font-size: .85rem; color: var(--muted); }
.guess-feedback .real-answer {
  margin-top: .5rem;
  font-weight: 400;
  font-size: .95rem;
  color: var(--text);
}
.guess-feedback .real-answer strong { color: var(--primary); }

/* ── drifting petals ── */
.petals {
  position: fixed;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: 0;
}
.petal {
  position: absolute;
  top: -6%;
  width: 16px;
  height: 16px;
  background:
    radial-gradient(circle at 50% 30%, #ffd6ec 0%, #ff9ec9 70%, #ff86bd 100%);
  border-radius: 80% 0 80% 0;
  opacity: .65;
  animation: petal-fall linear infinite;
}
.petal:nth-child(1) { left: 8%;  width: 14px; height: 14px; animation-duration: 17s; animation-delay: 0s;   }
.petal:nth-child(2) { left: 22%; width: 18px; height: 18px; animation-duration: 22s; animation-delay: -4s;
  background: radial-gradient(circle at 50% 30%, #f0dcfb 0%, #cfa8ef 70%, #b27fe0 100%); }
.petal:nth-child(3) { left: 37%; width: 12px; height: 12px; animation-duration: 19s; animation-delay: -9s;  }
.petal:nth-child(4) { left: 51%; width: 20px; height: 20px; animation-duration: 25s; animation-delay: -2s;
  background: radial-gradient(circle at 50% 30%, #f0dcfb 0%, #cfa8ef 70%, #b27fe0 100%); }
.petal:nth-child(5) { left: 64%; width: 14px; height: 14px; animation-duration: 20s; animation-delay: -13s; }
.petal:nth-child(6) { left: 76%; width: 17px; height: 17px; animation-duration: 23s; animation-delay: -6s;  }
.petal:nth-child(7) { left: 88%; width: 12px; height: 12px; animation-duration: 18s; animation-delay: -11s;
  background: radial-gradient(circle at 50% 30%, #f0dcfb 0%, #cfa8ef 70%, #b27fe0 100%); }
.petal:nth-child(8) { left: 95%; width: 15px; height: 15px; animation-duration: 21s; animation-delay: -16s; }

@keyframes petal-fall {
  0%   { transform: translateY(-10vh) translateX(0)     rotate(0deg);   opacity: 0; }
  10%  { opacity: .65; }
  50%  { transform: translateY(50vh)  translateX(40px)  rotate(180deg); }
  90%  { opacity: .65; }
  100% { transform: translateY(110vh) translateX(-30px) rotate(360deg); opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .petal { animation: none; display: none; }
}

/* ── bigger images on desktop browsers; phones keep the original size ── */
/* These flashcard images are small originals, so max-height can't enlarge them —
   we upscale by 1.5× (slight quality loss is expected). */
@media (min-width: 768px) {
  .flashcard { max-width: 820px; height: 430px; }   /* room for the scaled image */
  .guess-card, .guess-form { max-width: 820px; }
  .fc-img { transform: scale(1.5); transform-origin: center; }
  .guess-prompt { margin-block: 3rem; }             /* reserve space for the scaled image */
}

/* ── sad-cat anti-procrastination overlay (Study & Guess) ── */
.idle-cat {
  position: fixed;
  left: 50%;
  top: 50%;
  width: 160px;
  z-index: 50;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transition: left 4s ease-in-out, top 4s ease-in-out, opacity .6s ease;
}
.idle-cat.visible { opacity: 1; visibility: visible; }

.idle-cat-inner {
  animation: cat-bob 3s ease-in-out infinite;
  transition: filter .8s ease;
}
.idle-cat-inner svg {
  width: 160px;
  height: auto;
  display: block;
  filter: drop-shadow(0 8px 12px rgba(120,80,140,.28));
}
@keyframes cat-bob {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-12px); }
}

.idle-cat-bubble {
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  margin-bottom: 10px;
  white-space: nowrap;
  background: #fff;
  border: 2px solid var(--primary);
  color: var(--text);
  padding: .4rem .85rem;
  border-radius: 16px;
  font-size: .9rem;
  font-weight: 600;
  box-shadow: 0 4px 14px rgba(178,95,211,.28);
}
.idle-cat-bubble::after {
  content: "";
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 7px solid transparent;
  border-top-color: var(--primary);
}

/* sadness escalation hooks */
.idle-cat-svg #mouth,
.idle-cat-svg #brow-l,
.idle-cat-svg #brow-r {
  transform-box: fill-box;
  transform-origin: center;
  transition: transform .6s ease;
}
.idle-cat-svg .tear { display: none; }
.idle-cat-svg .tear path {
  transform-box: fill-box;
  transform-origin: center top;
  animation: tear-drip 1.8s ease-in infinite;
}
@keyframes tear-drip {
  0%   { opacity: 0; transform: translateY(-2px); }
  25%  { opacity: 1; }
  100% { opacity: .15; transform: translateY(14px); }
}

@media (max-width: 560px) {
  .idle-cat { width: 120px; }
  .idle-cat-inner svg { width: 120px; }
}
@media (prefers-reduced-motion: reduce) {
  .idle-cat-inner, .idle-cat-svg .tear path { animation: none; }
  .idle-cat { transition: opacity .6s ease; }
}
