/**
 * Tools4MtG Custom Styles
 * Dark strategic theme for Magic: The Gathering Commander tools
 * Overrides Bulma with custom design system
 */

/* ========================================
   CSS Custom Properties (Design Tokens)
   ======================================== */

:root {
  /* Primary - Deep Mystic Purple */
  --color-primary-50: oklch(97% 0.01 290);
  --color-primary-100: oklch(93% 0.03 290);
  --color-primary-200: oklch(86% 0.06 290);
  --color-primary-300: oklch(76% 0.1 290);
  --color-primary-400: oklch(65% 0.15 290);
  --color-primary-500: oklch(55% 0.18 290);
  --color-primary-600: oklch(48% 0.16 290);
  --color-primary-700: oklch(40% 0.13 290);
  --color-primary-800: oklch(32% 0.1 290);
  --color-primary-900: oklch(24% 0.07 290);
  --color-primary-950: oklch(16% 0.04 290);

  /* Accent - Moonlight Silver (cool, strategic, refined) */
  --color-accent-50: oklch(97% 0.01 260);
  --color-accent-100: oklch(92% 0.02 260);
  --color-accent-200: oklch(85% 0.04 260);
  --color-accent-300: oklch(78% 0.06 260);
  --color-accent-400: oklch(72% 0.08 260);
  --color-accent-500: oklch(65% 0.07 260);
  --color-accent-600: oklch(58% 0.06 260);
  --color-accent-700: oklch(50% 0.05 260);
  --color-accent-800: oklch(42% 0.04 260);
  --color-accent-900: oklch(34% 0.03 260);
  --color-accent-950: oklch(24% 0.02 260);

  /* Surface Colors */
  --color-bg-primary: oklch(12% 0.02 290);
  --color-bg-secondary: oklch(16% 0.03 290);
  --color-bg-tertiary: oklch(22% 0.04 290);
  --color-bg-elevated: oklch(28% 0.05 290);

  /* Text Colors */
  --color-text-primary: oklch(95% 0.01 290);
  --color-text-secondary: oklch(78% 0.02 290);
  --color-text-tertiary: oklch(62% 0.02 290);
  --color-text-disabled: oklch(45% 0.01 290);

  /* Semantic Colors */
  --color-success: oklch(65% 0.15 145);
  --color-warning: oklch(70% 0.1 75);
  --color-error: oklch(60% 0.18 25);
  --color-info: oklch(65% 0.12 250);

  /* MTG Color Accents */
  --color-mtg-white: oklch(90% 0.02 95);
  --color-mtg-blue: oklch(65% 0.15 250);
  --color-mtg-black: oklch(55% 0.05 290);
  --color-mtg-red: oklch(60% 0.18 35);
  --color-mtg-green: oklch(60% 0.15 145);

  /* Typography */
  --font-display: 'Oranienbaum', Georgia, serif;
  --font-body: 'Source Sans 3', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;

  /* Type Scale */
  --text-xs: 0.75rem;
  --text-sm: 0.875rem;
  --text-base: 1rem;
  --text-lg: 1.125rem;
  --text-xl: 1.25rem;
  --text-2xl: clamp(1.375rem, 1.2rem + 0.8vw, 1.75rem);
  --text-3xl: clamp(1.625rem, 1.35rem + 1.2vw, 2.25rem);
  --text-4xl: clamp(2rem, 1.5rem + 2vw, 3rem);
  --text-5xl: clamp(2.5rem, 1.75rem + 3vw, 4rem);

  /* Line Heights */
  --leading-tight: 1.25;
  --leading-snug: 1.375;
  --leading-normal: 1.5;
  --leading-relaxed: 1.625;

  /* Font Weights */
  --weight-normal: 400;
  --weight-medium: 500;
  --weight-semibold: 600;
  --weight-bold: 700;

  /* Spacing */
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.25rem;
  --space-6: 1.5rem;
  --space-8: 2rem;
  --space-10: 2.5rem;
  --space-12: 3rem;
  --space-16: 4rem;
  --space-20: 5rem;
  --space-24: 6rem;

  /* Border Radius */
  --radius-sm: 0.25rem;
  --radius-md: 0.5rem;
  --radius-lg: 0.75rem;
  --radius-xl: 1rem;
  --radius-2xl: 1.5rem;

  /* Shadows */
  --shadow-sm: 0 1px 2px 0 oklch(0% 0 0 / 0.3);
  --shadow-md: 0 4px 6px -1px oklch(0% 0 0 / 0.4), 0 2px 4px -2px oklch(0% 0 0 / 0.3);
  --shadow-lg: 0 10px 15px -3px oklch(0% 0 0 / 0.5), 0 4px 6px -4px oklch(0% 0 0 / 0.4);
  --shadow-xl: 0 20px 25px -5px oklch(0% 0 0 / 0.5), 0 8px 10px -6px oklch(0% 0 0 / 0.4);
  --shadow-glow-primary: 0 0 20px oklch(55% 0.18 290 / 0.3);
  --shadow-glow-accent: 0 0 20px oklch(72% 0.08 260 / 0.25);

  /* Animation */
  --ease-out-quart: cubic-bezier(0.25, 1, 0.5, 1);
  --ease-out-expo: cubic-bezier(0.16, 1, 0.3, 1);
  --duration-fast: 150ms;
  --duration-normal: 250ms;
  --duration-slow: 350ms;
}

