@import "tailwindcss";

@theme inline {
  --font-sans: var(--font-readable), "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", sans-serif;
  --font-display: var(--font-readable), "Noto Sans TC", sans-serif;
  --font-mono: ui-monospace, "SF Mono", "Menlo", monospace;

  --color-background: var(--x-bg);
  --color-foreground: var(--x-fg);
  --color-card: var(--x-card);
  --color-card-foreground: var(--x-fg);
  --color-popover: var(--x-popover);
  --color-popover-foreground: var(--x-fg);
  --color-primary: var(--x-primary);
  --color-primary-foreground: var(--x-primary-fg);
  --color-secondary: var(--x-secondary);
  --color-secondary-foreground: var(--x-fg);
  --color-muted: var(--x-muted);
  --color-muted-foreground: var(--x-muted-fg);
  --color-accent: var(--x-accent);
  --color-accent-foreground: var(--x-fg);
  --color-destructive: var(--x-destructive);
  --color-border: var(--x-border);
  --color-input: var(--x-input);
  --color-ring: var(--x-ring);
  --color-sidebar: var(--x-sidebar);
  --color-magic-gold: #e8b84a;
  --color-magic-cream: var(--x-fg);
  --color-gold-muted: var(--x-muted-fg);
  --color-gold-dim: var(--x-muted-fg);
  --color-gold-soft: var(--x-title);
  --color-ink-faint: var(--x-muted-fg);
  --color-teal: var(--x-teal);
  --color-success: var(--x-success);
  --color-success-bg: var(--x-success-bg);
  --color-success-border: var(--x-success-border);
  --color-warning: var(--x-warning);
  --color-warning-bg: var(--x-warning-bg);
  --color-warning-border: var(--x-warning-border);
  --color-danger: var(--x-danger);
  --color-danger-bg: var(--x-danger-bg);
  --color-danger-border: var(--x-danger-border);
  --color-indigo: var(--x-primary);
  --color-violet: #8b5cf6;
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 10px;
}

/* 深色模式（預設，script 載入前不閃爍） */
:root,
[data-theme="dark"] {
  color-scheme: dark;

  --x-bg: #0f1117;
  --x-fg: #e8eaed;
  --x-title: #f3f4f6;
  --x-card: #181b22;
  --x-popover: #1c1f27;
  --x-primary: #4d9fff;
  --x-primary-fg: #ffffff;
  --x-primary-hover: #3d8ef5;
  --x-secondary: #1c1f27;
  --x-muted: #13161d;
  --x-muted-fg: #8b9298;
  --x-accent: #1e2430;
  --x-destructive: #f87171;
  --x-border: #2a2f3a;
  --x-input: #13161d;
  --x-ring: #4d9fff;
  --x-sidebar: #0c0e13;
  --x-teal: #34d399;
  --x-success: #34d399;
  --x-success-bg: rgba(52, 211, 153, 0.12);
  --x-success-border: rgba(52, 211, 153, 0.35);
  --x-warning: #fbbf24;
  --x-warning-bg: rgba(251, 191, 36, 0.12);
  --x-warning-border: rgba(251, 191, 36, 0.35);
  --x-danger: #f87171;
  --x-danger-bg: rgba(248, 113, 113, 0.12);
  --x-danger-border: rgba(248, 113, 113, 0.35);
  --x-link-hover: #7ab8ff;
  --x-selection-bg: rgba(77, 159, 255, 0.28);
  --x-selection-fg: #ffffff;
  --x-nav-active-bg: #1e2430;
  --x-nav-hover-bg: #1a1d24;
  --x-nav-active-fg: #f0f1f3;
  --x-kv-value: #c4c8ce;
  --x-section-bg: #13161d;
  --x-mobile-chrome: rgba(12, 14, 19, 0.96);
  --x-login-overlay: linear-gradient(180deg, rgba(15, 17, 23, 0.4) 0%, rgba(15, 17, 23, 0.95) 100%);
  --x-login-panel: rgba(15, 17, 23, 0.4);
  --x-placeholder: #6b7280;
}

