/* ============================================
   D93 Labs Homepage — Design Tokens & Styles
   Based on OpenAI Apps SDK UI token system
   ============================================ */

/* --- Light Theme (default) --- */
:root,
[data-theme="light"] {
  color-scheme: light;

  /* Surfaces */
  --surface: #ffffff;
  --surface-secondary: #f9f9f9;
  --surface-elevated: #ffffff;

  /* Text */
  --text: #0d0d0d;
  --text-secondary: #5d5d5d;
  --text-tertiary: #8f8f8f;

  /* Borders & Dividers */
  --border: rgba(13, 13, 13, 0.10);
  --border-subtle: rgba(13, 13, 13, 0.05);

  /* Shadows */
  --shadow-sm: 0 1px 3px -1px rgba(0, 0, 0, 0.06), 0 1px 2px -1px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 4px 12px -2px rgba(0, 0, 0, 0.06), 0 2px 4px -1px rgba(0, 0, 0, 0.04);
  --shadow-lg: 0 8px 24px -4px rgba(0, 0, 0, 0.08), 0 4px 8px -2px rgba(0, 0, 0, 0.04);

  /* Info (Blue) */
  --info: #0285ff;
  --info-soft: #e5f3ff;
  --info-text: #003f7a;

  /* Success (Green) */
  --success: #04b84c;
  --success-soft: #d9f4e4;
  --success-text: #00692a;

  /* Discovery (Purple) */
  --discovery: #924ff7;
  --discovery-soft: #efe5fe;
  --discovery-text: #532d8d;

  /* Warning (Orange) */
  --warning: #fb6a22;
  --warning-soft: #ffe7d9;
  --warning-text: #923b0f;

  /* Caution (Yellow) */
  --caution: #ffc300;
  --caution-soft: #fff6d9;
  --caution-text: #6e5400;

  /* Logo container */
  --logo-bg: #ffffff;
  --logo-ring: rgba(13, 13, 13, 0.08);

  /* Toggle button */
  --toggle-bg: transparent;
  --toggle-hover: rgba(13, 13, 13, 0.06);
}

/* --- Dark Theme --- */
[data-theme="dark"] {
  color-scheme: dark;

  --surface: #212121;
  --surface-secondary: #131313;
  --surface-elevated: #303030;

  --text: #ffffff;
  --text-secondary: #afafaf;
  --text-tertiary: #767676;

  --border: rgba(255, 255, 255, 0.12);
  --border-subtle: rgba(255, 255, 255, 0.06);

  --shadow-sm: 0 1px 3px -1px rgba(0, 0, 0, 0.20), 0 1px 2px -1px rgba(0, 0, 0, 0.12);
  --shadow-md: 0 4px 12px -2px rgba(0, 0, 0, 0.24), 0 2px 4px -1px rgba(0, 0, 0, 0.16);
  --shadow-lg: 0 8px 24px -4px rgba(0, 0, 0, 0.36), 0 4px 8px -2px rgba(0, 0, 0, 0.20);

  --info-soft: rgba(2, 133, 255, 0.14);
  --info-text: #66b5ff;

  --success-soft: rgba(4, 184, 76, 0.14);
  --success-text: #66d492;

  --discovery-soft: rgba(146, 79, 247, 0.14);
  --discovery-text: #be95fa;

  --warning-soft: rgba(251, 106, 34, 0.14);
  --warning-text: #ff9e6c;

  --caution-soft: rgba(255, 195, 0, 0.14);
  --caution-text: #ffdb66;

  --logo-bg: #303030;
  --logo-ring: rgba(255, 255, 255, 0.08);

  --toggle-bg: transparent;
  --toggle-hover: rgba(255, 255, 255, 0.08);
}

/* --- Radius --- */
:root {
  --radius-md: 0.5rem;
  --radius-lg: 0.625rem;
  --radius-xl: 0.75rem;
  --radius-2xl: 1rem;
  --radius-3xl: 1.25rem;
}

/* ============================================
   Reset & Base
   ============================================ */

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

