/* =====================================================
   DrawTimer — Chiaroscuro Design System
   ===================================================== */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500;600;700&display=swap');

:root {
  /* Fonts */
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', 'SF Mono', 'Fira Code', 'Consolas', monospace;

  /* Backgrounds */
  --bg:              #0B0B0F;
  --bg-warm:         #13141a;
  --surface:         #16171c;
  --surface-hover:   #1c1d22;
  --surface-raised:  #222328;
  --surface-raised-gradient: linear-gradient(180deg, #222328 0%, #1e1f27 100%);
  --surface-element: #2b2c32;
  --overlay:         rgba(0, 0, 0, 0.6);

  /* White overlays for subtle elevation */
  --white-5:  rgba(255, 255, 255, 0.03);
  --white-8:  rgba(255, 255, 255, 0.05);
  --white-12: rgba(255, 255, 255, 0.08);
  --white-15: rgba(255, 255, 255, 0.18);
  --white-20: rgba(255, 255, 255, 0.25);

  /* Text */
  --text:            #E6E6E6;
  --text-white:      #FFFFFF;
  --text-muted:      #9592A4;
  --text-placeholder: #6A7782;
  --text-disabled:   #46474F;

  /* Accent */
  --blue:            #3B8EFF;
  --blue-hover:      #5EA8FF;
  --blue-light:      #70bcff;
  --blue-dim:        rgba(59, 142, 255, 0.14);
  --blue-glow:       rgba(59, 142, 255, 0.28);

  /* Semantic */
  --teal:            #2CC9A0;
  --teal-dim:        rgba(44, 201, 160, 0.16);
  --rose:            #E84466;
  --rose-dim:        rgba(232, 68, 102, 0.16);
  --rose-hover:      #F05878;
  --rose-light:      #f07088;
  --peach:           #FFA86E;
  --orange:          #FF8C4A;
  --orange-dim:      rgba(255, 140, 74, 0.16);

  /* Borders */
  --border:          #222328;
  --border-strong:   #31323a;
  --border-focus:    rgba(230, 230, 230, 0.4);

  /* Radius */
  --radius-xs: 6px;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 24px;
  --radius-full: 9999px;

  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.3);
  --shadow-md:
    0 0 rgba(0,0,0,0.30),
    0 9px 20px rgba(0,0,0,0.29),
    0 37px 37px rgba(0,0,0,0.26);
  --shadow-lg:
    0 0 rgba(0,0,0,0.30),
    0 9px 20px rgba(0,0,0,0.29),
    0 37px 37px rgba(0,0,0,0.26),
    0 84px 50px rgba(0,0,0,0.15),
    0 149px 60px rgba(0,0,0,0.04),
    0 233px 65px rgba(0,0,0,0.01);

  /* Motion */
  --ease: cubic-bezier(0.25, 0.1, 0.25, 1);
  --duration-fast: 200ms;
  --duration-base: 320ms;
  --duration-slow: 450ms;

  /* Legacy aliases */
  --color-primary: var(--blue);
  --color-error: var(--rose);
  --color-success: var(--teal);
  --color-text-secondary: var(--text-muted);
  --color-text-tertiary: var(--text-placeholder);
  --color-border: var(--border);
  --color-border-strong: var(--border-strong);
  --color-surface-elevated: var(--surface-raised);
  --color-text: var(--text);
  --color-surface: var(--surface);
  --color-background: var(--bg);
  --blue-ring: rgba(59, 142, 255, 0.22);
  --blue-tint: rgba(59, 142, 255, 0.1);
  --blue-subtle: rgba(59, 142, 255, 0.16);
}


/* =====================================================
   Reset & Base
   ===================================================== */

*, *::before, *::after {
  box-sizing: border-box;
}

html {
  overflow-y: auto;
}

body {
  background:
    radial-gradient(circle, rgba(255,255,255,0.09) 1px, transparent 1px) 0 0 / 32px 32px,
    linear-gradient(180deg, #0b0b11 0%, #0c0d14 100%);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.6;
  margin: 0;
  padding: 0;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body::after {
  content: '';
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 40vh;
  background: radial-gradient(ellipse 80% 60% at 50% 100%, rgba(71,159,250,0.10) 0%, transparent 70%);
  pointer-events: none;
  z-index: 0;
}

#app {
  max-width: 720px;
  margin: 0 auto;
  padding: 0 24px;
  position: relative;
  z-index: 1;
}


/* =====================================================
   Accessibility
   ===================================================== */

.skip-link {
  position: absolute;
  left: -9999px;
  top: 8px;
  z-index: 10000;
  padding: 8px 16px;
  background: var(--surface);
  color: var(--blue);
  border: 1px solid var(--blue);
  border-radius: var(--radius-sm);
  font-family: var(--font-sans);
  font-size: 14px;
  font-weight: 500;
  text-decoration: none;
}

.skip-link:focus,
.skip-link:focus-visible {
  left: 8px;
  outline: 2px solid var(--blue);
  outline-offset: 2px;
}

:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--blue-glow);
}

