/* ── Reset & Base ─────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  /* Palette: ink-on-washi — warm off-white ground, deep sumi ink, 
     single vermillion accent for Japanese flair */
  --bg:        #F7F5F0;
  --surface:   #FFFFFF;
  --sidebar:   #1A1A1A;
  --ink:       #1A1A1A;
  --ink-2:     #4A4A4A;
  --ink-3:     #8A8A8A;
  --border:    #E5E2DA;
  --accent:    #C0392B;       /* vermillion / shu */
  --accent-lt: #FAEAE8;

  /* Tag colors — muted, reminiscent of study highlighters */
  --rule:      #3B5BDB;   --rule-bg:      #EEF2FF;
  --irreg:     #C92A2A;   --irreg-bg:     #FFF5F5;
  --vocab:     #2F9E44;   --vocab-bg:     #EBFBEE;
  --grammar:   #E67700;   --grammar-bg:   #FFF3BF;
  --sentence:  #6741D9;   --sentence-bg:  #F3F0FF;
  --culture:   #0C8599;   --culture-bg:   #E3FAFC;

  --radius:    8px;
  --sidebar-w: 240px;
  --trans:     0.2s ease;
}

body {
  font-family: 'Inter', 'Noto Sans JP', sans-serif;
  background: var(--bg);
  color: var(--ink);
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ── Sidebar ──────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--sidebar);
  color: #E8E4DC;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition: width var(--trans);
  overflow: hidden;
  position: relative;
  z-index: 10;
}
.sidebar.collapsed { width: 52px; }
.sidebar.collapsed .logo-en,
.sidebar.collapsed .logo-version,
.sidebar.collapsed .unit-label,
.sidebar.collapsed .unit-count,
.sidebar.collapsed .sidebar-footer { opacity: 0; pointer-events: none; }

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 16px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  flex-shrink: 0;
}

.logo { display: flex; flex-direction: column; line-height: 1; }
.logo-jp {
  font-family: 'Noto Serif JP', serif;
  font-size: 18px;
  font-weight: 700;
  color: var(--accent);
  white-space: nowrap;
}
.logo-en {
  font-size: 11px;
  color: #888;
  letter-spacing: 0.08em;
  white-space: nowrap;
  transition: opacity var(--trans);
}
.logo-version {
  font-size: 9px;
  color: #555;
  letter-spacing: 0.04em;
  margin-left: 5px;
  font-family: 'Inter', sans-serif;
  white-space: nowrap;
  transition: opacity var(--trans);
}