/* ========================================
   Base Styles & Resets
   ======================================== */

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

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

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

/* Typography */
h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-display);
  color: var(--color-text-primary);
  line-height: var(--leading-tight);
  margin: 0 0 var(--space-4) 0;
  letter-spacing: 0.02em;
}

h1 { font-size: var(--text-4xl); }
h2 { font-size: var(--text-3xl); }
h3 { font-size: var(--text-2xl); }
h4 { font-size: var(--text-xl); }

p {
  margin: 0 0 var(--space-4) 0;
}

a {
  color: var(--color-primary-400);
  text-decoration: none;
  transition: color var(--duration-fast) var(--ease-out-quart);
}

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

/* ========================================
   Bulma Overrides
   ======================================== */

/* Navbar */
.navbar {
  background: var(--color-bg-secondary);
  border-bottom: 1px solid oklch(25% 0.03 290);
}

.navbar-item {
  color: var(--color-text-secondary);
  font-weight: var(--weight-medium);
}

.navbar-item:hover {
  background: var(--color-bg-tertiary);
  color: var(--color-text-primary);
}

.navbar-brand .navbar-item {
  font-family: var(--font-display);
  font-size: var(--text-xl);
  color: var(--color-accent-400);
  letter-spacing: 0.05em;
}

.navbar-brand .navbar-item:hover {
  color: var(--color-accent-300);
}

.navbar-burger {
  color: var(--color-text-secondary);
}

.navbar-burger:hover {
  background: var(--color-bg-tertiary);
}

/* Buttons */
.button {
  font-family: var(--font-body);
  font-weight: var(--weight-semibold);
  border-radius: var(--radius-md);
  transition: all var(--duration-fast) var(--ease-out-quart);
}

.button.is-primary {
  background: linear-gradient(135deg, var(--color-primary-600), var(--color-primary-500));
  border-color: var(--color-primary-400);
}

.button.is-primary:hover {
  background: linear-gradient(135deg, var(--color-primary-500), var(--color-primary-400));
  transform: translateY(-1px);
  box-shadow: var(--shadow-md), var(--shadow-glow-primary);
}

.button.is-light {
  background: var(--color-bg-tertiary);
  color: var(--color-text-secondary);
  border-color: oklch(40% 0.05 290);
}

.button.is-light:hover {
  background: var(--color-bg-elevated);
  border-color: var(--color-primary-500);
  color: var(--color-text-primary);
}

.button.is-danger {
  background: oklch(40% 0.15 25);
  border-color: oklch(50% 0.15 25);
  color: var(--color-text-primary);
}

.button.is-danger:hover {
  background: oklch(45% 0.15 25);
  transform: translateY(-1px);
}

.button.is-info {
  background: oklch(40% 0.12 250);
  border-color: oklch(50% 0.12 250);
  color: var(--color-text-primary);
}

.button.is-info:hover {
  background: oklch(45% 0.12 250);
}

.button.is-info.is-outlined {
  background: transparent;
  border-color: oklch(50% 0.12 250);
  color: oklch(70% 0.12 250);
}

.button.is-info.is-outlined:hover {
  background: oklch(30% 0.08 250);
  color: var(--color-text-primary);
}

.button.is-success {
  background: oklch(40% 0.12 145);
  border-color: oklch(50% 0.12 145);
  color: var(--color-text-primary);
}

.button.is-large {
  font-size: var(--text-lg);
  padding: var(--space-4) var(--space-8);
}