html {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  background: var(--surface-secondary);
}

body {
  font-family: ui-sans-serif, -apple-system, system-ui, "Segoe UI", "Helvetica", "Arial", sans-serif;
  background: var(--surface-secondary);
  color: var(--text);
  min-height: 100vh;
  transition: background-color 0.25s ease, color 0.25s ease;
}

/* ============================================
   Auth Overlay
   ============================================ */

.auth-overlay {
  position: fixed;
  inset: 0;
  background: var(--surface-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 1.5rem;
}

.auth-overlay.hidden {
  display: none;
}

.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-2xl);
  padding: 2.5rem 2rem;
  box-shadow: var(--shadow-md);
  width: 100%;
  max-width: 360px;
  text-align: center;
}

.auth-logo-wrap {
  width: 56px;
  height: 56px;
  border-radius: var(--radius-xl);
  background: var(--logo-bg);
  box-shadow: 0 0 0 1px var(--logo-ring);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 1.25rem;
}

.auth-logo {
  width: 44px;
  height: 44px;
  object-fit: contain;
}

.auth-title {
  font-size: 1.375rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
  margin-bottom: 0.25rem;
}

.auth-subtitle {
  font-size: 0.8125rem;
  color: var(--text-tertiary);
  margin-bottom: 1.5rem;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.auth-input {
  width: 100%;
  padding: 0.625rem 0.875rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  color: var(--text);
  font-size: 0.875rem;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.auth-input:focus {
  border-color: #0285ff;
  box-shadow: 0 0 0 3px rgba(2, 133, 255, 0.15);
}

.auth-input::placeholder {
  color: var(--text-tertiary);
}

.auth-button {
  width: 100%;
  padding: 0.625rem;
  border: none;
  border-radius: var(--radius-lg);
  background: #0d0d0d;
  color: #ffffff;
  font-size: 0.875rem;
  font-weight: 550;
  font-family: inherit;
  cursor: pointer;
  transition: background-color 0.15s ease;
}

[data-theme="dark"] .auth-button {
  background: #ededed;
  color: #0d0d0d;
}

.auth-button:hover {
  background: #303030;
}

[data-theme="dark"] .auth-button:hover {
  background: #cdcdcd;
}

.auth-button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.auth-error {
  font-size: 0.8125rem;
  color: #e25507;
  min-height: 1.25rem;
}

/* ============================================
   Page Layout
   ============================================ */

.page {
  max-width: 960px;
  margin: 0 auto;
  padding: 2.5rem 2rem;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ============================================
   Header
   ============================================ */

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 2.5rem;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 0.875rem;
}

.header-logo-wrap {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-xl);
  background: var(--logo-bg);
  box-shadow: 0 0 0 1px var(--logo-ring);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.header-logo {
  width: 36px;
  height: 36px;
  object-fit: contain;
}

.header-title {
  font-size: 1.375rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.2;
  color: var(--text);
}

.header-subtitle {
  font-size: 0.8125rem;
  color: var(--text-tertiary);
  font-weight: 450;
  margin-top: 0.125rem;
}

/* ============================================
   Theme Toggle
   ============================================ */

.theme-toggle {
  width: 40px;
  height: 40px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--toggle-bg);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease;
  flex-shrink: 0;
}

.theme-toggle:hover {
  background: var(--toggle-hover);
  color: var(--text);
}

.theme-toggle svg {
  width: 18px;
  height: 18px;
}

.icon-sun { display: none; }
.icon-moon { display: block; }

[data-theme="dark"] .icon-sun { display: block; }
[data-theme="dark"] .icon-moon { display: none; }

/* ============================================
   Cards Grid
   ============================================ */

.cards-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1.25rem;
  align-content: start;
}

/* ============================================
   Section Divider
   ============================================ */

.section-divider {
  margin-top: 2.5rem;
  margin-bottom: 1.25rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border-subtle);
}

.section-title {
  font-size: 1rem;
  font-weight: 620;
  letter-spacing: -0.01em;
  color: var(--text);
}