input:focus-visible,
textarea:focus-visible,
select:focus-visible {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 2px var(--blue-ring);
}

.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;
}


/* =====================================================
   Scrollbar
   ===================================================== */

::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: var(--radius-sm);
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

::-webkit-scrollbar-button {
  display: none;
  width: 0;
  height: 0;
}

html {
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}


/* =====================================================
   Global Transitions
   ===================================================== */

button,
a,
input,
textarea,
select {
  transition:
    color var(--duration-base) var(--ease),
    background-color var(--duration-base) var(--ease),
    border-color var(--duration-base) var(--ease),
    box-shadow var(--duration-base) var(--ease),
    opacity var(--duration-base) var(--ease),
    filter var(--duration-base) var(--ease);
}


/* =====================================================
   Buttons — Base
   ===================================================== */

.btn-primary,
.btn-ghost,
.btn-danger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 12px;
  font-family: var(--font-sans);
  font-size: 14px;
  font-weight: 500;
  line-height: 1;
  cursor: pointer;
  white-space: nowrap;
  border-radius: var(--radius-xs);
  background: transparent;
  text-decoration: none;
  border: none;
  gap: 4px;
}

.btn-primary:disabled,
.btn-ghost:disabled,
.btn-danger:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  color: var(--text-disabled);
}

.btn-primary:focus-visible,
.btn-ghost:focus-visible,
.btn-danger:focus-visible {
  box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--blue-glow);
}

.btn-primary:active:not(:disabled),
.btn-ghost:active:not(:disabled),
.btn-danger:active:not(:disabled) {
  filter: brightness(0.9);
}

.btn-primary svg,
.btn-ghost svg,
.btn-danger svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}


/* =====================================================
   Buttons — Primary
   ===================================================== */

.btn-primary {
  color: var(--text-white);
  background: radial-gradient(ellipse at bottom, var(--blue-light) 0%, var(--blue) 80%);
  border: 1px solid var(--white-15);
}

.btn-primary:hover:not(:disabled) {
  filter: brightness(1.2);
  border-color: var(--white-20);
}


/* =====================================================
   Buttons — Ghost
   ===================================================== */

.btn-ghost {
  color: var(--text-muted);
  background: radial-gradient(ellipse at bottom, var(--white-8) 0%, transparent 80%);
  border: 1px solid var(--border-strong);
}

.btn-ghost:hover:not(:disabled) {
  color: var(--text);
  filter: brightness(1.3);
  border-color: var(--text-placeholder);
}


/* =====================================================
   Buttons — Danger
   ===================================================== */

.btn-danger {
  color: var(--text-white);
  background: radial-gradient(ellipse at bottom, var(--rose-light) 0%, var(--rose) 80%);
  border: 1px solid var(--white-15);
}

.btn-danger:hover:not(:disabled) {
  filter: brightness(1.2);
  border-color: var(--white-20);
}


/* =====================================================
   Icon Buttons
   ===================================================== */

.btn-icon {
  padding: 4px;
  min-width: 32px;
  min-height: 32px;
  border-radius: var(--radius-xs);
  background: transparent;
  color: var(--text-placeholder);
  border: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition:
    color var(--duration-fast) var(--ease),
    background-color var(--duration-fast) var(--ease);
}

.btn-icon svg {
  width: 14px;
  height: 14px;
}

.btn-icon:hover {
  filter: brightness(1.3);
  color: var(--text);
}

.btn-icon:active:not(:disabled) {
  filter: brightness(0.9);
}

.btn-icon:focus-visible {
  box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--blue-glow);
}

.btn-icon-danger:hover {
  color: var(--rose);
}


/* =====================================================
   Navigation
   ===================================================== */

.nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  margin-bottom: 16px;
  margin-top: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}

.nav-brand-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.nav-brand {
  font-family: var(--font-sans);
  font-size: 22px;
  font-weight: 700;
  color: var(--text-white);
  text-decoration: none;
  letter-spacing: -0.04em;
}

.nav-brand:hover {
  color: var(--blue);
}

.nav-brand:focus-visible {
  box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--blue-glow);
  border-radius: var(--radius-sm);
}

.nav-links {
  display: flex;
  align-items: center;
  gap: 4px;
}

.nav-link {
  color: var(--text-muted);
  text-decoration: none;
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 500;
  padding: 8px 12px;
  border: none;
  background: none;
  cursor: pointer;
  border-radius: var(--radius-xs);
  transition:
    color var(--duration-fast) var(--ease),
    background-color var(--duration-fast) var(--ease);
}