/* Box/Card */
.box {
  background: var(--color-bg-secondary);
  border: 1px solid oklch(30% 0.04 290);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  transition: all var(--duration-fast) var(--ease-out-quart);
}

.box:hover {
  border-color: oklch(40% 0.06 290);
  box-shadow: var(--shadow-md);
}

.card {
  background: var(--color-bg-secondary);
  border: 1px solid oklch(30% 0.04 290);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  color: var(--color-text-secondary);
}

.card-content {
  padding: var(--space-6);
}

/* Form Elements */
.input, .select select {
  background: var(--color-bg-primary);
  color: var(--color-text-primary);
  border: 1px solid oklch(35% 0.04 290);
  border-radius: var(--radius-md);
  font-family: var(--font-body);
}

.input:focus, .select select:focus {
  border-color: var(--color-primary-500);
  box-shadow: 0 0 0 3px oklch(55% 0.18 290 / 0.15);
}

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

.label {
  color: var(--color-text-secondary);
  font-weight: var(--weight-semibold);
}

.help {
  color: var(--color-text-tertiary);
}

.checkbox {
  color: var(--color-text-secondary);
}

.checkbox:hover {
  color: var(--color-text-primary);
}

/* Raw Form Elements — Emmett auth forms don't add Bulma classes */
.box form input[type="text"],
.box form input[type="email"],
.box form input[type="password"] {
  background: var(--color-bg-primary);
  color: var(--color-text-primary);
  border: 1px solid oklch(35% 0.04 290);
  border-radius: var(--radius-md);
  font-family: var(--font-body);
  padding: var(--space-3) var(--space-4);
  width: 100%;
  font-size: var(--text-base);
  line-height: var(--leading-normal);
  transition: all var(--duration-fast) var(--ease-out-quart);
}

.box form input[type="text"]:focus,
.box form input[type="email"]:focus,
.box form input[type="password"]:focus {
  border-color: var(--color-primary-500);
  box-shadow: 0 0 0 3px oklch(55% 0.18 290 / 0.15);
  outline: none;
}

.box form label {
  display: block;
  color: var(--color-text-secondary);
  font-weight: var(--weight-semibold);
  font-size: var(--text-sm);
  margin-bottom: var(--space-2);
}

.box form input[type="checkbox"] {
  width: 1.25rem;
  height: 1.25rem;
  accent-color: var(--color-primary-500);
  margin-right: var(--space-2);
  vertical-align: middle;
}

.box form input[type="submit"] {
  background: linear-gradient(135deg, var(--color-primary-600), var(--color-primary-500));
  border: 1px solid var(--color-primary-400);
  border-radius: var(--radius-md);
  color: var(--color-text-primary);
  font-family: var(--font-body);
  font-weight: var(--weight-semibold);
  font-size: var(--text-base);
  padding: var(--space-3) var(--space-6);
  cursor: pointer;
  transition: all var(--duration-fast) var(--ease-out-quart);
}

.box form input[type="submit"]:hover {
  background: linear-gradient(135deg, var(--color-primary-500), var(--color-primary-400));
  transform: translateY(-1px);
  box-shadow: var(--shadow-md), var(--shadow-glow-primary);
}

/* Emmett form validation errors */
.emt_error {
  color: var(--color-error);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  margin-top: var(--space-2);
  line-height: var(--leading-snug);
}

/* Highlight fields with adjacent validation errors */
.box form > div:has(.emt_error) input[type="text"],
.box form > div:has(.emt_error) input[type="password"],
.box form > div:has(.emt_error) input[type="email"] {
  border-color: var(--color-error);
  box-shadow: 0 0 0 3px oklch(60% 0.18 25 / 0.15);
}

/* Form layout — grid so submit + remember me sit side-by-side */
.box form {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: var(--space-4);
  align-items: center;
}

/* Email + Password rows span full width */
.box form > div:nth-child(1),
.box form > div:nth-child(2) {
  grid-column: 1 / -1;
  margin-bottom: 0;
}

/* Submit button (4th div) — left column of bottom row */
.box form > div:nth-child(4) {
  grid-column: 1;
  grid-row: 3;
  justify-self: start;
  margin-bottom: 0;
}

/* Remember me (3rd div) — right column of bottom row */
.box form > div:nth-child(3) {
  grid-column: 2;
  grid-row: 3;
  justify-self: start;
  display: flex;
  flex-direction: row-reverse;
  align-items: center;
  gap: var(--space-2);
  margin-bottom: 0;
}