.sidebar-toggle {
  background: none;
  border: none;
  color: #888;
  font-size: 18px;
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  transition: color var(--trans), transform var(--trans);
  flex-shrink: 0;
}
.sidebar-toggle:hover { color: #E8E4DC; }
.sidebar.collapsed .sidebar-toggle { transform: rotate(180deg); }

.unit-nav {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
  scrollbar-width: thin;
  scrollbar-color: #333 transparent;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 16px;
  cursor: pointer;
  border-radius: 0;
  transition: background var(--trans);
  border-left: 3px solid transparent;
  white-space: nowrap;
}
.nav-item:hover { background: rgba(255,255,255,0.06); }
.nav-item.active {
  background: rgba(192,57,43,0.15);
  border-left-color: var(--accent);
  color: #fff;
}
.nav-item-num {
  font-size: 10px;
  font-family: 'Inter', monospace;
  color: var(--accent);
  background: rgba(192,57,43,0.2);
  border-radius: 4px;
  padding: 1px 5px;
  flex-shrink: 0;
  min-width: 26px;
  text-align: center;
}
.unit-label { font-size: 13px; overflow: hidden; text-overflow: ellipsis; transition: opacity var(--trans); }
.unit-count { margin-left: auto; font-size: 10px; color: #555; flex-shrink: 0; transition: opacity var(--trans); }

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid rgba(255,255,255,0.08);
  flex-shrink: 0;
  transition: opacity var(--trans);
}
.btn-add-unit {
  width: 100%;
  padding: 8px;
  background: rgba(192,57,43,0.18);
  color: #E8E4DC;
  border: 1px solid rgba(192,57,43,0.3);
  border-radius: var(--radius);
  font-size: 12px;
  cursor: pointer;
  transition: background var(--trans);
  letter-spacing: 0.03em;
}
.btn-add-unit:hover { background: rgba(192,57,43,0.32); }

/* ── Main ─────────────────────────────────────────────────────────── */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

/* ── Topbar ───────────────────────────────────────────────────────── */
.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.menu-btn {
  display: none;
  background: none;
  border: none;
  font-size: 18px;
  cursor: pointer;
  color: var(--ink-2);
}
.breadcrumb {
  font-size: 13px;
  color: var(--ink-2);
  font-weight: 500;
  flex: 1;
}
.search-input {
  padding: 7px 12px;
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: 13px;
  background: var(--bg);
  color: var(--ink);
  width: 220px;
  outline: none;
  transition: border-color var(--trans);
}
.search-input:focus { border-color: var(--accent); }

/* ── Content ──────────────────────────────────────────────────────── */
.content {
  flex: 1;
  overflow-y: auto;
  padding: 32px 36px;
  scrollbar-width: thin;
}

/* Welcome screen */
.welcome { text-align: center; padding: 80px 20px; }
.welcome-kana {
  font-family: 'Noto Serif JP', serif;
  font-size: 64px;
  color: var(--border);
  line-height: 1;
  margin-bottom: 16px;
}
.welcome h1 { font-size: 24px; font-weight: 600; margin-bottom: 8px; }
.welcome p { color: var(--ink-2); font-size: 14px; }
.legend-hint { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 20px; }

/* ── Unit header ──────────────────────────────────────────────────── */
.unit-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 28px;
  gap: 12px;
}
.unit-header-left {}
.unit-eyebrow {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--accent);
  font-weight: 600;
  margin-bottom: 4px;
}
.unit-heading {
  font-family: 'Noto Serif JP', serif;
  font-size: 28px;
  font-weight: 700;
  color: var(--ink);
}
.unit-actions { display: flex; gap: 8px; flex-shrink: 0; margin-top: 4px; }

/* ── Section ──────────────────────────────────────────────────────── */
.section-block {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  margin-bottom: 20px;
  overflow: hidden;
}
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  background: #FAFAF8;
  cursor: pointer;
  user-select: none;
}
.section-title-row { display: flex; align-items: center; gap: 10px; }
.section-chevron { font-size: 11px; color: var(--ink-3); transition: transform var(--trans); }
.section-block.collapsed .section-chevron { transform: rotate(-90deg); }
.section-name { font-size: 14px; font-weight: 600; color: var(--ink); }
.section-meta { font-size: 11px; color: var(--ink-3); }
.section-actions { display: flex; gap: 4px; opacity: 0; transition: opacity var(--trans); }
.section-header:hover .section-actions { opacity: 1; }
.section-body { padding: 12px 18px 16px; }
.section-block.collapsed .section-body { display: none; }

/* ── Notes ────────────────────────────────────────────────────────── */
.notes-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }

.note-card {
  display: flex;
  flex-direction: column;
  padding: 10px 12px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  background: var(--bg);
  transition: border-color var(--trans);
  position: relative;
}
.note-card:hover { border-color: var(--border); }

.note-top-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-bottom: 8px;
  margin-bottom: 8px;
  border-bottom: 1px solid var(--border);
}
.note-top-spacer { flex: 1; }

.note-tag {
  display: inline-flex;
  align-items: center;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.06em;
  padding: 2px 7px;
  border-radius: 20px;
  text-transform: uppercase;
  flex-shrink: 0;
}
.note-tag.rule     { background: var(--rule-bg);     color: var(--rule);    }
.note-tag.irregular{ background: var(--irreg-bg);    color: var(--irreg);   }
.note-tag.vocab    { background: var(--vocab-bg);    color: var(--vocab);   }
.note-tag.grammar  { background: var(--grammar-bg);  color: var(--grammar); }
.note-tag.sentence { background: var(--sentence-bg); color: var(--sentence);}
.note-tag.culture  { background: var(--culture-bg);  color: var(--culture);  }

