/* ==========================================================================
   Hoyer Vocabulary — Apple Minimalist Design System
   Radical simplicity, refined typography, fluid spring motion, mobile-first.
   ========================================================================== */

:root {
  --bg: #f5f5f7;
  --surface: #ffffff;
  --surface-hover: #fafafa;
  --glass: rgba(245, 245, 247, 0.8);
  --glass-elevated: rgba(255, 255, 255, 0.94);
  --backdrop: rgba(18, 18, 22, 0.34);

  --ink-primary: #1d1d1f;
  --ink-secondary: #6e6e73;
  --ink-tertiary: #8e8e93;

  --hairline: rgba(0, 0, 0, 0.068);
  --hairline-strong: rgba(0, 0, 0, 0.12);
  --track: rgba(118, 118, 128, 0.11);
  --track-hover: rgba(118, 118, 128, 0.17);

  --accent: #0071e3;
  --accent-hover: #0077ed;
  --accent-soft: rgba(0, 113, 227, 0.1);
  --accent-ring: rgba(0, 113, 227, 0.22);

  --green: #248a3d;
  --green-soft: rgba(52, 199, 89, 0.13);

  --amber: #b25900;
  --amber-soft: rgba(255, 149, 0, 0.13);

  --red: #d70015;
  --red-soft: rgba(255, 59, 48, 0.11);

  --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.03), 0 8px 24px rgba(0, 0, 0, 0.035);
  --shadow-thumb: 0 1px 3px rgba(0, 0, 0, 0.09), 0 0.5px 1px rgba(0, 0, 0, 0.05);
  --shadow-popover: 0 12px 36px rgba(0, 0, 0, 0.12), 0 1px 3px rgba(0, 0, 0, 0.06);
  --shadow-sheet: 0 24px 64px rgba(0, 0, 0, 0.18), 0 2px 8px rgba(0, 0, 0, 0.06);
  --shadow-toast: 0 10px 30px rgba(0, 0, 0, 0.16);

  --font-sans: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text",
    "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, sans-serif;
  --font-mono: "SF Mono", ui-monospace, "Cascadia Mono", Menlo, Consolas, monospace;

  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-glide: cubic-bezier(0.32, 0.72, 0, 1);
  --topbar-h: 54px;
}

:root[data-theme="dark"] {
  --bg: #000000;
  --surface: #1c1c1e;
  --surface-hover: #222225;
  --glass: rgba(14, 14, 16, 0.78);
  --glass-elevated: rgba(34, 34, 38, 0.94);
  --backdrop: rgba(0, 0, 0, 0.62);

  --ink-primary: #f5f5f7;
  --ink-secondary: #a1a1a6;
  --ink-tertiary: #7c7c82;

  --hairline: rgba(255, 255, 255, 0.085);
  --hairline-strong: rgba(255, 255, 255, 0.15);
  --track: rgba(255, 255, 255, 0.09);
  --track-hover: rgba(255, 255, 255, 0.15);

  --accent: #2997ff;
  --accent-hover: #45a5ff;
  --accent-soft: rgba(41, 151, 255, 0.16);
  --accent-ring: rgba(41, 151, 255, 0.3);

  --green: #30d158;
  --green-soft: rgba(48, 209, 88, 0.16);

  --amber: #ff9f0a;
  --amber-soft: rgba(255, 159, 10, 0.16);

  --red: #ff453a;
  --red-soft: rgba(255, 69, 58, 0.16);

  --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.3), 0 12px 28px rgba(0, 0, 0, 0.32);
  --shadow-thumb: 0 1px 3px rgba(0, 0, 0, 0.5);
  --shadow-popover: 0 16px 44px rgba(0, 0, 0, 0.55);
  --shadow-sheet: 0 28px 72px rgba(0, 0, 0, 0.68);
  --shadow-toast: 0 12px 34px rgba(0, 0, 0, 0.55);
}

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

:focus:not(:focus-visible) {
  outline: none;
}

html {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

body {
  margin: 0;
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--ink-primary);
  line-height: 1.5;
  min-height: 100dvh;
  transition: background-color 0.25s var(--ease), color 0.25s var(--ease);
}

button, input, select, textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  border: none;
  background: none;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

[hidden] {
  display: none !important;
}

