/* ==========================================================================
   Thready — App Foundation
   CSS Variables, Reset, Typography, Layout Primitives, Responsive Base
   ========================================================================== */

/* --- Google Fonts --- */
@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:ital,wght@0,300;0,400;0,500;0,600;0,700;0,800;1,400;1,600&family=Noto+Sans+JP:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500;600&display=swap');

/* ==========================================================================
   Design Tokens
   ========================================================================== */
:root {
  /* ---- Primary ---- */
  --color-primary: #6C5CE7;
  --color-primary-light: #A29BFE;
  --color-primary-dark: #4834D4;
  --color-primary-alpha-10: rgba(108, 92, 231, .10);
  --color-primary-alpha-20: rgba(108, 92, 231, .20);

  /* ---- Accent ---- */
  --color-accent: #00D2D3;
  --color-accent-light: #55EFC4;
  --color-accent-dark: #00B894;

  /* ---- Neutrals (Dark) ---- */
  --color-bg: #0F0F14;
  --color-bg-card: #1A1A24;
  --color-bg-elevated: #242430;
  --color-bg-hover: #2A2A38;
  --color-border: #2D2D3D;
  --color-border-light: #3A3A4E;
  --color-text: #F5F5F7;
  --color-text-secondary: #A0A0B8;
  --color-text-muted: #8888A0;

  /* ---- Status ---- */
  --color-success: #00B894;
  --color-warning: #FDCB6E;
  --color-error: #FF6B6B;
  --color-info: #74B9FF;

  /* ---- Typography ---- */
  --font-heading: 'Plus Jakarta Sans', 'Noto Sans JP', sans-serif;
  --font-body: 'Noto Sans JP', 'Plus Jakarta Sans', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;

  --text-xs: .75rem;
  --text-sm: .875rem;
  --text-base: 1rem;
  --text-lg: 1.125rem;
  --text-xl: 1.25rem;
  --text-2xl: 1.5rem;
  --text-3xl: 1.875rem;
  --text-4xl: 2.25rem;
  --text-5xl: 3rem;
  --text-6xl: 3.75rem;

  --leading-tight: 1.2;
  --leading-normal: 1.6;
  --leading-relaxed: 1.8;

  /* ---- Spacing (4px grid) ---- */
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 16px;
  --space-lg: 24px;
  --space-xl: 32px;
  --space-2xl: 48px;
  --space-3xl: 64px;
  --space-4xl: 96px;

  /* ---- Radius ---- */
  --radius-sm: 6px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 24px;
  --radius-full: 9999px;

  /* ---- Shadows ---- */
  --shadow-sm: 0 2px 8px rgba(0,0,0,.2);
  --shadow-md: 0 4px 16px rgba(0,0,0,.3);
  --shadow-lg: 0 8px 32px rgba(0,0,0,.4);
  --shadow-glow-primary: 0 0 24px rgba(108,92,231,.25);
  --shadow-glow-accent: 0 0 24px rgba(0,210,211,.2);

  /* ---- Motion ---- */
  --ease-out: cubic-bezier(.16,1,.3,1);
  --ease-in-out: cubic-bezier(.45,0,.55,1);
  --duration-fast: .15s;
  --duration-base: .2s;
  --duration-slow: .35s;

  /* ---- Layout ---- */
  --sidebar-width: 260px;
  --sidebar-collapsed: 72px;
  --topbar-height: 64px;
  --container-max: 1200px;
  --container-narrow: 720px;

  /* ---- Z-Index ---- */
  --z-sidebar: 100;
  --z-topbar: 110;
  --z-modal-backdrop: 200;
  --z-modal: 210;
  --z-toast: 300;
  --z-tooltip: 400;
}

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

html {
  overflow-x: hidden;
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-body);
  font-size: var(--text-base);
  line-height: var(--leading-normal);
  color: var(--color-text);
  background: var(--color-bg);
  min-height: 100vh;
  overflow-x: hidden;
}

img, picture, video, canvas, svg { display: block; max-width: 100%; }
input, button, textarea, select { font: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }
ul, ol { list-style: none; }
h1,h2,h3,h4,h5,h6 {
  font-family: var(--font-heading);
  font-weight: 700;
  line-height: var(--leading-tight);
}
button { cursor: pointer; border: none; background: none; }
:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--color-border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--color-text-muted); }

/* Selection */
::selection {
  background: var(--color-primary-alpha-20);
  color: var(--color-text);
}

/* ==========================================================================
   Typography Utilities
   ========================================================================== */
