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

/* ========================================
   CSS Custom Properties (Tailwind Slate/Cyan Theme)
   ======================================== */
:root {
  /* Colors - Base (Tailwind Colors) */
  --bg-body: #f8fafc;        /* slate-50 */
  --bg-card: #ffffff;        /* white */
  --bg-panel: #f1f5f9;       /* slate-100 */
  
  --text-main: #0f172a;      /* slate-900 */
  --text-muted: #475569;     /* slate-600 */
  --text-light: #94a3b8;     /* slate-400 */
  
  --border-light: #f1f5f9;   /* slate-100 */
  --border-base: #e2e8f0;    /* slate-200 */
  
  --color-cyan-50: #ecfeff;
  --color-cyan-100: #cffafe;
  --color-cyan-500: #06b6d4;
  --color-cyan-600: #0891b2;
  --color-cyan-700: #0e7490;
  
  /* Semantic */
  --accent-main: var(--color-cyan-600);
  --accent-hover: var(--color-cyan-700);
  --accent-ring: var(--color-cyan-500);

  --status-reg-bg: #dbeafe;      /* blue-100 */
  --status-reg-txt: #1e40af;     /* blue-800 */
  --status-tent-bg: #fef3c7;     /* amber-100 */
  --status-tent-txt: #92400e;    /* amber-800 */
  
  --tag-cos-bg: #fdf4ff;         /* fuchsia-50 */
  --tag-cos-txt: #a21caf;        /* fuchsia-700 */
  --tag-cos-border: #fae8ff;     /* fuchsia-100 */
  
  --tag-r18-bg: #fef2f2;         /* red-50 */
  --tag-r18-txt: #b91c1c;        /* red-700 */
  --tag-r18-border: #fee2e2;     /* red-100 */
  
  --tag-absent-bg: #f1f5f9;      /* slate-100 */
  --tag-absent-txt: #334155;     /* slate-700 */
  --tag-absent-border: #e2e8f0;  /* slate-200 */

  /* Area Colors mapped to richer solids */
  --area-a: #2563eb; /* blue-600 */
  --area-b: #7e22ce; /* purple-700 */
  --area-c: #db2777; /* pink-600 */
  --area-d: #d97706; /* amber-600 */
  --area-e: #0d9488; /* teal-600 */
  --area-f: #78350f; /* amber-900 */
  --area-g: #16a34a; /* green-600 */
  --area-h: #dc2626; /* red-600 */
  --area-i: #0891b2; /* cyan-600 */
  --area-j: #4f46e5; /* indigo-600 */
  --area-k: #c026d3; /* fuchsia-600 */
  --area-l: #65a30d; /* lime-600 */
  --area-m: #ea580c; /* orange-600 */
  --area-n: #0284c7; /* sky-600 */
  --area-o: #e11d48; /* rose-600 */
  --area-p: #7c3aed; /* violet-600 */
  --area-q: #059669; /* emerald-600 */
  --area-r: #ca8a04; /* yellow-600 */
  --area-s: #475569; /* slate-600 */

  /* Spacing */
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 16px;
  --space-lg: 20px;
  --space-xl: 32px;

  /* Border Radius */
  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 8px;
  --radius-xl: 12px;
  --radius-full: 9999px;

  /* Shadows (Tailwind) */
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.1);

  --transition-base: 200ms ease-in-out;
  --font-sans: 'Inter', -apple-system, 'Noto Sans JP', sans-serif;
}

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

body {
  font-family: var(--font-sans);
  background: var(--bg-body);
  color: var(--text-main);
  line-height: 1.5;
  min-height: 100vh;
  font-size: 14px;
}

/* ========================================
   Typography
   ======================================== */
h1, h2, h3, h4 { color: var(--text-main); font-weight: 700; }
.card-title { font-size: 20px; line-height: 1.25; font-weight: 700; color: var(--text-main); margin-top: 8px; }

/* ========================================
   Header
   ======================================== */
.header {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border-base);
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-sm);
}

.header-inner {
  max-width: 1440px;
  margin: 0 auto;
  padding: 16px var(--space-xl);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-lg);
}

.header-brand { display: flex; align-items: center; gap: var(--space-md); }
.header-logo { font-size: 24px; font-weight: 700; color: var(--text-main); }
.header-subtitle { font-size: 13px; color: var(--text-muted); font-weight: 500; margin-top: 2px; }

.header-stats { display: flex; gap: var(--space-md); }
.stat-item {
  text-align: center;
  padding: 8px 16px;
  background: var(--bg-body);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-base);
  min-width: 80px;
}
.stat-value { font-size: 20px; font-weight: 700; color: var(--text-main); }
.stat-label { font-size: 11px; color: var(--text-muted); font-weight: 600; }