.note-body { flex: 1; min-width: 0; width: 100%; }
.note-content {
  font-size: 13.5px;
  color: var(--ink);
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
}
.note-meta { display: flex; gap: 12px; margin-top: 5px; flex-wrap: wrap; }
.note-jp {
  font-family: 'Noto Sans JP', sans-serif;
  font-size: 13px;
  color: var(--accent);
  font-weight: 500;
}
.note-en {
  font-size: 12px;
  color: var(--ink-3);
  font-style: italic;
}

.note-actions {
  display: flex;
  gap: 2px;
  opacity: 0;
  transition: opacity var(--trans);
  flex-shrink: 0;
}
.note-card:hover .note-actions { opacity: 1; }

/* Add note button */
.btn-add-note {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--ink-3);
  background: none;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 7px 14px;
  cursor: pointer;
  width: 100%;
  justify-content: center;
  transition: all var(--trans);
}
.btn-add-note:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-lt); }

/* Add section button */
.btn-add-section {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--ink-2);
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: 12px;
  padding: 14px;
  cursor: pointer;
  width: 100%;
  justify-content: center;
  transition: all var(--trans);
  margin-top: 4px;
}
.btn-add-section:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-lt); }

/* ── Tags (legend) ────────────────────────────────────────────────── */
.tag { display: inline-flex; align-items: center; font-size: 11px; font-weight: 600;
  letter-spacing: 0.05em; padding: 3px 9px; border-radius: 20px; text-transform: uppercase; }
.tag-rule     { background: var(--rule-bg);     color: var(--rule);    }
.tag-irregular{ background: var(--irreg-bg);    color: var(--irreg);   }
.tag-vocab    { background: var(--vocab-bg);    color: var(--vocab);   }
.tag-grammar  { background: var(--grammar-bg);  color: var(--grammar); }
.tag-sentence { background: var(--sentence-bg); color: var(--sentence);}
.tag-culture  { background: var(--culture-bg);  color: var(--culture); }

/* ── Icon buttons ─────────────────────────────────────────────────── */
.icon-btn {
  background: none;
  border: none;
  width: 26px;
  height: 26px;
  border-radius: 5px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 13px;
  color: var(--ink-3);
  transition: background var(--trans), color var(--trans);
}
.icon-btn:hover { background: var(--bg); color: var(--ink); }
.icon-btn.danger:hover { background: #FFF5F5; color: var(--irreg); }

/* ── Modals ───────────────────────────────────────────────────────── */
.modal-backdrop {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.35);
  z-index: 100;
  backdrop-filter: blur(2px);
}
.modal-backdrop.open { display: block; }

.modal {
  display: none;
  position: fixed;
  top: 50%; left: 50%;
  transform: translate(-50%, -48%);
  background: var(--surface);
  border-radius: 14px;
  width: 440px;
  max-width: calc(100vw - 32px);
  box-shadow: 0 24px 80px rgba(0,0,0,0.18);
  z-index: 101;
  overflow: hidden;
  animation: slideUp 0.2s ease;
}
.modal.open { display: block; }

@keyframes slideUp {
  from { transform: translate(-50%, -44%); opacity: 0; }
  to   { transform: translate(-50%, -50%); opacity: 1; }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--border);
}
.modal-header h2 { font-size: 16px; font-weight: 600; }
.modal-close {
  background: none; border: none; font-size: 16px; color: var(--ink-3);
  cursor: pointer; width: 28px; height: 28px; border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  transition: background var(--trans);
}
.modal-close:hover { background: var(--bg); color: var(--ink); }

.modal-body {
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.modal-body label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-3);
  margin-bottom: -4px;
}
.modal-body input, .modal-body textarea, .modal-body select {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 9px 12px;
  font-size: 14px;
  font-family: inherit;
  color: var(--ink);
  background: var(--bg);
  outline: none;
  resize: vertical;
  transition: border-color var(--trans);
}
.modal-body input:focus, .modal-body textarea:focus { border-color: var(--accent); }

