:root {
  --bg0: #e8f2f4;
  --bg1: #d4e8ec;
  --ink: #0f2a32;
  --ink-soft: #3d5a63;
  --line: rgba(15, 42, 50, 0.12);
  --surface: rgba(255, 255, 255, 0.82);
  --surface-solid: #f7fbfd;
  --accent: #0b6e78;
  --accent-soft: #c5e6ea;
  --again: #b42318;
  --hard: #b54708;
  --good: #027a48;
  --easy: #175cd3;
  --shadow: 0 12px 40px rgba(15, 42, 50, 0.1);
  --radius: 18px;
  --font-ui: "Outfit", "Noto Sans JP", sans-serif;
  --font-body: "Noto Sans JP", sans-serif;
  --font-he: "Noto Sans Hebrew", "Noto Sans JP", sans-serif;
  --font-zh: "Noto Sans SC", "Noto Sans JP", sans-serif;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: var(--font-body);
  color: var(--ink);
  background:
    radial-gradient(1200px 600px at 10% -10%, #b8dde4 0%, transparent 55%),
    radial-gradient(900px 500px at 100% 0%, #9fd0c8 0%, transparent 50%),
    linear-gradient(165deg, var(--bg0), var(--bg1));
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}

.app {
  width: min(560px, 100%);
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: 0 16px calc(20px + var(--safe-bottom));
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 0 12px;
  position: sticky;
  top: 0;
  z-index: 10;
  backdrop-filter: blur(10px);
  background: linear-gradient(to bottom, rgba(232, 242, 244, 0.92), rgba(232, 242, 244, 0.7) 70%, transparent);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 0;
}

.brand-mark {
  width: 28px;
  height: 28px;
  border-radius: 9px;
  background:
    linear-gradient(135deg, #0b6e78 0%, #1a9aa5 55%, #7ec8c4 100%);
  box-shadow: 0 4px 12px rgba(11, 110, 120, 0.35);
}

.brand-name {
  font-family: var(--font-ui);
  font-weight: 800;
  font-size: 1.15rem;
  letter-spacing: -0.02em;
}

.nav {
  display: flex;
  gap: 4px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px;
}

.nav-btn {
  font-family: var(--font-ui);
  font-size: 0.8rem;
  font-weight: 600;
  padding: 7px 11px;
  border-radius: 999px;
  color: var(--ink-soft);
}

.nav-btn[aria-current="page"] {
  background: var(--ink);
  color: #fff;
}

.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding-bottom: 8px;
}

.view-title {
  font-family: var(--font-ui);
  font-size: 1.55rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  margin: 4px 0 0;
}

.view-lead {
  margin: 0;
  color: var(--ink-soft);
  font-size: 0.95rem;
  line-height: 1.5;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(8px);
}

.lang-grid {
  display: grid;
  gap: 10px;
}

.lang-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  text-align: left;
  padding: 16px 18px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--surface-solid);
  transition: transform 0.15s ease, border-color 0.15s ease;
}

.lang-btn:hover,
.lang-btn:focus-visible,
.lang-btn.is-selected {
  border-color: var(--accent);
  outline: none;
}

.lang-btn.is-selected {
  box-shadow: inset 0 0 0 1px var(--accent);
  background: #eef8f9;
}

.lang-btn:active {
  transform: scale(0.985);
}

.lang-btn .name {
  font-family: var(--font-ui);
  font-weight: 700;
  font-size: 1.05rem;
}

.lang-btn .meta {
  font-size: 0.8rem;
  color: var(--ink-soft);
}

.lang-btn .native {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--accent);
}

.lang-btn[data-lang="hebrew"] .native {
  font-family: var(--font-he);
}

.lang-btn[data-lang="chinese"] .native {
  font-family: var(--font-zh);
}

.section-label {
  font-family: var(--font-ui);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink-soft);
  margin: 0 0 10px;
}

.cat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.cat-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--surface-solid);
  border: 1px solid var(--line);
  font-size: 0.9rem;
}

.cat-item input {
  accent-color: var(--accent);
  width: 16px;
  height: 16px;
}

