/* ===========================
   1. CSS Variables & Reset
   =========================== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg-primary: #f3f4f8;
  --bg-secondary: #e8e9f0;
  --bg-card: rgba(255, 255, 255, 0.82);
  --bg-card-solid: #ffffff;
  --bg-card-hover: rgba(255, 255, 255, 0.95);
  --bg-toolbar: rgba(255, 255, 255, 0.92);

  --text-primary: #1a1a2e;
  --text-secondary: #4a4a65;
  --text-tertiary: #8888a0;
  --text-link: #5b6abf;

  --color-remifura: #d6336c;
  --color-remifura-light: #fff0f6;
  --color-fran: #e67700;
  --color-fran-light: #fff9db;
  --color-remi: #7048e8;
  --color-remi-light: #f3f0ff;

  --accent: #5c6bc0;
  --accent-hover: #3f51b5;
  --danger: #e53935;
  --danger-light: #ffebee;
  --success: #2e7d32;

  --shadow-xs: 0 1px 2px rgba(0,0,0,0.04);
  --shadow-sm: 0 2px 8px rgba(0,0,0,0.05);
  --shadow-md: 0 4px 20px rgba(0,0,0,0.07);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.10);

  --radius-xs: 6px;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;

  --font-ui: 'Inter', 'Noto Sans SC', 'Noto Sans JP', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-read: 'Noto Sans JP', 'Noto Sans SC', 'Inter', sans-serif;

  --transition-fast: 0.15s ease;
  --transition-normal: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-slow: 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

html {
  font-size: 16.5px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-ui);
  color: var(--text-primary);
  background: var(--bg-primary);
  line-height: 1.65;
  min-height: 100vh;
  overflow-x: hidden;
}

#app {
  min-height: 100vh;
}

a { color: inherit; text-decoration: none; }
button { border: none; background: none; cursor: pointer; font-family: inherit; }
input, select { font-family: inherit; }

/* ===========================
   2. Loading Screen
   =========================== */
.loading-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  gap: 16px;
  color: var(--text-tertiary);
  font-size: 14px;
}

.loading-spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--bg-secondary);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ===========================
   3. Common Components
   =========================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 16px;
  font-size: 13px;
  font-weight: 500;
  border-radius: var(--radius-sm);
  transition: all var(--transition-fast);
  white-space: nowrap;
  user-select: none;
  line-height: 1.4;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:active { transform: scale(0.97); }
.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-ghost {
  color: var(--text-secondary);
  background: rgba(0,0,0,0.04);
}
.btn-ghost:hover { background: rgba(0,0,0,0.08); }

.btn-danger {
  background: var(--danger);
  color: #fff;
}
.btn-danger:hover { background: #c62828; }

.btn-outline {
  border: 1.5px solid rgba(0,0,0,0.12);
  color: var(--text-secondary);
  background: transparent;
}
.btn-outline:hover { border-color: var(--accent); color: var(--accent); }
.btn-outline.active {
  border-color: var(--accent);
  color: #fff;
  background: var(--accent);
}

.btn-sm {
  padding: 4px 10px;
  font-size: 12px;
}

.page-container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 24px;
}

.page-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 20px 0 16px;
  flex-wrap: wrap;
}

.page-header h1 {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.back-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  transition: all var(--transition-fast);
}
.back-btn:hover { background: rgba(0,0,0,0.06); color: var(--text-primary); }
.back-btn::before { content: '←'; font-size: 16px; }

.category-section {
  margin-bottom: 28px;
}

.category-title {
  font-size: 16px;
  font-weight: 600;
  padding: 6px 0 6px 14px;
  margin-bottom: 12px;
  position: relative;
  letter-spacing: 0.02em;
}
.category-title::before {
  content: '';
  position: absolute;
  left: 0;
  top: 4px;
  bottom: 4px;
  width: 4px;
  border-radius: 2px;
}

.category-section[data-cat="レミフラ"] .category-title { color: var(--color-remifura); }
.category-section[data-cat="レミフラ"] .category-title::before { background: var(--color-remifura); }
.category-section[data-cat="フラン"] .category-title { color: var(--color-fran); }
.category-section[data-cat="フラン"] .category-title::before { background: var(--color-fran); }
.category-section[data-cat="レミ"] .category-title { color: var(--color-remi); }
.category-section[data-cat="レミ"] .category-title::before { background: var(--color-remi); }

