@import url('https://fonts.googleapis.com/css2?family=Syne:wght@400;600;800&family=Noto+Sans+JP:wght@300;400;500&display=swap');

  /* ══ THEMES ══ */
  :root[data-theme="dark"] {
    --bg: #0d0d0f;
    --surface: #16161a;
    --surface2: #1e1e24;
    --surface3: #252530;
    --border: #2a2a35;
    --border2: #363645;
    --accent: #7c6aff;
    --accent2: #ff6a9a;
    --text: #e8e8f0;
    --text-muted: #6b6b80;
    --en-color: #a8d8ff;
    --jp-color: #ffd6a8;
    --card-hover-border: #3a3a50;
    --header-bg: rgba(13,13,15,0.88);
    --shadow: rgba(0,0,0,0.5);
    --hidden-bg: rgba(255,255,255,0.06);
    --file-item-hover: rgba(124,106,255,0.08);
  }
  :root[data-theme="light"] {
    --bg: #f4f3ff;
    --surface: #ffffff;
    --surface2: #f0eff8;
    --surface3: #e8e7f4;
    --border: #dddcee;
    --border2: #c8c7e0;
    --accent: #6b58f0;
    --accent2: #e8457f;
    --text: #1a1a2e;
    --text-muted: #8080a0;
    --en-color: #2563a8;
    --jp-color: #b45309;
    --card-hover-border: #b0aee0;
    --header-bg: rgba(244,243,255,0.90);
    --shadow: rgba(100,100,160,0.12);
    --hidden-bg: rgba(0,0,0,0.06);
    --file-item-hover: rgba(107,88,240,0.07);
  }

  * { box-sizing: border-box; margin: 0; padding: 0; }
  body {
    font-family: 'Noto Sans JP', sans-serif;
    background: var(--bg); color: var(--text);
    min-height: 100vh; overflow-x: hidden;
    transition: background 0.25s, color 0.25s;
  }

  /* ── HEADER ── */
  header {
    position: sticky; top: 0; z-index: 100;
    background: var(--header-bg); backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border);
    padding: 10px 20px; display: flex; align-items: center; gap: 12px;
  }
  .logo {
    font-family: 'Syne', sans-serif; font-weight: 800; font-size: 19px;
    background: linear-gradient(135deg, var(--accent), var(--accent2));
    -webkit-background-clip: text; -webkit-text-fill-color: transparent;
    flex-shrink: 0;
  }
  .hdr-btn {
    display: flex; align-items: center; gap: 6px;
    background: var(--surface2); border: 1px solid var(--border);
    border-radius: 8px; padding: 6px 13px; font-size: 13px; color: var(--text);
    cursor: pointer; white-space: nowrap; transition: border-color 0.15s, background 0.15s;
    font-family: inherit;
  }
  .hdr-btn:hover { border-color: var(--accent); background: var(--surface3); }
  #fileInput { display: none; }
  #fileNameDisplay {
    font-size: 12px; color: var(--text-muted);
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 180px;
  }
  .spacer { flex: 1; }
  .header-right { display: flex; align-items: center; gap: 8px; }
  .theme-btn {
    width: 34px; height: 34px; border-radius: 8px; border: 1px solid var(--border);
    background: var(--surface2); color: var(--text); font-size: 16px; cursor: pointer;
    display: flex; align-items: center; justify-content: center; transition: all 0.15s;
  }
  .theme-btn:hover { border-color: var(--accent); background: var(--surface3); }
  .btn {
    font-family: 'Syne', sans-serif; font-weight: 600; font-size: 13px;
    padding: 7px 16px; border-radius: 8px; border: none; cursor: pointer; transition: all 0.15s;
  }
  .btn-primary { background: var(--accent); color: white; }
  .btn-primary:hover { filter: brightness(1.1); transform: translateY(-1px); }
  .btn-ghost { background: transparent; color: var(--text-muted); border: 1px solid var(--border); }
  .btn-ghost:hover { color: var(--text); border-color: var(--border2); }

  /* Clerk user-button override: match theme */
  .cl-userButtonBox { display: flex; align-items: center; }
  .cl-avatarBox { width: 32px !important; height: 32px !important; }

  /* ── CONTROLS ── */
  .controls {
    padding: 12px 20px; background: var(--surface); border-bottom: 1px solid var(--border);
    display: flex; flex-wrap: wrap; gap: 10px; align-items: center;
  }
  .control-group { display: flex; align-items: center; gap: 7px; flex-wrap: wrap; }
  .ctrl-label { font-size: 12px; color: var(--text-muted); white-space: nowrap; }
  .ctrl-input {
    background: var(--surface2); border: 1px solid var(--border); border-radius: 6px;
    color: var(--text); padding: 5px 9px; font-size: 13px; width: 76px; transition: border-color 0.15s;
  }
  .ctrl-input:focus { outline: none; border-color: var(--accent); }
  select.ctrl-input { width: auto; cursor: pointer; }
  .mode-tabs { display: flex; background: var(--surface2); border-radius: 8px; padding: 3px; gap: 2px; }
  .mode-tab {
    font-family: 'Syne', sans-serif; font-size: 12px; font-weight: 600;
    padding: 5px 11px; border-radius: 6px; border: none;
    background: transparent; color: var(--text-muted); cursor: pointer; transition: all 0.15s; white-space: nowrap;
  }
  .mode-tab.active { background: var(--accent); color: white; }
  .toggle { position: relative; width: 40px; height: 22px; flex-shrink: 0; }
  .toggle input { opacity: 0; width: 0; height: 0; }
  .toggle-slider {
    position: absolute; inset: 0; background: var(--surface2); border: 1px solid var(--border);
    border-radius: 11px; cursor: pointer; transition: 0.2s;
  }
  .toggle-slider::before {
    content: ''; position: absolute; width: 16px; height: 16px; left: 2px; top: 2px;
    background: var(--text-muted); border-radius: 50%; transition: 0.2s;
  }
  .toggle input:checked + .toggle-slider { background: var(--accent); border-color: var(--accent); }
  .toggle input:checked + .toggle-slider::before { transform: translateX(18px); background: white; }
  #applyBtn { background: var(--accent); color: white; }
  #applyBtn:hover { filter: brightness(1.1); }

  /* ── MAIN ── */
  main {
    max-width: 1000px; margin: 0 auto; padding: 28px 20px;
    min-height: calc(100vh - 200px);
  }
  .empty-state {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    padding: 100px 24px; text-align: center; gap: 14px; color: var(--text-muted);
  }
  .empty-icon { font-size: 56px; opacity: 0.25; }
  .empty-state h2 { font-family: 'Syne', sans-serif; font-size: 22px; color: var(--text); opacity: 0.4; }
  .empty-state p { font-size: 14px; max-width: 300px; line-height: 1.7; }

  /* ── CARD GRID ── */
  .card-grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
  .card-grid.single { grid-template-columns: 1fr; }
  .vocab-card {
    background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
    padding: 22px; position: relative; cursor: pointer; overflow: hidden;
    transition: transform 0.12s, border-color 0.12s, box-shadow 0.12s;
    animation: fadeUp 0.3s ease both;
  }
  .vocab-card:nth-child(1){animation-delay:0ms}.vocab-card:nth-child(2){animation-delay:35ms}
  .vocab-card:nth-child(3){animation-delay:70ms}.vocab-card:nth-child(4){animation-delay:105ms}
  .vocab-card:nth-child(n+5){animation-delay:140ms}
  @keyframes fadeUp { from{opacity:0;transform:translateY(12px)} to{opacity:1;transform:translateY(0)} }
  .vocab-card:hover { transform: translateY(-2px); border-color: var(--card-hover-border); box-shadow: 0 6px 24px var(--shadow); }
  .vocab-card::before {
    content: ''; position: absolute; top: 0; left: 0; right: 0; height: 2px;
    background: linear-gradient(90deg, var(--accent), var(--accent2)); opacity: 0; transition: opacity 0.15s;
  }
  .vocab-card:hover::before { opacity: 1; }
  .card-num { font-family: 'Syne', sans-serif; font-size: 11px; font-weight: 600;
    color: var(--text-muted); letter-spacing: 1px; margin-bottom: 10px; }
  .card-en { font-family: 'Syne', sans-serif; font-size: 21px; font-weight: 600;
    color: var(--en-color); line-height: 1.3; margin-bottom: 8px; min-height: 28px; word-break: break-word; }
  .card-jp { font-size: 15px; color: var(--jp-color); line-height: 1.5; min-height: 22px; word-break: break-word; }
  .hidden-text {
    background: var(--hidden-bg); border-radius: 4px; color: transparent !important;
    user-select: none; border: 1px dashed var(--border); transition: all 0.25s;
  }
  .hidden-text.revealed { background: transparent; color: inherit !important; border-color: transparent; }
  .card-actions { position: absolute; top: 10px; right: 10px; }
  .review-btn {
    width: 28px; height: 28px; border-radius: 50%; border: 1px solid var(--border);
    background: var(--surface2); color: var(--text-muted); font-size: 14px; cursor: pointer;
    transition: all 0.15s; display: flex; align-items: center; justify-content: center;
  }
  .review-btn:hover { border-color: var(--accent2); color: var(--accent2); }
  .review-btn.active { border-color: var(--accent2); color: var(--accent2); background: rgba(255,106,154,0.12); }

  /* ── PAGINATION ── */
  .pagination { display: flex; align-items: center; justify-content: center; gap: 12px; margin-top: 36px; padding-bottom: 40px; }
  .page-btn {
    background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
    color: var(--text); padding: 8px 18px; font-family: 'Syne', sans-serif;
    font-weight: 600; font-size: 14px; cursor: pointer; transition: all 0.15s;
  }
  .page-btn:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
  .page-btn:disabled { opacity: 0.3; cursor: not-allowed; }
  .page-info { font-size: 13px; color: var(--text-muted); min-width: 120px; text-align: center; }

  /* ── AUTO PROGRESS ── */
  .auto-progress { position: fixed; bottom: 0; left: 0; right: 0; height: 3px; background: var(--border); z-index: 200; }
  .auto-progress-bar { height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent2)); width: 0%; }

  /* ── REVIEW PANEL ── */
  .review-panel {
    position: fixed; right: 0; top: 0; bottom: 0; width: 300px;
    background: var(--surface); border-left: 1px solid var(--border); z-index: 300;
    transform: translateX(100%); transition: transform 0.3s cubic-bezier(0.4,0,0.2,1);
    display: flex; flex-direction: column; padding: 20px; gap: 14px; overflow-y: auto;
  }
  .review-panel.open { transform: translateX(0); }
  .review-panel-header { display: flex; align-items: center; justify-content: space-between; }
  .review-panel-title { font-family: 'Syne', sans-serif; font-weight: 800; font-size: 15px; color: var(--accent2); }
  .close-panel { background: none; border: none; color: var(--text-muted); font-size: 18px; cursor: pointer; }
  .close-panel:hover { color: var(--text); }
  .review-list-item {
    background: var(--surface2); border-radius: 8px; padding: 11px;
    font-size: 13px; display: flex; flex-direction: column; gap: 3px; position: relative;
  }
  .review-item-en { color: var(--en-color); font-weight: 500; }
  .review-item-jp { color: var(--jp-color); }
  .review-item-num { color: var(--text-muted); font-size: 11px; }
  .review-remove { position: absolute; top: 7px; right: 7px; background: none; border: none;
    color: var(--text-muted); cursor: pointer; font-size: 15px; line-height: 1; }
  .review-remove:hover { color: var(--accent2); }
  .review-toggle-btn {
    position: fixed; right: 22px; bottom: 22px; background: var(--accent2); border: none;
    border-radius: 50%; width: 50px; height: 50px; color: white; font-size: 19px; cursor: pointer;
    box-shadow: 0 4px 20px rgba(255,106,154,0.35); z-index: 250; transition: transform 0.15s;
    display: flex; align-items: center; justify-content: center;
  }
  .review-toggle-btn:hover { transform: scale(1.1); }
  .review-badge {
    position: absolute; top: -4px; right: -4px; background: var(--accent); color: white;
    border-radius: 10px; font-size: 10px; font-weight: 700; min-width: 17px; height: 17px;
    display: flex; align-items: center; justify-content: center; padding: 0 3px;
  }

  /* ── SERVER FILES MODAL ── */
  .modal-overlay {
    position: fixed; inset: 0; background: rgba(0,0,0,0.55); backdrop-filter: blur(6px);
    z-index: 500; display: flex; align-items: center; justify-content: center;
    opacity: 0; pointer-events: none; transition: opacity 0.2s;
  }
  .modal-overlay.open { opacity: 1; pointer-events: all; }
  .modal {
    background: var(--surface); border: 1px solid var(--border); border-radius: 16px;
    padding: 26px; width: 90%; max-width: 520px; display: flex; flex-direction: column;
    gap: 14px; box-shadow: 0 20px 60px var(--shadow);
  }
  .modal h3 { font-family: 'Syne', sans-serif; font-size: 17px; font-weight: 800; }
  .modal-sub { font-size: 12px; color: var(--text-muted); line-height: 1.6; }
  .modal-actions { display: flex; gap: 8px; justify-content: flex-end; }
  .modal input[type=text] {
    width: 100%; background: var(--surface2); border: 1px solid var(--border);
    border-radius: 8px; color: var(--text); padding: 9px 13px; font-size: 14px; transition: border-color 0.15s;
  }
  .modal input[type=text]:focus { outline: none; border-color: var(--accent); }
  .file-list { display: flex; flex-direction: column; gap: 4px; }
  .file-list-label { font-size: 11px; color: var(--text-muted); font-weight: 600;
    letter-spacing: 0.5px; text-transform: uppercase; margin-bottom: 4px; }
  .file-list-item {
    display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 8px;
    cursor: pointer; border: 1px solid transparent; transition: all 0.15s;
  }
  .file-list-item:hover { background: var(--file-item-hover); border-color: var(--border); }
  .file-icon { font-size: 18px; flex-shrink: 0; }
  .file-info { flex: 1; min-width: 0; }
  .file-name { font-size: 14px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .file-desc { font-size: 12px; color: var(--text-muted); }
  .file-list-divider { height: 1px; background: var(--border); margin: 6px 0; }
  .custom-path-section { display: flex; flex-direction: column; gap: 6px; }

  /* ── TOAST ── */
  .toast {
    position: fixed; bottom: 84px; left: 50%; transform: translateX(-50%) translateY(16px);
    background: var(--surface2); border: 1px solid var(--border2); border-radius: 8px;
    padding: 9px 18px; font-size: 13px; color: var(--text); z-index: 1000;
    opacity: 0; transition: all 0.25s; white-space: nowrap; box-shadow: 0 4px 16px var(--shadow);
  }
  .toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

  /* sync indicator */
  .sync-dot {
    width: 7px; height: 7px; border-radius: 50%; background: var(--text-muted);
    display: inline-block; margin-left: 4px; vertical-align: middle; transition: background 0.3s;
  }
  .sync-dot.syncing { background: var(--accent); animation: pulse 1s infinite; }
  .sync-dot.synced  { background: #4ade80; }
  @keyframes pulse { 0%,100%{opacity:1} 50%{opacity:0.3} }

  @media (max-width: 600px) {
    header { padding: 8px 12px; flex-wrap: wrap; gap: 6px; }
    .controls { padding: 10px 12px; }
    main { padding: 16px 12px; }
    .card-grid { grid-template-columns: 1fr; }
    .review-panel { width: 100%; }
    #fileNameDisplay { max-width: 100px; }
  }