.type-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.type-btn {
  padding: 5px 13px;
  border-radius: 20px;
  border: 1px solid var(--border);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  background: var(--bg);
  color: var(--ink-2);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  transition: all var(--trans);
}
.type-btn:hover { border-color: var(--accent); color: var(--accent); }
.type-btn.active[data-type="rule"]     { background: var(--rule-bg);     color: var(--rule);    border-color: var(--rule);    }
.type-btn.active[data-type="irregular"]{ background: var(--irreg-bg);    color: var(--irreg);   border-color: var(--irreg);   }
.type-btn.active[data-type="vocab"]    { background: var(--vocab-bg);    color: var(--vocab);   border-color: var(--vocab);   }
.type-btn.active[data-type="grammar"]  { background: var(--grammar-bg);  color: var(--grammar); border-color: var(--grammar); }
.type-btn.active[data-type="sentence"] { background: var(--sentence-bg); color: var(--sentence);border-color: var(--sentence);}
.type-btn.active[data-type="culture"]  { background: var(--culture-bg);  color: var(--culture); border-color: var(--culture); }

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  background: #FAFAF8;
}

.btn-primary {
  padding: 8px 20px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--trans);
}
.btn-primary:hover { background: #a93226; }

.btn-secondary {
  padding: 8px 16px;
  background: var(--bg);
  color: var(--ink-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  cursor: pointer;
  transition: background var(--trans);
}
.btn-secondary:hover { background: var(--border); }

.btn-danger {
  padding: 8px 20px;
  background: var(--irreg);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.btn-danger:hover { background: #b71c1c; }

/* ── Search highlight ─────────────────────────────────────────────── */
mark { background: #FFF3BF; color: var(--ink); border-radius: 2px; padding: 0 1px; }

/* ── Empty state ──────────────────────────────────────────────────── */
.empty-section { color: var(--ink-3); font-size: 13px; padding: 4px 0 8px; }

/* ── Desktop: sidebar always visible, full width ─────────────────── */
@media (min-width: 769px) {
  .sidebar {
    position: relative;
    transform: none !important;
    box-shadow: none;
    width: var(--sidebar-w) !important; /* never collapse on desktop */
  }
  .sidebar.collapsed {
    width: var(--sidebar-w) !important;
  }
  .sidebar.collapsed .logo-en,
  .sidebar.collapsed .unit-label,
  .sidebar.collapsed .unit-count,
  .sidebar.collapsed .sidebar-footer {
    opacity: 1 !important;
    pointer-events: auto !important;
  }
  .sidebar-overlay { display: none !important; }
  .menu-btn { display: none !important; }
  .sidebar-toggle { display: none; } /* hide collapse button on desktop too */
}

/* ── Responsive ───────────────────────────────────────────────────── */

/* Menu button always rendered, hidden on desktop */
.menu-btn {
  display: none;
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  color: var(--ink-2);
  min-width: 40px;
  min-height: 40px;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius);
  flex-shrink: 0;
  line-height: 1;
  -webkit-tap-highlight-color: transparent;
}
.menu-btn:active { background: var(--border); }

/* Sidebar overlay backdrop (mobile only) */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 49;
}
.sidebar-overlay.open { display: block; }

@media (max-width: 768px) {
  /* Sidebar slides in from left */
  .sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 50;
    width: 280px;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    box-shadow: 4px 0 24px rgba(0,0,0,0.3);
  }
  .sidebar.mobile-open { transform: translateX(0); }
  .sidebar.collapsed { width: 280px; } /* disable collapse on mobile */

  /* Show menu button */
  .menu-btn { display: flex; }

  /* Content full width */
  .content { padding: 20px 16px; }
  .topbar { padding: 8px 14px; gap: 10px; }
  .breadcrumb { line-height: 1.2; }
  .search-input { width: 120px; font-size: 14px; }

  /* Bigger touch targets for note actions */
  .icon-btn { width: 36px; height: 36px; font-size: 16px; }
  .note-actions { opacity: 1; } /* always visible on mobile */
  .section-actions { opacity: 1; }

  /* Study tabs wrap nicely */
  .study-type-tabs { gap: 8px; }
  .study-tab { padding: 8px 14px; font-size: 13px; }

  /* Type picker in modal */
  .type-btn { padding: 8px 14px; font-size: 13px; }

  /* Bigger modal inputs for mobile keyboard */
  .modal-body input,
  .modal-body textarea { font-size: 16px; } /* prevents iOS zoom */

  /* Unit header stacks on small screens */
  .unit-header { flex-direction: column; gap: 8px; }
  .unit-actions { align-self: flex-end; }
  .unit-heading { font-size: 22px; }
}

/* ── Sidebar section labels & divider ────────────────────────────── */
.sidebar-section-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: #555;
  padding: 10px 16px 4px;
  font-weight: 600;
}
.sidebar-divider {
  height: 1px;
  background: rgba(255,255,255,0.07);
  margin: 8px 0;
}
.nav-item-icon { font-size: 14px; flex-shrink: 0; }

/* ── Study View ──────────────────────────────────────────────────── */
.study-type-tabs {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 24px;
}
.study-tab {
  padding: 6px 14px;
  border-radius: 20px;
  border: 1px solid var(--border);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  background: var(--surface);
  color: var(--ink-2);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  transition: all var(--trans);
}
.study-tab:hover { border-color: var(--accent); color: var(--accent); }
.study-tab.active[data-type="rule"]      { background: var(--rule-bg);     color: var(--rule);     border-color: var(--rule);     }
.study-tab.active[data-type="irregular"] { background: var(--irreg-bg);    color: var(--irreg);    border-color: var(--irreg);    }
.study-tab.active[data-type="vocab"]     { background: var(--vocab-bg);    color: var(--vocab);    border-color: var(--vocab);    }
.study-tab.active[data-type="grammar"]   { background: var(--grammar-bg);  color: var(--grammar);  border-color: var(--grammar);  }
.study-tab.active[data-type="sentence"]  { background: var(--sentence-bg); color: var(--sentence); border-color: var(--sentence); }
.study-tab.active[data-type="culture"]   { background: var(--culture-bg);  color: var(--culture);  border-color: var(--culture);  }

.study-unit-group { margin-bottom: 28px; }
.study-unit-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--ink-3);
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.study-unit-label::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}
.study-empty {
  text-align: center;
  padding: 60px 20px;
  color: var(--ink-3);
  font-size: 14px;
}
.study-empty-kana { font-family: 'Noto Serif JP', serif; font-size: 48px; color: var(--border); margin-bottom: 12px; }
.study-count-badge {
  display: inline-block;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: 11px;
  color: var(--ink-3);
  padding: 2px 8px;
  margin-left: 8px;
  font-weight: 500;
}