/* ===========================
   4. Home Page
   =========================== */
.home-page {
  padding-bottom: 100px;
}

.home-header {
  text-align: center;
  padding: 48px 0 36px;
}
.home-header h1 {
  font-size: 28px;
  font-weight: 700;
  background: linear-gradient(135deg, var(--color-remifura), var(--color-remi));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: 0.04em;
}

.user-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(132px, 1fr));
  gap: 16px;
}

.user-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 20px 10px 16px;
  background: var(--bg-card);
  backdrop-filter: blur(10px);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  transition: transform var(--transition-normal), box-shadow var(--transition-normal);
  position: relative;
  border: 1px solid rgba(255,255,255,0.6);
}
.user-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-md);
}
.user-card:active {
  transform: translateY(-1px) scale(0.98);
}

.user-card.mark-mode {
  cursor: crosshair;
}
.user-card.mark-mode:hover {
  box-shadow: 0 0 0 2px var(--danger), var(--shadow-md);
}

.user-avatar {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  margin-bottom: 10px;
  box-shadow: 0 3px 10px rgba(0,0,0,0.12);
  flex-shrink: 0;
}

.user-name {
  font-size: 13px;
  font-weight: 500;
  text-align: center;
  color: var(--text-primary);
  line-height: 1.35;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  word-break: break-all;
}

.user-count {
  font-size: 11px;
  color: var(--text-tertiary);
  margin-top: 4px;
}

.mark-dot {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 10px;
  height: 10px;
  background: var(--danger);
  border-radius: 50%;
  box-shadow: 0 0 0 2.5px #fff, 0 0 6px rgba(229,57,53,0.4);
  animation: pulse-dot 2s ease infinite;
}

