/* ==========================================================================
   RESET & DASAR GLOBAL — NihongoDo
   ========================================================================== */
*,
*::before,
*::after {
  box-sizing: border-box;
}
html,
body {
  margin: 0;
  padding: 0;
}

html {
  color-scheme: dark;
}
html[data-theme="light"] {
  color-scheme: light;
}

body {
  background: var(--color-bg);
  color: var(--color-ink);
  font-family: var(--font-body);
  font-size: var(--fs-base);
  line-height: 1.5;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  position: relative;
}

/* Tekstur kertas washi halus di seluruh latar */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  background-image: radial-gradient(
    circle at 1px 1px,
    rgba(245, 240, 228, 0.035) 1px,
    transparent 1px
  );
  background-size: 22px 22px;
  pointer-events: none;
  z-index: 0;
}

#app-root,
body > * {
  position: relative;
  z-index: 1;
}

a {
  color: var(--indigo-light);
  text-decoration: none;
  transition: color var(--dur-fast) var(--ease);
}
a:hover {
  color: var(--washi);
  text-decoration: underline;
}

img,
svg {
  max-width: 100%;
  display: block;
}

button,
input,
select,
textarea {
  font-family: inherit;
  color: inherit;
}
button {
  cursor: pointer;
  background: none;
  border: none;
}

hr,
.divider {
  height: 1px;
  background: var(--border);
  border: none;
  margin: var(--space-4) 0;
}

/* 4.7: #fff → var(--washi) */
::selection {
  background: var(--shu);
  color: var(--washi);
}

::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}
::-webkit-scrollbar-track {
  background: var(--ink-1);
}
::-webkit-scrollbar-thumb {
  background: var(--ink-5);
  border-radius: var(--radius-full);
  border: 2px solid var(--ink-1);
}
::-webkit-scrollbar-thumb:hover {
  background: var(--indigo-light);
}

.placeholder-note {
  border: 1px dashed var(--border-light);
  background: var(--color-surface);
  padding: var(--space-3);
  border-radius: var(--radius-sm);
  color: var(--text-faint);
  font-size: var(--fs-sm);
}

:focus-visible {
  outline: 2px solid var(--indigo-light);
  outline-offset: 2px;
  border-radius: var(--radius-xs);
}

/* Input pencarian — dipakai di banyak halaman */
.search-input {
  background: var(--ink-3);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--font-body);
  font-size: var(--fs-sm);
  padding: 7px 12px;
  outline: none;
  transition: border-color var(--dur-fast) var(--ease);
  width: 100%;
}
.search-input:focus {
  border-color: var(--indigo-light);
}
.search-input::placeholder {
  color: var(--text-ghost);
}

/* Utility */
.hidden {
  display: none !important;
}
.text-faint {
  color: var(--text-faint);
}
.text-soft {
  color: var(--text-soft);
}
.text-ghost {
  color: var(--text-ghost);
}
.font-mono {
  font-family: var(--font-mono);
}
.block {
  display: block;
}
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

/* ── Tombol dengarkan / speak (dipakai di grammar, vocab, kanji, kana, kamus) ── */
.speak-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  cursor: pointer;
  padding: 2px 5px;
  border-radius: var(--radius-sm);
  color: var(--text-ghost);
  font-size: 14px;
  line-height: 1;
  transition:
    color var(--dur-fast) var(--ease),
    background var(--dur-fast) var(--ease);
  vertical-align: middle;
}
.speak-btn:hover {
  color: var(--indigo-light);
  background: var(--indigo-ghost);
}
.speak-btn:active {
  transform: scale(0.92);
}

/* Speak button di sebelah teks contoh — ukuran lebih kecil */
.ex-speak {
  font-size: 11px;
  padding: 1px 3px;
  margin-left: 2px;
  color: var(--text-ghost);
  opacity: 0.6;
}
.ex-speak:hover {
  opacity: 1;
  color: var(--indigo-light);
  background: var(--indigo-ghost);
}

/* ── Label contoh kalimat (dipakai di grammar, vocab, kanji, kana) ── */
.ex-label {
  font-family: var(--font-mono);
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-ghost);
  margin-top: 6px;
  display: block;
}
.example-list li .ex-label:first-child,
.kanji-example-list li .ex-label:first-child {
  margin-top: 0;
}

