/* ─── Reset & Base ─── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --black: #000;
  --white: #fff;
  --gray-100: #f5f5f5;
  --gray-200: #e8e8e8;
  --gray-400: #aaa;
  --gray-600: #666;
  --nav-h: 60px;
  --header-h: 52px;
  --radius: 12px;
  --font: -apple-system, BlinkMacSystemFont, 'Helvetica Neue', Arial, sans-serif;
}

html, body {
  height: 100%;
  overflow: hidden;
  font-family: var(--font);
  font-size: 16px;
  background: var(--white);
  color: var(--black);
  -webkit-font-smoothing: antialiased;
}

/* ─── Views ─── */
.view {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: var(--white);
  opacity: 0;
  pointer-events: none;
  transform: translateY(12px);
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 1;
}
.view.active {
  opacity: 1;
  pointer-events: all;
  transform: translateY(0);
  z-index: 2;
}

/* ─── Header ─── */
.view-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 16px;
  height: var(--header-h);
  border-bottom: 1px solid var(--gray-200);
  flex-shrink: 0;
}
.view-title { font-size: 17px; font-weight: 700; flex: 1; }
.app-title  { font-size: 18px; font-weight: 900; letter-spacing: 1px; flex: 1; }
.icon-btn {
  background: none; border: none; cursor: pointer;
  font-size: 20px; padding: 8px; line-height: 1;
  color: var(--black);
}

/* ─── View content ─── */
.view-content {
  flex: 1;
  overflow-y: auto;
  padding: 16px 16px calc(var(--nav-h) + 16px);
  -webkit-overflow-scrolling: touch;
}

/* ─── ONBOARDING ─── */
#view-onboarding .view-content,
.onboarding-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  gap: 48px;
  padding: 32px 24px;
}
.app-logo { text-align: center; }
.logo-icon {
  width: 100px; height: 100px;
  display: block;
  margin: 0 auto 16px;
  border-radius: 22px;
}
.logo-name {
  font-size: 28px;
  font-weight: 900;
  letter-spacing: 3px;
  margin-bottom: 8px;
}
.logo-tagline { color: var(--gray-600); font-size: 15px; }

.lang-select { text-align: center; }
.lang-select p { margin-bottom: 16px; font-size: 15px; color: var(--gray-600); }
.lang-buttons { display: flex; gap: 12px; justify-content: center; }
.btn-lang {
  padding: 14px 28px;
  border: 2px solid var(--black);
  background: var(--white);
  border-radius: var(--radius);
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.btn-lang:active, .btn-lang.selected {
  background: var(--black);
  color: var(--white);
}

/* ─── HOME ─── */
.readiness-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 20px 0 8px;
}
.ring-wrap {
  position: relative;
  width: 160px;
  height: 160px;
}
.ring-svg { width: 100%; height: 100%; }
.ring-track { fill: none; stroke: var(--gray-200); stroke-width: 8; }
.ring-progress {
  fill: none;
  stroke: var(--black);
  stroke-width: 8;
  stroke-linecap: round;
  stroke-dasharray: 314.16;
  stroke-dashoffset: 314.16;
  transition: stroke-dashoffset 0.7s cubic-bezier(.4,0,.2,1);
}
.ring-label {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
}
.ring-pct { font-size: 34px; font-weight: 900; line-height: 1; }
.ring-sub { font-size: 11px; color: var(--gray-500); text-transform: uppercase; letter-spacing: 1px; margin-top: 2px; }
.readiness-title { font-size: 17px; font-weight: 700; margin-top: 14px; letter-spacing: 0.3px; }
.week-dots { display: flex; gap: 7px; margin-top: 10px; margin-bottom: 4px; }
.week-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--gray-200); }
.week-dot.active { background: var(--black); }
.due-badge {
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--white); color: var(--black);
  font-size: 12px; font-weight: 700;
  min-width: 20px; height: 20px; padding: 0 5px;
  border-radius: 10px; margin-left: 8px;
}

/* ─── Home section label ─── */
.home-section-label {
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.08em; color: var(--gray-500);
  margin: 20px 0 8px;
}

