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

:root {
  /* Light theme */
  --background: #f8f9fa;
  --foreground: #1a1a1a;
  --card: #ffffff;
  --card-foreground: #1a1a1a;
  --primary: #2B322A;
  --primary-foreground: #ffffff;
  --secondary: #e2e8f0;
  --secondary-foreground: #1a1a1a;
  --muted: #f1f5f9;
  --muted-foreground: #64748b;
  --accent: #3d4a3c;
  --accent-foreground: #ffffff;
  --border: #e2e8f0;
  --input: #e2e8f0;
  --ring: #2B322A;
  --radius: 0.375rem;
  --section-bg: #f3f4f6;
  --tab-bg: #e5e7eb;
  --success: #10b981;
  --warning: #f59e0b;
  --error: #ef4444;
}

[data-theme="dark"] {
  --background: #0a0a0a;
  --foreground: #fafafa;
  --card: #141414;
  --card-foreground: #fafafa;
  --primary: #2B322A;
  --primary-foreground: #ffffff;
  --secondary: #262626;
  --secondary-foreground: #fafafa;
  --muted: #262626;
  --muted-foreground: #a1a1aa;
  --accent: #3d4a3c;
  --accent-foreground: #ffffff;
  --border: #262626;
  --input: #262626;
  --ring: #3d4a3c;
  --section-bg: #18181b;
  --tab-bg: #1a1a1a;
  --success: #10b981;
  --warning: #f59e0b;
  --error: #ef4444;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen", "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif;
  background: var(--background);
  color: var(--foreground);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background 0.3s ease, color 0.3s ease;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1rem;
}

.grid-layout {
  display: grid;
  grid-template-columns: minmax(300px, 580px) 1fr;
  gap: 1rem;
  align-items: start;
}

/* Sticky Preview for Desktop */
@media (min-width: 969px) {
  .preview-card {
    position: sticky;
    top: 1rem;
    max-height: calc(100vh - 2rem);
    overflow-y: auto;
    overflow-x: hidden;
  }
}

/* Mobile Responsive Layout */
@media (max-width: 968px) {
  .grid-layout {
    grid-template-columns: 1fr;
  }
  
  .preview-card {
    position: sticky;
    top: 0;
    z-index: 50;
    background: var(--card);
    box-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    overflow-x: auto;
    transition: padding 0.3s ease;
  }
  
  /* Reduce padding when scrolled to minimize space */
  .preview-card.scrolled {
    padding: 0.5rem;
  }
  
  .preview-card.scrolled .card-header {
    display: none;
  }
  
  .preview-card.scrolled .card-content {
    gap: 0;
  }
  
  .canvas-container {
    max-width: 100%;
  }
}

@media (max-width: 640px) {
  .timer-controls {
    grid-template-columns: 1fr 1fr !important;
    gap: 0.5rem !important;
  }
  
  .timer-controls .timer-input {
    grid-column: span 2;
  }
  
  .timer-controls .btn {
    width: 100%;
  }
  
  .score-control {
    justify-content: center;
  }
}

/* Card Component */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  box-shadow: 0 1px 3px 0 rgb(0 0 0 / 0.05);
  transition: background 0.3s ease, border-color 0.3s ease, box-shadow 0.3s ease;
}

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

.card-title {
  font-size: 0.875rem;
  font-weight: 600;
  line-height: 1.5;
  letter-spacing: -0.01em;
  color: var(--foreground);
}

.card-content {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

/* Canvas Container - Fixed aspect ratio */
.canvas-container {
  position: relative;
  width: 100%;
  max-width: 550px;
  margin: 0 auto;
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
}

.canvas-wrapper {
  position: relative;
  width: 100%;
  padding-bottom: 36.36%; /* 550:200 = 2.75:1 ratio = 36.36% */
}

canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: block;
  image-rendering: -webkit-optimize-contrast;
  image-rendering: crisp-edges;
}

/* Form Elements */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

label {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--muted-foreground);
}

input, select {
  width: 100%;
  height: 2rem;
  padding: 0 0.5rem;
  font-size: 0.8125rem;
  background: var(--background);
  color: var(--foreground);
  border: 1px solid var(--input);
  border-radius: var(--radius);
  outline: none;
  transition: all 0.2s;
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
}

input:focus, select:focus {
  border-color: var(--ring);
  box-shadow: 0 0 0 2px rgb(43 50 42 / 0.1);
}

input[type="number"] {
  -moz-appearance: textfield;
}

input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
}

select {
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.5rem center;
  background-size: 1rem;
  padding-right: 2rem;
}

[data-theme="dark"] select {
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23a1a1aa' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 2rem;
  padding: 0 0.75rem;
  font-size: 0.8125rem;
  font-weight: 500;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.2s;
  outline: none;
  white-space: nowrap;
  gap: 0.25rem;
}

.btn-primary {
  background: var(--primary);
  color: var(--primary-foreground);
  font-weight: 700;
}