/* 淺色模式 */
[data-theme="light"] {
  color-scheme: light;

  --x-bg: #f5f7fa;
  --x-fg: #202938;
  --x-title: #101828;
  --x-card: #ffffff;
  --x-popover: #ffffff;
  --x-primary: #2563eb;
  --x-primary-fg: #ffffff;
  --x-primary-hover: #1d4ed8;
  --x-secondary: #eef2f7;
  --x-muted: #f1f4f8;
  --x-muted-fg: #667085;
  --x-accent: #e8eef8;
  --x-destructive: #dc2626;
  --x-border: #dce3ec;
  --x-input: #ffffff;
  --x-ring: #2563eb;
  --x-sidebar: #f8fafc;
  --x-teal: #0f766e;
  --x-success: #0f766e;
  --x-success-bg: rgba(15, 118, 110, 0.08);
  --x-success-border: rgba(15, 118, 110, 0.25);
  --x-warning: #b45309;
  --x-warning-bg: rgba(180, 83, 9, 0.08);
  --x-warning-border: rgba(180, 83, 9, 0.25);
  --x-danger: #dc2626;
  --x-danger-bg: rgba(220, 38, 38, 0.08);
  --x-danger-border: rgba(220, 38, 38, 0.25);
  --x-link-hover: #1d4ed8;
  --x-selection-bg: rgba(37, 99, 235, 0.18);
  --x-selection-fg: #0f1216;
  --x-nav-active-bg: #e9effb;
  --x-nav-hover-bg: #eef2f7;
  --x-nav-active-fg: #0f1216;
  --x-kv-value: #3d4450;
  --x-section-bg: #f8fafc;
  --x-mobile-chrome: rgba(248, 250, 252, 0.94);
  --x-login-overlay: linear-gradient(180deg, rgba(246, 247, 249, 0.35) 0%, rgba(246, 247, 249, 0.96) 100%);
  --x-login-panel: rgba(255, 255, 255, 0.55);
  --x-placeholder: #9aa3af;
}

@layer base {
  * {
    @apply border-border;
  }

  body {
    @apply bg-background text-foreground;
    font-family: var(--font-sans);
    min-height: 100vh;
    font-size: 15px;
    line-height: 1.55;
    font-weight: 400;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
  }

  a {
    color: var(--color-primary);
  }

  a:hover {
    color: var(--x-link-hover);
  }

  ::selection {
    background: var(--x-selection-bg);
    color: var(--x-selection-fg);
  }

  ::placeholder {
    color: var(--x-placeholder);
    opacity: 1;
  }
}

