:root {
  --navy-900: #0d1b2a;
  --navy-800: #1b2d42;
  --navy-700: #243b55;
  --navy-600: #2e4a68;
  --navy-400: #5a7fa0;
  --navy-200: #aec6dc;
  --navy-100: #dde9f3;

  --gold-500: #c9a84c;
  --gold-400: #dfc07a;
  --gold-300: #ecdfa8;
  --gold-100: #faf6ea;

  --parchment: #f7f3e9;
  --parchment-dark: #ede7d5;

  --ink: #1a1a2e;
  --ink-soft: #3d3d5c;
  --ink-muted: #6b6b8a;

  --correct: #2d8a5e;
  --correct-bg: #e8f5ee;
  --miss: #b03a2e;
  --miss-bg: #fdecea;

  --shadow-card: 0 2px 12px rgba(13,27,42,0.1);
  --shadow-float: 0 8px 32px rgba(13,27,42,0.2);

  --radius: 10px;
  --radius-sm: 6px;
  --radius-lg: 16px;

  --font-serif: 'Noto Serif JP', Georgia, serif;
  --font-sans: 'Noto Sans JP', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
}

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

body {
  font-family: var(--font-sans);
  background: var(--parchment);
  color: var(--ink);
  min-height: 100vh;
  line-height: 1.6;
}

/* =============================================
   Utility
   ============================================= */