/* ========================================
   Filter Bar
   ======================================== */
.filter-bar {
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border-base);
  position: sticky;
  top: 85px;
  z-index: 90;
  padding: 12px 0;
}

.filter-inner {
  max-width: 1440px;
  margin: 0 auto;
  padding: 0 var(--space-xl);
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
}

/* Base Buttons */
.filter-btn, .talent-filter-btn {
  padding: 6px 14px;
  background: var(--bg-card);
  border: 1px solid var(--border-base);
  border-radius: var(--radius-full);
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-base);
  white-space: nowrap;
}

.filter-btn:hover, .talent-filter-btn:hover { background: var(--bg-body); color: var(--text-main); }
.filter-btn.active, .talent-filter-btn.has-selection {
  background: var(--accent-main);
  border-color: var(--accent-main);
  color: #fff;
}

.filter-btn.area-a.active { background: var(--area-a); border-color: var(--area-a); }
.filter-btn.area-b.active { background: var(--area-b); border-color: var(--area-b); }
.filter-btn.area-c.active { background: var(--area-c); border-color: var(--area-c); }
.filter-btn.area-d.active { background: var(--area-d); border-color: var(--area-d); }
.filter-btn.area-e.active { background: var(--area-e); border-color: var(--area-e); }
.filter-btn.area-f.active { background: var(--area-f); border-color: var(--area-f); }
.filter-btn.area-g.active { background: var(--area-g); border-color: var(--area-g); }
.filter-btn.area-h.active { background: var(--area-h); border-color: var(--area-h); }
.filter-btn.area-i.active { background: var(--area-i); border-color: var(--area-i); }
.filter-btn.area-j.active { background: var(--area-j); border-color: var(--area-j); }
.filter-btn.area-k.active { background: var(--area-k); border-color: var(--area-k); }
.filter-btn.area-l.active { background: var(--area-l); border-color: var(--area-l); }
.filter-btn.area-m.active { background: var(--area-m); border-color: var(--area-m); }
.filter-btn.area-n.active { background: var(--area-n); border-color: var(--area-n); }
.filter-btn.area-o.active { background: var(--area-o); border-color: var(--area-o); }
.filter-btn.area-p.active { background: var(--area-p); border-color: var(--area-p); }
.filter-btn.area-q.active { background: var(--area-q); border-color: var(--area-q); }
.filter-btn.area-r.active { background: var(--area-r); border-color: var(--area-r); }
.filter-btn.area-s.active { background: var(--area-s); border-color: var(--area-s); }

/* Search Inputs */
.search-box { flex: 1; min-width: 250px; position: relative; }
.search-box svg { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--text-light); width: 18px; height: 18px; pointer-events: none; }
.search-input {
  width: 100%;
  padding: 10px 16px 10px 40px;
  background: var(--bg-card);
  border: 1px solid var(--border-base);
  border-radius: var(--radius-full);
  color: var(--text-main);
  font-size: 14px;
  outline: none;
  transition: all var(--transition-base);
}
.search-input::placeholder { color: var(--text-light); }
.search-input:focus {
  border-color: var(--accent-ring);
  box-shadow: 0 0 0 3px var(--color-cyan-100);
}

.view-toggle {
  display: flex; gap: 4px; background: var(--bg-card); border: 1px solid var(--border-base); border-radius: var(--radius-lg); padding: 4px;
}
.view-toggle-btn { padding: 6px; border: none; background: transparent; color: var(--text-light); cursor: pointer; border-radius: var(--radius-sm); transition: all 0.15s; }
.view-toggle-btn.active { background: var(--color-cyan-50); color: var(--accent-main); }

/* ========================================
   Main Content
   ======================================== */
.main {
  max-width: 1440px;
  margin: 0 auto;
  padding: var(--space-xl);
  min-height: 50vh;
}
.results-info { display: flex; justify-content: space-between; align-items: center; margin-bottom: 24px; }
.results-count { font-size: 14px; font-weight: 500; color: var(--text-muted); }
.results-count span { font-weight: 700; color: var(--text-main); }

/* ========================================
   Circle Grid & Cards
   ======================================== */
.circle-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(400px, 1fr)); gap: 24px; }
.circle-grid.list-view { grid-template-columns: 1fr; }

.circle-card {
  background: var(--bg-card);
  border: 1px solid var(--border-base);
  border-radius: var(--radius-xl);
  overflow: hidden;
  transition: all var(--transition-base);
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
}
.circle-card:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); }
.circle-card.is-absent { opacity: 0.6; }

