/* =========================================================
   JLPT Story Dashboard — style.css
   Mobile-first, compact, no sidebar
   ========================================================= */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap');

/* ── Design tokens ─────────────────────────────────────── */
:root {
  --bg:        #080f1e;
  --panel:     #0d1626;
  --panel-2:   #141f33;
  --panel-3:   #1a2844;
  --line:      #243047;
  --text:      #e2e8f4;
  --muted:     #7a90b2;
  --accent:    #38bdf8;
  --accent-2:  #34d399;
  --accent-3:  #bd8c57;
  --danger:    #fb923c;
  --purple:    #a78bfa;
  --shadow:    0 16px 48px rgba(0,0,0,0.45);
  --shadow-sm: 0 4px 16px rgba(0,0,0,0.25);
  --radius:    16px;
  --radius-sm: 10px;
  --t: 0.2s cubic-bezier(.4,0,.2,1);
}

/* ── Reset ─────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

html {
  height: 100%;
  background: var(--bg);
  overscroll-behavior: none;
}

body {
  margin: 0;
  font-family: 'Inter', Arial, sans-serif;
  background: radial-gradient(ellipse at 20% 0%, #0a1628 0%, var(--bg) 70%);
  background-color: var(--bg);
  background-attachment: fixed;
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh;
  line-height: 1.6;
  overscroll-behavior: none;
  overscroll-behavior-y: none;
  overflow-x: hidden;
}

/* ── App shell — vertical stack ────────────────────────── */
.app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ── Brand inline (in generate bar) ───────────────────── */
.brand-inline {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 18px;
  font-weight: 800;
  letter-spacing: -0.3px;
  color: var(--accent);
  white-space: nowrap;
  text-decoration: none;
}
.brand-inline img {
  height: 24px;
  width: auto;
  border-radius: 4px;
}

/* ── Main ──────────────────────────────────────────────── */
main.main {
  flex: 1;
  padding: 16px;
  max-width: 960px;
  margin: 0 auto;
  width: 100%;
}

/* ── Generate bar ──────────────────────────────────────── */
.generate-bar {
  display: flex;
  align-items: center;
  justify-content: space-between; /* Logo left, actions right */
  position: relative;
  gap: 14px;
  margin-bottom: 16px;
}
.top-right-actions {
  position: absolute;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  gap: 10px;
}

.generate-bar-title {
  display: flex;
  align-items: center;
}

.generate-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

/* ── Shared select style ───────────────────────────────── */
.ctrl-select {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  font-size: 16px; /* Prevents auto-zoom on mobile */
  font-family: inherit;
  font-weight: 500;
  cursor: pointer;
  outline: none;
  transition: var(--t);
  -webkit-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%237a90b2' d='M1 1l5 5 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 28px;
}
.ctrl-select:focus { border-color: var(--accent); }
.ctrl-select optgroup { background: var(--panel-2); font-weight: 700; }
.ctrl-select option  { background: var(--panel-2); }

/* ── Switch ────────────────────────────────────────────── */
.switch {
  position: relative;
  display: inline-block;
  width: 36px;
  height: 20px;
}
.switch input { 
  opacity: 0;
  width: 0;
  height: 0;
}
.slider {
  position: absolute;
  cursor: pointer;
  top: 0; left: 0; right: 0; bottom: 0;
  background-color: var(--panel-2);
  border: 1px solid var(--line);
  transition: .3s;
}
.slider:before {
  position: absolute;
  content: "";
  height: 12px;
  width: 12px;
  left: 3px;
  bottom: 3px;
  background-color: var(--muted);
  transition: .3s;
}
input:checked + .slider {
  background-color: rgba(56,189,248,0.15);
  border-color: var(--accent);
}
input:checked + .slider:before {
  transform: translateX(16px);
  background-color: var(--accent);
}
.slider.round {
  border-radius: 20px;
}
.slider.round:before {
  border-radius: 50%;
}

/* ── Toggle buttons ────────────────────────────────────── */
.toggle-btn {
  padding: 6px 16px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: all var(--t);
  font-family: inherit;
}
@media (hover: hover) {
  .toggle-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: rgba(56,189,248,0.05);
  }
}

.toggle-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #080f1e;
  box-shadow: 0 0 12px rgba(56,189,248,0.3);
}

.hidden-line { display: none !important; }