/* ── Note edit button (replaces note-actions) ────────────────────── */
.note-actions { display: none; } /* hide old actions if any remain */

/* ── Unit header actions — subtler ───────────────────────────────── */
.unit-actions .icon-btn {
  opacity: 0.4;
  font-size: 15px;
}
.unit-actions .icon-btn:hover { opacity: 1; }

@media (max-width: 768px) {
  .unit-actions .icon-btn { opacity: 0.5; min-width: 36px; min-height: 36px; }
}

/* ── Section edit button (single, replaces section-actions) ──────── */
.section-actions { display: none !important; }

.section-edit-btn {
  opacity: 0;
  transition: opacity 0.15s;
  margin-left: auto;
  flex-shrink: 0;
}
.section-header:hover .section-edit-btn { opacity: 1; }

@media (max-width: 768px) {
  .section-edit-btn { opacity: 0.4; }
}

/* ── Mobile tap-to-edit behavior ─────────────────────────────────── */

/* Note card: clickable on mobile, pencil hidden */
.note-card { cursor: default; }

/* On mobile: card is tappable */
@media (max-width: 768px) {
  .note-card {
    cursor: pointer;
    -webkit-tap-highlight-color: rgba(192,57,43,0.08);
  }
  .note-card:active { background: #F0EDE8; }
}

/* desktop-only / mobile-only helpers */
.desktop-only { display: inline-flex; }
.mobile-only  { display: none; }

@media (max-width: 768px) {
  .desktop-only { display: none !important; }
  .mobile-only  { display: inline-flex !important; }
}

/* Section edit: desktop pencil, mobile "Edit" text */
.section-edit-btn { opacity: 0; transition: opacity 0.15s; margin-left: auto; flex-shrink: 0; }
.section-header:hover .section-edit-btn { opacity: 1; }

.section-edit-mobile {
  background: none;
  border: none;
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  padding: 4px 8px;
  border-radius: 6px;
  cursor: pointer;
  margin-left: auto;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
  letter-spacing: 0.03em;
}
.section-edit-mobile:active { background: var(--accent-lt); }

/* Hide sidebar toggle ‹ on mobile */
@media (max-width: 768px) {
  .sidebar-toggle { display: none; }
}

/* ── Unit edit button ────────────────────────────────────────────── */
.unit-edit-btn { margin-left: auto; flex-shrink: 0; }
.unit-actions  { display: none; } /* hide old unit-actions */

.unit-edit-mobile {
  background: none;
  border: none;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-3);
  padding: 4px 10px;
  border-radius: 6px;
  cursor: pointer;
  letter-spacing: 0.03em;
  -webkit-tap-highlight-color: transparent;
  align-self: flex-start;
  margin-top: 8px;
}
.unit-edit-mobile:active { background: var(--border); }

