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

:root {
  --bg-dark: #0d1b2a;
  --bg-card: #1a2744;
  --bg-card-hover: #1e2f52;
  --gold: #c9a84c;
  --gold-light: #e8c96a;
  --indigo: #3d5af1;
  --indigo-light: #6b7ff5;
  --text-primary: #f0f4ff;
  --text-secondary: #a8b4cc;
  --text-muted: #6b7a99;
  --green: #2ecc71;
  --yellow: #f39c12;
  --red: #e74c3c;
  --border: rgba(255, 255, 255, 0.08);
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  --radius: 16px;
  --radius-sm: 10px;
  --transition: 0.3s ease;
  --nav-height: 64px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html { scroll-behavior: smooth; }

body {
  font-family: 'Noto Sans JP', sans-serif;
  background: var(--bg-dark);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  overflow-x: hidden;
}

.app-shell {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  position: relative;
  padding-bottom: calc(var(--nav-height) + var(--safe-bottom));
}

/* ── Screens & transitions ── */
.screen {
  display: none;
  min-height: 100vh;
  flex-direction: column;
  position: relative;
}

.screen.active { display: flex; }

.screen.slide-in-left {
  animation: slideInLeft 0.35s ease forwards;
}

.screen.slide-in-right {
  animation: slideInRight 0.35s ease forwards;
}

.screen.slide-out-left {
  animation: slideOutLeft 0.3s ease forwards;
}

.screen.slide-out-right {
  animation: slideOutRight 0.3s ease forwards;
}

@keyframes slideInLeft {
  from { opacity: 0; transform: translateX(28px); }
  to { opacity: 1; transform: translateX(0); }
}

@keyframes slideInRight {
  from { opacity: 0; transform: translateX(-28px); }
  to { opacity: 1; transform: translateX(0); }
}

@keyframes slideOutLeft {
  from { opacity: 1; transform: translateX(0); }
  to { opacity: 0; transform: translateX(-28px); }
}

@keyframes slideOutRight {
  from { opacity: 1; transform: translateX(0); }
  to { opacity: 0; transform: translateX(28px); }
}

/* Sub-screens (list/detail) — no bottom padding conflict */
#screen-list.active,
#screen-detail.active {
  padding-bottom: 0;
}

#screen-list .screen-body,
#screen-detail .screen-body {
  padding-bottom: 2rem;
}

/* ── Particles ── */
.particles {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
}

.particle {
  position: absolute;
  width: 4px;
  height: 4px;
  background: var(--gold-light);
  border-radius: 50%;
  opacity: 0.25;
  animation: drift linear infinite;
}

@keyframes drift {
  0% { transform: translateY(100vh) translateX(0); opacity: 0; }
  10% { opacity: 0.3; }
  90% { opacity: 0.15; }
  100% { transform: translateY(-20px) translateX(30px); opacity: 0; }
}