/* Remove bottom margin from labels inside remember-me row */
.box form > div:nth-child(3) label {
  margin-bottom: 0;
}

/* Hide hidden inputs from grid */
.box form > input[type="hidden"] {
  display: none;
}

/* Table */
.table {
  background: transparent;
  color: var(--color-text-secondary);
}

.table thead th {
  color: var(--color-text-primary);
  border-bottom: 1px solid oklch(35% 0.04 290);
  font-weight: var(--weight-semibold);
}

.table td, .table th {
  border-bottom: 1px solid oklch(25% 0.03 290);
}

.table tbody tr:hover {
  background: var(--color-bg-tertiary);
}

.table.is-striped tbody tr:not(.is-selected):nth-child(even) {
  background: oklch(18% 0.03 290);
}

/* Notifications/Alerts */
.notification {
  border-radius: var(--radius-md);
  border: 1px solid;
}

.notification.is-success {
  background: oklch(20% 0.05 145);
  border-color: oklch(40% 0.1 145);
  color: oklch(75% 0.1 145);
}

.notification.is-warning {
  background: oklch(20% 0.04 75);
  border-color: oklch(40% 0.08 75);
  color: oklch(80% 0.08 75);
}

.notification.is-danger {
  background: oklch(18% 0.06 25);
  border-color: oklch(40% 0.12 25);
  color: oklch(75% 0.1 25);
}

.notification.is-info {
  background: oklch(20% 0.04 250);
  border-color: oklch(40% 0.08 250);
  color: oklch(75% 0.1 250);
}

.notification.is-light {
  background: var(--color-bg-tertiary);
  border-color: oklch(35% 0.05 290);
  color: var(--color-text-secondary);
}

.notification .delete {
  background: oklch(40% 0.05 290);
  opacity: 0.7;
}

.notification .delete:hover {
  background: oklch(50% 0.08 290);
  opacity: 1;
}

/* Tags */
.tag {
  background: var(--color-bg-tertiary);
  color: var(--color-text-secondary);
  border-radius: var(--radius-sm);
}

.tag.is-primary {
  background: var(--color-primary-600);
  color: var(--color-text-primary);
}

.tag.is-light {
  background: var(--color-bg-tertiary);
  color: var(--color-text-tertiary);
}

/* Select dropdown */
.select {
  border-radius: var(--radius-md);
}

.select.is-fullwidth select {
  background: var(--color-bg-primary);
  color: var(--color-text-primary);
  border-color: oklch(35% 0.04 290);
}

/* Progress */
.progress {
  background: var(--color-bg-tertiary);
  border-radius: var(--radius-sm);
}

.progress.is-primary::-webkit-progress-value {
  background: var(--color-primary-500);
}

.progress.is-small {
  height: 0.5rem;
}

/* Title/Subtitle */
.title {
  color: var(--color-text-primary);
  font-family: var(--font-display);
  font-weight: var(--weight-normal);
  letter-spacing: 0.02em;
}

.subtitle {
  color: var(--color-text-secondary);
  font-family: var(--font-body);
}

/* Section */
.section {
  padding: var(--space-8) var(--space-4);
}

@media (min-width: 768px) {
  .section {
    padding: var(--space-12) var(--space-6);
  }
}

/* Footer */
.footer {
  background: var(--color-bg-secondary);
  border-top: 1px solid oklch(25% 0.03 290);
  padding: var(--space-8) var(--space-6);
  color: var(--color-text-tertiary);
}

/* Details/Summary */
details {
  background: var(--color-bg-tertiary);
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-4);
}

summary {
  color: var(--color-text-tertiary);
  cursor: pointer;
  user-select: none;
}

summary:hover {
  color: var(--color-text-secondary);
}

details[open] summary {
  color: var(--color-text-secondary);
  margin-bottom: var(--space-3);
}

/* HR */
hr {
  background: oklch(30% 0.04 290);
  height: 1px;
  border: none;
  margin: var(--space-6) 0;
}

/* Focus states */
:focus-visible {
  outline: 2px solid var(--color-primary-500);
  outline-offset: 2px;
}

/* ========================================
   Custom Components
   ======================================== */

/* Accent Button - Main CTA */
.btn-accent {
  background: linear-gradient(135deg, var(--color-accent-600), var(--color-accent-500));
  color: oklch(15% 0.02 290);
  border: 1px solid var(--color-accent-400);
  border-radius: var(--radius-md);
  padding: var(--space-4) var(--space-8);
  font-weight: var(--weight-bold);
  font-size: var(--text-lg);
  transition: all var(--duration-fast) var(--ease-out-quart);
  box-shadow: var(--shadow-md);
}