/* ---------------- Top Bar (Always 1 sleek row) ---------------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--glass);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--hairline);
}

.topbar-inner {
  max-width: 780px;
  margin: 0 auto;
  height: var(--topbar-h);
  padding: 0 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--ink-primary);
}

.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 7px;
  background: var(--surface);
  border: 1px solid var(--hairline);
}

.brand-name {
  font-size: 15.5px;
  font-weight: 620;
  letter-spacing: -0.025em;
}

.topbar-right {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.icon-btn {
  width: 32px;
  height: 32px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--ink-secondary);
  transition: background-color 0.16s var(--ease), color 0.16s var(--ease), transform 0.12s var(--ease);
}

.icon-btn:hover {
  background: var(--track);
  color: var(--ink-primary);
}

.icon-btn:active {
  transform: scale(0.93);
}

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

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

.icon-btn-accent:hover {
  background: var(--accent);
  color: #ffffff;
}

/* Topbar Category Submenu Button & Dropdown */
.cat-menu-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 30px;
  padding: 0 10px 0 11px;
  border-radius: 999px;
  background: var(--track);
  color: var(--ink-primary);
  font-size: 12.5px;
  font-weight: 560;
  white-space: nowrap;
  transition: background-color 0.16s var(--ease), color 0.16s var(--ease), transform 0.12s var(--ease);
}

.cat-menu-btn:hover {
  background: var(--track-hover);
}

.cat-menu-btn:active {
  transform: scale(0.96);
}

.cat-menu-btn.is-filtered {
  background: var(--accent-soft);
  color: var(--accent);
}

.cat-menu-chevron {
  opacity: 0.72;
  transition: transform 0.2s var(--ease);
}

.cat-menu-btn[aria-expanded="true"] .cat-menu-chevron {
  transform: rotate(180deg);
}

.popover.cat-popover {
  width: 210px;
  padding: 6px;
  gap: 2px;
  border-radius: 15px;
  right: -40px;
  background: var(--surface);
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  border: 1px solid var(--hairline-strong);
  box-shadow: var(--shadow-sheet);
}

.cat-menu-item {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 10px;
  text-align: left;
  transition: background-color 0.14s var(--ease);
}

.cat-menu-item:hover {
  background: var(--track);
}

.cat-menu-item.is-active {
  background: var(--accent-soft);
}

.cat-menu-item-main {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.cat-menu-item-name {
  font-size: 13.5px;
  font-weight: 580;
  color: var(--ink-primary);
  line-height: 1.25;
}

.cat-menu-item.is-active .cat-menu-item-name {
  color: var(--accent);
}

.cat-menu-item-sub {
  font-size: 11px;
  color: var(--ink-tertiary);
  line-height: 1.3;
}

.cat-menu-item-right {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
  font-size: 12px;
  color: var(--ink-tertiary);
  font-variant-numeric: tabular-nums;
}

.cat-menu-check {
  color: var(--accent);
}

:root[data-theme="dark"] .icon-sun { display: block; }
:root[data-theme="dark"] .icon-moon { display: none; }
:root:not([data-theme="dark"]) .icon-sun { display: none; }
:root:not([data-theme="dark"]) .icon-moon { display: block; }

/* ---------------- Gliding Segmented Control ---------------- */

.segmented {
  position: relative;
  display: inline-flex;
  align-items: center;
  padding: 3px;
  border-radius: 11px;
  background: var(--track);
  gap: 2px;
}

.seg-thumb {
  position: absolute;
  top: 3px;
  bottom: 3px;
  left: 0;
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow-thumb);
  pointer-events: none;
  z-index: 0;
  opacity: 0;
  will-change: transform, width;
  transition:
    transform 0.36s var(--ease-glide),
    width 0.36s var(--ease-glide),
    opacity 0.16s ease;
}

.seg-thumb.is-ready {
  opacity: 1;
}

.seg-thumb.no-anim {
  transition: none !important;
}

.seg-btn {
  position: relative;
  z-index: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 6px 14px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 520;
  color: var(--ink-secondary);
  white-space: nowrap;
  transition: color 0.22s var(--ease);
}

.seg-btn:hover,
.seg-btn.is-active {
  color: var(--ink-primary);
}

.mode-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 19px;
  height: 18px;
  padding: 0 6px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 640;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  background: var(--accent-soft);
  color: var(--accent);
}

/* ---------------- Main Canvas & Large Primary Dock ---------------- */

.container {
  max-width: 780px;
  margin: 0 auto;
  padding: 16px 20px 72px;
}

.main-dock-wrap {
  display: flex;
  justify-content: center;
  max-width: 500px;
  margin: 0 auto 12px;
}

.main-dock {
  width: 100%;
  padding: 4px;
  border-radius: 15px;
  gap: 4px;
}

.main-dock .seg-thumb {
  top: 4px;
  bottom: 4px;
  border-radius: 11px;
}

.main-dock .mode-btn {
  flex: 1;
  height: 40px;
  padding: 0 12px;
  border-radius: 11px;
  font-size: 14.5px;
  font-weight: 600;
  gap: 6px;
  letter-spacing: -0.01em;
}

/* ---------------- Sticky Single-row Utility Bar ---------------- */