/* ── Welcome hero ── */
.screen-welcome {
  background: linear-gradient(165deg, #0d1b2a 0%, #1a237e 45%, #2a3a6e 75%, #c9a84c 140%);
  z-index: 1;
}

.hero {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 2.5rem 1.5rem 1rem;
}

.hero-logo {
  font-size: 3.5rem;
  margin-bottom: 1rem;
  filter: drop-shadow(0 4px 12px rgba(201, 168, 76, 0.3));
}

.hero h1 {
  font-family: 'Playfair Display', serif;
  font-size: clamp(1.35rem, 5vw, 1.75rem);
  font-weight: 600;
  margin-bottom: 0.5rem;
  background: linear-gradient(135deg, var(--text-primary), var(--gold-light));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.hero-sub-jp { font-size: 1.1rem; color: var(--gold-light); margin-bottom: 0.5rem; font-weight: 500; }
.hero-tagline { font-size: 0.9rem; color: var(--text-secondary); margin-bottom: 0.35rem; font-style: italic; font-family: 'Playfair Display', serif; }
.hero-tool { font-size: 0.8rem; color: var(--text-muted); margin-bottom: 1.25rem; }

.viewed-count {
  font-size: 0.8rem;
  color: var(--gold);
  background: rgba(201, 168, 76, 0.12);
  border: 1px solid rgba(201, 168, 76, 0.25);
  border-radius: 999px;
  padding: 0.4rem 1rem;
  margin-bottom: 0.75rem;
}

/* Progress bar */
.progress-wrap {
  width: 100%;
  max-width: 280px;
  margin-bottom: 1.5rem;
}

.progress-label {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-bottom: 0.4rem;
  text-align: left;
}

.progress-track {
  height: 8px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid var(--border);
}

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

.cta-group {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  width: 100%;
  max-width: 320px;
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 1rem 1.5rem;
  border: none;
  border-radius: 999px;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  text-decoration: none;
}

.btn-primary {
  background: linear-gradient(135deg, var(--gold), #a88a3a);
  color: var(--bg-dark);
  box-shadow: 0 4px 20px rgba(201, 168, 76, 0.35);
}

.btn-primary:hover { transform: translateY(-2px); box-shadow: 0 8px 28px rgba(201, 168, 76, 0.45); }

.btn-secondary {
  background: rgba(61, 90, 241, 0.2);
  color: var(--text-primary);
  border: 1px solid rgba(107, 127, 245, 0.4);
}

.btn-secondary:hover { background: rgba(61, 90, 241, 0.35); border-color: var(--indigo-light); }

.btn-outline {
  background: transparent;
  color: var(--gold-light);
  border: 1px solid rgba(201, 168, 76, 0.4);
}

.btn-outline:hover { background: rgba(201, 168, 76, 0.1); }

.btn-sm { padding: 0.7rem 1.2rem; font-size: 0.85rem; }
.btn-icon { font-size: 1.1rem; }

/* ── Screen layout ── */
.screen-body {
  flex: 1;
  padding: 1.25rem 1.25rem 0;
  position: relative;
  z-index: 1;
}

.screen-top { margin-bottom: 1.25rem; }

.back-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  background: none;
  border: none;
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 0.88rem;
  cursor: pointer;
  padding: 0.5rem 0;
  margin-bottom: 1rem;
  transition: color var(--transition);
}

.back-btn:hover { color: var(--gold-light); }

.screen-title { font-size: 1.2rem; font-weight: 500; margin-bottom: 0.25rem; }
.screen-subtitle { font-size: 0.85rem; color: var(--text-muted); }

.cat-header { display: flex; align-items: center; gap: 0.75rem; margin-bottom: 0.25rem; }
.cat-header .emoji { font-size: 2rem; }

/* ── Formality filters ── */
.formality-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-bottom: 1rem;
}

.filter-btn {
  padding: 0.4rem 0.75rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 0.72rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
}

.filter-btn:hover { border-color: var(--gold); color: var(--text-primary); }

.filter-btn.active {
  background: rgba(201, 168, 76, 0.2);
  border-color: var(--gold);
  color: var(--gold-light);
}

/* ── Category grid ── */
.cat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.85rem; }

.cat-card {
  position: relative;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1rem;
  text-align: center;
  cursor: pointer;
  transition: all var(--transition);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.cat-card::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: var(--radius);
  padding: 1px;
  background: linear-gradient(135deg, var(--gold), var(--indigo-light), var(--gold-light));
  -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  opacity: 0;
  transition: opacity var(--transition);
  pointer-events: none;
}

.cat-card:hover {
  transform: translateY(-4px);
  border-color: transparent;
  background: var(--bg-card-hover);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
}

.cat-card:hover::before { opacity: 1; }
.cat-card .emoji { font-size: 2rem; display: block; margin-bottom: 0.5rem; }
.cat-card .jp { font-size: 0.82rem; font-weight: 500; line-height: 1.4; margin-bottom: 0.25rem; }
.cat-card .en { font-size: 0.68rem; color: var(--text-muted); }