.cat-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.btn {
  font-family: var(--font-ui);
  font-weight: 700;
  font-size: 0.95rem;
  border-radius: 12px;
  padding: 12px 16px;
  border: 1px solid transparent;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  width: 100%;
}

.btn-primary:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-ghost {
  background: transparent;
  border-color: var(--line);
  color: var(--ink-soft);
}

.btn-soft {
  background: var(--accent-soft);
  color: var(--accent);
}

.study-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  color: var(--ink-soft);
}

.progress-bar {
  height: 6px;
  border-radius: 999px;
  background: rgba(15, 42, 50, 0.08);
  overflow: hidden;
}

.progress-bar > span {
  display: block;
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #0b6e78, #2bb3a8);
  transition: width 0.25s ease;
}

.flashcard {
  min-height: 280px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 28px 20px;
  text-align: center;
  border-radius: var(--radius);
  background: var(--surface-solid);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  cursor: pointer;
  user-select: none;
  position: relative;
  transition: transform 0.18s ease;
}

.flashcard:active {
  transform: scale(0.99);
}

.flashcard .hint {
  position: absolute;
  bottom: 14px;
  font-size: 0.78rem;
  color: var(--ink-soft);
}

.card-target {
  font-size: clamp(1.8rem, 7vw, 2.6rem);
  font-weight: 700;
  line-height: 1.25;
  word-break: break-word;
}

.card-target[dir="rtl"] {
  font-family: var(--font-he);
}

.lang-chinese .card-target {
  font-family: var(--font-zh);
}

.card-translit {
  font-size: 1.05rem;
  color: var(--ink-soft);
  letter-spacing: 0.01em;
}

.card-ja {
  font-size: clamp(1.35rem, 5vw, 1.85rem);
  font-weight: 700;
  line-height: 1.4;
}

.card-lemma {
  margin-top: 10px;
  font-size: 0.9rem;
  color: var(--ink-soft);
}

.speak-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 4px;
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-family: var(--font-ui);
  font-weight: 700;
  font-size: 0.85rem;
}

.speak-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.rating-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.rate-btn {
  font-family: var(--font-ui);
  font-weight: 700;
  font-size: 1rem;
  padding: 16px 10px;
  border-radius: 12px;
  color: #fff;
}

.rate-btn[data-grade="again"] { background: var(--again); }
.rate-btn[data-grade="good"] { background: var(--good); }

.hidden {
  display: none !important;
}

.empty-state,
.done-state {
  text-align: center;
  padding: 28px 16px;
}

.empty-state h2,
.done-state h2 {
  font-family: var(--font-ui);
  margin: 0 0 8px;
}

.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.stat-card {
  background: var(--surface-solid);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
}

.stat-card .label {
  font-size: 0.78rem;
  color: var(--ink-soft);
}

.stat-card .value {
  font-family: var(--font-ui);
  font-size: 1.55rem;
  font-weight: 800;
  margin-top: 4px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
}

.field label {
  font-weight: 600;
  font-size: 0.9rem;
}

.field input[type="number"] {
  width: 100%;
  padding: 11px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--surface-solid);
}

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}

.toggle-row:last-of-type {
  border-bottom: none;
}

.switch {
  position: relative;
  width: 46px;
  height: 28px;
  flex-shrink: 0;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.switch span {
  position: absolute;
  inset: 0;
  background: #c5d0d4;
  border-radius: 999px;
  transition: background 0.2s ease;
}

.switch span::after {
  content: "";
  position: absolute;
  width: 22px;
  height: 22px;
  left: 3px;
  top: 3px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.2s ease;
}

.switch input:checked + span {
  background: var(--accent);
}

.switch input:checked + span::after {
  transform: translateX(18px);
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.error-banner {
  background: #fef3f2;
  color: #b42318;
  border: 1px solid #fecdca;
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 0.9rem;
}

@media (max-width: 380px) {
  .nav-btn {
    padding: 7px 8px;
    font-size: 0.75rem;
  }

  .rating-row {
    gap: 8px;
  }

  .rate-btn {
    font-size: 0.95rem;
    padding: 14px 8px;
  }
}
