:root{
  --amber: #f59e0b;
  --amber-dark: #d97706;

  --ink: #111827;
  --ink-soft: #667085;
  --ink-faint: #9ca3af;

  --line: rgba(17, 24, 39, 0.08);
  --line-soft: rgba(17, 24, 39, 0.05);

  --danger-bg: #fff1f3;
  --danger-ink: #c81e1e;

  --shadow-sheet: 0 -8px 24px rgba(16,24,40,.10);
}

*{
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body{
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
}

body{
  background: #dfe6ef;
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

.phone{
  position: fixed;
  inset: 0;
  display: grid;
  place-items: stretch;
  padding: 0;
  overflow: hidden;
}

.app{
  width: min(430px, 100vw);
  height: 100%;
  margin: 0 auto;
  background: #fff;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

@media (min-width: 700px){
  .phone{
    padding: 16px;
    place-items: center;
  }
  .app{
    width: min(430px, 94vw);
    height: min(920px, 96vh);
    border-radius: 28px;
    box-shadow: 0 14px 42px rgba(15,23,42,.10);
    border: 1px solid rgba(17,24,39,.05);
  }
}

/* ─── Views ─────────────────────────────────────────────── */

/* Container that holds the two views, sits above the persistent add bar */
.viewContainer{
  flex: 1;
  min-height: 0;
  position: relative;
  overflow: hidden;
}

.view{
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: #fff;
  overflow: hidden;
  isolation: isolate;
}

.isHidden{ display: none !important; }
.isInvisible{ opacity: 0 !important; pointer-events: none !important; }

/* ─── Words View ─────────────────────────────────────────── */

.wordsScroll{
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 8px 28px 20px;
}

.wordsScroll::-webkit-scrollbar{ width: 4px; }
.wordsScroll::-webkit-scrollbar-thumb{
  background: rgba(17,24,39,.10);
  border-radius: 999px;
}

.wordsHeader{
  flex: 0 0 auto;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: calc(env(safe-area-inset-top, 0px) + 28px) 28px 20px;
  background: #fff;
  position: relative;
}

.headerBtns{
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 4px;
}

.wordsTitle{
  font-family: 'Playfair Display', Georgia, 'Times New Roman', serif;
  font-size: 34px;
  font-weight: 700;
  color: #1c1c1e;
  margin: 0;
  line-height: 1.1;
  letter-spacing: -0.02em;
}

.titleCount{
  font-family: Inter, ui-sans-serif, system-ui, sans-serif;
  font-size: 16px;
  font-weight: 400;
  color: var(--ink-faint);
  letter-spacing: 0;
  margin-left: 10px;
  vertical-align: middle;
  position: relative;
  top: -2px;
}

.headerIconBtn{
  background: none;
  border: none;
  padding: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  transition: opacity 0.14s ease;
  position: relative;
}

.headerIconBtn:active{ opacity: 0.6; }

.headerIconBtn svg{
  width: 20px;
  height: 20px;
}

/* Three-dot menu button — amber, prominent */
.headerMenuBtn{ color: var(--amber-dark); }
.headerMenuBtn svg{ width: 4px; height: 18px; }

/* Dropdown menu */
.menuDropdown{
  position: absolute;
  top: calc(100% - 8px);
  right: 20px;
  background: #fff;
  border-radius: 14px;
  box-shadow: 0 6px 24px rgba(16,24,40,.13);
  border: 1px solid rgba(17,24,39,.06);
  z-index: 200;
  min-width: 176px;
  overflow: hidden;
}

.menuItem{
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 13px 16px;
  border: none;
  background: none;
  font-size: 15px;
  font-family: inherit;
  color: var(--ink);
  cursor: pointer;
  text-align: left;
}

.menuItem + .menuItem{
  position: relative;
}
.menuItem + .menuItem::before{
  content: '';
  position: absolute;
  top: 0;
  left: 16px;
  right: 16px;
  height: 1px;
  background: var(--line);
}

.menuItem:active{ background: rgba(17,24,39,.04); }

.menuItem svg{
  width: 17px;
  height: 17px;
  flex-shrink: 0;
  color: var(--ink-soft);
}

.menuItemDisabled{
  color: var(--ink-faint);
  cursor: default;
}

.menuItemDisabled svg{ color: var(--ink-faint); }


/* ─── Active Filter Strip ───────────────────────────────── */

.activeFilterStrip{
  flex: 0 0 auto;
  display: flex;
  gap: 8px;
  padding: 0 28px 14px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.activeFilterStrip::-webkit-scrollbar{ display: none; }

.activeFilterPill{
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 11px 5px 13px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  border: none;
  cursor: pointer;
  flex-shrink: 0;
  transition: opacity .14s ease;
}

.activeFilterPill:active{ opacity: 0.75; }

.activeFilterPillX{
  font-size: 15px;
  opacity: 0.8;
  line-height: 1;
  margin-left: 1px;
}

/* ─── Word List ──────────────────────────────────────────── */

.group{
  margin-bottom: 4px;
}

.groupHeader{
  font-size: 11px;
  font-weight: 600;
  color: var(--ink-faint);
  letter-spacing: 0.07em;
  text-transform: uppercase;
  padding: 20px 0 6px;
  pointer-events: none;
  user-select: none;
}

.group:first-child .groupHeader{
  padding-top: 2px;
}

.groupHeader.groupHeaderSubject{
  text-transform: none;
  letter-spacing: 0;
  font-size: 0; /* container holds only the pill span */
  padding: 18px 0 8px;
  pointer-events: auto;
  user-select: auto;
}

.group:first-child .groupHeader.groupHeaderSubject{
  padding-top: 0;
}

.groupSubjectPill{
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 11px 5px 13px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0;
  border: none;
  cursor: pointer;
  transition: opacity .14s ease;
}

.groupSubjectPill:active{ opacity: 0.75; }

.groupSubjectPillX{
  font-size: 15px;
  opacity: 0.8;
  line-height: 1;
  margin-left: 1px;
}

.wordItem{
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 10px;
  padding: 11px 0;
  min-height: 44px;
  border: none;
  border-bottom: 1px solid rgba(17,24,39,.06);
  background: transparent;
  width: 100%;
  cursor: pointer;
  transition: background 0.12s ease;
  border-radius: 0;
  position: relative;
  overflow: visible;
}

/* No separator after the last word in each group */
.wordItem:last-child{
  border-bottom: none;
}

.wordItem:active{
  background: rgba(15,23,42,.04);
}

.wordText{
  font-size: 17px;
  font-weight: 500;
  line-height: 1.3;
  color: #1c1c1e;
  text-align: left;
}

.wordTagDots{
  display: flex;
  align-items: center;
  gap: 5px;
  flex: 0 0 auto;
}

.tagDot{
  width: 8px;
  height: 8px;
  border-radius: 999px;
  display: inline-block;
  flex: 0 0 auto;
}

.emptyStateWrap{
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 70vh;
  padding: 0 40px;
  text-align: center;
}
.emptyStateSVG{
  margin-bottom: 12px;
  opacity: 0.82;
}
.emptyStatePrimary{
  font-size: 16px;
  font-weight: 500;
  color: var(--ink);
  margin: 0;
}
.emptyStateSecondary{
  font-size: 14px;
  font-weight: 400;
  color: var(--ink-soft);
  margin: 0;
}
.emptyStateFilter{
  padding: 36px 28px 0;
  font-size: 14px;
  color: var(--ink-soft);
  text-align: center;
}

/* ─── Add Bar ────────────────────────────────────────────── */

.addBar{
  flex: 0 0 auto;
  padding: 10px 16px calc(env(safe-area-inset-bottom, 0px) + 10px);
  background: rgba(249,250,251,0.97);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--line-soft);
}

.addBarRow{
  display: flex;
  align-items: center;
  gap: 8px;
}

.addInputPill{
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  background: #fff;
  border: 1px solid rgba(17,24,39,.10);
  border-radius: 999px;
  padding: 0 6px 0 20px;
  height: 50px;
  box-shadow: 0 1px 4px rgba(0,0,0,.05);
  transition: border-color .16s ease, box-shadow .16s ease;
}

.addInputPill:focus-within{
  border-color: rgba(15,23,42,.16);
  box-shadow: 0 0 0 4px rgba(15,23,42,.04);
}

.addInput{
  flex: 1;
  height: 100%;
  border: none;
  background: transparent;
  padding: 0;
  font-size: 16px;
  color: var(--ink);
  outline: none;
  min-width: 0;
}

.addInput::placeholder{
  color: #adb5bd;
}

.addBtnRound{
  flex: 0 0 auto;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: none;
  background: var(--amber-dark);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: transform .14s ease;
}

.addBtnRound:active{
  transform: scale(.93);
}

.addBtnRound svg{
  width: 18px;
  height: 18px;
}

.addFilterBtn{
  flex: 0 0 auto;
  background: none;
  border: none;
  padding: 6px;
  color: var(--amber-dark);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
}
.addFilterBtn:active{ opacity: 0.6; }
.addFilterBtn svg{ width: 20px; height: 20px; }

/* ─── Define View ────────────────────────────────────────── */

.defineNav{
  flex: 0 0 auto;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(env(safe-area-inset-top, 0px) + 14px) 16px 10px;
  background: rgba(255,255,255,0.97);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

.defineNavTrash{
  background: none;
  border: none;
  padding: 6px;
  cursor: pointer;
  color: var(--ink-soft);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.14s ease;
}

.defineNavTrash svg{ width: 20px; height: 20px; }
.defineNavTrash:active{ opacity: 0.5; }

.defineNavWord{
  position: absolute;
  bottom: 10px;
  left: 50%;
  transform: translateX(-50%);
  font-family: 'Playfair Display', Georgia, serif;
  font-size: 17px;
  font-weight: 700;
  color: var(--ink);
  white-space: nowrap;
  max-width: 55%;
  overflow: hidden;
  text-overflow: ellipsis;
  opacity: 0;
  transition: opacity 0.18s ease;
  pointer-events: none;
}

.defineNav.wordVisible .defineNavWord{
  opacity: 1;
  pointer-events: auto;
  cursor: pointer;
}

.backBtn{
  display: inline-flex;
  align-items: center;
  background: none;
  border: none;
  color: var(--ink-soft);
  cursor: pointer;
  padding: 4px 2px;
}

.backBtn svg{
  width: 20px;
  height: 20px;
  stroke: var(--ink-soft);
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.backBtn:active{
  opacity: 0.7;
}

.defineScroll{
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.defineScroll::-webkit-scrollbar{ width: 4px; }
.defineScroll::-webkit-scrollbar-thumb{
  background: rgba(17,24,39,.10);
  border-radius: 999px;
}

/* ─── Define View ────────────────────────────────────────── */

.defineEmpty{
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 60px 28px;
  color: var(--ink-faint);
  font-size: 15px;
  font-style: italic;
  text-align: center;
}

.defineBodyLoader{
  padding: 20px 0 8px;
}

@keyframes skelShimmer {
  0%   { background-position: -400px 0; }
  100% { background-position: 400px 0; }
}

.skelLabel, .skelLine {
  border-radius: 4px;
  background: linear-gradient(90deg, #efefef 25%, #e0e0e0 50%, #efefef 75%);
  background-size: 800px 100%;
  animation: skelShimmer 1.4s ease-in-out infinite;
}

.skelLabel {
  height: 10px;
  width: 48px;
  margin-bottom: 12px;
}

.skelLine {
  height: 13px;
  margin-bottom: 10px;
}

.skelPhonetic {
  display: inline-block;
  height: 11px;
  width: 72px;
  border-radius: 4px;
  background: linear-gradient(90deg, #efefef 25%, #e0e0e0 50%, #efefef 75%);
  background-size: 800px 100%;
  animation: skelShimmer 1.4s ease-in-out infinite;
  vertical-align: middle;
}

@keyframes skelFadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.skelFadeIn {
  animation: skelFadeIn 0.2s ease-out forwards;
}

.defineOfflineMsg{
  font-size: 14px;
  color: var(--ink-faint);
  padding: 4px 0;
}

.defineHead{
  padding: 36px 28px 0;
}

.defineWord{
  font-family: 'Playfair Display', Georgia, 'Times New Roman', serif;
  font-size: 38px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: #1c1c1e;
  margin: 0;
  line-height: 1.1;
}

.definePhonetic{
  margin-top: 8px;
  font-size: 15px;
  font-style: italic;
  font-weight: 400;
  color: var(--ink-soft);
  letter-spacing: 0.01em;
}

.defineTagsRow{
  padding: 18px 28px 0;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.defineTagsList{
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.defineTagsList:empty{ display: none; }

.tagPill{
  border: 1px solid var(--line);
  border-radius: 999px;
  min-height: 32px;
  padding: 5px 12px;
  font-size: 13px;
  background: rgba(255,255,255,.8);
  color: var(--ink);
  cursor: pointer;
}

.tagPill.existingTag{
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-color: transparent;
  font-size: 13px;
  font-weight: 500;
}

.tagPill.existingTag .pillRemove{
  font-size: 15px;
  opacity: 0.8;
  line-height: 1;
}

.addTagPill{
  background: rgba(15,23,42,.04);
  border-color: transparent;
  color: var(--ink-soft);
  font-size: 13px;
}

.tagPill .tagDot{
  width: 8px;
  height: 8px;
}

.removeFromCollection{
  display: flex;
  align-items: center;
  gap: 8px;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--ink-soft);
  font-size: 14px;
  font-weight: 400;
  padding: 18px 28px 8px;
  width: 100%;
  text-align: left;
  transition: opacity 0.14s ease;
}

.removeFromCollection svg{
  width: 17px;
  height: 17px;
  flex-shrink: 0;
}

.removeFromCollection:active{ opacity: 0.5; }

/* Define sections — typography-only separation */
.defineSection{
  padding: 32px 28px 0;
}

.defineSectionLabel{
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.10em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin-bottom: 14px;
}

/* POS row: italic label + rule */
.definePOSRow{
  display: flex;
  align-items: center;
  gap: 14px;
  margin: 28px 0 14px;
}
.defineBody > .definePOSRow:first-child{ margin-top: 0; }

.definePOSLabel{
  font-family: 'Playfair Display', Georgia, serif;
  font-style: italic;
  font-size: 16px;
  font-weight: 400;
  color: var(--ink-soft);
  white-space: nowrap;
}

.definePOSRule{
  flex: 1;
  height: 1px;
  background: var(--line);
}

/* Definition items */
.defineDefItem{
  margin-bottom: 18px;
}

.defineDefRow{
  display: flex;
  gap: 10px;
  align-items: baseline;
}

.defineDefNum{
  font-size: 12px;
  color: var(--ink-faint);
  flex-shrink: 0;
  padding-top: 3px;
  min-width: 14px;
}

.defineDefContent{
  flex: 1;
}

.definitionText{
  font-size: 18px;
  line-height: 1.72;
  color: #1c1c1e;
  font-weight: 400;
}

.exampleText{
  margin-top: 12px;
  padding-left: 14px;
  border-left: 2px solid var(--amber-dark);
  font-size: 15px;
  line-height: 1.65;
  color: var(--ink-soft);
  font-style: italic;
  overflow-wrap: break-word;
}

.synonymsList{
  margin-top: 8px;
  font-size: 12px;
  color: var(--ink-soft);
}

.synonymsLabel{
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin-right: 4px;
}

/* Tappable words in definitions */
.wordLink{
  color: var(--amber-dark);
  text-decoration: underline;
  text-decoration-color: rgba(180,120,0,0.35);
  text-underline-offset: 2px;
  cursor: pointer;
}

/* Notes area */
.notesArea{
  width: 100%;
  min-height: 96px;
  border: none;
  outline: none;
  resize: none;
  font-family: Inter, ui-sans-serif, system-ui, sans-serif;
  font-size: 16px;
  font-weight: 400;
  line-height: 1.8em;
  color: #374151;
  background:
    repeating-linear-gradient(
      transparent 0,
      transparent calc(1.8em - 1px),
      rgba(17,24,39,.07) calc(1.8em - 1px),
      rgba(17,24,39,.07) 1.8em
    );
  background-size: 100% 1.8em;
  padding: 0 0 1.8em;
  display: block;
  overflow: hidden;
  field-sizing: content;
}

.notesArea::placeholder{
  color: var(--ink-faint);
  font-style: italic;
}

#defineContent{
  display: flex;
  flex-direction: column;
  min-height: 100%;
}

/* Footer */
.defineFooter{
  margin-top: auto;
  padding: 40px 28px calc(env(safe-area-inset-bottom, 0px) + 40px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.defineMetaLine{
  font-size: 11px;
  color: var(--ink-faint);
  text-align: center;
  letter-spacing: 0.01em;
}


/* ─── Unified Sort & Filter Sheet ───────────────────────── */

#optionsSheet{
  background: #fff;
  max-height: 72vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* Title row */
.sfTitleRow{
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 0 20px;
}

.sfTitle{
  font-family: 'Playfair Display', Georgia, 'Times New Roman', serif;
  font-size: 26px;
  font-weight: 700;
  color: var(--ink);
  margin: 0;
  letter-spacing: -0.01em;
}

.sfCloseBtn{
  background: none;
  border: none;
  cursor: pointer;
  font-size: 20px;
  color: var(--ink-soft);
  padding: 4px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.sfCloseBtn:active{ opacity: 0.6; }

/* Sections */
.sfSection{
  padding: 16px 0;
}

.sfSectionSort{
  border-top: 1px solid rgba(17,24,39,.10);
}

.sfSectionLabel{
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin-bottom: 14px;
}

.sfSectionHead{
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.sfSectionHead .sfSectionLabel{
  margin-bottom: 0;
}

/* Manage button */
.sfManageBtn{
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 13px;
  color: var(--ink-soft);
  background: none;
  border: none;
  cursor: pointer;
  padding: 2px 0;
}

.sfManageBtn:active{ opacity: 0.6; }

/* Subject pills */
.sfPills{
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 4px;
}

.sfPill{
  padding: 7px 14px;
  border-radius: 999px;
  border: 1.5px solid rgba(17,24,39,.18);
  background: transparent;
  color: var(--ink);
  font-size: 14px;
  cursor: pointer;
  transition: background .14s, color .14s, border-color .14s;
  white-space: nowrap;
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sfPill:active{ opacity: 0.75; }

.sfPill.isActive{
  font-weight: 500;
  border-color: transparent;
}

.sfPillUntagged{
  background: transparent;
  border: 1.5px dashed rgba(17,24,39,.25);
  color: var(--ink);
}

.sfPillUntagged.isActive{
  border: 1.5px dashed rgba(17,24,39,.45);
}

/* Group by subject row */
.sfGroupRow{
  display: flex;
  align-items: center;
  gap: 10px;
  padding-top: 14px;
}

.sfGroupCheck{
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}

.sfGroupCheck input{
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.sfCheckbox{
  width: 20px;
  height: 20px;
  border-radius: 6px;
  border: 1.5px solid var(--amber-dark);
  background: transparent;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background .15s, border-color .15s;
}

.sfGroupCheck input:checked + .sfCheckbox{
  background: var(--amber-dark);
  border-color: var(--amber-dark);
  color: #fff;
}

.sfCheckIcon{
  display: none;
  width: 12px;
  height: 12px;
}

.sfGroupCheck input:checked + .sfCheckbox .sfCheckIcon{
  display: block;
}

.sfGroupLabel{
  font-size: 15px;
  color: var(--ink);
}

.sfActionSep{
  font-size: 14px;
  color: var(--ink-faint);
  user-select: none;
}

.sfActionBtn{
  font-size: 14px;
  color: var(--amber-dark);
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
}

.sfActionBtn:active{ opacity: 0.6; }

/* Sort rows */
.sfSortRow{
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
}

.sfSortRow:last-child{ margin-bottom: 0; }

.sfSortRowLabel{
  font-size: 14px;
  color: var(--ink-soft);
  min-width: 80px;
  flex-shrink: 0;
  white-space: nowrap;
}

.sfSortBtns{
  display: flex;
  gap: 8px;
}

.sfSortBtn{
  height: 38px;
  padding: 0 18px;
  border-radius: 999px;
  border: none;
  background: rgba(17,24,39,.09);
  font-size: 14px;
  color: var(--ink);
  cursor: pointer;
  font-weight: 400;
  white-space: nowrap;
  transition: background .14s, color .14s;
}

.sfSortBtn.isActive{
  background: #1c1c1e;
  color: #fff;
  font-weight: 600;
}

.sfSortBtn:active:not(.isActive){
  background: rgba(17,24,39,.15);
}

/* Colored dot in By Subject group headers */
.groupDot{
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 8px;
  vertical-align: middle;
  position: relative;
  top: -1px;
}

/* ─── Backdrop & Sheets ──────────────────────────────────── */

.sheetBackdrop{
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.22);
  z-index: 40;
}

.bottomSheet{
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 50;
  background: #fff;
  border-top-left-radius: 20px;
  border-top-right-radius: 20px;
  box-shadow: var(--shadow-sheet);
  padding: 10px 24px calc(28px + env(safe-area-inset-bottom, 0px));
  max-width: 430px;
  margin: 0 auto;
  transform: translateY(100%);
  animation: sheetUp 240ms cubic-bezier(.22,1,.36,1) forwards;
  max-height: 85vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.sheetHandle{
  width: 40px;
  height: 4px;
  border-radius: 999px;
  background: #d1d5db;
  margin: 2px auto 20px;
}

/* Handle row with close button */
.sheetDragRow{
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  padding-bottom: 16px;
}

.sheetDragRow .sheetHandle{
  margin: 0;
}

.sheetCloseBtn{
  position: absolute;
  right: 0;
  top: 0;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: rgba(17,24,39,.07);
  border: none;
  cursor: pointer;
  color: var(--ink-soft);
  font-size: 17px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.sheetCloseBtn:active{
  background: rgba(17,24,39,.13);
}

/* ─── Subjects View (select + manage modes) ──────────────── */

#subjectsView:not(.isHidden):not(.isClosing){
  animation: slideInUp 280ms cubic-bezier(.22,1,.36,1) forwards;
}
#subjectsView.isClosing{
  animation: slideOutDown 220ms cubic-bezier(.4,0,1,1) forwards;
}

#defineView:not(.isHidden):not(.isClosing){
  animation: slideInRight 260ms cubic-bezier(.22,1,.36,1) forwards;
}
#defineView.isClosing{
  animation: slideOutRight 220ms cubic-bezier(.4,0,1,1) forwards;
}

.subjectsHeading{
  padding: calc(env(safe-area-inset-top, 0px) + 52px) 24px 20px;
}

.subjectsTitleRow{
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
}

.subjectsEditBtn{
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 13px;
  color: var(--ink-soft);
  background: none;
  border: none;
  cursor: pointer;
  padding: 2px 0;
  margin-top: 6px;
  flex-shrink: 0;
}
.subjectsEditBtn:active{ opacity: 0.6; }

.subjectsTitle{
  font-family: 'Playfair Display', Georgia, serif;
  font-size: 32px;
  font-weight: 700;
  color: var(--ink);
  margin: 0 0 4px;
  letter-spacing: -0.01em;
}

.subjectsSubtitle{
  font-size: 14px;
  line-height: 1.4;
  min-height: 1.4em;
  color: var(--ink-soft);
  margin: 0;
  transition: opacity 0.15s ease;
}
.subjectsSubtitle.isFading{ opacity: 0; }


.subjectsScroll{
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

#subjectsList{
  display: flex;
  flex-direction: column;
  padding-bottom: 20px;
}

/* Subject rows */
.subjectRow{
  display: flex;
  flex-direction: column;
  cursor: pointer;
}

.subjectRow::after{
  content: '';
  display: block;
  height: 1px;
  background: var(--line-soft);
  margin: 0 24px;
}

.subjectRow:last-child::after{
  display: none;
}

.subjectRowMain{
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 24px;
  min-height: 60px;
}

.subjectRowDot{
  width: 26px;
  height: 26px;
  border-radius: 50%;
  flex-shrink: 0;
  border: none;
  padding: 0;
  cursor: pointer;
}

.subjectRowDot:active{ opacity: 0.75; }

.subjectRowName{
  flex: 1;
  font-size: 17px;
  font-weight: 400;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

@keyframes subjectCtaIn {
  0%   { transform: scale(0); opacity: 0; }
  60%  { transform: scale(1.22); opacity: 1; }
  80%  { transform: scale(0.9); }
  100% { transform: scale(1); }
}
@keyframes subjectCtaOut {
  from { transform: scale(1); opacity: 1; }
  to   { transform: scale(0); opacity: 0; }
}

/* Select mode checkmark */
.subjectRowCheck{
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: transparent;
  border: 2px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s, border-color 0.15s;
}

.subjectRowCheck.isEntering{
  animation: subjectCtaIn 0.38s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

.subjectRow.isSelected .subjectRowCheck{
  background: var(--amber-dark);
  border-color: var(--amber-dark);
}

.subjectRow.isSelected .subjectRowCheck svg{
  display: block;
}

.subjectRowCheck svg{
  width: 16px;
  height: 16px;
  display: none;
}

.subjectRow.isSelected .subjectRowName{
  font-weight: 500;
}

/* Manage mode trash */
.subjectRowTrash{
  background: none;
  border: none;
  padding: 4px;
  cursor: pointer;
  color: var(--ink-faint);
  flex-shrink: 0;
  display: flex;
  align-items: center;
}

.subjectRowTrash.isEntering{
  animation: subjectCtaIn 0.38s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

.subjectRowTrash svg{
  width: 20px;
  height: 20px;
}

.subjectRowTrash.isPendingDelete{
  color: var(--danger-ink);
}

.subjectRowTrash:active{ opacity: 0.6; }

.subjectRowCheck.isLeaving,
.subjectRowTrash.isLeaving{
  animation: subjectCtaOut 0.14s ease-in forwards;
}

/* Color picker (inline expansion in manage mode) */
.subjectColorPicker{
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.32s cubic-bezier(0.4, 0, 0.2, 1);
}

.subjectColorPicker.isOpen{ max-height: 160px; }

.subjectColorPickerInner{
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  padding: 14px 24px 16px;
}

/* Rename input */
.subjectNameInput{
  flex: 1;
  font-size: 17px;
  font-family: inherit;
  color: var(--ink);
  border: none;
  border-bottom: 1.5px solid var(--amber-dark);
  outline: none;
  background: transparent;
  padding: 4px 0;
  min-width: 0;
}

/* "New subject" add row */
.subjectAddRow{
  cursor: pointer;
  color: var(--ink-faint);
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.28s cubic-bezier(0.4, 0, 0.2, 1);
}

.subjectAddRow.isVisible{
  max-height: 80px;
}

.subjectAddDot{
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 1.5px dashed var(--ink-faint);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  line-height: 1;
  color: var(--ink-faint);
}

.subjectAddDot::before{ content: "+"; }

.subjectAddLabel{
  font-size: 17px;
  color: var(--ink-faint);
}

/* Floating count label above Done bar */
.subjectsCountFloat{
  flex: 0 0 auto;
  display: block;
  text-align: center;
  font-size: 13px;
  color: var(--ink-faint);
  padding: 6px 24px 4px;
  background: rgba(249,250,251,0.97);
}
.subjectsCountFloat:empty{ display: none; }
.subjectsCountFloat{ display: none; } /* v1.5 — hide count for now */

/* Persistent Done bar */
.subjectsDoneBar{
  flex: 0 0 auto;
  border-top: 1px solid var(--line-soft);
  background: rgba(249,250,251,0.97);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  padding: 12px 24px calc(env(safe-area-inset-bottom, 0px) + 16px);
}

.subjectsDoneBarBtn{
  display: block;
  width: 100%;
  padding: 15px;
  background: #1c1c1e;
  color: #fff;
  border: none;
  border-radius: 100px;
  font-size: 16px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  text-align: center;
  letter-spacing: 0.01em;
}
.subjectsDoneBarBtn:active{ opacity: 0.75; }

/* colorSwatch shared */
.colorSwatch{
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 2.5px solid transparent;
  cursor: pointer;
  flex-shrink: 0;
  padding: 0;
}

.colorSwatch.isActive{ border-color: transparent; box-shadow: 0 0 0 2px #fff, 0 0 0 4px rgba(0,0,0,0.28); }

.colorSwatch:active{ opacity: 0.75; }

/* ─── Delete Modal ───────────────────────────────────────── */
.deleteModal{
  position: fixed;
  inset: 0;
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px 20px;
}

.deleteModal.isHidden{ display: none; }

.deleteModalBackdrop{
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.4);
}

.deleteModalCard{
  position: relative;
  background: #fff;
  border-radius: 18px;
  padding: 28px 24px 20px;
  width: 100%;
  max-width: 360px;
}

.deleteModalTitle{
  font-size: 18px;
  font-weight: 600;
  color: var(--ink);
  margin: 0 0 8px;
  line-height: 1.3;
}

.deleteModalBody{
  font-size: 14px;
  color: var(--ink-soft);
  margin: 0 0 24px;
  line-height: 1.5;
}

.deleteModalBtns{
  display: flex;
  gap: 10px;
}

.deleteModalCancel,
.deleteModalConfirm{
  flex: 1;
  padding: 13px;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
}

.deleteModalCancel{
  background: transparent;
  border: 1.5px solid var(--line);
  color: var(--ink);
}

.deleteModalConfirm{
  background: #c0392b;
  border: none;
  color: #fff;
}

.deleteModalCancel:active{ opacity: 0.65; }
.deleteModalConfirm:active{ opacity: 0.85; }

/* Hide subject dots on word rows when grouped by subject */
.isGroupedBySubject .wordTagDots{
  display: none;
}

/* ─── Animations ─────────────────────────────────────────── */

@keyframes slideInRight{
  from{ transform: translateX(100%); }
  to{ transform: translateX(0); }
}

@keyframes slideOutRight{
  from{ transform: translateX(0); }
  to{ transform: translateX(100%); }
}

@keyframes slideInUp{
  from{ transform: translateY(100%); }
  to{ transform: translateY(0); }
}

@keyframes slideOutDown{
  from{ transform: translateY(0); }
  to{ transform: translateY(100%); }
}

@keyframes sheetUp{
  from{ transform: translateY(100%); }
  to{ transform: translateY(0); }
}

@keyframes sheetDown{
  from{ transform: translateY(0); }
  to{ transform: translateY(110%); }
}

.bottomSheet.isClosing{
  animation: sheetDown 220ms cubic-bezier(.4,0,1,1) forwards;
}

/* Highlighter flash — stripe only as wide as the word itself.
   z-index:1 on .wordText creates a stacking context so the ::after
   at z-index:-1 stays inside it (behind text) rather than escaping
   behind the scroll container's white background. */
.wordItem.flash .wordText{
  position: relative;
  z-index: 1;
}

.wordItem.flash .wordText::after{
  content: '';
  position: absolute;
  top: 50%;
  left: -5px;
  right: -14px;
  height: 1.5em;
  transform: translateY(-50%);
  background: rgba(245, 158, 11, 0.22);
  border-radius: 3px;
  pointer-events: none;
  animation: highlighterFlash 850ms ease forwards;
  z-index: -1;
}

@keyframes highlighterFlash{
  0%  { opacity: 1; }
  55% { opacity: 1; }
  100%{ opacity: 0; }
}