.circle-card-header { padding: 20px; display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; border-bottom: 1px solid var(--border-light); }
.circle-info { flex: 1; min-width: 0; }
.circle-name { font-size: 22px; font-weight: 700; color: var(--text-main); margin-bottom: 6px; line-height: 1.3; letter-spacing: -0.02em; word-break: break-word; overflow-wrap: anywhere; }
.circle-info-top { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }

/* Badges */
.circle-space-badge {
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--text-main); color: #fff;
  font-weight: 700; padding: 4px 10px; border-radius: var(--radius-sm); font-size: 13px;
}
.circle-space-badge.area-A { background: var(--area-a); }
.circle-space-badge.area-B { background: var(--area-b); }
.circle-space-badge.area-C { background: var(--area-c); }
.circle-space-badge.area-D { background: var(--area-d); }
.circle-space-badge.area-E { background: var(--area-e); }
.circle-space-badge.area-F { background: var(--area-f); }
.circle-space-badge.area-G { background: var(--area-g); }
.circle-space-badge.area-H { background: var(--area-h); }
.circle-space-badge.area-I { background: var(--area-i); }
.circle-space-badge.area-J { background: var(--area-j); }
.circle-space-badge.area-K { background: var(--area-k); }
.circle-space-badge.area-L { background: var(--area-l); }
.circle-space-badge.area-M { background: var(--area-m); }
.circle-space-badge.area-N { background: var(--area-n); }
.circle-space-badge.area-O { background: var(--area-o); }
.circle-space-badge.area-P { background: var(--area-p); }
.circle-space-badge.area-Q { background: var(--area-q); }
.circle-space-badge.area-R { background: var(--area-r); }
.circle-space-badge.area-S { background: var(--area-s); }

.circle-author {
  font-size: 14px; font-weight: 500; color: var(--text-muted); margin-top: 4px;
}
.circle-author a { color: var(--accent-main); text-decoration: none; }
.circle-author a:hover { text-decoration: underline; }

.circle-genre-badge {
  display: inline-flex; align-items: center; padding: 4px 10px; border-radius: var(--radius-md); font-size: 12px; font-weight: 700;
  margin-top: 12px; margin-right: 6px; border: 1px solid var(--border-base); background: var(--bg-body); color: var(--text-muted);
}
.genre-cosplay { background: var(--tag-cos-bg) !important; color: var(--tag-cos-txt) !important; border-color: var(--tag-cos-border) !important; }
.genre-r18 { background: var(--tag-r18-bg) !important; color: var(--tag-r18-txt) !important; border-color: var(--tag-r18-border) !important; }
.genre-absent { background: var(--tag-absent-bg) !important; color: var(--tag-absent-txt) !important; border-color: var(--tag-absent-border) !important; }

/* Talent Modal */
#talent-match-or.active, #talent-match-and.active {
  background: var(--accent-main) !important;
  color: #fff !important;
  font-weight: bold !important;
}

/* Talents Tags */
.circle-talents {
  display: flex; flex-wrap: wrap; gap: 8px; padding: 0 20px 16px; margin-top: 12px;
}
.talent-tag {
  display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px;
  border-radius: var(--radius-md); font-size: 12px; font-weight: 600;
}
.talent-tag-dot { width: 8px; height: 8px; border-radius: 50%; }

/* Oshinagaki Bottom Section */
.circle-oshinagaki {
  padding: 16px 20px;
  background: var(--bg-body);
  border-top: 1px solid var(--border-light);
  flex-grow: 1;
}

.oshinagaki-status {
  display: inline-flex; align-items: center; gap: 6px; padding: 4px 12px; border-radius: var(--radius-full); font-size: 12px; font-weight: 600;
}
.oshinagaki-status.registered { background: var(--status-reg-bg); color: var(--status-reg-txt); }
.oshinagaki-status.tentative { background: var(--status-tent-bg); color: var(--status-tent-txt); }

.oshinagaki-link { color: inherit; text-decoration: none; }
.oshinagaki-link:hover { text-decoration: underline; }

