/* ═══════════════════════════════════════════
   nihongo-study — main stylesheet
   ═══════════════════════════════════════════ */

:root {
  --red:       #C0392B;
  --red-dark:  #962d22;
  --red-light: #e74c3c;
  --ink:       #0D0D0F;
  --ink2:      #1a1a1e;
  --ink3:      #2a2a30;
  --ivory:     #F5F0E8;
  --ivory2:    #EDE8DF;
  --ivory3:    #D5CFCA;
  --muted:     #8a8070;
  --muted2:    #b0a898;
  --gold:      #C9A84C;
  --green:     #2ecc71;
  --green-dark:#27ae60;
  --blue:      #3498db;
  --font-jp:   'Noto Serif JP', 'Hiragino Mincho ProN', 'Yu Mincho', serif;
  --font-ui:   'Segoe UI', system-ui, -apple-system, sans-serif;
  --radius:    10px;
  --radius-lg: 16px;
  --tr:        0.2s ease;
}

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

body {
  background: var(--ink);
  color: var(--ivory);
  font-family: var(--font-ui);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ─── SCROLLBAR ─── */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #ffffff18; border-radius: 3px; }

/* ─── HEADER ─── */
header {
  background: var(--ink2);
  border-bottom: 1px solid #ffffff0f;
  padding: 0 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 58px;
  position: sticky; top: 0; z-index: 100;
  gap: 1rem;
}

.logo {
  display: flex; align-items: center; gap: 10px;
  text-decoration: none; color: inherit;
  flex-shrink: 0;
}
.logo-kanji { font-family: var(--font-jp); font-size: 22px; color: var(--red); line-height: 1; }
.logo-text  { font-size: 14px; font-weight: 600; letter-spacing: 0.02em; }
.logo-sub   { font-size: 10px; color: var(--muted); display: block; font-weight: 400; }

.header-right { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }

.lang-toggle {
  display: flex; gap: 3px;
  background: var(--ink3);
  border-radius: 8px; padding: 3px;
}
.lang-btn {
  padding: 4px 11px; border-radius: 6px; border: none;
  cursor: pointer; font-size: 12px; font-weight: 600;
  background: transparent; color: var(--muted); transition: var(--tr);
}
.lang-btn.active { background: var(--red); color: #fff; }

.header-status {
  font-size: 11px; color: var(--muted);
  white-space: nowrap;
}
.header-status.ok { color: var(--green); }
.header-status.err { color: var(--red-light); }

/* ─── LAYOUT ─── */
.app-shell { display: flex; flex: 1; overflow: hidden; min-height: 0; }

aside {
  width: 210px; min-width: 210px;
  background: var(--ink2);
  border-right: 1px solid #ffffff0a;
  padding: 1.25rem 0;
  display: flex; flex-direction: column; gap: 2px;
  overflow-y: auto;
}

main {
  flex: 1; overflow-y: auto;
  padding: 2rem 2.5rem;
}

/* ─── SIDEBAR NAV ─── */
.nav-label {
  font-size: 10px; font-weight: 700; letter-spacing: 0.1em;
  color: var(--muted); text-transform: uppercase;
  padding: 0.75rem 1.25rem 0.3rem;
}

.nav-item {
  display: flex; align-items: center; gap: 9px;
  padding: 8px 1.25rem; cursor: pointer;
  border: none; background: none; width: 100%; text-align: left;
  color: var(--ivory3); font-size: 13px; position: relative;
  transition: var(--tr); font-family: inherit;
}
.nav-item:hover { background: #ffffff07; color: var(--ivory); }
.nav-item.active { background: #c0392b15; color: var(--red-light); }
.nav-item.active::before {
  content: ''; position: absolute; left: 0; top: 0; bottom: 0;
  width: 3px; background: var(--red); border-radius: 0 2px 2px 0;
}

.jlpt-badge {
  font-size: 10px; font-weight: 700; padding: 2px 7px;
  border-radius: 5px; margin-left: auto;
}
.N5 { background:#2ecc7120; color:#2ecc71; }
.N4 { background:#3498db20; color:#3498db; }
.N3 { background:#f39c1220; color:#f39c12; }
.N2 { background:#e67e2220; color:#e67e22; }
.N1 { background:#e74c3c20; color:#e74c3c; }

/* ─── MOBILE NAV ─── */
.mobile-nav {
  display: none;
  overflow-x: auto; gap: 4px;
  padding: 0.65rem 1rem;
  background: var(--ink2);
  border-bottom: 1px solid #ffffff0a;
  scrollbar-width: none;
}
.mobile-nav::-webkit-scrollbar { display: none; }
.mob-btn {
  padding: 5px 14px; border-radius: 20px;
  border: 1px solid #ffffff12; background: transparent;
  color: var(--muted2); font-size: 12px; font-weight: 600;
  white-space: nowrap; cursor: pointer; flex-shrink: 0; font-family: inherit;
  transition: var(--tr);
}
.mob-btn.active { background: var(--red); border-color: var(--red); color: #fff; }

/* ─── WORD OF THE DAY ─── */
.wotd {
  background: var(--ink2);
  border: 1px solid #c0392b33;
  border-radius: var(--radius-lg);
  padding: 1.75rem 2rem;
  margin-bottom: 2rem;
  position: relative; overflow: hidden;
}
.wotd::after {
  content: '今日'; position: absolute;
  right: -8px; top: -12px;
  font-family: var(--font-jp); font-size: 90px;
  color: #ffffff04; pointer-events: none; user-select: none; line-height: 1;
}
.wotd-eyebrow {
  font-size: 10px; font-weight: 700; letter-spacing: 0.12em;
  text-transform: uppercase; color: var(--red-light); margin-bottom: 0.75rem;
  display: flex; align-items: center; gap: 8px;
}
.wotd-eyebrow span { flex: 1; height: 1px; background: #c0392b30; }
.wotd-kanji { font-family: var(--font-jp); font-size: 56px; line-height: 1; margin-bottom: 4px; }
.wotd-reading { font-family: var(--font-jp); font-size: 17px; color: var(--muted2); margin-bottom: 8px; }
.wotd-pos {
  display: inline-block; font-size: 11px; padding: 2px 8px;
  background: #ffffff0c; border-radius: 4px; color: var(--muted); margin-bottom: 12px;
}
.wotd-reveal-row { display: flex; align-items: center; gap: 12px; }
.reveal-btn {
  padding: 7px 16px; border-radius: 8px;
  background: var(--red); color: #fff; border: none;
  cursor: pointer; font-size: 13px; font-weight: 600;
  transition: var(--tr); font-family: inherit;
}
.reveal-btn:hover { background: var(--red-light); }
.wotd-trans {
  font-size: 18px; font-weight: 600; color: var(--gold);
  opacity: 0; transition: opacity 0.3s;
}
.wotd-trans.show { opacity: 1; }
.wotd-example {
  margin-top: 12px; font-size: 13px; color: var(--muted2);
  line-height: 1.6; border-top: 1px solid #ffffff0c; padding-top: 10px;
}
.wotd-example .jp { font-family: var(--font-jp); color: var(--ivory3); margin-bottom: 2px; }

/* ─── LEVEL GRID (home) ─── */
.level-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px,1fr));
  gap: 10px; margin-bottom: 2rem;
}
.level-card {
  background: var(--ink2); border-radius: var(--radius-lg);
  padding: 1.25rem 1rem; text-align: center; cursor: pointer;
  border: 1px solid transparent; transition: var(--tr);
  font-family: inherit;
}
.level-card:hover { transform: translateY(-2px); }
.level-card .icon { font-family: var(--font-jp); font-size: 30px; margin-bottom: 4px; }
.level-card .name { font-size: 18px; font-weight: 700; margin-bottom: 2px; }
.level-card .count { font-size: 12px; color: var(--muted); }

/* ─── SECTION HEADER ─── */
.section-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 1.5rem; gap: 1rem; flex-wrap: wrap;
}
.section-title {
  font-size: 18px; font-weight: 700;
  display: flex; align-items: center; gap: 10px;
}

.mode-tabs {
  display: flex; gap: 3px; background: var(--ink3);
  border-radius: 8px; padding: 3px;
}
.mode-tab {
  padding: 5px 13px; border-radius: 6px; border: none;
  cursor: pointer; font-size: 12px; font-weight: 600;
  background: transparent; color: var(--muted); transition: var(--tr);
  font-family: inherit;
}
.mode-tab.active { background: var(--ink2); color: var(--ivory); }

/* ─── SEARCH ─── */
.search-bar { display: flex; gap: 8px; margin-bottom: 1.25rem; }
.search-input {
  flex: 1; padding: 9px 14px; border-radius: 8px;
  border: 1px solid #ffffff12; background: var(--ink2);
  color: var(--ivory); font-size: 14px; outline: none;
  transition: var(--tr); font-family: inherit;
}
.search-input::placeholder { color: var(--muted); }
.search-input:focus { border-color: #c0392b88; }

/* ─── VOCAB GRID ─── */
.vocab-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px,1fr));
  gap: 10px;
}
.vocab-card {
  background: var(--ink2); border: 1px solid #ffffff0c;
  border-radius: var(--radius); padding: 1rem 1.1rem;
  transition: var(--tr);
}
.vocab-card:hover { border-color: #c0392b44; background: #1a1a22; }

.vc-kanji  { font-family: var(--font-jp); font-size: 26px; line-height: 1.2; margin-bottom: 2px; }
.vc-read   { font-family: var(--font-jp); font-size: 12px; color: var(--muted2); margin-bottom: 6px; }
.vc-pos    { font-size: 10px; padding: 2px 6px; border-radius: 4px; background: #ffffff08; color: var(--muted); display: inline-block; margin-bottom: 8px; }
.vc-trans  { font-size: 14px; color: var(--gold); cursor: pointer; min-height: 20px; }
.vc-masked { color: transparent; background: #ffffff0c; border-radius: 3px; user-select: none; }
.vc-more   { font-size: 11px; color: var(--muted); background: none; border: none; cursor: pointer; padding: 4px 0 0; font-family: inherit; }
.vc-example { display: none; margin-top: 8px; font-size: 12px; color: var(--muted); line-height: 1.5; }
.vc-example.open { display: block; }
.vc-example .jp { font-family: var(--font-jp); color: var(--muted2); font-size: 13px; }

/* ─── FLASHCARD ─── */
.fc-wrap { display: flex; flex-direction: column; align-items: center; padding: 1.5rem 0; }
.fc-progress { width: 100%; max-width: 460px; height: 3px; background: var(--ink3); border-radius: 2px; margin-bottom: 1.5rem; overflow: hidden; }
.fc-bar { height: 100%; background: var(--red); transition: width 0.3s; }

.fc-card { width: 100%; max-width: 460px; height: 260px; perspective: 1000px; cursor: pointer; margin-bottom: 1.5rem; }
.fc-inner { width: 100%; height: 100%; transition: transform 0.45s; transform-style: preserve-3d; position: relative; }
.fc-card.flipped .fc-inner { transform: rotateY(180deg); }
.fc-face {
  position: absolute; width: 100%; height: 100%;
  backface-visibility: hidden;
  background: var(--ink2); border: 1px solid #ffffff12;
  border-radius: var(--radius-lg);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 1.5rem; text-align: center;
}
.fc-back { transform: rotateY(180deg); }
.fc-kanji  { font-family: var(--font-jp); font-size: 52px; line-height: 1; margin-bottom: 6px; }
.fc-read   { font-family: var(--font-jp); font-size: 17px; color: var(--muted2); }
.fc-hint   { font-size: 11px; color: var(--muted); margin-top: 12px; }
.fc-trans  { font-size: 22px; font-weight: 700; color: var(--gold); margin-bottom: 4px; }
.fc-pos2   { font-size: 12px; color: var(--muted); }
.fc-ex     { font-family: var(--font-jp); font-size: 12px; color: var(--muted2); margin-top: 10px; line-height: 1.5; }

.fc-controls { display: flex; gap: 10px; align-items: center; }
.fc-btn { padding: 9px 20px; border-radius: 8px; border: none; cursor: pointer; font-size: 13px; font-weight: 600; transition: var(--tr); font-family: inherit; }
.fc-prev { background: var(--ink3); color: var(--ivory3); }
.fc-next { background: var(--red); color: #fff; }
.fc-btn:hover { opacity: 0.85; }
.fc-counter { font-size: 13px; color: var(--muted); min-width: 60px; text-align: center; }

/* ─── QUIZ ─── */
.quiz-wrap { max-width: 540px; }
.quiz-scorebar { display: flex; align-items: center; gap: 10px; margin-bottom: 1.25rem; }
.quiz-score-text { font-size: 13px; color: var(--muted); }
.quiz-score-pill { margin-left: auto; font-size: 13px; font-weight: 700; padding: 3px 12px; border-radius: 20px; background: #c0392b20; color: var(--red-light); }

.quiz-q { background: var(--ink2); border: 1px solid #ffffff0c; border-radius: var(--radius-lg); padding: 1.75rem; text-align: center; margin-bottom: 1.25rem; }
.quiz-kanji { font-family: var(--font-jp); font-size: 50px; line-height: 1; margin-bottom: 4px; }
.quiz-read  { font-family: var(--font-jp); font-size: 15px; color: var(--muted2); }
.quiz-pos   { font-size: 11px; color: var(--muted); margin-top: 4px; }

.quiz-opts { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 1.25rem; }
.quiz-opt {
  padding: 13px 14px; border-radius: var(--radius);
  border: 1px solid #ffffff12; background: var(--ink2);
  color: var(--ivory); cursor: pointer; font-size: 14px; font-weight: 500;
  text-align: center; transition: var(--tr); font-family: inherit; line-height: 1.3;
}
.quiz-opt:hover:not(.done) { border-color: var(--red); background: #c0392b15; }
.quiz-opt.correct { background: #27ae6020; border-color: var(--green); color: var(--green); }
.quiz-opt.wrong   { background: #c0392b20; border-color: var(--red); color: var(--red-light); }
.quiz-opt.done    { cursor: default; }

.quiz-next { width: 100%; padding: 11px; border-radius: 8px; background: var(--red); color: #fff; border: none; cursor: pointer; font-size: 14px; font-weight: 700; display: none; transition: var(--tr); font-family: inherit; }
.quiz-next.show { display: block; }
.quiz-next:hover { background: var(--red-light); }

/* ─── WRITE ─── */
.write-wrap { max-width: 540px; }
.write-prog { display: flex; align-items: center; gap: 8px; margin-bottom: 1rem; }
.write-prog-text { font-size: 13px; color: var(--muted); }
.write-prog-bar { flex: 1; height: 3px; background: var(--ink3); border-radius: 2px; overflow: hidden; }
.write-prog-fill { height: 100%; background: var(--red); transition: width 0.3s; }

.write-q { background: var(--ink2); border: 1px solid #ffffff0c; border-radius: var(--radius-lg); padding: 1.75rem; text-align: center; margin-bottom: 1rem; }
.write-kanji { font-family: var(--font-jp); font-size: 52px; line-height: 1; }
.write-read  { font-family: var(--font-jp); font-size: 15px; color: var(--muted2); margin-top: 4px; }
.write-pos   { font-size: 11px; color: var(--muted); margin-top: 4px; }

.write-row { display: flex; gap: 8px; margin-bottom: 1rem; }
.write-input {
  flex: 1; padding: 11px 14px; border-radius: 8px;
  border: 1px solid #ffffff15; background: var(--ink2);
  color: var(--ivory); font-size: 15px; outline: none;
  transition: var(--tr); font-family: inherit;
}
.write-input::placeholder { color: var(--muted); }
.write-input:focus { border-color: #c0392b88; }
.write-submit { padding: 11px 18px; border-radius: 8px; background: var(--red); color: #fff; border: none; cursor: pointer; font-size: 14px; font-weight: 700; transition: var(--tr); font-family: inherit; }
.write-submit:hover { background: var(--red-light); }

.write-feedback { padding: 11px 14px; border-radius: 8px; font-size: 14px; font-weight: 600; text-align: center; display: none; margin-bottom: 10px; }
.write-feedback.ok  { background: #27ae6020; border: 1px solid var(--green); color: var(--green); display: block; }
.write-feedback.err { background: #c0392b20; border: 1px solid var(--red); color: var(--red-light); display: block; }
.write-ans { font-size: 13px; color: var(--muted); margin-bottom: 10px; display: none; }
.write-next { width: 100%; padding: 11px; border-radius: 8px; background: var(--ink3); color: var(--ivory); border: none; cursor: pointer; font-size: 14px; font-weight: 600; display: none; font-family: inherit; margin-bottom: 10px; transition: var(--tr); }
.write-next.show { display: block; }
.write-next:hover { background: var(--ink); }
.write-tip { font-size: 11px; color: var(--muted); }

/* ─── TIPS CARD (home) ─── */
.tips-card { background: var(--ink2); border-radius: var(--radius); padding: 1.25rem; border: 1px solid #ffffff0a; }
.tips-title { font-size: 11px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; margin-bottom: .75rem; }
.tips-list { display: flex; flex-direction: column; gap: 7px; font-size: 13px; color: var(--muted2); line-height: 1.5; }
.tips-list strong { color: var(--ivory3); }

/* ─── EMPTY / LOADING ─── */
.empty { text-align: center; padding: 3rem 1rem; color: var(--muted); grid-column: 1/-1; }
.empty .icon { font-size: 44px; margin-bottom: 12px; }
.loading-msg { text-align: center; padding: 4rem 1rem; color: var(--muted); }
.loading-dot { display: inline-block; animation: blink 1.2s infinite; }
.loading-dot:nth-child(2) { animation-delay: .2s; }
.loading-dot:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%,80%,100% { opacity: 0.2; } 40% { opacity: 1; } }

/* ─── ANIMATIONS ─── */
@keyframes fadeUp { from { opacity:0; transform:translateY(8px); } to { opacity:1; transform:translateY(0); } }
.fade-up { animation: fadeUp 0.25s ease forwards; }

/* ─── RESPONSIVE ─── */
@media (max-width: 768px) {
  aside { display: none; }
  .mobile-nav { display: flex; }
  main { padding: 1rem; }
  .wotd { padding: 1.25rem; }
  .wotd-kanji { font-size: 42px; }
  .vocab-grid { grid-template-columns: 1fr; }
  .quiz-opts { grid-template-columns: 1fr; }
  header { padding: 0 1rem; }
  .mode-tabs { flex-wrap: wrap; }
  .fc-card { height: 240px; }
  .section-header { flex-direction: column; align-items: flex-start; }
}
@media (max-width: 480px) {
  .level-grid { grid-template-columns: repeat(3, 1fr); }
  .logo-text { display: none; }
}