.nav-link:hover {
  color: var(--text);
  filter: brightness(1.3);
}

.nav-link:active {
  opacity: 0.8;
}

.nav-link:focus-visible {
  box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--blue-glow);
}

.nav-link.active {
  color: var(--text);
  background: radial-gradient(ellipse at bottom, var(--white-8) 0%, var(--white-5) 80%);
}

.version-pill {
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 3px 10px;
  border-radius: var(--radius-full);
  border: 1px solid var(--border);
  background: radial-gradient(ellipse at bottom, var(--white-5) 0%, transparent 80%);
  color: var(--text-placeholder);
}


/* =====================================================
   Modal
   ===================================================== */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: var(--overlay);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 16px;
  overflow-y: auto;
  overscroll-behavior: contain;
  animation: fadeIn var(--duration-base) var(--ease);
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal-card {
  display: flex;
  flex-direction: column;
  background: var(--surface-raised-gradient);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  padding: 20px 0 0;
  width: 100%;
  max-width: 420px;
  overflow: hidden;
  box-shadow: var(--shadow-lg);
  animation: modal-enter var(--duration-base) var(--ease);
}

@keyframes modal-enter {
  from { opacity: 0; transform: translateY(8px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 0 24px 20px;
  border-bottom: 1px solid var(--border-strong);
  flex-shrink: 0;
}

.modal-header .modal-title {
  margin: 0;
}

.modal-title {
  margin: 0 0 16px;
  font-family: var(--font-sans);
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.02em;
}

.modal-close {
  margin: -4px -4px 0 0;
}

.modal-close:focus-visible {
  box-shadow: 0 0 0 2px var(--surface-raised), 0 0 0 4px var(--blue-glow);
}

.modal-body {
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.6;
  padding: 16px 24px 20px;
}

.modal-body p {
  margin: 0;
}

.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  flex-wrap: wrap;
  padding: 0 24px 20px;
}


/* =====================================================
   View Transitions
   ===================================================== */

@keyframes panel-enter {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

#app > *:not(:first-child) {
  animation: panel-enter var(--duration-base) var(--ease) both;
}

#app > *:nth-child(2) { animation-delay: 0ms; }
#app > *:nth-child(3) { animation-delay: 60ms; }
#app > *:nth-child(4) { animation-delay: 120ms; }


/* =====================================================
   Empty States
   ===================================================== */

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 64px 24px;
  color: var(--text-muted);
  font-family: var(--font-sans);
  font-size: 14px;
  gap: 16px;
}

.empty-state-icon {
  font-size: 48px;
  line-height: 1;
  opacity: 0.5;
}

.empty-state-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  margin: 0;
}

.empty-state-desc {
  color: var(--text-muted);
  max-width: 40ch;
  margin: 0;
}


/* =====================================================
   Upload Zone
   ===================================================== */

.upload-zone {
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius-md);
  padding: 32px 24px;
  text-align: center;
  cursor: pointer;
  transition:
    border-color var(--duration-fast) var(--ease),
    background-color var(--duration-fast) var(--ease);
  margin-bottom: 24px;
}

.upload-zone:hover {
  border-color: var(--blue);
  background: var(--blue-tint);
}

.upload-zone.dragover {
  border-color: var(--blue);
  background: var(--blue-dim);
  border-style: solid;
}

.upload-zone-icon {
  font-size: 32px;
  margin-bottom: 8px;
  opacity: 0.6;
}

.upload-zone-text {
  color: var(--text-muted);
  font-size: 14px;
  margin: 0 0 4px;
}

.upload-zone-hint {
  color: var(--text-placeholder);
  font-size: 12px;
  margin: 0;
}

.upload-zone input[type="file"] {
  display: none;
}

.upload-error {
  color: var(--rose);
  font-size: 13px;
  text-align: center;
  margin-top: 8px;
  min-height: 1.25em;
}


/* =====================================================
   Image Grid
   ===================================================== */

.image-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
}

.image-card {
  position: relative;
  aspect-ratio: 3 / 4;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--border);
  transition:
    border-color var(--duration-fast) var(--ease),
    box-shadow var(--duration-fast) var(--ease);
}

.image-card:hover {
  border-color: var(--border-strong);
}

.image-card img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.image-card-delete {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 28px;
  height: 28px;
  min-width: 28px;
  min-height: 28px;
  border-radius: var(--radius-xs);
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text-muted);
  opacity: 0;
  transition:
    opacity var(--duration-fast) var(--ease),
    color var(--duration-fast) var(--ease);
}

.image-card:hover .image-card-delete {
  opacity: 1;
}