.utility-bar {
  position: sticky;
  top: var(--topbar-h);
  z-index: 35;
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 -20px 10px;
  padding: 8px 20px;
  background: var(--glass);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--hairline);
}

.search-field {
  position: relative;
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
}

.search-icon {
  position: absolute;
  left: 12px;
  color: var(--ink-tertiary);
  pointer-events: none;
}

.search-field input {
  width: 100%;
  height: 38px;
  padding: 0 32px 0 35px;
  border-radius: 11px;
  border: 1px solid var(--hairline);
  background: var(--surface);
  font-size: 14px;
  transition: border-color 0.18s var(--ease), box-shadow 0.18s var(--ease);
}

.search-field input::placeholder {
  color: var(--ink-tertiary);
}

.search-field input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3.5px var(--accent-ring);
}

.search-field input::-webkit-search-cancel-button {
  -webkit-appearance: none;
}

.search-clear {
  position: absolute;
  right: 8px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--track);
  color: var(--ink-secondary);
  font-size: 13px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.utility-actions {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.chip-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 38px;
  padding: 0 12px;
  border-radius: 11px;
  border: 1px solid var(--hairline);
  background: var(--surface);
  font-size: 13px;
  font-weight: 500;
  color: var(--ink-secondary);
  white-space: nowrap;
  transition: all 0.16s var(--ease);
}

.chip-btn:hover {
  border-color: var(--hairline-strong);
  color: var(--ink-primary);
}

.chip-btn.is-active {
  border-color: transparent;
  background: var(--accent-soft);
  color: var(--accent);
}

/* Filter Popover */
.popover-anchor {
  position: relative;
}

.popover {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 60;
  width: 264px;
  padding: 14px;
  border-radius: 16px;
  background: var(--surface);
  border: 1px solid var(--hairline-strong);
  box-shadow: var(--shadow-sheet);
  display: flex;
  flex-direction: column;
  gap: 14px;
  animation: popIn 0.18s var(--ease);
}

.popover-section {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.popover-label {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--ink-tertiary);
  padding-left: 2px;
}

.popover-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.pop-pill {
  height: 28px;
  padding: 0 10px;
  border-radius: 8px;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--ink-secondary);
  background: var(--track);
  transition: all 0.15s var(--ease);
}

.pop-pill:hover {
  color: var(--ink-primary);
  background: var(--track-hover);
}

.pop-pill.is-active {
  background: var(--ink-primary);
  color: var(--bg);
}

.popover-reset {
  width: 100%;
  height: 32px;
  border-radius: 9px;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--accent);
  background: var(--accent-soft);
  transition: filter 0.15s ease;
}

.popover-reset:hover {
  filter: brightness(0.95);
}

/* Quiet 1-line Summary */
.meta-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 2px 4px 12px;
  font-size: 12.5px;
  color: var(--ink-tertiary);
  font-variant-numeric: tabular-nums;
}

.meta-left {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.meta-collapse-btn {
  flex-shrink: 0;
  white-space: nowrap;
  color: var(--ink-secondary);
  font-size: 12.5px;
  font-weight: 520;
  padding: 2px 8px;
  margin-right: -4px;
  border-radius: 8px;
  transition: background-color 0.15s var(--ease), color 0.15s var(--ease);
}

.meta-collapse-btn:hover {
  background: var(--track);
  color: var(--ink-primary);
}

/* ---------------- Inset Grouped Word List ---------------- */

.date-section {
  margin-bottom: 22px;
  transition: margin-bottom 0.24s var(--ease);
}

.date-section.is-collapsed {
  margin-bottom: 10px;
}

.date-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 0 6px 8px;
  border: 1px solid transparent;
  border-radius: 14px;
  transition:
    background-color 0.22s var(--ease),
    border-color 0.22s var(--ease),
    padding 0.22s var(--ease),
    box-shadow 0.22s var(--ease);
}

.date-section.is-collapsed .date-header {
  background: var(--surface);
  border-color: var(--hairline);
  box-shadow: var(--shadow-card);
  padding: 11px 14px;
}

.date-toggle-btn {
  flex: 1;
  min-width: 0;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 0;
  text-align: left;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink-secondary);
  transition: color 0.15s var(--ease);
}

.date-toggle-btn:hover {
  color: var(--ink-primary);
}

.date-section.is-collapsed .date-toggle-btn {
  font-size: 13.5px;
  color: var(--ink-primary);
}

.date-chevron {
  flex-shrink: 0;
  color: var(--ink-tertiary);
  transition: transform 0.26s var(--ease), color 0.15s var(--ease);
}

.date-section.is-collapsed .date-chevron {
  transform: rotate(-90deg);
}

