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

:root{
  --bg: #F7F1E4;
  --paper: #FFFCF5;
  --ink: #2B2620;
  --ink-soft: #6b6156;
  --blue: #3E5C78;
  --blue-deep: #2C425A;
  --brown: #B8783C;
  --sakura: #E8AAB4;
  --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; }

.jp{ font-family: 'Noto Sans JP', sans-serif; }

#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(43,38,32,.15); margin-bottom: .75rem; animation: mascot-idle-bob 2.6s ease-in-out infinite; cursor: pointer; }
.home-mascot.mascot-react{ animation: mascot-pop .5s cubic-bezier(.34,1.56,.64,1); }
.home-title{
  font-size: 2.6rem; color: var(--blue-deep); font-style: italic; font-weight: 700;
  letter-spacing: .01em; position: relative; display: inline-block;
}
.home-title::after{
  content:''; display:block; width: 46%; height: 3px; margin: .3rem auto 0;
  background: var(--brown); border-radius: 999px;
}
.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: #ddd4c2; 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(62,92,120,.35);
}
.btn-primary:active{ transform: scale(.97); }
.btn-launch{ padding: .65rem 2rem; font-size: 1rem; width: auto; }

/* ===================== 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(--sakura); }
.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, #FFF6E0, #FFE9C2); border: 3px solid var(--brown); }
.bonus-ribbon{
  position:absolute; top:1rem; left:1rem;
  background: var(--brown); 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(43,38,32,.08);
  border-radius: var(--card-radius) var(--card-radius) 0 0;
  overflow:hidden;
}
.reveal-fill{ height:100%; width:0%; background: var(--brown); transition: width linear; }

.card-front .front-glyph{ font-size: clamp(4.5rem, 22vw, 7rem); font-family:'Noto Sans JP',sans-serif; }
.card-back .back-glyph-small{ font-size: clamp(3.4rem, 18vw, 5rem); font-family:'Noto Sans JP',sans-serif; margin-bottom: .5rem; color: var(--ink); font-weight: 500; }
.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.3rem; font-family:'Noto Sans JP',sans-serif; }
.example-field{ margin-top: .75rem; padding-top: .6rem; border-top: 1px dashed rgba(43,38,32,.15); max-width: 90%; }
.example-field .value{ font-size: 1.05rem; font-style: italic; color: var(--ink-soft); }

.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:56px; height:56px; animation: mascot-pop .45s cubic-bezier(.34,1.56,.64,1); }
.mascot-toast.grade-again img{ animation: mascot-pop .45s cubic-bezier(.34,1.56,.64,1), mascot-shake .5s ease .45s; }
.mascot-toast.grade-hard img{ animation: mascot-pop .45s cubic-bezier(.34,1.56,.64,1), mascot-tilt .6s ease-in-out .45s 2; }
.mascot-toast.grade-bonus img{ width:64px; height:64px; animation: mascot-pop .55s cubic-bezier(.34,1.56,.64,1); }

@keyframes mascot-pop {
  0%   { transform: scale(.4) rotate(-8deg); opacity: 0; }
  55%  { transform: scale(1.18) rotate(4deg); opacity: 1; }
  75%  { transform: scale(.94) rotate(-2deg); }
  100% { transform: scale(1) rotate(0deg); }
}
@keyframes mascot-shake {
  0%, 100% { transform: translateX(0) rotate(0); }
  20% { transform: translateX(-4px) rotate(-6deg); }
  40% { transform: translateX(4px) rotate(6deg); }
  60% { transform: translateX(-3px) rotate(-4deg); }
  80% { transform: translateX(3px) rotate(4deg); }
}
@keyframes mascot-tilt {
  0%, 100% { transform: rotate(0); }
  50% { transform: rotate(-10deg); }
}
@keyframes mascot-idle-bob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}

/* ===================== 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(43,38,32,.15);
  touch-action: none; cursor: grab;
}
.recap-swipe-hint{ margin-top:.75rem; font-size:.85rem; color: var(--ink-soft); }
.recap-mascot{ width:120px; height:120px; margin-bottom:1rem; animation: mascot-celebrate-in .7s cubic-bezier(.34,1.56,.64,1), mascot-idle-bob 2.6s ease-in-out .7s infinite; }
.recap-mascot.perfect{ animation: mascot-celebrate-perfect .9s cubic-bezier(.34,1.56,.64,1), mascot-idle-bob 2.6s ease-in-out .9s infinite; }
@keyframes mascot-celebrate-in {
  0%   { transform: scale(.3) rotate(-15deg) translateY(40px); opacity: 0; }
  50%  { transform: scale(1.25) rotate(8deg) translateY(-10px); opacity: 1; }
  70%  { transform: scale(.92) rotate(-4deg) translateY(4px); }
  85%  { transform: scale(1.05) rotate(2deg) translateY(-2px); }
  100% { transform: scale(1) rotate(0deg) translateY(0); }
}
@keyframes mascot-celebrate-perfect {
  0%   { transform: scale(.3) rotate(0deg); opacity: 0; }
  45%  { transform: scale(1.35) rotate(360deg); opacity: 1; }
  70%  { transform: scale(.9) rotate(360deg); }
  100% { transform: scale(1) rotate(360deg); }
}
.recap-brand{ font-family:'Playfair Display', serif; font-style: italic; font-weight: 700; color: var(--blue-deep); font-size: 1.1rem; letter-spacing: .02em; margin-bottom: .25rem; }
.recap-title{ font-size:1.6rem; color: var(--blue-deep); 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-message{ color: var(--brown); font-weight:600; margin-bottom:1.5rem; }

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