.section-subtitle {
  font-size: 0.8125rem;
  color: var(--text-tertiary);
  margin-top: 0.25rem;
}

/* ============================================
   App Card
   ============================================ */

.app-card {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-top: 3px solid var(--card-accent);
  border-radius: var(--radius-2xl);
  padding: 1.5rem;
  text-decoration: none;
  color: inherit;
  box-shadow: var(--shadow-sm);
  transition:
    transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1),
    box-shadow 0.2s ease,
    border-color 0.2s ease;
  position: relative;
  overflow: hidden;
}

.app-card::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--card-accent);
  opacity: 0;
  box-shadow: 0 2px 12px var(--card-accent);
  transition: opacity 0.2s ease;
}

.app-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-lg);
}

.app-card:hover::after {
  opacity: 0.5;
}

.app-card:active {
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

/* Card icon */
.app-card-icon {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-xl);
  background: var(--card-icon-bg);
  color: var(--card-accent);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 1.125rem;
  flex-shrink: 0;
}

.app-card-icon svg {
  width: 24px;
  height: 24px;
}

/* Card content */
.app-card-title {
  font-size: 1.0625rem;
  font-weight: 620;
  letter-spacing: -0.01em;
  margin-bottom: 0.5rem;
  color: var(--text);
  line-height: 1.3;
}

.app-card-desc {
  font-size: 0.8125rem;
  line-height: 1.55;
  color: var(--text-secondary);
  flex: 1;
}

.app-card-link {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  margin-top: 1.125rem;
  font-size: 0.8125rem;
  font-weight: 550;
  color: var(--card-link);
  transition: gap 0.15s ease;
}

.app-card:hover .app-card-link {
  gap: 0.5rem;
}

.app-card-link svg {
  width: 14px;
  height: 14px;
}

/* --- Card color variants --- */

.app-card--info {
  --card-accent: #0285ff;
  --card-icon-bg: var(--info-soft);
  --card-link: var(--info-text);
}

.app-card--success {
  --card-accent: #04b84c;
  --card-icon-bg: var(--success-soft);
  --card-link: var(--success-text);
}

.app-card--discovery {
  --card-accent: #924ff7;
  --card-icon-bg: var(--discovery-soft);
  --card-link: var(--discovery-text);
}

.app-card--warning {
  --card-accent: #fb6a22;
  --card-icon-bg: var(--warning-soft);
  --card-link: var(--warning-text);
}

.app-card--caution {
  --card-accent: #ffc300;
  --card-icon-bg: var(--caution-soft);
  --card-link: var(--caution-text);
}

/* ============================================
   Entrance Animation
   ============================================ */

@keyframes card-in {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.app-card {
  animation: card-in 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94) both;
}

.app-card:nth-child(1) { animation-delay: 0.06s; }
.app-card:nth-child(2) { animation-delay: 0.12s; }
.app-card:nth-child(3) { animation-delay: 0.18s; }
.app-card:nth-child(4) { animation-delay: 0.24s; }

/* ============================================
   Footer
   ============================================ */

.footer {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  margin-top: 3rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border-subtle);
}

.footer-flag {
  height: 16px;
  width: auto;
  border-radius: 2px;
  box-shadow: 0 0 0 0.5px rgba(0, 0, 0, 0.1);
}

.footer-text {
  font-size: 0.75rem;
  color: var(--text-tertiary);
  font-weight: 400;
}

/* ============================================
   Responsive
   ============================================ */

@media (max-width: 768px) {
  .cards-grid {
    grid-template-columns: 1fr;
    gap: 1rem;
  }
}

@media (max-width: 640px) {
  .page {
    padding: 1.5rem 1.25rem;
  }

  .header {
    margin-bottom: 1.75rem;
  }

  .header-title {
    font-size: 1.1875rem;
  }

  .app-card {
    padding: 1.25rem;
  }

  .section-divider {
    margin-top: 1.75rem;
  }

  .footer {
    margin-top: 2rem;
  }
}

@media (max-width: 380px) {
  .header-subtitle {
    display: none;
  }
}