/* ─── Featured conversation card ─── */
.featured-convo {
  display: flex; align-items: center; gap: 14px;
  background: var(--black); color: var(--white);
  border-radius: var(--radius); padding: 18px 16px;
  width: 100%; text-align: left; cursor: pointer;
  border: none; margin-bottom: 10px;
  transition: opacity 0.15s;
}
.featured-convo:active { opacity: 0.85; }
.featured-icon { font-size: 30px; flex-shrink: 0; line-height: 1; }
.featured-info { flex: 1; min-width: 0; }
.featured-title { font-size: 16px; font-weight: 700; color: var(--white); }
.featured-sub { font-size: 12px; color: rgba(255,255,255,0.55); margin-top: 3px; }
.featured-cta { font-size: 18px; color: rgba(255,255,255,0.7); flex-shrink: 0; }

/* ─── Due cards pill ─── */
.home-pill {
  display: flex; align-items: center; gap: 10px;
  border: 1.5px solid var(--gray-200); border-radius: var(--radius);
  padding: 13px 16px; width: 100%; text-align: left;
  background: var(--white); cursor: pointer; margin-bottom: 16px;
  transition: background 0.15s;
}
.home-pill:active { background: var(--gray-100); }
.home-pill.pill-dim { opacity: 0.4; cursor: default; }
.pill-icon { font-size: 18px; }
.pill-label { flex: 1; font-size: 15px; font-weight: 500; }

/* ─── Stats grid ─── */
.home-stats {
  display: grid; grid-template-columns: 1fr 1fr 1fr;
  gap: 8px; margin-bottom: 12px;
}
.stat-card {
  background: var(--gray-100); border-radius: 10px;
  padding: 14px 8px; text-align: center;
}
.stat-num { font-size: 18px; font-weight: 800; line-height: 1; }
.stat-label { font-size: 10px; color: var(--gray-500); margin-top: 5px; text-transform: uppercase; letter-spacing: 0.04em; }

/* ─── Home quick links ─── */
.home-links { display: flex; gap: 8px; }
.home-link {
  flex: 1; padding: 12px 8px;
  border: 1.5px solid var(--gray-200); border-radius: var(--radius);
  text-align: center; font-size: 13px; font-weight: 600;
  background: var(--white); cursor: pointer;
  transition: background 0.15s;
}
.home-link:active { background: var(--gray-100); }

/* ─── Convo end XP ─── */
.convo-end-xp {
  font-size: 22px; font-weight: 800;
  background: var(--black); color: var(--white);
  padding: 8px 24px; border-radius: 999px;
}

.section-progress { display: flex; flex-direction: column; gap: 14px; }
.section-item {}
.section-name { font-size: 14px; font-weight: 700; margin-bottom: 5px; display: flex; justify-content: space-between; }
.section-name span { font-weight: 400; color: var(--gray-600); font-size: 13px; }
.section-bar {
  height: 4px;
  background: var(--gray-200);
  border-radius: 2px;
  overflow: hidden;
}
.section-bar-fill {
  height: 100%;
  background: var(--black);
  border-radius: 2px;
  transition: width 0.5s ease;
}
.section-locked { opacity: 0.35; }

/* ─── Buttons ─── */
.btn-primary {
  display: block;
  width: 100%;
  padding: 16px;
  background: var(--black);
  color: var(--white);
  border: none;
  border-radius: var(--radius);
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  text-align: center;
  transition: opacity 0.15s;
}
.btn-primary:active { opacity: 0.7; }

.btn-secondary {
  display: block;
  width: 100%;
  padding: 16px;
  background: var(--white);
  color: var(--black);
  border: 1.5px solid var(--black);
  border-radius: var(--radius);
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  text-align: center;
  transition: background 0.15s, color 0.15s;
}
.btn-secondary:active { background: var(--black); color: var(--white); }
.btn-full { width: 100%; }

.btn-danger {
  width: 100%;
  padding: 14px;
  background: var(--white);
  color: var(--black);
  border: 1.5px solid var(--black);
  border-radius: var(--radius);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}

/* ─── LEARN VIEW ─── */
#learn-content { display: flex; flex-direction: column; gap: 10px; }