/* UI-05: Utility classes pengganti inline styles yang telah dipindahkan ── */
/* stat-review: warna angka ulasan (merah cinnabar) */
.stat-review {
  color: var(--shu-light);
}
/* loading-placeholder: teks loading placeholder terpusat */
.loading-placeholder {
  text-align: center;
  padding: var(--space-5) var(--space-3);
}
/* filter-label: label di sebelah kontrol filter */
.filter-label {
  font-size: var(--fs-sm);
  color: var(--text-faint);
  align-self: center;
}
/* text-small: alias ukuran font kecil */
.text-small {
  font-size: var(--fs-sm);
}
/* ls-mode-row--centered: mode-row pemusatan konten */
.ls-mode-row--centered {
  margin-bottom: var(--space-4);
  justify-content: center;
}

/* UI-07: Transisi tema dark/light — aktif hanya setelah .theme-ready ────────
   Class ini ditambahkan oleh initTheme() setelah paint pertama selesai
   agar tidak ada animasi transisi saat halaman pertama kali dimuat.
   Hanya property WARNA yang di-transisi (bukan layout/geometry/transform)
   sehingga tidak menimpa transisi komponen yang sudah ada (c-button, link, dll).
   Tidak menggunakan !important agar komponen-spesifik tetap menang.
   ─────────────────────────────────────────────────────────────────────────── */

/* Elemen root: body, surface, card — biasanya tidak punya transition sendiri */
.theme-ready body,
.theme-ready main,
.theme-ready header,
.theme-ready footer,
.theme-ready nav,
.theme-ready aside,
.theme-ready section,
.theme-ready article,
.theme-ready [class*="page-"],
.theme-ready [class*="c-card"],
.theme-ready [class*="card-"],
.theme-ready [class*="-panel"],
.theme-ready [class*="-surface"] {
  transition:
    background-color 0.2s var(--ease),
    border-color 0.2s var(--ease);
}

/* Teks di elemen-elemen yang tidak punya transisi warna sendiri */
.theme-ready h1,
.theme-ready h2,
.theme-ready h3,
.theme-ready h4,
.theme-ready h5,
.theme-ready h6,
.theme-ready p,
.theme-ready li,
.theme-ready span,
.theme-ready label,
.theme-ready td,
.theme-ready th {
  transition: color 0.2s var(--ease);
}

/* Input/select/textarea — border-color saja (tidak overwrite focus transition) */
.theme-ready input,
.theme-ready select,
.theme-ready textarea {
  transition:
    background-color 0.2s var(--ease),
    border-color 0.15s var(--ease),
    color 0.2s var(--ease);
}

/* Hormati prefers-reduced-motion */
@media (prefers-reduced-motion: reduce) {
  .theme-ready * {
    transition-duration: 0s !important;
  }
}

/* Error state saat fetch data gagal (10.3) */
.fetch-error {
  text-align: center;
  padding: var(--space-5) var(--space-3);
  color: var(--text-faint);
  grid-column: 1 / -1;
}
.fetch-error p {
  margin: 0 0 var(--space-3);
  font-size: var(--fs-sm);
}
.fetch-error .c-button {
  display: inline-flex;
}

/* ── Stroke Order Animations ── */
@keyframes so-draw {
  to {
    stroke-dashoffset: 0;
  }
}
@keyframes so-spin {
  to {
    transform: rotate(360deg);
  }
}

/* ==========================================================================
   VIEW TRANSITIONS — animasi "swap" halus saat berpindah halaman.
   Progressive enhancement: browser yang belum mendukung akan mengabaikan
   @view-transition tanpa efek samping apa pun (aman default).
   ========================================================================== */
@view-transition {
  navigation: auto;
}

::view-transition-old(root) {
  animation: kfViewOut 0.28s var(--ease) both;
}
::view-transition-new(root) {
  animation: kfViewIn 0.32s var(--ease) both;
}

@keyframes kfViewOut {
  from {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
  to {
    opacity: 0;
    transform: translateY(-10px) scale(0.99);
  }
}
@keyframes kfViewIn {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.99);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@media (prefers-reduced-motion: reduce) {
  @view-transition {
    navigation: none;
  }
}
.component-load-error {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  padding: var(--space-3);
  color: var(--text-faint);
  background: var(--surface-2, transparent);
  border-bottom: 1px solid var(--border-subtle, currentColor);
  font-size: var(--fs-sm);
}