.btn-accent:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg), var(--shadow-glow-accent);
  color: oklch(10% 0.02 290);
}

/* Slot Machine Display */
.slot-display {
  font-family: var(--font-display);
  font-size: var(--text-3xl);
  color: var(--color-accent-400);
  text-align: center;
  min-height: 1.5em;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s ease;
  letter-spacing: 0.02em;
}

.slot-spinning .slot-display {
  opacity: 0.85;
  color: var(--color-primary-400);
}

.slot-landed .slot-display {
  animation: slot-land 0.5s var(--ease-out-expo);
}

@keyframes slot-land {
  0% {
    transform: scale(1);
    text-shadow: none;
  }
  40% {
    transform: scale(1.05);
    text-shadow: 0 0 25px var(--color-accent-400);
    color: var(--color-accent-300);
  }
  100% {
    transform: scale(1);
    text-shadow: none;
  }
}

/* Card Hover Effect */
.card-hover {
  transition: all var(--duration-fast) var(--ease-out-quart);
}

.card-hover:hover {
  transform: translateY(-2px);
  border-color: oklch(40% 0.06 290);
  box-shadow: var(--shadow-lg);
}

/* Glow Animation - Subtle */
.glow-pulse {
  animation: glow-pulse 2.5s ease-in-out infinite;
}

@keyframes glow-pulse {
  0%, 100% {
    box-shadow: 0 0 15px oklch(72% 0.08 260 / 0.15);
  }
  50% {
    box-shadow: 0 0 25px oklch(72% 0.08 260 / 0.25);
  }
}

/* Podmate Checkbox Items */
.podmate-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3);
  border-radius: var(--radius-md);
  transition: background var(--duration-fast) var(--ease-out-quart);
  cursor: pointer;
}

.podmate-item:hover {
  background: var(--color-bg-tertiary);
}

.podmate-item input[type="checkbox"] {
  width: 1.25rem;
  height: 1.25rem;
  accent-color: var(--color-primary-500);
  cursor: pointer;
}

/* Empty State */
.empty-state {
  text-align: center;
  padding: var(--space-12) var(--space-6);
  color: var(--color-text-tertiary);
}

.empty-state-icon {
  font-size: var(--text-5xl);
  margin-bottom: var(--space-4);
  opacity: 0.5;
}

/* Loading Spinner */
.htmx-indicator {
  opacity: 0;
  transition: opacity var(--duration-fast);
}

.htmx-request .htmx-indicator,
.htmx-indicator.htmx-request {
  opacity: 1;
}

/* Results Container */
#results {
  animation: fade-in-up 0.4s var(--ease-out-quart);
}

@keyframes fade-in-up {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Weight Table */
.weight-table {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
}

.weight-table th,
.weight-table td {
  padding: var(--space-2) var(--space-3);
}

/* Status Badges */
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
}

.status-badge.connected {
  background: oklch(20% 0.05 145);
  color: oklch(75% 0.1 145);
}

.status-badge.disconnected {
  background: oklch(18% 0.04 75);
  color: oklch(78% 0.08 75);
}

/* Link styling in content */
.content a {
  color: var(--color-primary-400);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.content a:hover {
  color: var(--color-primary-300);
}

/* Section numbering accent */
.section-number {
  color: var(--color-accent-400);
  font-family: var(--font-display);
  font-size: 0.9em;
  letter-spacing: 0.05em;
}

/* ========================================
   Reduced Motion
   ======================================== */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }

  .slot-landed .slot-display {
    animation: none;
  }

  .glow-pulse {
    animation: none;
  }
}

/* ========================================
   Mobile Optimizations
   ======================================== */

@media (max-width: 768px) {
  .button.is-large {
    font-size: var(--text-base);
    padding: var(--space-3) var(--space-6);
  }

  .slot-display {
    font-size: var(--text-2xl);
  }

  .box {
    padding: var(--space-4);
  }

  .card-content {
    padding: var(--space-4);
  }
}

/* ========================================
   Print Styles
   ======================================== */

@media print {
  body {
    background: white;
    color: black;
  }

  .navbar,
  .footer {
    display: none;
  }

  .box,
  .card {
    border: 1px solid #ccc;
    box-shadow: none;
  }
}
