:root {
  --bg-page: #f7f6fd;
  --bg-card: #ffffff;
  --surface: #edeaff;
  --surface-hover: #e2ddfc;
  --border: #e3dff5;
  --accent: #5e48e8;
  --accent-light: #7a68f0;
  --accent-soft: #edeafc;
  --text-main: #1e1b38;
  --text-muted: #6b668d;
  --text-sub: #444062;
  --shadow-sm: 0 4px 12px rgba(60, 40, 130, 0.05);
  --shadow-md: 0 10px 30px rgba(60, 40, 130, 0.08);
  --shadow-lg: 0 18px 45px rgba(60, 40, 130, 0.12);
  --radius-sm: 12px;
  --radius-md: 20px;
  --radius-lg: 28px;
  --radius-xl: 36px;
}

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

body {
  font-family: 'Fredoka', 'Noto Sans JP', sans-serif;
  background-color: var(--bg-page);
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}

/* Screens */
.screen {
  display: none;
  width: 100%;
  max-width: 900px;
  margin: 0 auto;
  padding: 24px 20px 48px;
  flex: 1;
}

.screen.active {
  display: flex;
  flex-direction: column;
}

/* Header & Brand */
.app-header {
  text-align: center;
  margin-bottom: 28px;
  position: relative;
}

.brand-badge {
  display: inline-block;
  background: var(--surface);
  color: var(--accent);
  font-size: 0.85rem;
  font-weight: 600;
  padding: 6px 16px;
  border-radius: 999px;
  margin-bottom: 12px;
  letter-spacing: 0.5px;
}

.app-title {
  font-size: clamp(1.8rem, 5vw, 2.5rem);
  font-weight: 700;
  color: var(--text-main);
  line-height: 1.2;
  margin-bottom: 8px;
}

.app-subtitle {
  color: var(--text-muted);
  font-size: 1rem;
  font-weight: 500;
}

/* Search Bar */
.search-box {
  margin-bottom: 24px;
  position: relative;
}

.search-input {
  width: 100%;
  padding: 16px 20px 16px 48px;
  font-size: 1rem;
  font-family: inherit;
  border: 2px solid var(--border);
  border-radius: var(--radius-md);
  background: #ffffff;
  color: var(--text-main);
  outline: none;
  transition: all 0.2s ease;
  box-shadow: var(--shadow-sm);
}

.search-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-soft);
}

.search-icon {
  position: absolute;
  left: 18px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  font-size: 1.1rem;
  pointer-events: none;
}

/* Chapters Grid */
.chapters-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
}

.chapter-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 20px;
  cursor: pointer;
  transition: all 0.22s cubic-bezier(0.16, 1, 0.3, 1);
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  text-align: left;
}

.chapter-card:hover {
  transform: translateY(-3px);
  border-color: var(--accent-light);
  box-shadow: var(--shadow-md);
}

.chapter-card:active {
  transform: translateY(-1px);
}

.chapter-num {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--accent);
  background: var(--surface);
  display: inline-block;
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  width: fit-content;
  margin-bottom: 10px;
}

.chapter-title {
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text-main);
  margin-bottom: 8px;
  line-height: 1.35;
}

.chapter-meta {
  font-size: 0.85rem;
  color: var(--text-muted);
  font-weight: 500;
}

/* Study View Top Bar */
.study-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  gap: 12px;
}

.back-btn {
  background: var(--bg-card);
  border: 1.5px solid var(--border);
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-weight: 600;
  color: var(--text-main);
  cursor: pointer;
  transition: all 0.2s;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.95rem;
}

.back-btn:hover {
  background: var(--surface);
  border-color: var(--accent-light);
  color: var(--accent);
}

.study-title-wrap {
  text-align: center;
  flex: 1;
}

.study-chapter-name {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 380px;
  margin: 0 auto;
}

.card-counter {
  font-size: 0.85rem;
  color: var(--text-muted);
  font-weight: 600;
  margin-top: 2px;
}

.study-tools {
  display: flex;
  gap: 8px;
}