/* ── Mobile viewport fix (address bar) ──────────────────────────── */
@media (max-width: 768px) {
  body {
    height: 100dvh; /* dynamic viewport — excludes address bar */
    min-height: 100dvh;
  }

  /* Extra padding at bottom so last item not hidden behind address bar */
  .content {
    padding-bottom: 80px;
  }

  /* Modal sits above address bar */
  .modal {
    max-height: 85dvh;
    overflow-y: auto;
  }
}

/* ── Login screen ────────────────────────────────────────────────── */
.login-screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #1A1A1A;
  z-index: 9999;
}
.login-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  width: 300px;
  padding: 0 24px;
}
.login-kana {
  font-family: 'Noto Serif JP', serif;
  font-size: 56px;
  color: var(--accent);
  line-height: 1;
  margin-bottom: 4px;
}
.login-title {
  font-family: 'Noto Sans JP', sans-serif;
  font-size: 15px;
  color: #888;
  font-weight: 400;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  margin-top: -8px;
}
.login-box input {
  width: 100%;
  padding: 14px 16px;
  border-radius: var(--radius);
  border: 1px solid rgba(255,255,255,0.12);
  background: rgba(255,255,255,0.06);
  color: #E8E4DC;
  font-size: 16px;
  text-align: center;
  outline: none;
  letter-spacing: 0.12em;
  font-family: inherit;
  transition: border-color 0.2s;
}
.login-box input:focus { border-color: var(--accent); background: rgba(255,255,255,0.09); }
.login-box input::placeholder { color: #555; letter-spacing: 0.05em; }
.login-box button {
  width: 100%;
  padding: 14px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  letter-spacing: 0.08em;
  font-family: inherit;
  transition: background 0.2s;
}
.login-box button:hover { background: #a93226; }
.login-box button:active { background: #922b21; }
.login-error {
  font-size: 12px;
  color: #e07070;
  min-height: 16px;
  letter-spacing: 0.03em;
}

/* ── Backup actions ──────────────────────────────────────────────── */
.backup-actions {
  display: flex;
  gap: 6px;
  margin-top: 8px;
}
.btn-backup {
  flex: 1;
  padding: 7px 8px;
  background: rgba(255,255,255,0.04);
  color: #999;
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: var(--radius);
  font-size: 11px;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
  letter-spacing: 0.02em;
}
.btn-backup:hover { background: rgba(255,255,255,0.08); color: #E8E4DC; }

/* ── Streak badge ────────────────────────────────────────────────── */
.streak-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 16px;
  cursor: pointer;
  border-bottom: 1px solid rgba(255,255,255,0.07);
  transition: background 0.15s;
}
.streak-badge:hover { background: rgba(255,255,255,0.04); }
.streak-fire { font-size: 16px; }
.streak-num { color: #E8E4DC; font-weight: 700; font-size: 14px; }
.streak-label { color: #888; font-size: 12px; }

.sidebar.collapsed .streak-label,
.sidebar.collapsed .streak-num { display: none; }

/* ── Stale unit dot ──────────────────────────────────────────────── */
.stale-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #E67700;
  flex-shrink: 0;
  margin-left: -2px;
}

/* ── Share card modal ────────────────────────────────────────────── */
.share-card-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  z-index: 200;
  align-items: center;
  justify-content: center;
}
.share-card-overlay.open { display: flex; }
.share-card-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  max-width: 92vw;
}
.share-card-img {
  max-width: 320px;
  max-height: 70vh;
  border-radius: 16px;
  box-shadow: 0 24px 60px rgba(0,0,0,0.4);
}
.share-card-actions {
  display: flex;
  gap: 10px;
}

/* ── Dashboard ───────────────────────────────────────────────────── */
.dashboard { max-width: 640px; }

.dash-header { text-align: center; margin-bottom: 28px; }
.dash-kana {
  font-family: 'Noto Serif JP', serif;
  font-size: 40px;
  color: var(--border);
  line-height: 1;
  margin-bottom: 6px;
}
.dash-title { font-size: 22px; font-weight: 600; color: var(--ink); }

.dash-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-bottom: 18px;
}
@media (max-width: 560px) {
  .dash-stats { grid-template-columns: repeat(2, 1fr); }
}
.dash-stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px 10px;
  text-align: center;
}
.dash-stat-streak {
  background: linear-gradient(135deg, #FFF3E0, #FFE8D6);
  border-color: #FFD8A8;
}
.dash-stat-icon { display: none; }
.dash-stat-value { font-size: 22px; font-weight: 700; color: var(--ink); line-height: 1.1; }
.dash-stat-label { font-size: 10.5px; color: var(--ink-3); margin-top: 3px; text-transform: uppercase; letter-spacing: 0.04em; }

.dash-share-btn {
  display: block;
  width: 100%;
  padding: 11px;
  margin-bottom: 28px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
  cursor: pointer;
  transition: all var(--trans);
}
.dash-share-btn:hover { background: var(--accent-lt); border-color: var(--accent); }

.dash-section { margin-bottom: 24px; }
.dash-section-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--ink-3);
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.dash-resume-card {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  cursor: pointer;
  transition: border-color var(--trans), transform var(--trans);
}
.dash-resume-card:hover { border-color: var(--accent); }
.dash-resume-card:active { transform: scale(0.99); }
.dash-resume-eyebrow { font-size: 10.5px; color: var(--accent); font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
.dash-resume-title { font-size: 14px; font-weight: 600; color: var(--ink); flex: 1; margin-top: 1px; }
.dash-resume-arrow { font-size: 18px; color: var(--ink-3); }

.dash-stale-list { display: flex; flex-direction: column; gap: 6px; }
.dash-stale-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  color: var(--ink-2);
  cursor: pointer;
  transition: border-color var(--trans);
}
.dash-stale-item:hover { border-color: var(--grammar); }