.date-count {
  font-weight: 500;
  color: var(--ink-tertiary);
  font-variant-numeric: tabular-nums;
}

.date-study-btn {
  flex-shrink: 0;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--accent);
  padding: 2px 8px;
  border-radius: 999px;
  transition: background-color 0.15s var(--ease);
}

.date-study-btn:hover {
  background: var(--accent-soft);
}

.date-body {
  display: grid;
  grid-template-rows: 1fr;
  opacity: 1;
  transition: grid-template-rows 0.28s var(--ease), opacity 0.2s var(--ease);
}

.date-section.is-collapsed .date-body {
  grid-template-rows: 0fr;
  opacity: 0;
  pointer-events: none;
}

.date-body-inner {
  overflow: hidden;
  min-height: 0;
}

.word-group {
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: 16px;
  box-shadow: var(--shadow-card);
  overflow: hidden;
}

.word-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px;
  transition: background-color 0.14s var(--ease), opacity 0.2s var(--ease);
}

.word-row + .word-row {
  border-top: 1px solid var(--hairline);
}

.word-row:hover {
  background: var(--surface-hover);
}

.word-main {
  flex: 1;
  min-width: 0;
}

.word-head {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 7px;
}

.word-term {
  font-size: 17px;
  font-weight: 620;
  letter-spacing: -0.02em;
  color: var(--ink-primary);
}

.phonetic-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 1.5px 7px;
  border-radius: 6px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--ink-secondary);
  background: var(--track);
  transition: background-color 0.15s var(--ease), color 0.15s var(--ease);
}

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

.phonetic-btn.is-loading {
  background: var(--accent-soft);
  color: var(--accent);
  animation: pulseSoft 0.9s ease-in-out infinite;
}

.phonetic-btn.is-speaking {
  background: var(--accent);
  color: #ffffff;
}

@keyframes pulseSoft {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.55; }
}

.pos-tag {
  font-size: 12px;
  color: var(--ink-tertiary);
  font-style: italic;
  touch-action: manipulation;
  transition: filter 0.22s var(--ease);
}

.is-blurred .pos-tag {
  filter: blur(5px);
  user-select: none;
  -webkit-user-select: none;
  cursor: pointer;
}

.is-blurred .word-row.is-peeked .pos-tag {
  filter: blur(0);
  cursor: pointer;
}

.badge-count {
  display: inline-flex;
  align-items: center;
  padding: 1px 6px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  background: var(--amber-soft);
  color: var(--amber);
}

.badge-cat {
  display: inline-flex;
  align-items: center;
  padding: 1px 6px;
  border-radius: 5px;
  font-size: 11px;
  font-weight: 500;
  background: var(--track);
  color: var(--ink-tertiary);
}

.badge-srs {
  display: inline-flex;
  align-items: center;
  padding: 1px 7px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 550;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.badge-srs.is-due {
  background: var(--accent-soft);
  color: var(--accent);
}

.badge-srs.is-learning {
  background: var(--amber-soft);
  color: var(--amber);
}

.badge-srs.is-mastered {
  background: var(--green-soft);
  color: var(--green);
}

.badge-srs.is-scheduled {
  background: transparent;
  border: 1px solid var(--hairline);
  color: var(--ink-tertiary);
}

.word-body {
  margin-top: 4px;
  touch-action: manipulation;
  transition: filter 0.22s var(--ease);
}

.is-blurred .word-body {
  filter: blur(7px);
  user-select: none;
  -webkit-user-select: none;
  cursor: pointer;
}

.is-blurred .word-row.is-peeked .word-body {
  filter: blur(0);
  cursor: pointer;
}

.word-meaning {
  font-size: 14.5px;
  color: var(--ink-primary);
}

.word-note {
  margin-top: 2px;
  font-size: 12.5px;
  color: var(--ink-secondary);
  line-height: 1.55;
}

.word-actions {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
  opacity: 0.65;
  transition: opacity 0.16s var(--ease);
}

.word-row:hover .word-actions,
.word-row:focus-within .word-actions {
  opacity: 1;
}

.act-btn {
  height: 28px;
  min-width: 28px;
  padding: 0 6px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 500;
  color: var(--ink-secondary);
  transition: background-color 0.15s var(--ease), color 0.15s var(--ease), transform 0.12s var(--ease);
}

.act-btn:hover {
  background: var(--track);
  color: var(--ink-primary);
}

.act-btn:active {
  transform: scale(0.92);
}

.act-btn.is-mastered {
  color: var(--green);
  background: var(--green-soft);
}

.act-btn.is-forgot:hover {
  color: var(--amber);
  background: var(--amber-soft);
}

/* Empty State */
.empty-state {
  text-align: center;
  padding: 56px 20px;
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: 16px;
  box-shadow: var(--shadow-card);
}

.empty-title {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
}

.empty-desc {
  margin: 6px 0 0;
  font-size: 13.5px;
  color: var(--ink-secondary);
}

/* ---------------- Study Mode (Distraction-Free Single Screen) ---------------- */

.study-shell {
  max-width: 540px;
  margin: 4px auto 0;
}

.study-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
  padding: 0 2px;
}

