@font-face {
  font-family: 'HoneyInk';
  src: url('honeyink-webfont-deseret.woff2') format('woff2'),
       url('honeyink-webfont-deseret.woff') format('woff');
  font-weight: normal;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: 'AdamicBee';
  src: url('AdamicBee3_0.ttf') format('truetype');
  font-weight: normal;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: 'Noto Sans Deseret';
  src: url('NotoSansDeseret-Regular.ttf') format('truetype');
  font-weight: normal;
  font-style: normal;
  font-display: swap;
}

:root {
  --bg-1: #7a9cb5;
  --bg-2: #d9a066;
  --card-bg: #faf3e6;
  --text: #4a3728;
  --muted: #8a7358;
  --good: #445631;
  --again: #b5562f;
  --accent: #b5562f;
  --on-gradient: #3b2a1a;

  --box-0: #c9b088;
  --box-1: #d9a066;
  --box-2: #c17a42;
  --box-3: #a8763a;
  --box-4: #8a9c5a;
  --box-5: #5c7a3e;
}

@media (prefers-color-scheme: dark) {
  :root {
    --card-bg-front: #453b2f;
    --card-bg: #272f1e;
    --text: #f0e6d2;
    --muted: #b8a888;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: "Special Elite", serif;
  font-weight: 400;
  font-style: normal;
  background: rgb(156, 144, 128);
  background-attachment: fixed;
  color: var(--text);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0 0 3rem;
}

.deseret {
  font-family: 'HoneyInk', 'AdamicBee', 'Noto Sans Deseret', sans-serif;
}

.app-header {
  width: 100%;
  max-width: 640px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  padding: 1.5rem 1rem 1rem;
  color: var(--on-gradient);
  text-align: center;
}

.app-header h1 {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 700;
}

.app-header h1 .deseret {
  font-size: 1.3rem;
  margin-right: 0.4rem;
}

button {
  font-family: inherit;
}

.tabs {
  display: flex;
  gap: 0.5rem;
  background: rgba(74,55,40,0.18);
  padding: 0.3rem;
  border-radius: 999px;
}

.tab-btn {
  border: none;
  background: transparent;
  color: var(--on-gradient);
  padding: 0.5rem 1.1rem;
  border-radius: 999px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s ease;
}

.tab-btn.active {
  background: #faf3e6;
  color: var(--accent);
}

main {
  width: 100%;
  max-width: 640px;
  padding: 0 1rem;
}

.view {
  display: none;
}
.view.active {
  display: block;
}

/* ---------- Study view ---------- */

.session-bar {
  display: flex;
  justify-content: space-between;
  color: var(--on-gradient);
  font-weight: 600;
  font-size: 0.9rem;
  margin-bottom: 0.75rem;
  padding: 0 0.25rem;
}

#card-stage {
  perspective: 1400px;
  width: 100%;
}

.flashcard {
  width: 100%;
  min-height: 260px;
  cursor: pointer;
}

.flashcard-inner {
  display: grid;
  width: 100%;
  transform-style: preserve-3d;
  transform: rotateY(0deg);
}

.flashcard.flipped .flashcard-inner {
  transform: rotateY(180deg);
}

.flashcard.flip-to-back .flashcard-inner {
  animation: flip-to-back 0.7s cubic-bezier(.45,.05,.3,1) forwards;
}

.flashcard.flip-to-front .flashcard-inner {
  animation: flip-to-front 0.7s cubic-bezier(.45,.05,.3,1) forwards;
}

.flashcard.flip-to-back .flashcard-face,
.flashcard.flip-to-front .flashcard-face {
  animation: page-shade 0.7s cubic-bezier(.45,.05,.3,1) forwards;
}

@keyframes flip-to-back {
  0%   { transform: rotateY(0deg)   rotateZ(0deg) translateY(0)     scale(1); }
  10%  { transform: rotateY(-6deg)  rotateZ(calc(var(--tilt, 0) * 0.3deg))  translateY(0)     scale(1.005); }
  48%  { transform: rotateY(90deg)  rotateZ(calc(var(--tilt, 0) * 1deg))    translateY(-9px)  scale(1.025); }
  80%  { transform: rotateY(168deg) rotateZ(calc(var(--tilt, 0) * -0.4deg)) translateY(-3px)  scale(1.01); }
  100% { transform: rotateY(180deg) rotateZ(0deg) translateY(0)     scale(1); }
}

