@import url('https://fonts.googleapis.com/css2?family=Playfair+Display:ital,wght@0,600;0,700;1,600&family=Unbounded:wght@500;700;800&family=DM+Sans:wght@400;500;700&display=swap');

:root{
  /* Russian folk palette: cornflower blue + khokhloma red/gold on warm
     parchment, deliberately distinct from the kanji app's navy/sakura mix */
  --bg: #FBF2DE;
  --paper: #FFFBF2;
  --ink: #2A2118;
  --ink-soft: #7A6A55;
  --blue: #2E5FA3;
  --blue-deep: #1B3A66;
  --gold: #C9932E;
  --red: #B23A2E;
  --good: #4C8C6B;
  --again: #C1584B;
  --hard: #D9A441;
  --card-radius: 28px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

html{ font-size: 100%; } /* respects the user's OS text-size setting */

body{
  margin:0;
  background: var(--bg);
  color: var(--ink);
  font-family: 'DM Sans', -apple-system, sans-serif;
  font-size: 1.125rem; /* ~18px base — deliberately large for effortless reading */
  line-height: 1.5;
  overscroll-behavior: none;
  height: 100dvh;
  overflow: hidden;
}

h1,h2,h3{ font-family: 'Playfair Display', serif; margin: 0; }

#app{ height: 100dvh; position: relative; }

.view{ display:none; height:100%; }
.view.active{ display:flex; flex-direction:column; }

/* ===================== HOME ===================== */

.view-home{
  padding: calc(var(--safe-top) + 2rem) 1.5rem calc(var(--safe-bottom) + 2rem);
  align-items: center;
  gap: 1.5rem;
  overflow-y: auto;
}
.home-header{ text-align:center; }
.home-mascot{ width: 110px; height:110px; border-radius: 28px; box-shadow: 0 8px 24px rgba(42,33,24,.15); margin-bottom: .75rem; }
.home-title{ font-size: 2rem; color: var(--blue-deep); font-style: italic; }
.home-sub{ color: var(--ink-soft); font-size: 1.05rem; margin-top: .35rem; }

.deck-toggles{
  width:100%; max-width: 420px;
  display:flex; flex-direction:column; gap: .6rem;
}
.level-toggle{
  display:flex; align-items:center; justify-content:space-between;
  background: var(--paper);
  border: 2px solid transparent;
  border-radius: 18px;
  padding: 1rem 1.25rem;
  font-size: 1.15rem;
  font-weight: 500;
  transition: border-color .15s ease, opacity .15s ease;
}
.level-toggle.active{ border-color: var(--blue); }
.level-toggle.locked{ opacity: .5; }
.level-toggle .count{ color: var(--ink-soft); font-size: .95rem; font-weight:400; }
.toggle-switch{
  width: 50px; height: 30px; border-radius: 999px;
  background: #e3d6bb; position:relative; flex-shrink:0; margin-left:1rem;
  transition: background .15s ease;
}
.toggle-switch::after{
  content:''; position:absolute; top:3px; left:3px;
  width:24px; height:24px; border-radius:50%;
  background: white; box-shadow: 0 2px 4px rgba(0,0,0,.2);
  transition: transform .15s ease;
}
.level-toggle.active .toggle-switch{ background: var(--blue); }
.level-toggle.active .toggle-switch::after{ transform: translateX(20px); }
.level-toggle.locked .toggle-switch{ pointer-events:none; }
.lock-icon{ margin-left:.4rem; }

.home-stats{ color: var(--ink-soft); font-size: 1rem; text-align:center; }

.btn-primary{
  background: var(--blue); color: white; border:none;
  border-radius: 999px; padding: 1rem 2.5rem;
  font-family:'DM Sans',sans-serif; font-weight:700; font-size: 1.15rem;
  box-shadow: 0 6px 18px rgba(46,95,163,.35);
}
.btn-primary:active{ transform: scale(.97); }
.btn-launch{ width: 100%; max-width: 420px; }

/* ===================== STUDY ===================== */

.view-study{
  background: var(--blue-deep);
  color: white;
}
.study-header{
  display:flex; align-items:center; gap: .75rem;
  padding: calc(var(--safe-top) + .75rem) 1.25rem .75rem;
}
.icon-btn{
  background: rgba(255,255,255,.15); border:none; color:white;
  width:40px; height:40px; border-radius:50%; font-size:1.1rem;
  display:flex; align-items:center; justify-content:center;
}
.header-spacer{ width:40px; }
.dots{ flex:1; display:flex; gap:6px; justify-content:center; }
.dot{ height:6px; flex:1; max-width: 36px; border-radius:999px; background: rgba(255,255,255,.25); }
.dot.done{ background: var(--gold); }
.dot.current{ background: rgba(255,255,255,.55); }

.card-stack{
  flex:1; position:relative;
  display:flex; align-items:center; justify-content:center;
  padding: 1rem 1.5rem calc(var(--safe-bottom) + 1.5rem);
}

.study-card{
  position:absolute;
  width: min(88vw, 400px);
  height: min(60vh, 480px);
  background: var(--paper);
  border-radius: var(--card-radius);
  box-shadow: 0 20px 50px rgba(0,0,0,.35);
  display:flex; flex-direction:column; align-items:center; justify-content:center;
  color: var(--ink);
  padding: 2rem;
  text-align:center;
  touch-action: none;
  will-change: transform;
}
.study-card.bonus{ background: linear-gradient(160deg, #FFF3DC, #FCE0B0); border: 3px solid var(--red); }
.bonus-ribbon{
  position:absolute; top:1rem; left:1rem;
  background: var(--red); color:white; font-size:.85rem; font-weight:700;
  padding:.3rem .75rem; border-radius:999px;
}

.reveal-bar{
  position:absolute; top:0; left:0; right:0; height:6px;
  background: rgba(42,33,24,.08);
  border-radius: var(--card-radius) var(--card-radius) 0 0;
  overflow:hidden;
}
.reveal-fill{ height:100%; width:0%; background: var(--gold); transition: width linear; }

.card-front .front-glyph{ font-size: clamp(2.6rem, 12vw, 4.2rem); font-family:'Unbounded',sans-serif; font-weight:700; }
.card-back .back-glyph-small{ font-size: clamp(1.9rem, 9vw, 2.8rem); font-family:'Unbounded',sans-serif; margin-bottom: .5rem; color: var(--ink); font-weight: 700; }
.back-field{ margin: .2rem 0; }
.back-field .label{ font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-soft); }
.back-field .value{ font-size: 1.2rem; font-family:'DM Sans',sans-serif; }

.tap-hint{ margin-top:1.5rem; color: var(--ink-soft); font-size: .95rem; }

.swipe-tint{
  position:absolute; inset:0; border-radius: var(--card-radius);
  opacity:0; pointer-events:none; display:flex; align-items:center; justify-content:center;
  font-size: 3rem; font-weight:700;
}
.swipe-tint.good{ background: rgba(76,140,107,.55); color:white; }
.swipe-tint.again{ background: rgba(193,88,75,.55); color:white; }
.swipe-tint.hard{ background: rgba(217,164,65,.55); color:white; }

.mascot-toast{
  position:absolute; left:50%; bottom: calc(var(--safe-bottom) + 1.5rem);
  transform: translateX(-50%) translateY(20px);
  display:flex; align-items:center; gap:.6rem;
  background: rgba(255,255,255,.95); color: var(--ink);
  padding: .6rem 1.1rem; border-radius: 999px;
  font-weight:600; font-size:1rem;
  box-shadow: 0 8px 20px rgba(0,0,0,.25);
  opacity:0; transition: opacity .2s ease, transform .2s ease;
  pointer-events:none;
}
.mascot-toast.show{ opacity:1; transform: translateX(-50%) translateY(0); }
.mascot-toast img{ width:32px; height:32px; }

/* ===================== RECAP ===================== */

.view-recap{
  background: var(--bg);
  align-items:center; justify-content:center;
  padding: calc(var(--safe-top) + 1.5rem) 1.5rem calc(var(--safe-bottom) + 1.5rem);
}
.recap-card{
  background: var(--paper); border-radius: 32px; padding: 2.5rem 2rem;
  max-width: 420px; width:100%; text-align:center;
  box-shadow: 0 20px 50px rgba(42,33,24,.15);
}
.recap-mascot{ width:120px; height:120px; margin-bottom:1rem; }
.recap-title{ font-size:1.6rem; color: var(--blue-deep); font-style: italic; margin-bottom:1.25rem; }
.recap-stats{ display:flex; justify-content:center; gap:2rem; margin-bottom:1rem; }
.recap-stats .stat-num{ font-size:1.8rem; font-weight:700; font-family:'Playfair Display',serif; }
.recap-stats .stat-label{ font-size:.85rem; color: var(--ink-soft); }
.recap-streak{ color: var(--red); font-weight:600; margin-bottom:1.5rem; }

@media (prefers-reduced-motion: reduce){
  .study-card{ transition:none !important; }
  .dot.current::after{ animation:none; width:100%; }
}