.image-card-delete:hover {
  color: var(--rose);
  border-color: var(--rose);
}

.image-card-name {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 20px 8px 6px;
  background: linear-gradient(transparent, rgba(0,0,0,0.7));
  color: var(--text);
  font-size: 11px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: none;
}

.image-count {
  color: var(--text-placeholder);
  font-family: var(--font-mono);
  font-size: 12px;
  margin-bottom: 12px;
}


/* =====================================================
   Duration Picker
   ===================================================== */

.draw-setup {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
  padding: 32px 0;
}

.draw-setup-title {
  font-family: var(--font-sans);
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
  margin: 0;
  letter-spacing: -0.04em;
}

.duration-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}

.duration-pill {
  padding: 8px 16px;
  border-radius: var(--radius-full);
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  background: radial-gradient(ellipse at bottom, var(--white-8) 0%, var(--surface-element) 80%);
  border: 1px solid var(--border-strong);
  cursor: pointer;
  transition:
    color var(--duration-fast) var(--ease),
    border-color var(--duration-fast) var(--ease),
    background var(--duration-fast) var(--ease);
}

.duration-pill:hover {
  color: var(--text);
  border-color: var(--text-placeholder);
  filter: brightness(1.2);
}

.duration-pill:focus-visible {
  box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--blue-glow);
}

.duration-pill.selected {
  color: var(--blue);
  background: var(--blue-dim);
  border-color: var(--blue);
}

.custom-duration {
  display: flex;
  align-items: center;
  gap: 8px;
}

.custom-duration input {
  width: 72px;
  padding: 8px 12px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 13px;
  text-align: center;
  outline: none;
}

.custom-duration input:focus-visible {
  border-color: var(--blue);
  box-shadow: 0 0 0 2px var(--blue-ring);
}

.custom-duration-label {
  color: var(--text-muted);
  font-size: 13px;
}

.draw-start-btn {
  padding: 14px 40px;
  font-size: 16px;
  font-weight: 600;
}

.draw-no-images {
  color: var(--text-placeholder);
  font-size: 14px;
  text-align: center;
}


/* =====================================================
   Drawing Session (Immersive Fullscreen)
   ===================================================== */

.drawing-session {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: var(--bg);
  display: flex;
  flex-direction: column;
}

.drawing-image-container {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  overflow: hidden;
}

.drawing-image {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: var(--radius-sm);
}

.drawing-progress {
  height: 3px;
  background: var(--border);
  flex-shrink: 0;
}

.drawing-progress-bar {
  height: 100%;
  background: var(--blue);
  transition: width 100ms linear;
}

.drawing-progress-bar.warning {
  background: var(--orange);
}

.drawing-bottom-bar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 24px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.drawing-counter {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--text-muted);
  min-width: 48px;
}

.drawing-timer {
  font-family: var(--font-mono);
  font-size: 48px;
  font-weight: 700;
  color: var(--text-white);
  letter-spacing: -0.02em;
  line-height: 1;
  flex: 1;
  text-align: center;
}

.drawing-timer.warning {
  color: var(--orange);
}

.drawing-controls {
  display: flex;
  gap: 8px;
}

.drawing-flash {
  position: fixed;
  inset: 0;
  z-index: 101;
  background: var(--text-white);
  opacity: 0;
  pointer-events: none;
  animation: flash 200ms ease-out;
}

@keyframes flash {
  0% { opacity: 0.3; }
  100% { opacity: 0; }
}


/* =====================================================
   Section Headers
   ===================================================== */

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--text-muted);
  font-family: var(--font-sans);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 12px 0 6px;
  margin-bottom: 0;
}


/* =====================================================
   Responsive — Tablet
   ===================================================== */

@media (max-width: 767px) {
  .drawing-timer {
    font-size: 32px;
  }

  .drawing-bottom-bar {
    padding: 12px 16px;
  }

  .image-grid {
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 8px;
  }
}


/* =====================================================
   Responsive — Mobile
   ===================================================== */

@media (max-width: 480px) {
  #app {
    padding: 0 16px;
  }

  .nav {
    gap: 8px;
  }

  .nav-link {
    font-size: 12px;
  }

  .drawing-timer {
    font-size: 24px;
  }

  .drawing-bottom-bar {
    padding: 10px 12px;
    gap: 12px;
  }

  .drawing-controls .btn-ghost,
  .drawing-controls .btn-danger {
    padding: 8px 10px;
    font-size: 13px;
  }

  .upload-zone {
    padding: 24px 16px;
  }

  .image-grid {
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  }

  .modal-card {
    margin: 16px;
    max-width: none;
  }

  .draw-setup-title {
    font-size: 18px;
  }
}


/* =====================================================
   Reduced Motion
   ===================================================== */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