.section-group { }
.section-group-title {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--gray-600);
  margin: 16px 0 8px;
}
.lesson-card {
  border: 1.5px solid var(--gray-200);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  align-items: center;
  gap: 14px;
  cursor: pointer;
  transition: border-color 0.15s;
  background: var(--white);
  width: 100%;
  text-align: left;
}
.lesson-card:active { border-color: var(--black); background: var(--gray-100); }
.lesson-card.locked { opacity: 0.4; cursor: not-allowed; }
.lesson-icon { font-size: 24px; width: 36px; text-align: center; flex-shrink: 0; }
.lesson-info { flex: 1; }
.lesson-name { font-size: 15px; font-weight: 700; margin-bottom: 2px; }
.lesson-sub  { font-size: 13px; color: var(--gray-600); }
.lesson-badge {
  font-size: 11px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 20px;
  background: var(--black);
  color: var(--white);
}
.lesson-badge.done { background: var(--gray-200); color: var(--gray-600); }

/* ─── SESSION HEADER ─── */
.session-progress {
  flex: 1;
  height: 6px;
  background: var(--gray-200);
  border-radius: 3px;
  overflow: hidden;
}
.session-bar-fill {
  height: 100%;
  background: var(--black);
  border-radius: 3px;
  transition: width 0.3s ease;
  width: 0%;
}
.session-count { font-size: 13px; color: var(--gray-600); white-space: nowrap; }

/* ─── REVIEW CARD ─── */
.review-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 20px 16px calc(var(--nav-h) + 20px);
}
.card-wrap {
  width: 100%;
  max-width: 380px;
  perspective: 1000px;
  margin-bottom: 24px;
}
.card {
  width: 100%;
  height: 240px;
  cursor: pointer;
}
.card-inner {
  width: 100%;
  height: 100%;
  position: relative;
  transform-style: preserve-3d;
  transition: transform 0.45s ease;
  border-radius: var(--radius);
}
.card-inner.flipped { transform: rotateY(180deg); }

.card-front, .card-back {
  position: absolute;
  inset: 0;
  border-radius: var(--radius);
  border: 2px solid var(--black);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}
.card-back { transform: rotateY(180deg); }

.card-jp { font-size: 56px; line-height: 1.1; font-weight: 700; text-align: center; margin-bottom: 10px; }
.card-romaji { font-size: 20px; color: var(--gray-600); margin-bottom: 6px; }
.card-meaning { font-size: 18px; font-weight: 600; text-align: center; }
.card-type { font-size: 11px; letter-spacing: 1px; text-transform: uppercase; color: var(--gray-400); margin-bottom: 12px; }
.card-example { font-size: 13px; color: var(--gray-600); text-align: center; margin-top: 12px; line-height: 1.5; }
.card-hint { font-size: 13px; color: var(--gray-400); }

.card-actions {
  width: 100%;
  max-width: 380px;
  margin-bottom: 14px;
}
.btn-reveal {
  width: 100%;
  padding: 16px;
  background: var(--black);
  color: var(--white);
  border: none;
  border-radius: var(--radius);
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
}

.grade-buttons {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  width: 100%;
  max-width: 380px;
  margin-bottom: 14px;
}
.btn-grade {
  padding: 14px 4px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  border: 1.5px solid var(--black);
  background: var(--white);
  transition: background 0.12s, color 0.12s;
}
.btn-grade:active { background: var(--black); color: var(--white); }
.btn-again { border-color: var(--black); }
.btn-easy  { border-color: var(--black); }

.btn-hear {
  background: none;
  border: 1.5px solid var(--gray-200);
  border-radius: var(--radius);
  padding: 10px 20px;
  font-size: 14px;
  cursor: pointer;
  color: var(--gray-600);
}
.btn-hear:active { border-color: var(--black); color: var(--black); }

/* ─── SPEAK VIEW ─── */
.speak-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
  padding: 24px 16px calc(var(--nav-h) + 20px);
}
.speak-card {
  width: 100%;
  max-width: 380px;
  min-height: 200px;
  border: 2px solid var(--black);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 28px 20px;
  gap: 14px;
  text-align: center;
}
.speak-meaning { font-size: 22px; font-weight: 700; line-height: 1.3; }
.speak-hint    { font-size: 16px; color: var(--gray-600); }
.speak-answer  { font-size: 32px; font-weight: 700; }
.speak-answer small { display: block; font-size: 16px; font-weight: 400; color: var(--gray-600); margin-top: 4px; }