/* ── Buttons ───────────────────────────────────────────── */
.primary-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: linear-gradient(135deg, var(--accent) 0%, #60a5fa 100%);
  color: #080f1e;
  border: none;
  border-radius: var(--radius-sm);
  padding: 9px 18px;
  font-size: 14px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(56,189,248,0.3);
  transition: var(--t);
  white-space: nowrap;
  text-decoration: none;
}
.primary-btn:hover { transform: translateY(-1px); box-shadow: 0 6px 20px rgba(56,189,248,0.4); }
.primary-btn:active { transform: translateY(0); }
.primary-btn:disabled { opacity: 0.6; cursor: not-allowed; transform: none; }

.tts-all-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;  
  color: #080f1e;
  border: none;
  border-radius: var(--radius-sm);
  padding: 14px;
  font-size: 13px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(52,211,153,0.25);
  transition: var(--t);
}
.tts-all-btn:hover { transform: translateY(-1px); }
.tts-all-btn:disabled { opacity: 0.6; cursor: not-allowed; transform: none; }

.tts-all-btn.reading-active {
  background: rgba(239, 68, 68, 0.15) !important;
  color: #ef4444 !important;
  border: 1px solid rgba(239, 68, 68, 0.4) !important;
  box-shadow: 0 4px 12px rgba(239, 68, 68, 0.25) !important;
  opacity: 1 !important;
}

.stop-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(251,146,60,0.15);
  color: var(--danger);
  border: 1px solid rgba(251,146,60,0.3);
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  transition: var(--t);
}
.stop-btn:hover { background: rgba(251,146,60,0.25); }

/* ── Card ──────────────────────────────────────────────── */
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.lib-wrapper {
  padding: 16px;
}