.hidden { display: none !important; }
.active { display: block; }

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 9px 18px; border: none; border-radius: var(--radius-sm);
  font-family: var(--font-sans); font-size: 14px; font-weight: 500;
  cursor: pointer; transition: all 0.18s ease; text-decoration: none;
  white-space: nowrap;
}
.btn-primary { background: var(--navy-800); color: #fff; }
.btn-primary:hover { background: var(--navy-700); transform: translateY(-1px); box-shadow: var(--shadow-card); }
.btn-secondary { background: var(--parchment-dark); color: var(--navy-800); border: 1px solid var(--parchment-dark); }
.btn-primary {
  background: var(--navy-800); color: #fff;
}
.btn-primary:hover { background: var(--navy-700); transform: translateY(-1px); box-shadow: var(--shadow-card); }
.btn-secondary {
  background: var(--parchment-dark); color: var(--navy-800);
  border: 1px solid var(--parchment-dark);
}
.btn-secondary:hover { background: var(--navy-100); border-color: var(--navy-200); }
.btn-ghost { background: transparent; color: var(--navy-400); }
.btn-ghost:hover { background: var(--navy-100); color: var(--navy-800); }
.btn-icon {
  width: 32px; height: 32px; padding: 0; border-radius: 50%;
  justify-content: center; font-size: 18px; font-weight: 400;
  background: var(--gold-500); color: #fff;
}
.btn-icon:hover { background: var(--gold-400); transform: scale(1.1); }
.btn-full { width: 100%; justify-content: center; }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-lg { padding: 14px 32px; font-size: 16px; border-radius: var(--radius); }
.btn-correct { background: var(--correct); color: #fff; }
.btn-correct:hover { background: #246a4a; transform: translateY(-1px); }
.btn-miss { background: var(--miss); color: #fff; }
.btn-miss:hover { background: #8e2e24; transform: translateY(-1px); }
.btn-danger { background: var(--miss); color: #fff; }
.btn-danger:hover { background: #8e2e24; }

.hint { font-size: 11px; color: var(--ink-muted); font-weight: 400; margin-left: 6px; }

/* =============================================
   Screens
   ============================================= */
.screen { display: none; min-height: 100vh; }
.screen.active { display: flex; flex-direction: column; }

/* =============================================
   Auth Screen
   ============================================= */
#auth-screen {
  background: var(--navy-900);
  background-image:
    radial-gradient(ellipse at 20% 50%, rgba(201,168,76,0.08) 0%, transparent 50%),
    radial-gradient(ellipse at 80% 20%, rgba(46,74,104,0.4) 0%, transparent 50%);
  align-items: center; justify-content: center;
}

.auth-container {
  width: 100%; max-width: 400px;
  background: var(--parchment);
  border-radius: var(--radius-lg);
  padding: 40px;
  box-shadow: var(--shadow-float);
}

.auth-brand { text-align: center; margin-bottom: 28px; }
.brand-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 64px; height: 64px; border-radius: 16px;
  background: linear-gradient(135deg, var(--navy-800), var(--navy-600));
  font-family: var(--font-serif); font-size: 28px; color: var(--gold-400);
  margin-bottom: 12px; box-shadow: 0 4px 16px rgba(13,27,42,0.3);
}
.brand-name { font-family: var(--font-serif); font-size: 28px; color: var(--navy-900); letter-spacing: 0.04em; }
.brand-tagline { font-size: 13px; color: var(--ink-muted); margin-top: 4px; }

.auth-tabs {
  display: flex; border-bottom: 2px solid var(--parchment-dark);
  margin-bottom: 24px;
}
.tab-btn {
  flex: 1; padding: 10px; border: none; background: transparent;
  font-family: var(--font-sans); font-size: 14px; font-weight: 500;
  color: var(--ink-muted); cursor: pointer;
  border-bottom: 2px solid transparent; margin-bottom: -2px;
  transition: all 0.18s;
}
.tab-btn.active { color: var(--navy-800); border-bottom-color: var(--gold-500); }
.auth-form { display: none; flex-direction: column; gap: 16px; }
.auth-form.active { display: flex; }

.field-group { display: flex; flex-direction: column; gap: 6px; }
.field-group label { font-size: 13px; font-weight: 500; color: var(--ink-soft); }
.field-group input, .field-group select, .field-group textarea {
  padding: 10px 12px; border: 1.5px solid var(--parchment-dark);
  border-radius: var(--radius-sm); font-family: var(--font-sans); font-size: 14px;
  background: #fff; color: var(--ink); transition: border-color 0.18s;
  width: 100%;
}
.field-group input:focus, .field-group select:focus, .field-group textarea:focus {
  outline: none; border-color: var(--navy-600);
  box-shadow: 0 0 0 3px rgba(46,74,104,0.1);
}
.field-group textarea { resize: vertical; min-height: 80px; }

.auth-error {
  font-size: 13px; color: var(--miss); background: var(--miss-bg);
  border-radius: var(--radius-sm); padding: 8px 12px;
  display: none;
}
.auth-error.visible { display: block; }

/* =============================================
   Navbar
   ============================================= */
.navbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 24px; height: 60px;
  background: var(--navy-900);
  border-bottom: 1px solid var(--navy-700);
  position: sticky; top: 0; z-index: 100;
}
.nav-brand { display: flex; align-items: center; gap: 10px; text-decoration: none; }
  flex-shrink: 0;
}
.nav-brand { display: flex; align-items: center; gap: 10px; }
.brand-icon-sm {
  width: 36px; height: 36px; border-radius: 8px;
  background: linear-gradient(135deg, var(--navy-700), var(--navy-600));
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-serif); font-size: 16px; color: var(--gold-400);
}
.nav-title { font-family: var(--font-serif); font-size: 18px; color: #fff; letter-spacing: 0.04em; }

.nav-center { display: flex; gap: 4px; }
.nav-btn {
  padding: 8px 16px; border: none; border-radius: var(--radius-sm);
  background: transparent; color: var(--navy-200);
  font-family: var(--font-sans); font-size: 14px; cursor: pointer;
  transition: all 0.18s; text-decoration: none; display: inline-flex; align-items: center;
}
.nav-btn:hover, .nav-btn.active { background: var(--navy-700); color: #fff; }
  transition: all 0.18s;
}
.nav-btn:hover { background: var(--navy-700); color: #fff; }
.nav-btn.active { background: var(--navy-700); color: #fff; }

.nav-right { display: flex; align-items: center; gap: 12px; }
.nav-user { font-size: 13px; color: var(--navy-200); }

/* =============================================
   Field Group (フォーム共通)
   ============================================= */
.field-group { display: flex; flex-direction: column; gap: 6px; }
.field-group label { font-size: 13px; font-weight: 500; color: var(--ink-soft); }
.field-group input, .field-group select, .field-group textarea {
  padding: 10px 12px; border: 1.5px solid var(--parchment-dark);
  border-radius: var(--radius-sm); font-family: var(--font-sans); font-size: 14px;
  background: #fff; color: var(--ink); transition: border-color 0.18s; width: 100%;
}
.field-group input:focus, .field-group select:focus, .field-group textarea:focus {
  outline: none; border-color: var(--navy-600);
  box-shadow: 0 0 0 3px rgba(46,74,104,0.1);
}
.field-group textarea { resize: vertical; min-height: 80px; }

/* =============================================
   Error / Alert
   ============================================= */
.alert {
  font-size: 13px; border-radius: var(--radius-sm); padding: 10px 14px;
  display: none; margin-top: 4px;
}
.alert.visible { display: block; }
.alert-error { background: var(--miss-bg); color: var(--miss); border-left: 3px solid var(--miss); }
.alert-success { background: var(--correct-bg); color: var(--correct); border-left: 3px solid var(--correct); }

/* =============================================
   Toast
   ============================================= */
.toast {
  position: fixed; bottom: 24px; right: 24px; z-index: 2000;
  padding: 12px 20px; border-radius: var(--radius); background: var(--navy-900);
  color: #fff; font-size: 14px; box-shadow: var(--shadow-float);
  animation: toastIn 0.2s ease; pointer-events: none;
}
.toast.hidden { display: none; }
@keyframes toastIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
.toast.success { border-left: 4px solid var(--correct); }
.toast.error { border-left: 4px solid var(--miss); }
   Views
   ============================================= */
#main-screen { flex-direction: column; }
.view { display: none; flex: 1; }
.view.active { display: flex; }

/* =============================================
   Home View — Sidebar + Content
   ============================================= */
#view-home { height: calc(100vh - 60px); overflow: hidden; }

.sidebar {
  width: 240px; flex-shrink: 0;
  background: var(--navy-800);
  border-right: 1px solid var(--navy-700);
  display: flex; flex-direction: column;
  overflow-y: auto;
}
.sidebar-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px 16px 12px;
  border-bottom: 1px solid var(--navy-700);
}
.sidebar-header h2 { font-size: 13px; font-weight: 600; color: var(--navy-200); letter-spacing: 0.08em; text-transform: uppercase; }

.nav-list { padding: 8px 0; flex: 1; }
.nav-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px; cursor: pointer; transition: background 0.15s;
  color: var(--navy-100); font-size: 14px; gap: 8px;
  border-left: 3px solid transparent;
}
.nav-item:hover { background: var(--navy-700); }
.nav-item.active { background: var(--navy-700); border-left-color: var(--gold-500); color: var(--gold-300); }
.nav-item-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-item-actions { display: flex; gap: 4px; opacity: 0; transition: opacity 0.15s; }
.nav-item:hover .nav-item-actions { opacity: 1; }
.icon-btn {
  width: 24px; height: 24px; border: none; border-radius: 4px;
  background: transparent; color: var(--navy-200); cursor: pointer; font-size: 12px;
  display: flex; align-items: center; justify-content: center; transition: background 0.15s;
}
.icon-btn:hover { background: var(--navy-600); color: #fff; }
.icon-btn.danger:hover { background: var(--miss); }

.content-area {
  flex: 1; overflow-y: auto;
  background: var(--parchment);
  display: flex; flex-direction: column;
}

.placeholder {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 8px;
  color: var(--ink-muted); text-align: center;
}
.placeholder-icon { font-size: 48px; margin-bottom: 8px; }

.content-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px 28px 16px; border-bottom: 1px solid var(--parchment-dark);
  background: #fff;
}
.breadcrumb { font-size: 14px; color: var(--ink-soft); }
.breadcrumb strong { color: var(--navy-800); font-family: var(--font-serif); }
.content-actions { display: flex; gap: 8px; }

.unit-tabs-container {
  padding: 12px 28px;
  background: #fff;
  border-bottom: 1px solid var(--parchment-dark);
  overflow-x: auto;
}
.unit-tabs { display: flex; gap: 6px; min-width: max-content; }
.unit-tab {
  padding: 6px 14px; border: 1.5px solid var(--parchment-dark);
  border-radius: 20px; background: transparent;
  font-family: var(--font-sans); font-size: 13px; color: var(--ink-soft);
  cursor: pointer; transition: all 0.15s; white-space: nowrap;
  display: flex; align-items: center; gap: 6px;
}
.unit-tab:hover { border-color: var(--navy-400); color: var(--navy-800); }
.unit-tab.active { background: var(--navy-800); color: #fff; border-color: var(--navy-800); }
.unit-tab-actions { display: flex; gap: 2px; }
.unit-tab .tab-icon-btn {
  width: 18px; height: 18px; border: none; background: rgba(255,255,255,0.2);
  border-radius: 3px; cursor: pointer; color: inherit; font-size: 10px;
  display: inline-flex; align-items: center; justify-content: center; transition: background 0.15s;
}
.unit-tab:not(.active) .tab-icon-btn { background: rgba(0,0,0,0.06); }
.unit-tab .tab-icon-btn:hover { background: rgba(255,255,255,0.4); }

.words-grid {
  padding: 24px 28px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
  align-content: start;
}

.word-card {
  background: #fff; border-radius: var(--radius);
  border: 1px solid var(--parchment-dark);
  padding: 18px; transition: all 0.18s;
  position: relative;
  box-shadow: var(--shadow-card);
}
.word-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-float); border-color: var(--navy-200); }
.word-card-term {
  font-family: var(--font-serif); font-size: 18px; font-weight: 600;
  color: var(--navy-900); margin-bottom: 8px;
}
.word-card-def { font-size: 14px; color: var(--ink-soft); line-height: 1.6; }
.word-card-meta {
  display: flex; align-items: center; justify-content: space-between;
  margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--parchment-dark);
}
.miss-badge {
  font-size: 11px; padding: 3px 8px; border-radius: 12px;
  background: var(--miss-bg); color: var(--miss); font-weight: 600;
}
.miss-badge.none { background: var(--correct-bg); color: var(--correct); }
.word-card-actions { display: flex; gap: 4px; opacity: 0; transition: opacity 0.15s; }
.word-card:hover .word-card-actions { opacity: 1; }

.empty-words {
  grid-column: 1 / -1; text-align: center; padding: 60px 20px;
  color: var(--ink-muted);
}
.empty-words-icon { font-size: 40px; margin-bottom: 12px; }

/* =============================================
   Test View
   ============================================= */
#view-test {
  align-items: center; justify-content: center;
  background: var(--navy-900);
  min-height: calc(100vh - 60px);
  flex-direction: column; padding: 24px;
}