.speak-actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  width: 100%;
  max-width: 380px;
}
.btn-big {
  width: 100%;
  padding: 16px;
  font-size: 16px;
}
.btn-mic {
  width: 100%;
  padding: 16px;
  background: var(--black);
  color: var(--white);
  border: none;
  border-radius: var(--radius);
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  transition: opacity 0.15s;
}
.btn-mic.listening {
  animation: pulse 1s infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}
.mic-status {
  font-size: 14px;
  color: var(--gray-600);
  text-align: center;
}
.speak-grade {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  width: 100%;
}

/* ─── SETTINGS ─── */
.settings-section { margin-bottom: 28px; }
.settings-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--gray-600);
  margin-bottom: 12px;
}
.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 0;
  border-bottom: 1px solid var(--gray-200);
  font-size: 15px;
}
.settings-row select {
  border: 1px solid var(--gray-200);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 14px;
  background: var(--white);
  cursor: pointer;
}
.settings-footer {
  margin-top: 40px;
  text-align: center;
  font-size: 13px;
  color: var(--gray-400);
  line-height: 1.8;
}

/* ─── MODALS ─── */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}
.modal.hidden { display: none; }
.modal-inner {
  background: var(--white);
  border-radius: 20px;
  padding: 36px 24px;
  width: 100%;
  max-width: 340px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  animation: modal-in 0.25s ease;
}
@keyframes modal-in {
  from { transform: scale(0.85); opacity: 0; }
  to   { transform: scale(1);    opacity: 1; }
}
.modal-big { font-size: 56px; line-height: 1; }
.modal-title { font-size: 22px; font-weight: 900; }
.modal-xp { font-size: 28px; font-weight: 700; }
.modal-stats { font-size: 14px; color: var(--gray-600); line-height: 1.8; }
.modal-unlock-name { font-size: 18px; font-weight: 700; }

/* ─── BOTTOM NAV ─── */
#bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0; right: 0;
  height: var(--nav-h);
  display: flex;
  border-top: 1px solid var(--gray-200);
  background: var(--white);
  z-index: 50;
}
#bottom-nav.hidden { display: none; }
.nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--gray-400);
  transition: color 0.15s;
  padding: 6px 0;
}
.nav-btn.active { color: var(--black); }
.nav-icon  { font-size: 20px; line-height: 1; }
.nav-label { font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; }

/* ─── Tip Card ─── */
.tip-title {
  font-size: 17px;
  font-weight: 700;
  margin-bottom: 12px;
  text-align: center;
}
.tip-body {
  font-size: 13px;
  line-height: 1.7;
  color: var(--gray-600);
  text-align: left;
}

/* ─── Scenario Card ─── */
.scenario-situation {
  font-size: 13px;
  color: var(--gray-600);
  text-align: center;
  margin-bottom: 10px;
  font-style: italic;
}
.scenario-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--gray-400);
  margin-bottom: 4px;
}

/* ─── Optional tag ─── */
.optional-tag {
  font-size: 10px;
  font-weight: 400;
  color: var(--gray-400);
  border: 1px solid var(--gray-200);
  border-radius: 4px;
  padding: 1px 5px;
  margin-left: 6px;
  vertical-align: middle;
}

/* ─── Utilities ─── */
.hidden { display: none !important; }

/* ─── Animations ─── */
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%       { transform: translateX(-8px); }
  40%       { transform: translateX(8px); }
  60%       { transform: translateX(-5px); }
  80%       { transform: translateX(5px); }
}
.shake { animation: shake 0.4s ease; }

@keyframes pop {
  0%   { transform: scale(1); }
  50%  { transform: scale(1.08); }
  100% { transform: scale(1); }
}
.pop { animation: pop 0.25s ease; }

/* ─── Conversations list ─── */
.convo-intro {
  font-size: 14px; color: var(--gray-600); margin-bottom: 20px; text-align: center;
}
.convo-list { display: flex; flex-direction: column; gap: 10px; }
.convo-card {
  display: flex; align-items: center; gap: 14px;
  padding: 16px; border: 1px solid var(--gray-200);
  border-radius: var(--radius); background: var(--white);
  text-align: left; width: 100%; cursor: pointer;
  transition: background 0.15s;
}
.convo-card:active { background: var(--gray-100); }
.convo-card-icon { font-size: 28px; line-height: 1; flex-shrink: 0; }
.convo-card-info { flex: 1; min-width: 0; }
.convo-card-title { font-size: 15px; font-weight: 700; }
.convo-card-sub { font-size: 12px; color: var(--gray-600); margin-top: 2px; }
.convo-arrow { font-size: 20px; color: var(--gray-400); flex-shrink: 0; }
.convo-done { font-size: 16px; color: var(--black); font-weight: 900; flex-shrink: 0; }