.card-header {
  padding: 13px 16px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.card-header strong { font-size: 13px; font-weight: 700; }
.card-body { padding: 14px; }


/* ── Badges ────────────────────────────────────────────── */
.badge-row { display: flex; gap: 5px; flex-wrap: wrap; margin: 8px 0 10px; }
.badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 999px;
  background: rgba(148,163,184,0.1);
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  border: 1px solid var(--line);
}
.badge.accent { background: rgba(56,189,248,0.1);  color: var(--accent);   border-color: rgba(56,189,248,0.2); }
.badge.green  { background: rgba(52,211,153,0.1);  color: var(--accent-2); border-color: rgba(52,211,153,0.2); }
.badge.purple { background: rgba(167,139,250,0.1); color: var(--purple); border-color: rgba(167,139,250,0.2); }
.badge.level-n5    { background: rgba(52,211,153,0.1); color: #4ade80; border-color: rgba(52,211,153,0.2); }
.badge.level-n5-n4 { background: rgba(59,130,246,0.1); color: #60a5fa; border-color: rgba(59,130,246,0.2); }
.badge.level-n4    { background: rgba(250,204,21,0.1); color: #facc15; border-color: rgba(250,204,21,0.2); }
.badge.level-n4-n3 { background: rgba(249,115,22,0.1); color: #fb923c; border-color: rgba(249,115,22,0.2); }
.badge.level-n3    { background: rgba(239,68,68,0.1); color: #f87171; border-color: rgba(239,68,68,0.2); }


/* ── Empty state ───────────────────────────────────────── */
.detail-empty {
  min-height: 260px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 30px;
  color: var(--muted);
}
.detail-empty .icon-big { font-size: 36px; margin-bottom: 12px; opacity: 0.5; }
.detail-empty h3 { margin: 0 0 6px; color: var(--text); font-size: 16px; }
.detail-empty p  { margin: 0; font-size: 13px; }

/* ── Detail view ───────────────────────────────────────── */
.detail-view { display: none; }
.detail-view.active { display: block; }

.detail-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.detail-top h2 { margin: 0 0 5px; font-size: 17px; font-weight: 800; }

/* ── Tabs ──────────────────────────────────────────────── */
.tabs {
  display: flex;
  padding: 0;
  border-bottom: 2px solid var(--line);
}
.tab-btn {
  flex: 1;
  background: transparent;
  color: var(--muted);
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  padding: 13px 10px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
  font-family: inherit;
  transition: var(--t);
  white-space: nowrap;
  text-align: center;
}
.tab-btn:hover { color: var(--text); background: rgba(255,255,255,0.03); }
.tab-btn.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  background: rgba(56,189,248,0.04);
}

/* ── Tab panels ────────────────────────────────────────── */
.tab-panel { display: none; padding: 14px; }
.tab-panel.active { display: block; }

/* ── Story tab header ──────────────────────────────────── */
.story-tab-header {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-bottom: 14px;
  flex-wrap: wrap;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}
.tts-progress { font-size: 16px; color: var(--accent-2); font-weight: 700; }

/* ── Lists ─────────────────────────────────────────────── */
.word-list, .quiz-list { display: grid; gap: 10px; }

.story-lines {
  display: grid;
  gap: 10px;
  position: relative;
  max-height: 60vh;
  overflow-y: auto;
  padding-right: 6px;
}
.story-lines::-webkit-scrollbar { width: 6px; }
.story-lines::-webkit-scrollbar-track { background: rgba(0,0,0,0.1); border-radius: 10px; }
.story-lines::-webkit-scrollbar-thumb { background: var(--line); border-radius: 10px; }
.story-lines::-webkit-scrollbar-thumb:hover { background: var(--muted); }

.word-item, .line-item, .quiz-item {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  background: rgba(255,255,255,0.02);
  transition: border-color var(--t);
}
.line-item.playing {
  border-color: var(--accent-2);
  background: rgba(52,211,153,0.05);
}
.line-item.marked {
  border-color: #ef4444;
  background: rgba(239, 68, 68, 0.05);
}

.line-num { font-size: 10px; font-weight: 700; color: var(--accent); margin-bottom: 4px; letter-spacing: 0.4px; text-transform: uppercase; }
.jp-line  { font-size: 28px; line-height: 1.9; margin-bottom: 5px; font-weight: 500; }
.jp-only-text {
  /*white-space: pre-wrap;*/
  font-size: 1.8rem;
  line-height: 1.8;
  padding: 15px;
  font-weight: 500;
}

.hiragana-line { font-size: 24px; color: var(--accent-2); margin-bottom: 5px; font-weight: 500; opacity: 0.9; }
.romaji-line { font-size: 18px; color: var(--muted); margin-bottom: 5px; font-weight: 400; opacity: 0.8; }
.en-line  { color: #bd8c57; font-size: 20px; line-height: 1.7; }

.word-jp     { font-size: 22px; font-weight: 700; margin-bottom: 2px; }
.word-romaji { font-size: 14px; color: var(--accent); font-weight: 500; margin-bottom: 3px; letter-spacing: 0.3px; }
.word-en     { color: var(--muted); font-size: 14px; }

/* ── Quiz ──────────────────────────────────────────────── */
.quiz-question { font-size: 18px; font-weight: 700; margin-bottom: 12px; line-height: 1.5; }
.q-prefix { color: #ef4444; margin-right: 4px; }

.choice-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
  margin-bottom: 10px;
}
.choice-btn {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  cursor: pointer;
  font-size: 15px;
  font-family: inherit;
  font-weight: 500;
  transition: var(--t);
  text-align: left;
}
.choice-btn:hover { border-color: var(--accent); background: rgba(56,189,248,0.07); }
.choice-btn.correct-choice { border-color: var(--accent-2); background: rgba(52,211,153,0.1); color: var(--accent-2); }
.choice-btn.wrong-choice   { border-color: var(--danger);   background: rgba(251,146,60,0.08); color: var(--danger); }
.choice-btn:disabled { cursor: not-allowed; }

.result {
  font-size: 12px;
  font-weight: 700;
  padding: 6px 10px;
  border-radius: 7px;
}
.result.correct   { color: #4ade80; background: rgba(74,222,128,0.09); }
.result.incorrect { color: #fca5a5; background: rgba(252,165,165,0.09); }

/* ── Save button ───────────────────────────────────────── */
.save-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(52,211,153,0.12);
  color: var(--accent-2);
  border: 1px solid rgba(52,211,153,0.3);
  border-radius: var(--radius-sm);
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  transition: var(--t);
  white-space: nowrap;
  margin-top: 8px;
}
.save-btn:hover:not(:disabled) { background: rgba(52,211,153,0.22); transform: translateY(-1px); }
.save-btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }
.save-btn.saved {
  background: rgba(52,211,153,0.08);
  color: var(--accent-2);
  border-color: rgba(52,211,153,0.2);
  cursor: default;
}

/* ── Library link ──────────────────────────────────────── */
.lib-link {
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
  text-decoration: none;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--panel-2);
  transition: var(--t);
  white-space: nowrap;
  margin-left: 10px;
}
.lib-link:hover { color: var(--accent); border-color: rgba(56,189,248,0.3); background: rgba(56,189,248,0.06); }

/* ── Spinner ───────────────────────────────────────────── */
.spinner {
  display: inline-block;
  width: 13px; height: 13px;
  border: 2px solid rgba(8,15,30,0.3);
  border-top-color: #080f1e;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Toast ─────────────────────────────────────────────── */
#toast {
  position: fixed;
  bottom: 20px; right: 16px;
  background: var(--panel-3);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 11px 16px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 0.3s, transform 0.3s;
  z-index: 9999;
  max-width: 300px;
  pointer-events: none;
}
#toast.show    { opacity: 1; transform: translateY(0); }
#toast.error   { 
  border-color: #ef4444; 
  color: #fff; 
  background: #ef4444; 
  box-shadow: 0 10px 30px rgba(239, 68, 68, 0.4);
  font-weight: 700;
  max-width: 400px;
}
#toast.success { border-color: var(--accent-2); color: var(--accent-2); }

/* ── Shake Animation ── */
.error-shake {
  animation: shake 0.4s cubic-bezier(.36,.07,.19,.97) both;
  border-color: #ef4444 !important;
}

@keyframes shake {
  10%, 90% { transform: translate3d(-1px, 0, 0); }
  20%, 80% { transform: translate3d(2px, 0, 0); }
  30%, 50%, 70% { transform: translate3d(-4px, 0, 0); }
  40%, 60% { transform: translate3d(4px, 0, 0); }
}

/* ── Shadow FAB ───────────────────────────────────────── */
.shadow-fab {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 75px;
  height: 75px;
  border-radius: 50%;
  border: none;  
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  z-index: 1000; 
}
.shadow-fab svg {
  width: 32px;
  height: 32px;
  fill: currentColor;  
}
.shadow-fab.paused {
  background: linear-gradient(135deg, #ef4444 0%, #f87171 100%);
  color: white;
}
.shadow-fab.playing {
  background: linear-gradient(135deg, #facc15 0%, #eab308 100%);
  color: #080f1e;
}

/* ── Guess Tab ────────────────────────────────────────── */
.guess-counter {
  margin-left: auto;
  font-size: 18px;
  font-weight: 700;
  color: var(--accent);
}

.guess-jp {
  font-size: 33px;
  font-weight: 700;
  margin-bottom: 24px;
  line-height: 1.6;
  transition: filter 0.3s ease;
}
.guess-jp.blurry {
  filter: blur(10px);
  -webkit-filter: blur(10px);
  opacity: 0.5;
  user-select: none;
  pointer-events: none;
  transform: scale(0.98);
}
.guess-en {
  font-size: 26px;
  color: var(--muted);
  line-height: 1.5;
}

.nav-arrow-btn {
  background: var(--panel-2);
  color: var(--accent);
  border: 1px solid var(--line);
  border-radius: 50%;
  width: 55px;
  height: 55px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  cursor: pointer;
  transition: all var(--t);
  box-shadow: var(--shadow-sm);
  outline: none;
}
@media (hover: hover) {
  .nav-arrow-btn:hover {
    background: var(--panel-3);
    border-color: var(--accent);
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(56,189,248,0.2);
  }
}
.nav-arrow-btn:active {
  transform: translateY(0) scale(0.95);
}

@keyframes slideUpFade {
  0% { opacity: 0; transform: translateY(15px); }
  100% { opacity: 1; transform: translateY(0); }
}
.animate-enter {
  animation: slideUpFade 0.5s cubic-bezier(0.2, 1, 0.3, 1) forwards;
}

/* ── Wide screens: 2-col grid ──────────────────────────── */
@media (min-width: 720px) {
  main.main { padding: 20px 24px; }

  .generate-bar { flex-wrap: nowrap; }

  .word-list { grid-template-columns: 1fr 1fr; }

  .choice-grid { grid-template-columns: 1fr 1fr; }
}

/* ── Narrow phones ─────────────────────────────────────── */
@media (max-width: 480px) {
  .generate-bar { flex-direction: row; justify-content: space-between; align-items: center; }
  .generate-bar-title { justify-content: flex-start; width: auto; margin-bottom: 0; }
  .generate-controls { flex-direction: column; width: 100%; gap: 10px; }
  .ctrl-select { font-size: 16px; padding: 12px 14px; padding-right: 28px; width: 100%; }
  .primary-btn { padding: 12px 14px; font-size: 15px; width: 100%; justify-content: center; }
  .top-right-actions { position: static; transform: none; width: auto; justify-content: flex-end; }
  .choice-grid { grid-template-columns: 1fr; }
  .choice-btn { padding: 16px 12px; font-size: 16px; }
  .shadow-fab {
    bottom: 202px;
    right: 20px;
    width: 70px;
    height: 70px;
    font-size: 20px;
  }
  .jp-only-text {
    font-size: 27px;
    padding: 10px;
  }
  .lib-wrapper {
    padding: 0;
    background: transparent;
    border: none;
    box-shadow: none;
  }
  .guess-counter {
    margin-left: 0;
    flex: 1;
    text-align: center;
  }
  main.main {
    padding-bottom: 100px;
  }
}