@keyframes flip-to-front {
  0%   { transform: rotateY(180deg) rotateZ(0deg) translateY(0)     scale(1); }
  10%  { transform: rotateY(186deg) rotateZ(calc(var(--tilt, 0) * -0.3deg)) translateY(0)     scale(1.005); }
  48%  { transform: rotateY(90deg)  rotateZ(calc(var(--tilt, 0) * -1deg))   translateY(-9px)  scale(1.025); }
  80%  { transform: rotateY(12deg)  rotateZ(calc(var(--tilt, 0) * 0.4deg))  translateY(-3px)  scale(1.01); }
  100% { transform: rotateY(0deg)   rotateZ(0deg) translateY(0)     scale(1); }
}

@keyframes page-shade {
  0%   { filter: brightness(1); }
  48%  { filter: brightness(0.7); }
  100% { filter: brightness(1); }
}

.flashcard-face {
  position: relative;
  grid-area: 1 / 1;
  min-height: 260px;
  backface-visibility: hidden;
  border-radius: 24px;
  background: var(--card-bg);
  box-shadow: 0 12px 30px rgba(0,0,0,0.2);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  text-align: center;
  border: 2px solid #2f2211;
}

.flashcard-face.flashcard-front {
  background: var(--card-bg-front);
}

.box-pip {
  position: absolute;
  top: 1rem;
  right: 1rem;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--box-0);
}

.glyph-big {
  font-size: 5.5rem;
  line-height: 1;
  flex-shrink: 0;
}

.tap-hint {
  color: var(--muted);
  font-size: 0.85rem;
  margin-top: 1.25rem;
}

.flashcard-back {
  transform: rotateY(180deg);
  flex-direction: row;
  justify-content: center;
  gap: 1.75rem;
}

.answer-info {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.3rem;
  text-align: left;
  min-width: 0;
}

.answer-emoji {
  font-size: 1.9rem;
  margin-bottom: 0.15rem;
  filter: grayscale(1) sepia(0.55) brightness(0.85) contrast(0.95);
  opacity: 0.85;
}

.answer-example {
  color: var(--muted);
  font-size: 1.1rem;
}

.answer-example strong {
  color: var(--accent);
  font-size: 1.3rem;
}

.grade-buttons {
  display: grid;
  grid-template-rows: 0fr;
  margin-top: 0;
  transition: grid-template-rows 0.35s ease, margin-top 0.35s ease;
}

.grade-buttons.visible {
  grid-template-rows: 1fr;
  margin-top: 1.25rem;
}

.grade-buttons-inner {
  display: flex;
  gap: 1rem;
  overflow: hidden;
  min-height: 0;
  opacity: 0;
  transform: translateY(-8px);
  transition: opacity 0.25s ease, transform 0.25s ease;
}

.grade-buttons.visible .grade-buttons-inner {
  opacity: 1;
  transform: translateY(0);
}

.session-complete.hidden {
  display: none;
}

.grade-btn {
  position: relative;
  z-index: 0;
  overflow: hidden;
  flex: 1;
  border: none;
  padding: 0.9rem 1rem;
  border-radius: 4px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  color: #fff;
  box-shadow: 0 8px 20px rgba(0,0,0,0.15);
  transition: transform 0.15s ease;
}

.grade-btn:active {
  transform: scale(0.96);
}

.grade-btn.again { background: var(--again); }
.grade-btn.good { background: var(--good); }

.grade-btn::before,
.reset-btn::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  opacity: 0.4;
  mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='400' height='120'%3E%3Cfilter id='wg'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.012 0.22' numOctaves='4' seed='7' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23wg)'/%3E%3C/svg%3E");
}

.session-complete {
  background: var(--card-bg);
  border-radius: 24px;
  padding: 2.5rem 1.5rem;
  text-align: center;
  color: var(--text);
  box-shadow: 0 12px 30px rgba(0,0,0,0.2);
}

.session-complete .celebrate {
  font-size: 1.6rem;
  margin: 0 0 0.5rem;
}

.session-complete button {
  margin-top: 1.25rem;
  width: 100%;
}