/* Tweet Embed */
.tweet-embed-container { margin-top: 12px; border-radius: var(--radius-xl); overflow: hidden; border: 1px solid var(--border-base); background: #fff; display: flex; justify-content: center; align-items: center; padding: 16px; }

/* Form Buttons Area */
.add-url-btn {
  display: inline-flex; align-items: center; gap: 4px; padding: 6px 12px; margin-top: 12px;
  background: transparent; border: 1px solid var(--border-base); border-radius: var(--radius-lg);
  color: var(--text-muted); font-size: 13px; font-weight: 500; cursor: pointer; transition: all var(--transition-base); background: #fff;
}
.add-url-btn:hover { border-color: var(--accent-ring); color: var(--text-main); }

.url-input-form { display: none; margin-top: 12px; gap: 8px; align-items: center; }
.url-input-form.visible { display: flex; }
.url-input { flex: 1; padding: 8px 12px; background: #fff; border: 1px solid var(--border-base); border-radius: var(--radius-md); font-size: 13px; }
.url-input:focus { border-color: var(--accent-ring); outline: none; box-shadow: 0 0 0 2px var(--color-cyan-100); }
.url-save-btn { padding: 6px 16px; background: var(--accent-main); color: #fff; border: none; border-radius: var(--radius-md); font-size: 13px; font-weight: 500; cursor: pointer; }
.url-save-btn:hover { background: var(--accent-hover); }
.url-cancel-btn { padding: 6px 16px; background: var(--bg-body); color: var(--text-muted); border: 1px solid var(--border-base); border-radius: var(--radius-md); font-size: 13px; font-weight: 500; cursor: pointer; }
.url-cancel-btn:hover { background: var(--border-base); }

/* Memo */
.circle-memo { padding: 0 20px 16px; margin-top: -8px; }
.memo-text { font-size: 13px; color: var(--text-muted); background: var(--bg-body); padding: 8px 12px; border-radius: var(--radius-lg); border: 1px solid var(--border-base); }

/* ========================================
   List View Layout
   ======================================== */
.circle-grid.list-view .circle-card {
  display: flex !important;
  flex-direction: row;
  align-items: stretch;
}
.circle-grid.list-view .circle-card-header {
  flex: 1;
  border-bottom: none;
  border-right: 1px solid var(--border-light);
}
.circle-grid.list-view .circle-talents {
  flex-direction: column;
  align-items: flex-start;
  margin-top: 20px;
  padding: 0 20px 20px 0;
}
.circle-grid.list-view .circle-oshinagaki {
  width: 400px;
  flex-shrink: 0;
  border-top: none;
  border-left: 1px solid var(--border-light);
}

/* ========================================
   Dropdowns & Modals
   ======================================== */
.talent-filter-wrapper { position: relative; }
.talent-dropdown {
  position: absolute; top: calc(100% + 8px); left: 0; width: 320px; max-height: 480px; overflow-y: auto;
  background: #fff; border: 1px solid var(--border-base); border-radius: var(--radius-xl); box-shadow: var(--shadow-lg); z-index: 200; display: none; padding: 12px;
}
.talent-dropdown.open { display: block; }
.talent-dropdown-search { width: 100%; padding: 8px 12px; border: 1px solid var(--border-base); border-radius: var(--radius-md); margin-bottom: 12px; font-size: 14px; }
.talent-dropdown-search:focus { border-color: var(--accent-main); outline: none; box-shadow: 0 0 0 2px var(--color-cyan-100); }
.talent-group-label { font-size: 12px; font-weight: 600; color: var(--text-light); padding: 8px 8px 4px; }
.talent-color-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; display: inline-block; border: 1px solid rgba(0,0,0,0.1); }
.talent-option { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: var(--radius-md); cursor: pointer; font-size: 14px; color: var(--text-main); }
.talent-option:hover { background: var(--bg-body); }
.talent-option.selected { background: var(--color-cyan-50); color: var(--accent-main); font-weight: 600; }

.modal-overlay { position: fixed; inset: 0; background: rgba(15, 23, 42, 0.5); backdrop-filter: blur(2px); z-index: 1000; display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal { background: #fff; width: 100%; max-width: 500px; border-radius: var(--radius-xl); box-shadow: var(--shadow-lg); border: 1px solid var(--border-base); overflow: hidden; }
.modal-header { padding: 16px 20px; border-bottom: 1px solid var(--border-base); display: flex; justify-content: space-between; align-items: center; }
.modal-title { font-size: 16px; font-weight: 700; color: var(--text-main); }
.modal-close-btn { background: none; border: none; font-size: 20px; cursor: pointer; color: var(--text-muted); }

/* ========================================
   Empty State & Toast
   ======================================== */
.empty-state { text-align: center; padding: 80px 20px; background: #fff; border-radius: var(--radius-xl); border: 1px solid var(--border-base); box-shadow: var(--shadow-sm); }
.empty-state-icon { font-size: 32px; margin-bottom: 16px; color: var(--text-light); display: flex; justify-content: center; }
.empty-state-title { font-size: 18px; font-weight: 700; margin-bottom: 8px; color: var(--text-main); }
.empty-state-text { font-size: 14px; color: var(--text-muted); }

.toast-container { position: fixed; bottom: 24px; right: 24px; z-index: 2000; display: flex; flex-direction: column; gap: 8px; }
.toast { padding: 12px 20px; background: #fff; border: 1px solid var(--border-base); border-radius: var(--radius-lg); color: var(--text-main); font-size: 14px; font-weight: 600; box-shadow: var(--shadow-md); transform: translateY(20px); opacity: 0; animation: toastIn 300ms ease forwards; }
.toast.success { border-left: 4px solid var(--area-e); }
.toast.error { border-left: 4px solid var(--area-c); }

@keyframes toastIn { to { transform: translateY(0); opacity: 1; } }

/* ========================================
   Responsive
   ======================================== */
@media (max-width: 768px) {
  .header-inner { flex-direction: column; align-items: flex-start; padding: 16px; gap: 16px; }
  .header-stats { width: 100%; overflow-x: auto; padding-bottom: 8px; }
  .stat-item { flex: 1; }
  .filter-inner { padding: 12px 16px; }
  .main { padding: 16px; }
  .circle-grid { grid-template-columns: 1fr; }
  .circle-grid.list-view .circle-card { flex-direction: column; }
  .circle-grid.list-view .circle-card-header { border-right: none; border-bottom: 1px solid var(--border-light); }
  .circle-grid.list-view .circle-oshinagaki { width: auto; border-left: none; border-top: 1px solid var(--border-light); }
}


/* ========================================
   Smartphone UI (Public Environment Specific)
   ======================================== */
@media (max-width: 768px) {
  .header-inner {
    padding: 12px 16px !important;
    flex-direction: row !important;
    align-items: center !important;
  }
  .header-brand {
    display: none !important;
  }
  .header-tools {
    display: flex !important;
    flex-direction: row !important;
    width: 100% !important;
    max-width: none !important;
    align-items: center !important;
  }
  #mobile-menu-btn {
    display: flex !important;
    margin-left: auto !important;
  }
  
  /* Filter bar becomes a mobile dropdown menu */
  .filter-bar {
    position: fixed;
    top: 65px;
    left: 0;
    right: 0;
    background: var(--bg-card);
    box-shadow: var(--shadow-md);
    border-bottom: 1px solid var(--border-base);
    padding: 16px;
    display: none;
    z-index: 100;
    max-height: calc(100vh - 65px);
    overflow-y: auto;
  }
  body.mobile-menu-open .filter-bar {
    display: block !important;
  }
  .filter-inner {
    flex-direction: column;
    align-items: stretch;
    padding: 0;
    gap: 16px;
  }
  .filter-secondary-row {
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 16px !important;
    margin-top: 0 !important;
  }
  .filter-secondary-left {
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 16px !important;
  }
  .filter-secondary-right {
    width: 100% !important;
    margin-left: 0 !important;
    justify-content: space-between !important;
  }
  #area-filters {
    flex-wrap: wrap !important;
    overflow-x: visible;
    margin-right: 0;
    padding-right: 0;
  }
  .status-genre-row::-webkit-scrollbar {
    display: none;
  }
  .status-genre-row .filter-group {
    flex-wrap: nowrap !important;
  }

  /* Keep search box full width inside header tools */
  .search-box {
    max-width: none !important;
    width: auto !important;
    flex: 1 1 auto !important;
    margin: 0 !important;
  }

  .filter-btn, .talent-filter-btn {
    font-size: 13px;
    padding: 8px 12px;
  }

  /* Talent dropdown breaks out of hamburger menu via position:fixed */
  .talent-filter-wrapper {
    position: static !important;
  }
  .talent-dropdown {
    position: fixed !important;
    top: auto;
    left: 16px !important;
    right: 16px !important;
    bottom: auto;
    width: auto !important;
    max-height: 60vh;
    border-radius: var(--radius-xl) !important;
    z-index: 1000 !important;
    padding: 12px !important;
    box-shadow: 0 4px 24px rgba(0,0,0,0.15), var(--shadow-lg) !important;
    overflow-y: auto !important;
  }

  /* Hide view toggle on mobile as grid becomes single column anyway */
  .view-toggle {
    display: none !important;
  }
  
  .mobile-only-about {
    display: block !important;
  }

  .circle-grid {
    grid-template-columns: 1fr;
    gap: 16px;
  }
  .circle-card-header {
    padding: 16px;
    flex-direction: column;
    align-items: flex-start;
  }
  .circle-space-badge {
    position: absolute;
    top: 16px;
    right: 16px;
  }
  .circle-card {
    position: relative;
  }
  .circle-name {
    padding-right: 48px;
    font-size: 18px;
  }
  .main {
    padding: 16px;
  }
}