/* ── Search ── */
.search-box { margin-bottom: 0.75rem; }

.search-input {
  width: 100%;
  padding: 1rem 1.25rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.95rem;
  transition: border-color var(--transition);
}

.search-input:focus { outline: none; border-color: var(--indigo-light); }
.search-input::placeholder { color: var(--text-muted); }
.search-btn { width: 100%; margin-top: 0.75rem; }

.empty-state {
  text-align: center;
  padding: 2.5rem 1rem;
  color: var(--text-muted);
  font-size: 0.9rem;
  line-height: 1.7;
}

/* ── Phrase cards ── */
.phrase-list { display: flex; flex-direction: column; gap: 0.85rem; padding-bottom: 1rem; }

.phrase-card {
  position: relative;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 3rem 1.25rem 1.25rem;
  transition: all var(--transition);
  box-shadow: var(--shadow);
}

.phrase-card:hover {
  transform: translateY(-4px);
  border-color: var(--gold);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
}

.phrase-card-main { cursor: pointer; }

.phrase-card .jp-preview {
  font-family: 'Noto Serif JP', serif;
  font-size: 1.05rem;
  font-weight: 700;
  margin-bottom: 0.35rem;
  line-height: 1.5;
}

.phrase-card .en-preview { font-size: 0.82rem; color: var(--text-secondary); line-height: 1.5; }

.phrase-card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 0.75rem;
}

.viewed-dot { font-size: 0.7rem; color: var(--green); }

.heart-btn {
  position: absolute;
  top: 1rem;
  right: 1rem;
  background: none;
  border: none;
  font-size: 1.25rem;
  cursor: pointer;
  padding: 0.25rem;
  line-height: 1;
  transition: transform var(--transition);
}

.heart-btn:hover { transform: scale(1.15); }
.heart-btn.active { animation: heartPop 0.3s ease; }

@keyframes heartPop {
  0% { transform: scale(1); }
  50% { transform: scale(1.35); }
  100% { transform: scale(1); }
}

/* ── Badges ── */
.badge {
  display: inline-block;
  font-size: 0.65rem;
  font-weight: 700;
  padding: 0.25rem 0.6rem;
  border-radius: 999px;
  letter-spacing: 0.03em;
}

.badge-very_formal { background: rgba(231, 76, 60, 0.2); color: #ff8a80; border: 1px solid rgba(231, 76, 60, 0.4); }
.badge-formal { background: rgba(201, 168, 76, 0.2); color: var(--gold-light); border: 1px solid rgba(201, 168, 76, 0.4); }
.badge-casual { background: rgba(46, 204, 113, 0.2); color: var(--green); border: 1px solid rgba(46, 204, 113, 0.4); }

/* ── Detail view ── */
.detail-content { padding-bottom: 1rem; }

.detail-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.5rem;
}

.detail-heart { position: static; font-size: 1.5rem; }

.detail-jp {
  font-family: 'Noto Serif JP', serif;
  font-size: clamp(1.4rem, 5vw, 1.75rem);
  font-weight: 700;
  line-height: 1.6;
  margin-bottom: 0.75rem;
}

.detail-romaji { font-style: italic; color: var(--text-secondary); font-size: 1rem; margin-bottom: 0.75rem; }
.detail-english { color: var(--text-primary); font-size: 0.95rem; margin-bottom: 1rem; line-height: 1.7; }

.context-box {
  background: rgba(61, 90, 241, 0.1);
  border: 1px solid rgba(61, 90, 241, 0.2);
  border-radius: var(--radius-sm);
  padding: 1.15rem;
  margin-bottom: 1.25rem;
  font-size: 0.88rem;
  color: var(--text-secondary);
  line-height: 1.7;
}

.context-box strong {
  color: var(--indigo-light);
  display: block;
  margin-bottom: 0.35rem;
  font-size: 0.75rem;
  letter-spacing: 0.05em;
}

.example-box {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 1.15rem;
  margin-bottom: 1.25rem;
}

