/* app/assets/stylesheets/application.css */

/* Layers for cascade control */
@layer reset, base, components, utilities;

/* Design tokens */
:root {
  /* Colors: neutral, warm grays */
  --color-bg: #faf9f7;
  --color-bg-subtle: #f5f4f2;
  --color-surface: #ffffff;
  --color-border: #e5e4e2;
  --color-border-strong: #d4d3d1;

  --color-text: #1a1918;
  --color-text-secondary: #6b6966;
  --color-text-tertiary: #9a9895;

  --color-accent: #da7756;
  --color-accent-hover: #c5684a;

  /* Typography */
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, monospace;

  --text-xs: 0.75rem;
  --text-sm: 0.875rem;
  --text-base: 1rem;
  --text-lg: 1.125rem;
  --text-xl: 1.25rem;
  --text-2xl: 1.5rem;

  /* Spacing */
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-6: 1.5rem;
  --space-8: 2rem;
  --space-12: 3rem;

  /* Borders */
  --radius-sm: 0.25rem;
  --radius-md: 0.5rem;
  --radius-lg: 0.75rem;
  --radius-full: 9999px;

  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.07);

  /* Transitions */
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
}

/* Dark mode */
@media (prefers-color-scheme: dark) {
  :root {
    --color-bg: #161514;
    --color-bg-subtle: #1e1d1c;
    --color-surface: #242322;
    --color-border: #3a3836;
    --color-border-strong: #4a4846;

    --color-text: #f5f4f2;
    --color-text-secondary: #a8a5a2;
    --color-text-tertiary: #6b6966;

    --color-accent: #e8916f;
    --color-accent-hover: #f0a080;
  }
}

/* Reset */
@layer reset {
  *, *::before, *::after {
    box-sizing: border-box;
  }

  * {
    margin: 0;
  }

  html {
    -webkit-font-smoothing: antialiased;
  }

  body {
    line-height: 1.5;
  }

  img, picture, video, canvas, svg {
    display: block;
    max-width: 100%;
  }

  input, button, textarea, select {
    font: inherit;
  }

  p, h1, h2, h3, h4, h5, h6 {
    overflow-wrap: break-word;
  }
}

/* Base */
@layer base {
  body {
    font-family: var(--font-sans);
    font-size: var(--text-base);
    color: var(--color-text);
    background-color: var(--color-bg);
    min-height: 100dvh;
  }

  a {
    color: var(--color-accent);
    text-decoration: none;
  }

  a:hover {
    text-decoration: underline;
  }

  h1, h2, h3 {
    font-weight: 600;
    line-height: 1.25;
  }

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

/* Components */
@layer components {
  /* Button */
  .btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-4);
    font-size: var(--text-sm);
    font-weight: 500;
    color: var(--color-text);
    background-color: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all 150ms var(--ease-out);
  }

  .btn:hover {
    background-color: var(--color-bg-subtle);
    border-color: var(--color-border-strong);
    text-decoration: none;
  }

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

  .btn--primary {
    color: white;
    background-color: var(--color-accent);
    border-color: var(--color-accent);
  }

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

  .btn--secondary {
    background-color: transparent;
  }

  /* Form inputs */
  .input {
    width: 100%;
    padding: var(--space-2) var(--space-3);
    font-size: var(--text-base);
    color: var(--color-text);
    background-color: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    transition: border-color 150ms;
  }

  .input:focus {
    outline: none;
    border-color: var(--color-accent);
  }

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

  /* Form field */
  .field {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
  }

  .field label {
    font-size: var(--text-sm);
    font-weight: 500;
    color: var(--color-text-secondary);
  }

  /* Card */
  .card {
    background-color: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: var(--space-6);
  }

  /* Page layout */
  .page {
    max-width: 40rem;
    margin: 0 auto;
    padding: var(--space-8) var(--space-4);
  }

  .page-header {
    margin-bottom: var(--space-8);
  }

  .page-header h1 {
    margin-bottom: var(--space-2);
  }

  .page-header p {
    color: var(--color-text-secondary);
  }
}

/* Wheel specific styles */
.wheel-page {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  padding: var(--space-8);
  text-align: center;
}

.wheel-header {
  margin-bottom: var(--space-8);
}

.wheel-header h1 {
  font-size: var(--text-2xl);
  font-weight: 600;
  letter-spacing: -0.02em;
}

.current-mode {
  margin-top: var(--space-2);
  color: var(--color-text-secondary);
}

.current-mode strong {
  color: var(--color-text);
}

.duration {
  font-size: var(--text-sm);
  color: var(--color-text-tertiary);
}