/* ---------- Letter map ---------- */

.hint-text {
  color: var(--on-gradient);
  font-size: 0.9rem;
  text-align: center;
  margin-bottom: 1rem;
}

.letter-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(70px, 1fr));
  gap: 0.6rem;
}

.letter-tile {
  background: var(--card-bg);
  border-radius: 14px;
  padding: 0.9rem 0.3rem;
  text-align: center;
  cursor: pointer;
  border: 3px solid transparent;
  box-shadow: 0 4px 12px rgba(0,0,0,0.12);
  transition: transform 0.15s ease;
}

.letter-tile:active {
  transform: scale(0.94);
}

.letter-tile .deseret {
  font-size: 2.2rem;
  display: block;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  justify-content: center;
  margin-top: 1.25rem;
  color: var(--on-gradient);
  font-size: 0.8rem;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.swatch {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 50%;
}

.swatch.box-0 { background: var(--box-0); }
.swatch.box-1 { background: var(--box-1); }
.swatch.box-2 { background: var(--box-2); }
.swatch.box-3 { background: var(--box-3); }
.swatch.box-4 { background: var(--box-4); }
.swatch.box-5 { background: var(--box-5); }

/* ---------- Stats view ---------- */

.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.9rem;
  margin-bottom: 1.5rem;
}

.stat-card {
  background: var(--card-bg);
  border-radius: 18px;
  padding: 1.1rem;
  text-align: center;
  box-shadow: 0 6px 18px rgba(0,0,0,0.12);
}

.stat-card h3 {
  margin: 0;
  font-size: 1.9rem;
}

.stat-card p {
  margin: 0.2rem 0 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.ring-wrap {
  position: relative;
  width: 110px;
  height: 110px;
  margin: 0 auto;
}

.ring {
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}

.ring-bg {
  fill: none;
  stroke: var(--box-0);
  stroke-width: 12;
}

.ring-fg {
  fill: none;
  stroke: var(--good);
  stroke-width: 12;
  stroke-linecap: round;
  stroke-dasharray: 326.7;
  stroke-dashoffset: 326.7;
  transition: stroke-dashoffset 0.6s ease;
}

.ring-label {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.ring-label span {
  font-size: 1.3rem;
  font-weight: 700;
}

.ring-label small {
  color: var(--muted);
  font-size: 0.7rem;
}

.section-title {
  color: var(--on-gradient);
  font-size: 1rem;
  margin: 1.5rem 0 0.6rem;
}

.box-bars {
  background: var(--card-bg);
  border-radius: 18px;
  padding: 1rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  box-shadow: 0 6px 18px rgba(0,0,0,0.12);
}

.box-bar-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.8rem;
}

.box-bar-row .box-bar-label {
  width: 70px;
  color: var(--muted);
  flex-shrink: 0;
}

.box-bar-track {
  flex: 1;
  height: 10px;
  border-radius: 999px;
  background: rgba(120,120,140,0.15);
  overflow: hidden;
}

.box-bar-fill {
  height: 100%;
  border-radius: 999px;
  transition: width 0.4s ease;
}

.box-bar-row .box-bar-count {
  width: 24px;
  text-align: right;
  color: var(--muted);
  flex-shrink: 0;
}

.reset-btn {
  position: relative;
  z-index: 0;
  overflow: hidden;
  margin-top: 1.75rem;
  width: 100%;
  border: none;
  background: rgba(250,243,230,0.9);
  color: var(--again);
  font-weight: 700;
  padding: 0.8rem;
  border-radius: 14px;
  cursor: pointer;
}

/* ---------- Confetti ---------- */

#confetti-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 50;
}

.confetti-piece {
  position: absolute;
  top: -10px;
  font-size: 1.5rem;
  animation: confetti-fall 1.4s ease-in forwards;
}

@keyframes confetti-fall {
  to {
    transform: translateY(110vh) rotate(360deg);
    opacity: 0;
  }
}

/* ---------- Film grain ---------- */

.film-grain {
  position: fixed;
  inset: 0;
  z-index: 60;
  pointer-events: none;
  opacity: 0.22;
  mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

@media (max-width: 420px) {
  .glyph-big { font-size: 4.2rem; }
}