.example-box h4 { font-size: 0.72rem; color: var(--gold); letter-spacing: 0.08em; margin-bottom: 0.5rem; }

.example-box pre {
  font-family: 'Noto Sans JP', sans-serif;
  font-size: 0.85rem;
  color: var(--text-secondary);
  white-space: pre-wrap;
  line-height: 1.8;
}

.action-row { display: flex; flex-direction: column; gap: 0.65rem; margin-bottom: 1.5rem; }
.related-section { margin-top: 0.5rem; }
.related-section h4 { font-size: 0.8rem; color: var(--text-muted); margin-bottom: 0.75rem; letter-spacing: 0.05em; }

/* ── Quiz ── */
.quiz-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
  font-size: 0.82rem;
  color: var(--text-secondary);
}

.quiz-stats {
  display: flex;
  gap: 1rem;
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 1rem;
}

.quiz-jp {
  font-family: 'Noto Serif JP', serif;
  font-size: 1.5rem;
  font-weight: 700;
  text-align: center;
  margin-bottom: 0.5rem;
  line-height: 1.6;
}

.quiz-hint {
  text-align: center;
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 1.25rem;
}

.quiz-options { display: flex; flex-direction: column; gap: 0.65rem; margin-bottom: 1rem; }

.quiz-option {
  padding: 1rem 1.15rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.88rem;
  text-align: left;
  cursor: pointer;
  transition: all var(--transition);
  line-height: 1.5;
}

.quiz-option:hover:not(:disabled) { border-color: var(--indigo-light); background: var(--bg-card-hover); }
.quiz-option:disabled { cursor: default; }
.quiz-option.correct { border-color: var(--green); background: rgba(46, 204, 113, 0.15); }
.quiz-option.wrong { border-color: var(--red); background: rgba(231, 76, 60, 0.15); }

.quiz-speak { width: 100%; margin-top: 0.5rem; }

.quiz-result { text-align: center; padding: 2rem 1rem; }

.quiz-result-score {
  font-family: 'Playfair Display', serif;
  font-size: 3rem;
  color: var(--gold-light);
  margin-bottom: 0.5rem;
}

.quiz-result-label { font-size: 1.1rem; margin-bottom: 0.5rem; }
.quiz-result-best { font-size: 0.82rem; color: var(--text-muted); margin-bottom: 1.5rem; }

/* ── Footer ── */
.app-footer {
  text-align: center;
  padding: 1.5rem 1.25rem 1rem;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: auto;
  position: relative;
  z-index: 1;
}

.app-footer strong { color: var(--gold-light); }

/* ── Bottom navigation ── */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 480px;
  height: calc(var(--nav-height) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: rgba(13, 27, 42, 0.95);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-around;
  z-index: 100;
  transition: transform 0.3s ease;
}

.bottom-nav.hidden {
  transform: translateX(-50%) translateY(100%);
}

.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2rem;
  background: none;
  border: none;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 0.62rem;
  font-weight: 500;
  cursor: pointer;
  padding: 0.5rem 0.25rem;
  transition: color var(--transition);
}

.nav-item .nav-icon { font-size: 1.35rem; line-height: 1; }
.nav-item.active { color: var(--gold-light); }
.nav-item:hover { color: var(--text-primary); }

/* ── Toast ── */
.toast {
  position: fixed;
  bottom: calc(var(--nav-height) + var(--safe-bottom) + 1rem);
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: var(--bg-card);
  border: 1px solid var(--gold);
  color: var(--text-primary);
  padding: 0.85rem 1.5rem;
  border-radius: 999px;
  font-size: 0.9rem;
  z-index: 999;
  box-shadow: var(--shadow);
  transition: transform 0.35s ease;
  white-space: nowrap;
  max-width: 90vw;
  overflow: hidden;
  text-overflow: ellipsis;
}

.toast.show { transform: translateX(-50%) translateY(0); }

#screen-detail .toast,
#screen-list .toast {
  bottom: calc(1rem + var(--safe-bottom));
}