.wheel-container {
  position: relative;
  width: min(80vw, 400px);
  aspect-ratio: 1;
  margin-bottom: var(--space-8);
}

.wheel {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background-color: var(--color-surface);
  border: 2px solid var(--color-border);
  box-shadow: var(--shadow-md);
  position: relative;
  overflow: hidden;
}

.wheel-segment {
  position: absolute;
  width: 50%;
  height: 50%;
  left: 50%;
  top: 0;
  transform-origin: 0% 100%;
  transform: rotate(calc(var(--segment-index) * (360deg / var(--total-segments))));
  background-color: var(--mode-color, var(--color-bg-subtle));
  display: flex;
  align-items: center;
  justify-content: center;
  clip-path: polygon(0% 100%, 100% 0%, 100% 100%);
}

.wheel-segment.selected {
  filter: brightness(1.1);
  box-shadow: inset 0 0 0 3px white;
}

.segment-label {
  position: absolute;
  top: 60%;
  left: 30%;
  font-size: var(--text-xs);
  font-weight: 600;
  color: white;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
  transform: rotate(calc((var(--segment-index) + 0.5) * (360deg / var(--total-segments)) * -1 + 45deg));
  white-space: nowrap;
}

.wheel-center {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 10;
}

.spin-button {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background-color: var(--color-surface);
  border: 2px solid var(--color-border);
  font-size: var(--text-base);
  font-weight: 600;
  color: var(--color-text);
  cursor: pointer;
  box-shadow: var(--shadow-md);
  transition: all 150ms var(--ease-out);
}

.spin-button:hover:not(:disabled) {
  background-color: var(--color-accent);
  border-color: var(--color-accent);
  color: white;
  transform: scale(1.05);
}

.spin-button:disabled {
  opacity: 0.7;
  cursor: not-allowed;
}

.wheel-pointer {
  position: absolute;
  top: -10px;
  left: 50%;
  transform: translateX(-50%);
  width: 0;
  height: 0;
  border-left: 12px solid transparent;
  border-right: 12px solid transparent;
  border-top: 20px solid var(--color-accent);
  z-index: 20;
}

.current-session {
  margin-bottom: var(--space-6);
}

.wheel-nav {
  display: flex;
  gap: var(--space-4);
}

.wheel-nav a {
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
}

.empty-state {
  text-align: center;
  padding: var(--space-12);
}

.empty-state p {
  color: var(--color-text-secondary);
  margin-bottom: var(--space-4);
}

/* Utilities */
@layer utilities {
  .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;
  }

  .flex { display: flex; }
  .flex-col { flex-direction: column; }
  .items-center { align-items: center; }
  .justify-between { justify-content: space-between; }
  .gap-2 { gap: var(--space-2); }
  .gap-4 { gap: var(--space-4); }
  .gap-6 { gap: var(--space-6); }

  .mt-4 { margin-top: var(--space-4); }
  .mt-6 { margin-top: var(--space-6); }
  .mb-4 { margin-bottom: var(--space-4); }

  .text-sm { font-size: var(--text-sm); }
  .text-secondary { color: var(--color-text-secondary); }
}

/* Flash messages */
.flash-container {
  position: fixed;
  top: var(--space-4);
  right: var(--space-4);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.flash {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-3) var(--space-4);
  background-color: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  min-width: 300px;
  max-width: 500px;
}

.flash--notice {
  border-left: 4px solid #10b981;
}

.flash--alert {
  border-left: 4px solid #ef4444;
}

.flash-close {
  background: none;
  border: none;
  font-size: var(--text-xl);
  color: var(--color-text-tertiary);
  cursor: pointer;
  padding: 0;
  line-height: 1;
}

.flash-close:hover {
  color: var(--color-text);
}

/* Mode color badge */
.mode-color-badge {
  width: 24px;
  height: 24px;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
}

/* Alert styles */
.alert {
  padding: var(--space-4);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-4);
}

.alert--error {
  background-color: #fef2f2;
  border: 1px solid #fecaca;
  color: #991b1b;
}

.alert--error h3 {
  margin-bottom: var(--space-2);
  font-size: var(--text-base);
}

.alert--error ul {
  list-style: disc;
  margin-left: var(--space-4);
}

/* Badge */
.badge {
  display: inline-flex;
  padding: var(--space-1) var(--space-2);
  font-size: var(--text-xs);
  font-weight: 500;
  border-radius: var(--radius-sm);
}

.badge--success {
  background-color: #d1fae5;
  color: #065f46;
}

.badge--secondary {
  background-color: var(--color-bg-subtle);
  color: var(--color-text-secondary);
}

/* Grid */
.grid {
  display: grid;
}