@layer utilities {
  .font-display {
    font-family: var(--font-display);
  }

  .brand-title {
    font-weight: 600;
    font-size: 15px;
    color: var(--x-title);
    line-height: 1.25;
    letter-spacing: -0.01em;
  }

  .page-title {
    font-weight: 600;
    font-size: clamp(28px, 4vw, 42px);
    color: var(--x-title);
    letter-spacing: -0.02em;
    line-height: 1.12;
  }

  .page-eyebrow {
    font-size: 11px;
    font-weight: 500;
    letter-spacing: 0.04em;
    color: var(--x-muted-fg);
    text-transform: uppercase;
  }

  .page-lead {
    margin-top: 0.25rem;
    max-width: 42rem;
    font-size: 15px;
    line-height: 1.7;
    color: var(--x-muted-fg);
  }

  .font-readable {
    font-family: var(--font-sans);
    font-size: 14px;
    line-height: 1.55;
    color: var(--x-fg);
  }

  .text-label {
    font-size: 11px;
    font-weight: 500;
    letter-spacing: 0.03em;
    color: var(--x-muted-fg);
    text-transform: uppercase;
  }

  .brand-art {
    image-rendering: auto;
  }

  .app-bg {
    background-color: var(--x-bg);
    background-image:
      linear-gradient(180deg, color-mix(in srgb, var(--x-bg) 88%, transparent) 0%, color-mix(in srgb, var(--x-bg) 98%, transparent) 100%),
      url("/brand/xunlou-login-bg.jpg");
    background-size: cover;
    background-position: center 35%;
  }

  .app-bg-dashboard {
    background: var(--x-bg);
  }

  .app-main-content {
    position: relative;
    z-index: 1;
    padding-bottom: calc(4.75rem + env(safe-area-inset-bottom, 0px));
  }

  .safe-bottom {
    padding-bottom: max(0.5rem, env(safe-area-inset-bottom, 0px));
  }

  .mobile-floating {
    bottom: calc(4.75rem + env(safe-area-inset-bottom, 0px));
  }

  @media (min-width: 1024px) {
    .app-main-content {
      padding-bottom: 2rem;
    }

    .mobile-floating {
      bottom: 1.25rem;
    }
  }

  .app-sidebar {
    position: relative;
    z-index: 2;
    background: var(--x-sidebar);
    border-right: 1px solid var(--x-border);
    box-shadow: 18px 0 50px rgba(15, 23, 42, 0.035);
  }

  .account-switcher-trigger {
    border: 1px solid color-mix(in srgb, var(--x-border) 80%, transparent);
    background: color-mix(in srgb, var(--x-card) 65%, var(--x-sidebar));
  }

  .account-switcher-trigger:hover,
  .account-switcher-trigger:focus-visible {
    border-color: color-mix(in srgb, var(--x-primary) 35%, var(--x-border));
    background: var(--x-accent);
  }

  .tool-card,
  .post-card,
  .pixel-panel {
    background: var(--x-card);
    border: 1px solid var(--x-border);
    border-radius: 18px;
    color: var(--x-fg);
  }

  .post-card::before,
  .post-card::after {
    content: none;
  }

  .feed-divider {
    border-bottom: 1px solid var(--x-border);
  }

  .nav-item-active {
    font-weight: 500;
    color: var(--x-fg);
    background: var(--x-nav-active-bg);
    box-shadow: 0 1px 0 rgba(255,255,255,.8), 0 8px 22px rgba(15,23,42,.05);
  }

  .nav-item-idle {
    font-weight: 400;
    color: var(--x-muted-fg);
  }

  .nav-item-idle:hover,
  .nav-item-idle:focus-visible {
    color: var(--x-fg);
  }

  .nav-item:focus-visible {
    outline: none;
  }

  .skeleton {
    background: var(--x-muted);
    border: 1px solid var(--x-border);
    border-radius: 18px;
  }

  .tool-btn,
  .pixel-btn {
    border-radius: 6px;
    font-weight: 500;
    transition: background 0.12s ease, border-color 0.12s ease, color 0.12s ease;
  }

  .tool-input,
  .pixel-input {
    border-radius: 6px;
    border: 1px solid var(--x-border);
    background: var(--x-input);
    color: var(--x-fg);
    font-family: var(--font-sans);
  }

  .tool-input:focus-visible,
  .pixel-input:focus-visible {
    border-color: var(--x-ring);
    box-shadow: 0 0 0 2px color-mix(in srgb, var(--x-ring) 22%, transparent);
    outline: none;
  }

  .login-hero-overlay {
    background: var(--x-login-overlay);
  }

  .login-form-panel {
    background: var(--x-login-panel);
  }

  .magic-divider,
  .tool-divider {
    height: 1px;
    background: var(--x-border);
  }

  .mobile-topbar,
  .mobile-bottom-nav {
    border-color: var(--x-border);
    background: var(--x-mobile-chrome);
    backdrop-filter: blur(8px);
  }

  .brand-logo {
    border-radius: 10px;
    border: 1px solid color-mix(in srgb, var(--x-primary) 28%, var(--x-border));
    background: var(--x-card);
    box-shadow:
      0 0 0 1px color-mix(in srgb, var(--x-primary) 10%, transparent),
      0 4px 14px color-mix(in srgb, var(--x-primary) 22%, transparent);
  }

  .brand-title-accent {
    background: linear-gradient(120deg, var(--x-primary), var(--x-teal));
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
  }

  .tool-section {
    border: 1px solid var(--x-border);
    border-radius: 16px;
    background: var(--x-section-bg);
  }

  .tool-section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    font-size: 12px;
    font-weight: 500;
    color: var(--x-muted-fg);
  }

  .tool-kv-label {
    font-size: 11px;
    font-weight: 500;
    color: var(--x-muted-fg);
    text-transform: uppercase;
    letter-spacing: 0.03em;
  }

  .tool-kv-value {
    margin-top: 0.25rem;
    font-size: 13px;
    line-height: 1.5;
    color: var(--x-kv-value);
  }

  .animate-fade-in {
    animation: fadeIn 0.2s ease-out both;
  }

  .animate-fade-in-up {
    animation: fadeInUp 0.25s ease-out both;
  }

  @keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
  }

  @keyframes fadeInUp {
    from {
      opacity: 0;
      transform: translateY(4px);
    }
    to {
      opacity: 1;
      transform: translateY(0);
    }
  }

  @media (prefers-reduced-motion: reduce) {
    .animate-fade-in,
    .animate-fade-in-up {
      animation: none;
    }
  }
}