.study-progress-wrap {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.study-back-btn {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  height: 28px;
  padding: 0 8px 0 4px;
  margin-left: -4px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 560;
  color: var(--accent);
  flex-shrink: 0;
  transition: background-color 0.15s var(--ease), transform 0.12s var(--ease);
}

.study-back-btn:hover {
  background: var(--accent-soft);
}

.study-back-btn:active {
  transform: scale(0.95);
}

.study-progress-text {
  font-size: 13px;
  font-weight: 540;
  color: var(--ink-secondary);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.study-breakdown {
  font-size: 12px;
  color: var(--ink-tertiary);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.study-top-actions {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
}

.study-meta-right {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.study-srs-tag {
  display: inline-flex;
  align-items: center;
  padding: 1.5px 7px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 560;
  font-variant-numeric: tabular-nums;
  background: var(--track);
  color: var(--ink-secondary);
}

.study-srs-tag.is-learning {
  background: var(--amber-soft);
  color: var(--amber);
}

.study-srs-tag.is-review {
  background: var(--accent-soft);
  color: var(--accent);
}

.study-shuffle-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--ink-secondary);
  padding: 4px 10px;
  border-radius: 999px;
  transition: background-color 0.15s var(--ease), color 0.15s var(--ease);
}

.study-shuffle-btn:hover {
  background: var(--track);
  color: var(--ink-primary);
}

.progress-rail {
  height: 3px;
  border-radius: 999px;
  background: var(--track);
  overflow: hidden;
  margin-bottom: 16px;
}

.progress-fill {
  height: 100%;
  border-radius: 999px;
  background: var(--accent);
  transition: width 0.4s var(--ease);
}

.study-card {
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: 22px;
  box-shadow: var(--shadow-card);
  padding: 28px 28px 26px;
  min-height: 320px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  cursor: pointer;
  transition: box-shadow 0.2s var(--ease);
}

.study-card-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  color: var(--ink-tertiary);
}

.study-meta-left {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.study-front {
  text-align: center;
  padding: 24px 0 18px;
}

.study-word {
  margin: 0;
  font-size: clamp(28px, 6vw, 42px);
  font-weight: 650;
  letter-spacing: -0.03em;
  line-height: 1.15;
}

.study-sub {
  margin-top: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
}

.study-answer {
  border-top: 1px solid var(--hairline);
  padding-top: 18px;
  margin-top: 6px;
  text-align: center;
  animation: fadeSlideIn 0.22s var(--ease);
}

.study-meaning-row {
  display: inline-flex;
  align-items: baseline;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px;
}

.study-meaning {
  font-size: 18px;
  font-weight: 550;
  color: var(--ink-primary);
}

.study-note {
  margin-top: 8px;
  font-size: 13.5px;
  color: var(--ink-secondary);
  line-height: 1.6;
}

.study-hint {
  text-align: center;
  font-size: 13px;
  color: var(--ink-tertiary);
  padding-top: 14px;
}

.study-actions {
  margin-top: 14px;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.study-btn {
  height: 56px;
  padding: 0 4px;
  border-radius: 14px;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  transition: transform 0.12s var(--ease), filter 0.15s ease, background-color 0.15s ease, opacity 0.15s ease;
}

.study-btn:active {
  transform: scale(0.96);
}

.study-btn:disabled {
  opacity: 0.55;
  pointer-events: none;
}

.study-btn-title {
  font-size: 14px;
  font-weight: 600;
  line-height: 1.15;
}

.study-btn-sub {
  font-size: 11px;
  font-weight: 500;
  line-height: 1.1;
  opacity: 0.8;
  font-variant-numeric: tabular-nums;
}

.study-btn-again {
  background: var(--red-soft);
  color: var(--red);
}
.study-btn-again:hover { filter: brightness(0.96); }

.study-btn-hard {
  background: var(--amber-soft);
  color: var(--amber);
}
.study-btn-hard:hover { filter: brightness(0.96); }

.study-btn-good {
  background: var(--accent);
  color: #ffffff;
}
.study-btn-good:hover { background: var(--accent-hover); }
.study-btn-good .study-btn-sub { opacity: 0.86; }

.study-btn-easy {
  background: var(--green-soft);
  color: var(--green);
}
.study-btn-easy:hover { filter: brightness(0.96); }

.study-shortcuts {
  margin-top: 14px;
  text-align: center;
  font-size: 12px;
  color: var(--ink-tertiary);
}

.study-shortcuts kbd {
  font-family: var(--font-mono);
  font-size: 11px;
  background: var(--track);
  padding: 2px 6px;
  border-radius: 5px;
  margin: 0 2px;
}

.study-done {
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: 22px;
  box-shadow: var(--shadow-card);
  padding: 44px 24px;
  text-align: center;
}

.study-done-icon {
  width: 48px;
  height: 48px;
  margin: 0 auto 14px;
  border-radius: 50%;
  background: var(--green-soft);
  color: var(--green);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.study-done h2 {
  margin: 0;
  font-size: 20px;
  font-weight: 650;
}

.study-done p {
  margin: 8px 0 22px;
  font-size: 14px;
  color: var(--ink-secondary);
}

.study-done-actions {
  display: inline-flex;
  gap: 10px;
}

/* ---------------- Fixed Add / Import / Edit Page ---------------- */

.add-shell {
  max-width: 560px;
  margin: 4px auto 0;
}

.add-page-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
  padding: 0 2px;
}

.add-page-title {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--ink-secondary);
}

.add-card {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: 20px;
  box-shadow: var(--shadow-card);
  padding: 18px 20px 20px;
}

.modal-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

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

.form-grid-3 {
  display: grid;
  grid-template-columns: 1.25fr 0.85fr 1fr;
  gap: 10px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.field span {
  font-size: 12px;
  font-weight: 500;
  color: var(--ink-secondary);
}

.field input,
.field select,
.field textarea {
  width: 100%;
  padding: 8.5px 11px;
  border-radius: 10px;
  border: 1px solid var(--hairline-strong);
  background: var(--surface);
  font-size: 14px;
  transition: border-color 0.16s var(--ease), box-shadow 0.16s var(--ease);
}

.field textarea {
  resize: vertical;
  min-height: 64px;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3.5px var(--accent-ring);
}

.checkbox-field {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  align-self: end;
  padding-bottom: 9px;
  font-size: 13.5px;
  cursor: pointer;
}

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

.edit-srs-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 10px;
  background: var(--bg);
  border: 1px solid var(--hairline);
  font-size: 12px;
  color: var(--ink-secondary);
  font-variant-numeric: tabular-nums;
}

.edit-srs-reset {
  font-size: 12px;
  font-weight: 540;
  color: var(--red);
  padding: 2px 8px;
  border-radius: 999px;
  flex-shrink: 0;
  transition: background-color 0.15s var(--ease);
}

.edit-srs-reset:hover {
  background: var(--red-soft);
}

.edit-srs-reset.is-armed {
  background: var(--red-soft);
}

.modal-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 6px;
  padding-top: 12px;
  border-top: 1px solid var(--hairline);
}

.modal-footer-right {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}

.btn-primary,
.btn-secondary,
.btn-danger-ghost {
  height: 36px;
  padding: 0 16px;
  border-radius: 999px;
  font-size: 13.5px;
  font-weight: 550;
  transition: all 0.15s var(--ease);
}

.btn-primary {
  background: var(--accent);
  color: #ffffff;
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled {
  opacity: 0.42;
  cursor: not-allowed;
}

.btn-secondary {
  background: var(--track);
  color: var(--ink-primary);
}
.btn-secondary:hover { background: var(--track-hover); }

.btn-danger-ghost {
  padding: 0 10px;
  color: var(--red);
}
.btn-danger-ghost:hover { background: var(--red-soft); }

/* ---------------- Modal Tabs & JSON Import ---------------- */

.modal-tabs-wrap {
  margin-bottom: 16px;
}

.modal-segmented {
  width: 100%;
}

.modal-segmented .seg-btn {
  flex: 1;
  padding: 6px 12px;
  font-size: 13px;
}

.import-cat-segmented {
  width: 100%;
  overflow-x: auto;
  scrollbar-width: none;
}
.import-cat-segmented::-webkit-scrollbar { display: none; }

.import-cat-segmented .seg-btn {
  flex: 1;
  padding: 5.5px 10px;
  font-size: 12.5px;
}

.import-pane {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.prompt-card {
  background: var(--bg);
  border: 1px solid var(--hairline);
  border-radius: 12px;
  padding: 10px 12px;
}

.prompt-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.prompt-card-title {
  font-size: 13.5px;
  font-weight: 580;
  color: var(--ink-primary);
}

.prompt-card-btns {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.prompt-preview-btn {
  height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--ink-secondary);
  background: var(--track);
  transition: background-color 0.15s var(--ease), color 0.15s var(--ease);
}

.prompt-preview-btn:hover {
  background: var(--track-hover);
  color: var(--ink-primary);
}

.btn-copy-prompt {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 28px;
  padding: 0 11px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 12.5px;
  font-weight: 560;
  transition: all 0.16s var(--ease);
}

.btn-copy-prompt:hover {
  background: var(--accent);
  color: #ffffff;
}

.btn-copy-prompt.is-copied {
  background: var(--green-soft);
  color: var(--green);
}

.prompt-preview {
  margin: 10px 0 0;
  padding: 10px 12px;
  max-height: 170px;
  overflow: auto;
  border-radius: 10px;
  background: var(--surface);
  border: 1px solid var(--hairline);
  font-family: var(--font-mono);
  font-size: 11.5px;
  line-height: 1.55;
  color: var(--ink-secondary);
  white-space: pre-wrap;
  word-break: break-word;
}

.field-label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.field-label-row label:first-child {
  font-size: 12px;
  font-weight: 500;
  color: var(--ink-secondary);
}

.file-link-btn {
  font-size: 12.5px;
  font-weight: 500;
  color: var(--accent);
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 6px;
  transition: background-color 0.15s var(--ease);
}

.file-link-btn:hover {
  background: var(--accent-soft);
}

.import-fallback-cat {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 11px;
  background: var(--amber-soft);
  color: var(--amber);
  font-size: 12.5px;
  font-weight: 500;
  animation: fadeSlideIn 0.2s var(--ease);
}

.import-fallback-cat select {
  height: 30px;
  padding: 0 10px;
  border-radius: 8px;
  border: 1px solid var(--hairline-strong);
  background: var(--surface);
  color: var(--ink-primary);
  font-size: 12.5px;
  font-weight: 500;
}

.json-textarea {
  font-family: var(--font-mono) !important;
  font-size: 12.5px !important;
  line-height: 1.55;
  min-height: 148px !important;
}

.import-status {
  font-size: 12.5px;
  color: var(--ink-tertiary);
}

.import-status.is-valid {
  color: var(--green);
}

.import-status.is-error {
  color: var(--red);
}

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  z-index: 100;
  padding: 9px 18px;
  border-radius: 999px;
  background: var(--ink-primary);
  color: var(--bg);
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  box-shadow: var(--shadow-toast);
  animation: toastIn 0.22s var(--ease);
}

/* Animations */
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes fadeSlideIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes popIn {
  from { opacity: 0; transform: translateY(-4px) scale(0.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes sheetIn {
  from { opacity: 0; transform: scale(0.96) translateY(8px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}
@keyframes toastIn {
  from { opacity: 0; transform: translate(-50%, 10px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

/* ---------------- Calendar / Future Review Schedule ---------------- */

.cal-shell {
  max-width: 620px;
  margin: 4px auto 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.cal-summary {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.cal-stat-card {
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: 16px;
  box-shadow: var(--shadow-card);
  padding: 13px 14px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.cal-stat-num {
  font-size: 21px;
  font-weight: 650;
  letter-spacing: -0.025em;
  line-height: 1.2;
  color: var(--ink-primary);
  font-variant-numeric: tabular-nums;
}

.cal-stat-num.is-accent {
  color: var(--accent);
}

.cal-stat-num.is-green {
  color: var(--green);
}

.cal-stat-label {
  font-size: 11.5px;
  font-weight: 500;
  color: var(--ink-tertiary);
}

.cal-card {
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: 20px;
  box-shadow: var(--shadow-card);
  padding: 16px 16px 14px;
}

.cal-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 12px;
}

.cal-month-title {
  font-size: 15.5px;
  font-weight: 620;
  letter-spacing: -0.015em;
  font-variant-numeric: tabular-nums;
}

.cal-nav-actions {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.cal-today-btn {
  height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 550;
  color: var(--accent);
  background: var(--accent-soft);
  margin-right: 4px;
  transition: filter 0.15s ease;
}

.cal-today-btn:hover {
  filter: brightness(0.96);
}

.cal-nav-btn {
  width: 28px;
  height: 28px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--ink-secondary);
  background: var(--track);
  transition: background-color 0.15s var(--ease), color 0.15s var(--ease);
}

.cal-nav-btn:hover {
  background: var(--track-hover);
  color: var(--ink-primary);
}

.cal-weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  margin-bottom: 6px;
}

.cal-weekday {
  text-align: center;
  font-size: 11px;
  font-weight: 580;
  color: var(--ink-tertiary);
  padding: 2px 0;
}

.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}

.cal-cell {
  min-height: 48px;
  padding: 5px 2px;
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: 4px;
  border: 1px solid transparent;
  transition: background-color 0.14s var(--ease), border-color 0.14s var(--ease), transform 0.1s var(--ease);
}

.cal-cell:not(.is-empty):hover {
  background: var(--track);
}

.cal-cell:not(.is-empty):active {
  transform: scale(0.95);
}

.cal-cell.is-empty {
  pointer-events: none;
}

.cal-cell.is-past {
  opacity: 0.42;
}

.cal-cell.is-today {
  border-color: var(--accent-ring);
  background: var(--accent-soft);
}

.cal-cell.is-selected {
  background: var(--accent) !important;
  border-color: transparent;
  color: #ffffff;
  opacity: 1;
}

.cal-day {
  font-size: 13px;
  font-weight: 560;
  line-height: 1.2;
  font-variant-numeric: tabular-nums;
}

.cal-cell.is-today:not(.is-selected) .cal-day {
  color: var(--accent);
  font-weight: 680;
}

.cal-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 15px;
  padding: 0 5px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 620;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  background: var(--accent-soft);
  color: var(--accent);
}

.cal-count.is-heavy {
  background: var(--amber-soft);
  color: var(--amber);
}

.cal-cell.is-selected .cal-count {
  background: rgba(255, 255, 255, 0.24);
  color: #ffffff;
}

.cal-section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 0 6px 8px;
}

.cal-section-title {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink-secondary);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.cal-list-card {
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: 16px;
  box-shadow: var(--shadow-card);
  overflow: hidden;
}

.cal-empty-day {
  padding: 24px 18px;
  text-align: center;
  font-size: 13px;
  color: var(--ink-tertiary);
}

.cal-word-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
}

.cal-word-row + .cal-word-row {
  border-top: 1px solid var(--hairline);
}

.cal-word-left {
  min-width: 0;
  flex: 1;
}

.cal-word-top {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 6px;
}

.cal-word-term {
  font-size: 15.5px;
  font-weight: 600;
  color: var(--ink-primary);
}

.cal-word-meaning {
  margin-top: 2px;
  font-size: 13px;
  color: var(--ink-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cal-upcoming-row {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 16px;
  text-align: left;
  transition: background-color 0.14s var(--ease);
}

.cal-upcoming-row + .cal-upcoming-row {
  border-top: 1px solid var(--hairline);
}

.cal-upcoming-row:hover {
  background: var(--surface-hover);
}

.cal-upcoming-date {
  font-size: 13.5px;
  font-weight: 560;
  color: var(--ink-primary);
}

.cal-upcoming-sub {
  margin-left: 6px;
  font-size: 12px;
  color: var(--ink-tertiary);
}

.cal-upcoming-right {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  font-weight: 580;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

/* ---------------- Mobile Narrow Screen (360px - 600px) ---------------- */

@media (max-width: 600px) {
  :root {
    --topbar-h: 50px;
  }

  .topbar-inner {
    padding: 0 14px;
    gap: 8px;
  }

  .brand {
    gap: 6px;
  }

  .brand-mark {
    width: 24px;
    height: 24px;
  }

  .brand-name {
    font-size: 14.5px;
  }

  .topbar-right {
    gap: 6px;
  }

  .icon-btn {
    width: 32px;
    height: 32px;
  }

  .container {
    padding: 12px 14px 64px;
  }

  .main-dock-wrap {
    max-width: none;
    margin-bottom: 8px;
  }

  .main-dock .mode-btn {
    height: 42px;
    font-size: 14.5px;
  }

  .add-card {
    padding: 16px 16px 18px;
    border-radius: 18px;
  }

  .utility-bar {
    margin: 0 -14px 10px;
    padding: 8px 14px;
  }

  .chip-label-hide-xs {
    display: none;
  }

  .chip-btn {
    padding: 0 11px;
  }

  .word-row {
    padding: 13px 14px;
  }

  .word-actions {
    opacity: 1;
  }

  .act-btn.is-forgot {
    display: none;
  }

  .study-card {
    padding: 22px 18px 20px;
    min-height: 290px;
  }

  .study-actions {
    gap: 6px;
  }

  .study-btn {
    height: 54px;
    border-radius: 12px;
  }

  .study-btn-title {
    font-size: 13.5px;
  }

  .study-btn-sub {
    font-size: 10.5px;
  }

  .study-shortcuts {
    display: none;
  }

  .cal-summary {
    gap: 8px;
  }

  .cal-stat-card {
    padding: 11px 12px;
    border-radius: 14px;
  }

  .cal-stat-num {
    font-size: 18.5px;
  }

  .cal-card {
    padding: 14px 10px 12px;
    border-radius: 18px;
  }

  .cal-cell {
    min-height: 44px;
    border-radius: 10px;
  }

  .form-grid-2,
  .form-grid-3 {
    grid-template-columns: 1fr;
  }
}