.icon-btn {
  background: var(--bg-card);
  border: 1.5px solid var(--border);
  width: 42px;
  height: 42px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  cursor: pointer;
  color: var(--text-sub);
  transition: all 0.2s;
}

.icon-btn:hover {
  border-color: var(--accent-light);
  color: var(--accent);
}

.icon-btn.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

/* Progress Line */
.progress-container {
  width: 100%;
  height: 6px;
  background: var(--surface);
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: 24px;
}

.progress-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-light));
  width: 0%;
  border-radius: 999px;
  transition: width 0.25s ease;
}

/* STACKED FLASHCARD (NO FLIP RULE) */
.card-stage {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px 0 24px;
}

.flashcard {
  width: 100%;
  max-width: 540px;
  background: var(--bg-card);
  border-radius: var(--radius-xl);
  border: 1.5px solid var(--border);
  box-shadow: var(--shadow-lg);
  padding: 44px 32px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  position: relative;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  animation: cardPop 0.25s cubic-bezier(0.18, 0.89, 0.32, 1.28);
}

@keyframes cardPop {
  0% {
    opacity: 0;
    transform: scale(0.96) translateY(8px);
  }
  100% {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.card-sound-btn {
  position: absolute;
  top: 20px;
  right: 20px;
  background: var(--surface);
  border: none;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 1.25rem;
  color: var(--accent);
  transition: all 0.2s;
}

.card-sound-btn:hover {
  background: var(--accent);
  color: #ffffff;
  transform: scale(1.08);
}

/* 1. Foreign Character / Word (Largest, on top) */
.card-main-char {
  font-family: 'Noto Sans JP', sans-serif;
  font-size: clamp(3rem, 11vw, 4.5rem);
  font-weight: 700;
  color: var(--text-main);
  line-height: 1.15;
  margin-top: 10px;
  margin-bottom: 6px;
  word-break: break-word;
}

.card-kana-sub {
  font-family: 'Noto Sans JP', sans-serif;
  font-size: clamp(1.2rem, 4vw, 1.6rem);
  font-weight: 500;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 4px 16px;
  border-radius: 999px;
  margin-bottom: 12px;
  display: inline-block;
}

.card-kana-sub:empty {
  display: none;
}

/* 2. Thin Divider */
.card-divider {
  width: 70px;
  height: 3px;
  background: var(--border);
  border-radius: 99px;
  margin: 18px 0;
}

/* 3. Romaji (Medium, below) */
.card-romaji {
  font-size: clamp(1.3rem, 4vw, 1.8rem);
  font-weight: 600;
  color: var(--text-sub);
  letter-spacing: 0.5px;
  margin-bottom: 12px;
}

/* 4. Indonesian Meaning (Clear & readable) */
.card-meaning {
  font-size: clamp(1.15rem, 3.5vw, 1.45rem);
  font-weight: 500;
  color: var(--accent);
  line-height: 1.4;
  max-width: 90%;
  background: var(--surface);
  padding: 10px 22px;
  border-radius: var(--radius-md);
  margin-top: 6px;
}

/* Navigation Controls */
.study-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 20px;
  margin-top: 10px;
}

.nav-btn {
  background: var(--bg-card);
  border: 2px solid var(--accent);
  color: var(--accent);
  font-family: inherit;
  font-size: 1.05rem;
  font-weight: 600;
  padding: 14px 32px;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  min-width: 150px;
  box-shadow: var(--shadow-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.nav-btn:hover:not(:disabled) {
  background: var(--accent);
  color: #ffffff;
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.nav-btn:active:not(:disabled) {
  transform: translateY(0);
}

.nav-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  border-color: var(--border);
  color: var(--text-muted);
}

.nav-hint {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-top: 16px;
}

/* Responsive adjustments */
@media (max-width: 600px) {
  .screen {
    padding: 16px 14px 36px;
  }
  
  .flashcard {
    padding: 36px 20px 30px;
    border-radius: var(--radius-lg);
  }
  
  .nav-btn {
    padding: 12px 22px;
    font-size: 0.95rem;
    min-width: 120px;
  }
  
  .study-chapter-name {
    max-width: 180px;
    font-size: 0.95rem;
  }
}