.test-setup-card {
  background: var(--parchment); border-radius: var(--radius-lg);
  padding: 40px; width: 100%; max-width: 480px;
  box-shadow: var(--shadow-float);
  display: flex; flex-direction: column; gap: 20px;
}
.test-setup-card h2 {
  font-family: var(--font-serif); font-size: 22px; color: var(--navy-900);
  border-bottom: 2px solid var(--gold-500); padding-bottom: 12px;
}

.radio-group { display: flex; flex-direction: column; gap: 8px; }
.radio-label {
  display: flex; align-items: center; gap: 10px; cursor: pointer;
  font-size: 14px; color: var(--ink-soft);
}
.radio-label input[type="radio"] { accent-color: var(--navy-700); }

/* Test Session */
.test-session {
  width: 100%; max-width: 680px; display: flex; flex-direction: column;
  align-items: center; gap: 32px;
}

.test-progress-bar { width: 100%; }
.progress-track {
  height: 6px; background: var(--navy-700); border-radius: 3px;
  overflow: hidden; margin-bottom: 8px;
}
.progress-fill {
  height: 100%; background: var(--gold-500);
  border-radius: 3px; transition: width 0.4s ease;
  width: 0%;
}
.progress-label { font-size: 13px; color: var(--navy-200); font-family: var(--font-mono); }