.btn-primary:hover {
  background: var(--accent);
}

.btn-secondary {
  background: var(--secondary);
  color: var(--secondary-foreground);
}

.btn-secondary:hover {
  background: var(--muted);
}

.btn-outline {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--foreground);
}

.btn-outline:hover {
  background: var(--muted);
  border-color: var(--muted);
}

.btn-icon {
  width: 1.75rem;
  height: 1.75rem;
  padding: 0;
  font-size: 1rem;
}

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

/* Theme Toggle */
.theme-toggle {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 60;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 9999px;
  padding: 0.25rem;
  display: flex;
  gap: 0.125rem;
  box-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1);
  transition: transform 0.3s ease, opacity 0.3s ease;
}

/* Adjust theme toggle position on mobile */
@media (max-width: 968px) {
  .theme-toggle {
    z-index: 40; /* Below sticky preview */
    top: auto;
    bottom: 1rem; /* Move to bottom on mobile */
    right: 1rem;
  }
  
  /* Hide theme toggle when scrolled */
  .theme-toggle.hidden-on-scroll {
    transform: translateY(4rem);
    opacity: 0;
    pointer-events: none;
  }
}

.theme-btn {
  width: 2rem;
  height: 2rem;
  border-radius: 9999px;
  border: none;
  background: transparent;
  color: var(--muted-foreground);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.theme-btn:hover {
  color: var(--foreground);
}

.theme-btn.active {
  background: var(--primary);
  color: var(--primary-foreground);
}

/* Timer Controls */
.timer-section {
  background: var(--muted);
  padding: 0.75rem;
  border-radius: var(--radius);
  transition: opacity 0.3s ease, max-height 0.3s ease, padding 0.3s ease;
  overflow: hidden;
}

/* Hide timer section when scrolling on mobile */
@media (max-width: 968px) {
  .preview-card.scrolled .timer-section {
    opacity: 0;
    max-height: 0;
    padding: 0;
    margin: 0;
    pointer-events: none;
  }
}

.timer-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--foreground);
  margin-bottom: 0.5rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.timer-controls {
  display: grid;
  grid-template-columns: 1fr auto auto auto;
  gap: 0.5rem;
  align-items: center;
}

.timer-input {
  width: 100%;
  max-width: 5rem;
}

/* Score Controls */
.score-control {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.score-input {
  width: 3.5rem;
  text-align: center;
}

/* Sections */
.section {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  background: var(--section-bg);
  padding: 0.75rem;
  border-radius: var(--radius);
  margin-bottom: 0.75rem;
}

.section:last-child {
  margin-bottom: 0;
}

.section-title {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--foreground);
  padding-bottom: 0.25rem;
  margin-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
}

/* Tabs */
.tabs {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.tab-list {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  background: var(--tab-bg);
  padding: 0.125rem;
  border-radius: var(--radius);
  gap: 0.125rem;
}

.tab-trigger {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.375rem 0.5rem;
  font-size: 0.75rem;
  font-weight: 600;
  border: none;
  border-radius: calc(var(--radius) - 2px);
  background: transparent;
  color: var(--muted-foreground);
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}

.tab-trigger:hover {
  color: var(--foreground);
}

.tab-trigger.active {
  background: var(--background);
  color: var(--foreground);
  box-shadow: 0 1px 2px 0 rgb(0 0 0 / 0.05);
}

/* Divider - Hidden since sections have backgrounds now */
.divider {
  display: none;
}

/* Stat Input Group */
.stat-inputs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

/* Override Inputs */
.override-inputs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
  padding: 0.5rem;
  background: var(--muted);
  border-radius: var(--radius);
  margin-top: 0.5rem;
}

/* Details/Summary styling */
details summary {
  cursor: pointer;
  font-size: 0.75rem;
  color: var(--muted-foreground);
  user-select: none;
  padding: 0.25rem 0;
}

details summary:hover {
  color: var(--foreground);
}

details[open] summary {
  color: var(--foreground);
}

/* Header */
.header {
  margin-bottom: 1rem;
  text-align: center;
}

.header h1 {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.025em;
  color: #2B322A;
}

.header p {
  color: var(--muted-foreground);
  font-size: 0.75rem;
  margin-top: 0.125rem;
}

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

/* Focus-visible improvements */
.btn:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 2px solid var(--ring);
  outline-offset: 2px;
}

/* Loading state */
@keyframes pulse {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.5;
  }
}

.loading {
  animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

/* Hover card effect */
.card:hover {
  box-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1);
}

/* Print styles */
@media print {
  .timer-controls,
  .btn,
  button,
  .theme-toggle {
    display: none !important;
  }
}

/* Credit Line */
.credit-line {
  text-align: center;
  font-size: 0.7rem;
  color: var(--muted-foreground);
  margin-top: 0.5rem;
}

.credit-line a {
  color: var(--foreground);
  text-decoration: none;
  font-weight: 500;
}

.credit-line a:hover {
  text-decoration: underline;
}