/* ─── Active conversation view ─── */
#view-convo {
  display: none; flex-direction: column; height: 100%;
}
#view-convo.active { display: flex; }

.convo-situation {
  padding: 10px 16px; background: var(--gray-100);
  font-size: 13px; color: var(--gray-600); line-height: 1.4;
  border-bottom: 1px solid var(--gray-200); flex-shrink: 0;
}

.convo-chat {
  flex: 1; overflow-y: auto; padding: 16px;
  display: flex; flex-direction: column; gap: 14px;
}

/* Chat bubbles */
.chat-bubble { max-width: 82%; word-break: break-word; }

.chat-bubble.narrator {
  align-self: center; text-align: center;
  font-size: 12px; color: var(--gray-500);
  font-style: italic; max-width: 90%; padding: 6px 0;
}

.chat-bubble.them {
  align-self: flex-start;
  background: var(--black); color: var(--white);
  border-radius: 4px 18px 18px 18px;
  padding: 12px 14px;
}
.bubble-jp { font-size: 17px; font-weight: 600; line-height: 1.4; }
.bubble-sub { font-size: 11px; color: rgba(255,255,255,0.65); margin-top: 5px; }

.chat-bubble.you {
  align-self: flex-end;
  background: var(--white); color: var(--black);
  border: 1.5px solid var(--black);
  border-radius: 18px 4px 18px 18px;
  padding: 10px 14px;
}
.chat-bubble.you.failed {
  border-color: var(--gray-400); color: var(--gray-500);
  text-decoration: line-through;
}
.bubble-you-text { font-size: 15px; font-weight: 500; }

/* Conversation footer (mic area) */
.convo-footer {
  flex-shrink: 0; display: flex; flex-direction: column;
  align-items: center; padding: 14px 20px 20px;
  border-top: 1px solid var(--gray-200); gap: 10px;
}
.convo-prompt {
  font-size: 13px; color: var(--gray-600); text-align: center;
  opacity: 0.4; transition: opacity 0.3s; min-height: 18px;
}

.convo-mic-btn {
  position: relative; width: 68px; height: 68px;
  border-radius: 50%; background: var(--black);
  border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: transform 0.15s;
}
.convo-mic-btn:active { transform: scale(0.93); }
.mic-glyph { font-size: 22px; color: var(--white); position: relative; z-index: 1; }

.mic-ripple {
  position: absolute; inset: 0; border-radius: 50%;
  background: var(--black); opacity: 0;
  transition: opacity 0.2s;
}
.convo-mic-btn.active .mic-ripple {
  animation: mic-pulse 1.4s ease-in-out infinite;
}
.convo-mic-btn.listening { background: #111; }
.convo-mic-btn.speaking { background: var(--gray-400); }

@keyframes mic-pulse {
  0%   { transform: scale(1);   opacity: 0.35; }
  50%  { transform: scale(1.5); opacity: 0; }
  100% { transform: scale(1);   opacity: 0; }
}

.convo-hint {
  display: none; font-size: 13px; color: var(--gray-600);
  text-align: center; padding: 0 12px;
}
.convo-model {
  display: none; text-align: center;
  background: var(--gray-100); border-radius: 10px;
  padding: 10px 16px; width: 100%;
}
.model-jp { font-size: 20px; font-weight: 700; }
.model-romaji { font-size: 13px; color: var(--gray-600); }
.convo-skip-wrap { display: none; }
.btn-sm { padding: 8px 20px; font-size: 14px; }

/* Conversation end screen */
.convo-end {
  display: none; flex-direction: column; align-items: center;
  justify-content: center; flex: 1;
  padding: 32px 24px; gap: 16px; text-align: center;
}
.convo-end-icon { font-size: 52px; }
.convo-end-msg { font-size: 18px; font-weight: 700; line-height: 1.4; }

/* ─── Safe area (notch) ─── */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  #bottom-nav {
    height: calc(var(--nav-h) + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
  }
}