.flashcard-area { width: 100%; display: flex; flex-direction: column; align-items: center; gap: 24px; }

.flashcard {
  width: 100%; background: var(--parchment);
  border-radius: var(--radius-lg); padding: 48px 40px;
  min-height: 240px; display: flex; flex-direction: column;
  align-items: center; justify-content: center; text-align: center;
  box-shadow: var(--shadow-float);
  border: 1px solid var(--parchment-dark);
  position: relative;
}
.card-label {
  font-size: 11px; font-weight: 600; letter-spacing: 0.1em; text-transform: uppercase;
  color: var(--ink-muted); margin-bottom: 20px;
}
.card-question {
  font-family: var(--font-serif); font-size: 28px; font-weight: 600;
  color: var(--navy-900); line-height: 1.4;
}
.flashcard-back { width: 100%; }
.card-answer-label {
  font-size: 11px; font-weight: 600; letter-spacing: 0.1em; text-transform: uppercase;
  color: var(--gold-500); margin-bottom: 16px;
}
.card-answer {
  font-size: 20px; color: var(--navy-800); line-height: 1.6;
}

.card-actions { display: flex; gap: 16px; justify-content: center; }

/* Test Result */
.test-result { width: 100%; max-width: 560px; }
.result-card {
  background: var(--parchment); border-radius: var(--radius-lg);
  padding: 48px 40px; box-shadow: var(--shadow-float);
  display: flex; flex-direction: column; gap: 24px;
  border-top: 4px solid var(--gold-500);
}
.result-score {
  text-align: center; font-family: var(--font-serif); font-size: 56px;
  font-weight: 700; color: var(--navy-900); line-height: 1;
}
.result-stats { text-align: center; color: var(--ink-muted); font-size: 15px; }
.result-actions { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }

.miss-words-section h3 {
  font-family: var(--font-serif); font-size: 16px; color: var(--miss);
  margin-bottom: 12px; display: flex; align-items: center; gap: 8px;
}
.miss-list { display: flex; flex-direction: column; gap: 8px; max-height: 240px; overflow-y: auto; }
.miss-word-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 14px; background: var(--miss-bg);
  border-radius: var(--radius-sm); border-left: 3px solid var(--miss);
}
.miss-word-term { font-family: var(--font-serif); font-weight: 600; color: var(--navy-900); }
.miss-word-def { font-size: 13px; color: var(--ink-soft); }

/* =============================================
   Modal
   ============================================= */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(13,27,42,0.6);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000; backdrop-filter: blur(4px);
}
.modal-overlay.hidden { display: none; }
.modal {
  background: var(--parchment); border-radius: var(--radius-lg);
  width: 100%; max-width: 440px; box-shadow: var(--shadow-float);
  overflow: hidden; animation: modalIn 0.2s ease;
}
@keyframes modalIn { from { opacity: 0; transform: scale(0.95) translateY(-10px); } to { opacity: 1; transform: none; } }
@keyframes modalIn {
  from { opacity: 0; transform: scale(0.95) translateY(-10px); }
  to { opacity: 1; transform: none; }
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px 24px 16px; border-bottom: 1px solid var(--parchment-dark);
}
.modal-header h3 { font-family: var(--font-serif); font-size: 17px; color: var(--navy-900); }
.modal-close {
  width: 28px; height: 28px; border: none; background: transparent;
  color: var(--ink-muted); cursor: pointer; font-size: 14px; border-radius: 4px;
  transition: background 0.15s;
}
.modal-close:hover { background: var(--parchment-dark); }
.modal-body { padding: 20px 24px 24px; display: flex; flex-direction: column; gap: 16px; }

/* =============================================
   Loading spinner
   ============================================= */
.loading-screen {
  position: fixed; inset: 0; background: var(--navy-900);
  display: flex; align-items: center; justify-content: center;
  z-index: 9999; flex-direction: column; gap: 16px;
}
.spinner {
  width: 40px; height: 40px; border: 3px solid var(--navy-600);
  border-top-color: var(--gold-400); border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-text { color: var(--navy-200); font-size: 14px; }
   Toast
   ============================================= */
.toast {
  position: fixed; bottom: 24px; right: 24px; z-index: 2000;
  padding: 12px 20px; border-radius: var(--radius); background: var(--navy-900);
  color: #fff; font-size: 14px; box-shadow: var(--shadow-float);
  animation: toastIn 0.2s ease;
}
.toast.hidden { display: none; }
@keyframes toastIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}
.toast.success { border-left: 4px solid var(--correct); }
.toast.error { border-left: 4px solid var(--miss); }

/* =============================================
   Responsive
   ============================================= */
@media (max-width: 640px) {
  .navbar { padding: 0 12px; }
  .nav-title { display: none; }
  .nav-center { gap: 2px; }
  .nav-btn { padding: 6px 10px; font-size: 12px; }
  .sidebar { width: 200px; }
  .words-grid { padding: 16px; grid-template-columns: 1fr; }
  .content-header { padding: 14px 16px; flex-direction: column; align-items: flex-start; gap: 10px; }
  .unit-tabs-container { padding: 10px 16px; }
  .navbar { padding: 0 12px; }
  .nav-title { display: none; }
  .flashcard { padding: 32px 24px; }
  .card-question { font-size: 22px; }
  .result-score { font-size: 40px; }
  .test-setup-card, .result-card { padding: 28px 20px; }
}