.dash-type-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}
@media (min-width: 500px) {
  .dash-type-grid { grid-template-columns: repeat(3, 1fr); }
}
.dash-type-pill {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color var(--trans);
}
.dash-type-pill:hover { border-color: var(--accent); }
.dash-type-count { font-size: 13px; font-weight: 600; color: var(--ink-3); }

/* ── Relearn flag ────────────────────────────────────────────────── */
.note-flag-btn {
  background: none;
  border: none;
  font-size: 15px;
  cursor: pointer;
  opacity: 0.35;
  transition: opacity 0.15s, transform 0.15s;
  padding: 4px 4px;
  flex-shrink: 0;
  line-height: 1;
}
.note-card:hover .note-flag-btn { opacity: 0.7; }
.note-flag-btn.active { opacity: 1; }
.note-flag-btn:active { transform: scale(1.2); }

.note-card.flagged {
  border-color: #FFD43B;
  background: #FFFBEB;
}

@media (max-width: 768px) {
  .note-flag-btn { opacity: 0.5; font-size: 17px; }
  .note-flag-btn.active { opacity: 1; }
}

.study-tab-relearn.active {
  background: #FFF3BF;
  color: #E67700;
  border-color: #FFD43B;
}

.dash-relearn-card {
  background: #FFFBEB;
  border-color: #FFE066;
}
.dash-relearn-card:hover { border-color: #E67700; }
.dash-relearn-card .dash-resume-eyebrow { color: #E67700; }

/* ── Drag and drop ───────────────────────────────────────────────── */
.section-drag-handle {
  cursor: grab;
  color: var(--ink-3);
  font-size: 14px;
  padding: 2px 4px;
  flex-shrink: 0;
  opacity: 0;
  transition: opacity 0.15s;
  user-select: none;
  touch-action: none; /* let our JS handle touch instead of browser scroll */
}
.section-header:hover .section-drag-handle { opacity: 0.6; }
.section-drag-handle:active { cursor: grabbing; }

.note-drag-handle {
  cursor: grab;
  color: var(--ink-3);
  font-size: 13px;
  padding: 4px 4px;
  flex-shrink: 0;
  opacity: 0;
  transition: opacity 0.15s;
  user-select: none;
  touch-action: none;
}
.note-card:hover .note-drag-handle { opacity: 0.5; }
.note-drag-handle:active { cursor: grabbing; opacity: 1; }

.section-block.dragging { opacity: 0.4; }
.note-card.dragging { opacity: 0.4; }

.sections-container { display: contents; }

/* Mobile: handles always visible since there's no hover state */
@media (max-width: 768px) {
  .section-drag-handle,
  .note-drag-handle {
    opacity: 0.45;
    font-size: 18px;
    padding: 6px 8px;
  }
}

/* Long-press active drag visual feedback */
.note-card.lp-active,
.section-block.lp-active {
  opacity: 1 !important;
  background: var(--surface);
  border-radius: 10px;
}
.lp-placeholder {
  border: 2px dashed var(--accent);
  border-radius: var(--radius);
  opacity: 0.4;
  margin-bottom: 8px;
  background: var(--accent-lt);
}

/* Drag handles don't apply inside Study View (aggregated, cross-unit) */
.study-unit-group .note-drag-handle { display: none; }

/* Drag handles don't apply in search results either (read-only listing) */
.search-result-block .note-drag-handle,
.search-result-block .section-drag-handle { display: none; }

/* ── Dashboard study time chart ──────────────────────────────────── */
.dash-chart-section { margin-bottom: 22px; }

.chart-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 14px;
  overflow-x: auto;
}
.chart-tab {
  padding: 6px 13px;
  border-radius: 20px;
  border: 1px solid var(--border);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  background: var(--surface);
  color: var(--ink-2);
  white-space: nowrap;
  transition: all var(--trans);
}
.chart-tab:hover { border-color: var(--accent); color: var(--accent); }
.chart-tab.active {
  background: var(--accent-lt);
  color: var(--accent);
  border-color: var(--accent);
}

.chart-summary {
  font-size: 12px;
  color: var(--ink-3);
  margin-bottom: 8px;
  font-weight: 600;
}

.chart-bars {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  height: 130px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 12px 8px;
  overflow-x: auto;
}
.chart-bar-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  flex: 1;
  min-width: 14px;
  height: 100%;
  gap: 6px;
}
.chart-bar {
  width: 100%;
  max-width: 22px;
  background: var(--accent);
  border-radius: 3px 3px 0 0;
  opacity: 0.85;
  transition: opacity 0.15s;
  min-height: 2px;
}
.chart-bar-wrap:hover .chart-bar { opacity: 1; }
.chart-bar-label {
  font-size: 9px;
  color: var(--ink-3);
  white-space: nowrap;
  transform: rotate(0deg);
}
.chart-bar-label-hidden { visibility: hidden; }

.chart-empty {
  text-align: center;
  padding: 30px 0;
  color: var(--ink-3);
  font-size: 13px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
}

@media (max-width: 768px) {
  .chart-bars { height: 110px; }
  .chart-bar-label { font-size: 8px; }
}

/* ── Chart tooltip ───────────────────────────────────────────────── */
.chart-tooltip {
  display: none;
  align-items: baseline;
  gap: 6px;
  background: var(--ink);
  color: #fff;
  font-size: 12px;
  padding: 6px 12px;
  border-radius: 8px;
  margin-bottom: 8px;
  width: fit-content;
}
.chart-tooltip.visible { display: flex; }
.chart-tooltip strong { font-size: 14px; font-weight: 700; }
.chart-tooltip span { color: #ccc; font-size: 11px; }

.chart-bar-wrap { cursor: pointer; }
.chart-bar-wrap.highlighted .chart-bar { opacity: 1; background: #a93226; }

/* ── Dashboard stats subtitle ────────────────────────────────────── */
.dash-stats-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--ink-3);
  margin-bottom: 10px;
}