@keyframes pulse-dot {
  0%, 100% { box-shadow: 0 0 0 2.5px #fff, 0 0 6px rgba(229,57,53,0.4); }
  50% { box-shadow: 0 0 0 2.5px #fff, 0 0 12px rgba(229,57,53,0.6); }
}

/* Floating Action Buttons */
.fab-group {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 200;
}

.fab {
  padding: 10px 18px;
  font-size: 13px;
  font-weight: 600;
  color: #fff;
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  transition: all var(--transition-normal);
  white-space: nowrap;
}
.fab:hover { transform: scale(1.04); }
.fab:active { transform: scale(0.97); }

.fab-mark {
  background: linear-gradient(135deg, #5c6bc0, #7c4dff);
}
.fab-mark.active {
  background: linear-gradient(135deg, #e53935, #ff5252);
}

.fab-hide {
  background: linear-gradient(135deg, #26a69a, #00897b);
}
.fab-hide.active {
  background: linear-gradient(135deg, #ff7043, #f4511e);
}

/* ===========================
   5. User Page
   =========================== */
.user-page {
  padding-bottom: 60px;
}

.user-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 0 16px;
  flex-wrap: wrap;
}

.user-toolbar .spacer { flex: 1; }

.work-card {
  background: var(--bg-card-solid);
  border-radius: var(--radius-md);
  padding: 16px 18px;
  margin-bottom: 10px;
  box-shadow: var(--shadow-xs);
  border: 1px solid rgba(0,0,0,0.04);
  transition: box-shadow var(--transition-fast), border-color var(--transition-fast);
  position: relative;
}
.work-card:hover {
  box-shadow: var(--shadow-sm);
  border-color: rgba(0,0,0,0.08);
}

.work-card-inner {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}

.work-checkbox {
  display: none;
  flex-shrink: 0;
  margin-top: 2px;
}
.work-checkbox input[type="checkbox"] {
  width: 18px;
  height: 18px;
  cursor: pointer;
  accent-color: var(--accent);
}

.delete-mode .work-checkbox { display: block; }
.delete-mode .work-card { cursor: pointer; }
.delete-mode .work-card:hover { background: rgba(92,107,192,0.04); }
.delete-mode .work-card.selected { background: rgba(92,107,192,0.08); border-color: var(--accent); }

.work-deleted-mark {
  display: none;
  color: var(--danger);
  font-size: 16px;
  font-weight: 700;
  flex-shrink: 0;
  margin-top: 1px;
  line-height: 1;
}
.work-card.is-deleted .work-deleted-mark { display: block; }

.work-info {
  flex: 1;
  min-width: 0;
}

.work-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  cursor: pointer;
  transition: color var(--transition-fast);
  line-height: 1.5;
}
.work-title:hover { color: var(--accent); }
.delete-mode .work-title { cursor: default; pointer-events: none; }

.work-desc {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 6px;
  line-height: 1.6;
  position: relative;
}
.work-desc.clamped {
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.expand-toggle {
  font-size: 12px;
  color: var(--accent);
  margin-top: 4px;
  cursor: pointer;
  display: inline-block;
  padding: 2px 0;
}
.expand-toggle:hover { text-decoration: underline; }

.work-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 8px;
}

.tag {
  display: inline-block;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(0,0,0,0.04);
  color: var(--text-tertiary);
  line-height: 1.5;
}
.tag.r18 {
  background: var(--danger-light);
  color: var(--danger);
  font-weight: 600;
}

.work-meta {
  display: flex;
  gap: 12px;
  margin-top: 8px;
  font-size: 12px;
  color: var(--text-tertiary);
}

.work-meta .char-count::before { content: '📝 '; }
.work-meta .work-cat::before { content: '📂 '; }

/* ===========================
   6. Work Page
   =========================== */
.work-page {
  padding-bottom: 60px;
}

.work-toolbar {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  padding: 10px 16px;
  background: var(--bg-toolbar);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid rgba(0,0,0,0.06);
  box-shadow: var(--shadow-xs);
}

.toolbar-spacer {
  flex: 1;
  min-width: 0;
}

.toolbar-sep {
  width: 1px;
  height: 24px;
  background: rgba(0,0,0,0.08);
  margin: 0 2px;
  flex-shrink: 0;
}

.toggle-group {
  display: inline-flex;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1.5px solid rgba(0,0,0,0.10);
}
.toggle-group .btn {
  border-radius: 0;
  padding: 5px 12px;
  font-size: 12px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
}
.toggle-group .btn.active {
  background: var(--accent);
  color: #fff;
}
.toggle-group .btn:not(.active):hover {
  background: rgba(0,0,0,0.04);
}

.model-select {
  padding: 5px 8px;
  font-size: 12px;
  border: 1.5px solid rgba(0,0,0,0.10);
  border-radius: var(--radius-sm);
  background: #fff;
  color: var(--text-primary);
  max-width: 240px;
  cursor: pointer;
  outline: none;
}
.model-select:focus { border-color: var(--accent); }

.stream-label {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  color: var(--text-secondary);
  cursor: pointer;
  user-select: none;
}
.stream-label input[type="checkbox"] {
  accent-color: var(--accent);
}

.btn-translate {
  font-weight: 600;
}
.btn-translate.translating {
  background: var(--text-tertiary);
  cursor: not-allowed;
}

.btn-mobile {
  font-size: 16px;
  padding: 5px 8px;
  border-radius: var(--radius-sm);
}
.btn-mobile:hover { background: rgba(0,0,0,0.06); }
.btn-mobile.active {
  background: var(--accent);
  color: white;
  border-radius: var(--radius-sm);
}

/* Work content */
.work-content {
  max-width: 820px;
  margin: 0 auto;
  padding: 28px 24px;
  font-family: var(--font-read);
  font-size: 15px;
  line-height: 1.9;
  color: var(--text-primary);
}

.work-content.mobile-mode {
  font-size: 19px;
  line-height: 2.0;
  padding: 24px 16px;
}

.para-spacer {
  height: 0.8em;
}

.orig-line {
  padding: 2px 0;
  transition: opacity var(--transition-fast);
}
.orig-line.hidden { display: none; }

.trans-line {
  padding: 3px 0 3px 14px;
  color: #2c5f8a;
  border-left: 3px solid rgba(44,95,138,0.15);
  margin: 2px 0 6px;
  font-size: 0.95em;
  transition: opacity var(--transition-fast);
  position: relative;
}
.trans-line.hidden { display: none; }
.trans-line:empty { display: none; }

.trans-line[contenteditable="true"] {
  outline: none;
  background: rgba(44,95,138,0.03);
  border-radius: 0 var(--radius-xs) var(--radius-xs) 0;
  cursor: text;
  min-height: 1.4em;
}
.trans-line[contenteditable="true"]:focus {
  background: rgba(44,95,138,0.06);
  border-left-color: var(--accent);
}

/* Annotation tooltip */
.annotation {
  color: #3366cc;
  cursor: help;
  border-bottom: 1px dashed rgba(51,102,204,0.4);
  position: relative;
}

.annotation-tip {
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  background: #1a1a2e;
  color: #fff;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  line-height: 1.5;
  white-space: nowrap;
  max-width: 280px;
  white-space: normal;
  z-index: 500;
  box-shadow: var(--shadow-lg);
  pointer-events: none;
  animation: tip-in 0.15s ease;
}
.annotation-tip::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 5px solid transparent;
  border-top-color: #1a1a2e;
}
.annotation-tip.pinned {
  pointer-events: auto;
}

@keyframes tip-in {
  from { opacity: 0; transform: translateX(-50%) translateY(4px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* Usage display */
.usage-bar {
  max-width: 720px;
  margin: 32px auto 0;
  padding: 14px 20px;
  background: rgba(0,0,0,0.03);
  border-radius: var(--radius-md);
  font-size: 13px;
  color: var(--text-secondary);
  display: flex;
  gap: 20px;
  flex-wrap: wrap;
}
.usage-bar span {
  font-weight: 500;
  color: var(--text-primary);
}

/* Edit FAB */
.edit-fab {
  position: fixed;
  left: -40px;
  top: 50%;
  transform: translateY(-50%);
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #5c6bc0, #7c4dff);
  color: #fff;
  font-size: 18px;
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
  box-shadow: var(--shadow-md);
  cursor: pointer;
  z-index: 300;
  transition: left var(--transition-normal);
  user-select: none;
}
.edit-fab:hover,
.edit-fab.visible {
  left: 0;
}
.edit-fab.active {
  background: linear-gradient(135deg, #e53935, #ff5252);
  left: 0;
}

/* ===========================
   7. Modal
   =========================== */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: rgba(0,0,0,0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: fade-in 0.2s ease;
}

.modal-card {
  background: #fff;
  border-radius: var(--radius-lg);
  padding: 28px;
  max-width: 400px;
  width: 100%;
  box-shadow: var(--shadow-lg);
  animation: modal-in 0.25s ease;
}

.modal-title {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 8px;
}
.modal-desc {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 16px;
  line-height: 1.5;
}
.modal-input {
  width: 100%;
  padding: 10px 14px;
  font-size: 14px;
  border: 1.5px solid rgba(0,0,0,0.12);
  border-radius: var(--radius-sm);
  outline: none;
  transition: border-color var(--transition-fast);
}
.modal-input:focus { border-color: var(--accent); }

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 20px;
}

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes modal-in {
  from { opacity: 0; transform: scale(0.95) translateY(8px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

/* ===========================
   8. Error & Empty States
   =========================== */
.error-msg {
  text-align: center;
  padding: 48px 20px;
  color: var(--danger);
  font-size: 14px;
}
.empty-msg {
  text-align: center;
  padding: 48px 20px;
  color: var(--text-tertiary);
  font-size: 14px;
}

.inline-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 48px 0;
  gap: 10px;
  color: var(--text-tertiary);
  font-size: 14px;
}
.inline-loading .loading-spinner {
  width: 24px;
  height: 24px;
  border-width: 2.5px;
}

/* ===========================
   9. Responsive
   =========================== */
@media (max-width: 600px) {
  .home-header { padding: 32px 0 24px; }
  .home-header h1 { font-size: 22px; }
  .user-grid { grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 10px; }
  .user-card { padding: 14px 8px 12px; }
  .user-avatar { width: 44px; height: 44px; margin-bottom: 8px; }
  .user-name { font-size: 12px; }
  .user-count { font-size: 10px; }

  .page-container { padding: 0 12px; }
  .page-header h1 { font-size: 18px; }
  .work-card { padding: 12px 14px; }
  .work-title { font-size: 14px; }

  .work-toolbar { padding: 8px 10px; gap: 4px; }
  .work-content { padding: 20px 14px; }

  .fab-group { bottom: 16px; right: 16px; }
  .fab { padding: 8px 14px; font-size: 12px; }
}

@media (max-width: 380px) {
  .user-grid { grid-template-columns: repeat(3, 1fr); gap: 8px; }
}

/* ===========================
   10. Scrollbar
   =========================== */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: rgba(0,0,0,0.12);
  border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
  background: rgba(0,0,0,0.2);
}