.heading-1 { font-size: var(--text-5xl); font-weight: 800; letter-spacing: -.02em; }
.heading-2 { font-size: var(--text-4xl); font-weight: 700; letter-spacing: -.015em; }
.heading-3 { font-size: var(--text-3xl); font-weight: 700; }
.heading-4 { font-size: var(--text-2xl); font-weight: 600; }
.heading-5 { font-size: var(--text-xl); font-weight: 600; }
.heading-6 { font-size: var(--text-lg); font-weight: 600; }
.text-sm { font-size: var(--text-sm); }
.text-xs { font-size: var(--text-xs); }
.text-muted { color: var(--color-text-secondary); }
.text-mono { font-family: var(--font-mono); }
.text-gradient {
  background: linear-gradient(135deg, var(--color-primary-light), var(--color-accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* ==========================================================================
   Layout Primitives
   ========================================================================== */
.container {
  width: 100%;
  max-width: var(--container-max);
  margin: 0 auto;
  padding: 0 var(--space-lg);
}
.container--narrow { max-width: var(--container-narrow); }

.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.items-start { align-items: flex-start; }
.justify-between { justify-content: space-between; }
.justify-center { justify-content: center; }
.gap-xs { gap: var(--space-xs); }
.gap-sm { gap: var(--space-sm); }
.gap-md { gap: var(--space-md); }
.gap-lg { gap: var(--space-lg); }
.gap-xl { gap: var(--space-xl); }

.grid { display: grid; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }

.sr-only {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}

.hidden { display: none !important; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ==========================================================================
   App Layout — Sidebar + Content
   ========================================================================== */
.app-layout {
  display: flex;
  min-height: 100vh;
}

.app-sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: var(--sidebar-width);
  background: var(--color-bg-card);
  border-right: 1px solid var(--color-border);
  z-index: var(--z-sidebar);
  display: flex;
  flex-direction: column;
  transition: width var(--duration-slow) var(--ease-out);
  overflow: hidden;
}

.app-sidebar.is-collapsed {
  width: var(--sidebar-collapsed);
}

.app-content {
  flex: 1;
  margin-left: var(--sidebar-width);
  min-height: 100vh;
  min-width: 0;
  overflow-x: hidden;
  transition: margin-left var(--duration-slow) var(--ease-out);
}

.app-sidebar.is-collapsed ~ .app-content {
  margin-left: var(--sidebar-collapsed);
}

.app-topbar {
  position: sticky;
  top: 0;
  height: var(--topbar-height);
  background: rgba(15, 15, 20, .85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--space-xl);
  z-index: var(--z-topbar);
}

.app-page {
  padding: var(--space-xl);
  max-width: 1400px;
  width: 100%;
  min-width: 0;
  overflow-wrap: break-word;
}

/* ==========================================================================
   Public (non-app) Layout
   ========================================================================== */
.public-layout {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.public-layout .site-main {
  flex: 1;
}

/* ==========================================================================
   Skip Link
   ========================================================================== */
.skip-link {
  position: fixed;
  top: -100%;
  left: var(--space-md);
  background: var(--color-primary);
  color: #fff;
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--radius-sm);
  z-index: 9999;
  font-weight: 600;
  transition: top var(--duration-fast);
}
.skip-link:focus {
  top: var(--space-md);
}

/* ==========================================================================
   Responsive
   ========================================================================== */
@media (max-width: 1199px) {
  .app-sidebar {
    width: var(--sidebar-collapsed);
  }
  .app-content {
    margin-left: var(--sidebar-collapsed);
  }
  .grid-4 { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 767px) {
  :root {
    --text-5xl: 2.25rem;
    --text-4xl: 1.875rem;
    --text-3xl: 1.5rem;
  }

  .app-sidebar {
    transform: translateX(-100%);
    width: var(--sidebar-width);
    z-index: var(--z-modal);
  }
  .app-sidebar.is-open {
    transform: translateX(0);
  }
  .app-content {
    margin-left: 0;
  }
  .app-page {
    padding: var(--space-md);
    padding-bottom: calc(72px + var(--space-md));
  }
  .grid-2, .grid-3, .grid-4 {
    grid-template-columns: 1fr;
  }
  .container {
    padding: 0 var(--space-md);
  }
  .hide-mobile { display: none !important; }
}

@media (min-width: 768px) {
  .hide-desktop { display: none !important; }
}

/* ==========================================================================
   Mobile Bottom Nav
   ========================================================================== */
.mobile-bottom-nav {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 72px;
  background: var(--color-bg-card);
  border-top: 1px solid var(--color-border);
  z-index: var(--z-sidebar);
  padding-bottom: env(safe-area-inset-bottom, 0);
}

@media (max-width: 767px) {
  .mobile-bottom-nav {
    display: flex;
    align-items: center;
    justify-content: space-around;
  }
}

.mobile-bottom-nav__item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: var(--space-sm) var(--space-md);
  color: var(--color-text-muted);
  font-size: var(--text-xs);
  transition: color var(--duration-fast);
  position: relative;
}
.mobile-bottom-nav__item.is-active,
.mobile-bottom-nav__item:hover {
  color: var(--color-primary-light);
}
.mobile-bottom-nav__icon {
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.mobile-bottom-nav__icon svg {
  width: 22px;
  height: 22px;
  stroke-width: 1.8;
}
.mobile-bottom-nav__label {
  font-weight: 500;
}

/* ==========================================================================
   Sidebar Overlay (Mobile)
   ========================================================================== */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.6);
  z-index: calc(var(--z-modal) - 1);
  opacity: 0;
  transition: opacity var(--duration-base);
}
.sidebar-overlay.is-visible {
  display: block;
  opacity: 1;
}

/* ==========================================================================
   Loading / Skeleton
   ========================================================================== */
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: .4; }
}

.skeleton {
  background: var(--color-bg-elevated);
  border-radius: var(--radius-sm);
  animation: pulse 1.8s ease-in-out infinite;
}
.skeleton--text { height: 14px; width: 80%; margin-bottom: var(--space-sm); }
.skeleton--title { height: 20px; width: 60%; margin-bottom: var(--space-md); }
.skeleton--avatar { width: 40px; height: 40px; border-radius: var(--radius-full); }
.skeleton--card { height: 160px; border-radius: var(--radius-md); }
