/* Timeline Runner - Mobile-First Base Styles */
/* Requirements: 8.1, 8.2, 8.3, 8.4, 8.7 */

/* ============================================
   Reset & Base
   ============================================ */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  /* System font stack for performance */
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen,
    Ubuntu, Cantarell, 'Helvetica Neue', sans-serif;
  /* Req 8.7: Minimum 16px font size for body text */
  font-size: 16px;
  line-height: 1.5;
  color: #1a1a1a;
  background: linear-gradient(180deg, #fff0f3 0%, #fff5f7 100%);
  /* Prevent horizontal scroll (Req 8.3) */
  overflow-x: hidden;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

/* ============================================
   App Shell - Single Column Layout (Req 8.1)
   ============================================ */
#app {
  display: flex;
  flex-direction: column;
  height: 100%;
  /* Constrain to 480px max, centered (Req 8.1) */
  max-width: 480px;
  min-width: 320px;
  margin: 0 auto;
  background: #ffffff;
  position: relative;
  box-shadow: 0 0 40px rgba(0, 0, 0, 0.06);
}

/* ============================================
   Header
   ============================================ */
#app-header {
  padding: 12px 16px;
  background: #ffffff;
  border-bottom: 1px solid #e0e0e0;
  flex-shrink: 0;
  display: flex;
  align-items: center;
}

#app-header h1 {
  font-size: 20px;
  font-weight: 600;
  line-height: 1.3;
}

/* ============================================
   Main Content Area
   ============================================ */
#app-content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 16px;
  /* Padding at bottom to account for fixed nav + playback controls (Req 8.4) */
  padding-bottom: 130px;
  -webkit-overflow-scrolling: touch;
}

/* ============================================
   Fixed Bottom Navigation Bar (Req 8.4)
   ============================================ */
#bottom-nav {
  display: flex;
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 480px;
  /* Req 8.2, 8.4: min-height 44px for tap targets */
  min-height: 56px;
  border-top: 1px solid #e0e0e0;
  background: #ffffff;
  z-index: 100;
  flex-shrink: 0;
}

.nav-tab {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  /* Req 8.2: 44x44px minimum tap target */
  min-height: 44px;
  min-width: 44px;
  padding: 8px 12px;
  text-decoration: none;
  color: #666666;
  font-size: 14px;
  font-weight: 500;
  border: none;
  background: transparent;
  cursor: pointer;
  transition: color 0.2s ease, background-color 0.2s ease;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.nav-tab:hover {
  background-color: #f0f0f0;
}

.nav-tab:active {
  background-color: #e8e8e8;
}

/* Active tab state */
.nav-tab.active {
  color: #e91e63;
  font-weight: 600;
  position: relative;
}

.nav-tab.active::after {
  content: '';
  position: absolute;
  top: 0;
  left: 20%;
  right: 20%;
  height: 3px;
  background: #e91e63;
  border-radius: 0 0 3px 3px;
}

/* ============================================
   Buttons - 44x44px minimum tap target (Req 8.2)
   ============================================ */
button,
[role="button"],
.btn {
  /* Req 8.2: minimum 44x44px touch target */
  min-height: 44px;
  min-width: 44px;
  padding: 10px 16px;
  font-size: 16px;
  font-family: inherit;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  user-select: none;
  transition: background-color 0.2s ease, opacity 0.2s ease;
}

.btn-primary {
  background: #e91e63;
  color: #ffffff;
  font-weight: 600;
}

.btn-primary:hover {
  background: #d81b60;
}

.btn-primary:active {
  background: #c2185b;
}

.btn-primary:disabled {
  background: #b0b0b0;
  cursor: not-allowed;
  opacity: 0.7;
}

.btn-secondary {
  background: #f0f0f0;
  color: #333333;
  font-weight: 500;
}

.btn-secondary:hover {
  background: #e0e0e0;
}

.btn-secondary:active {
  background: #d0d0d0;
}

.btn-danger {
  background: #ff3b30;
  color: #ffffff;
  font-weight: 600;
}

.btn-danger:hover {
  background: #e0332b;
}

.btn-danger:active {
  background: #c62d27;
}

.btn-full-width {
  width: 100%;
}

/* Icon-only buttons (delete, settings, etc.) */
.btn-icon {
  padding: 10px;
  background: transparent;
  border-radius: 50%;
}

.btn-icon:hover {
  background: #f0f0f0;
}

.btn-icon:active {
  background: #e0e0e0;
}

/* ============================================
   Links - 44x44px minimum tap target (Req 8.2)
   ============================================ */
a {
  min-height: 44px;
  min-width: 44px;
  display: inline-flex;
  align-items: center;
  color: #e91e63;
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

a:hover {
  text-decoration: underline;
}

/* ============================================
   Form Inputs (Req 8.2, 8.7)
   ============================================ */
input,
textarea,
select {
  /* Req 8.7: minimum 16px to prevent iOS zoom */
  font-size: 16px;
  font-family: inherit;
  /* Req 8.2: minimum 44px height for touch target */
  min-height: 44px;
  padding: 10px 12px;
  width: 100%;
  border: 1px solid #d0d0d0;
  border-radius: 8px;
  background: #ffffff;
  color: #1a1a1a;
  line-height: 1.5;
  -webkit-appearance: none;
  appearance: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

input:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: #e91e63;
  box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.15);
}

input::placeholder,
textarea::placeholder {
  color: #999999;
}

textarea {
  min-height: 88px;
  resize: vertical;
}

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

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

/* ============================================
   Typography
   ============================================ */
h1 { font-size: 20px; font-weight: 600; line-height: 1.3; }
h2 { font-size: 18px; font-weight: 600; line-height: 1.3; }
h3 { font-size: 16px; font-weight: 600; line-height: 1.4; }

p {
  /* Req 8.7: 16px minimum */
  font-size: 16px;
  line-height: 1.5;
  margin-bottom: 8px;
}

small {
  font-size: 14px;
  color: #666666;
}

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

.text-center { text-align: center; }
.text-muted { color: #666666; }
.text-error { color: #ff3b30; }
.text-success { color: #34c759; }

.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mb-8 { margin-bottom: 8px; }
.mb-16 { margin-bottom: 16px; }

/* ============================================
   Cards / List Items
   ============================================ */
.card {
  background: #ffffff;
  border: none;
  border-radius: 14px;
  padding: 16px;
  margin-bottom: 14px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06), 0 1px 3px rgba(0, 0, 0, 0.04);
  transition: box-shadow 0.2s ease, transform 0.15s ease;
}

.card:active {
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.10);
  transform: scale(0.98);
}

/* Block cards get a subtle left border accent */
.block-card {
  border-left: 4px solid #fce4ec;
  background: linear-gradient(135deg, #ffffff 0%, #fff8fa 100%);
}

.block-card:nth-child(2n) {
  border-left-color: #fce4ec;
  background: linear-gradient(135deg, #ffffff 0%, #fff0f3 100%);
}

.block-card:nth-child(3n) {
  border-left-color: #fbe9e7;
  background: linear-gradient(135deg, #ffffff 0%, #fff3f0 100%);
}

.block-card:nth-child(4n) {
  border-left-color: #fce4ec;
  background: linear-gradient(135deg, #ffffff 0%, #fff8fa 100%);
}

/* ============================================
   Empty State
   ============================================ */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 48px 24px;
  text-align: center;
}

.empty-state p {
  color: #666666;
  margin-bottom: 16px;
}

/* ============================================
   Loading / Feedback
   ============================================ */
.loading-spinner {
  width: 24px;
  height: 24px;
  border: 3px solid #e0e0e0;
  border-top-color: #e91e63;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.save-indicator {
  font-size: 14px;
  color: #34c759;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.save-indicator.visible {
  opacity: 1;
}

/* ============================================
   Error Messages
   ============================================ */
.error-message {
  background: #fff2f2;
  border: 1px solid #ffcccc;
  border-radius: 8px;
  padding: 12px;
  color: #cc0000;
  font-size: 14px;
  margin-top: 8px;
}

.inline-warning {
  color: #ff9500;
  font-size: 14px;
  margin-top: 4px;
}

/* ============================================
   Dialog / Modal
   ============================================ */
.dialog-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 200;
}

.dialog {
  background: #ffffff;
  border-radius: 16px;
  padding: 24px;
  width: 100%;
  max-width: 320px;
  text-align: center;
}

.dialog h2 {
  margin-bottom: 12px;
}

.dialog p {
  color: #666666;
  margin-bottom: 20px;
}

.dialog-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* ============================================
   Block Image Area (Req 4.1, 4.2, 4.4, 4.5)
   ============================================ */
.block-image-area {
  width: 80px;
  height: 80px;
  border-radius: 12px;
  overflow: hidden;
  background: linear-gradient(135deg, #e8ecf4 0%, #f0f0f0 100%);
  flex-shrink: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.05);
  transition: transform 0.15s ease;
}

.block-image-area:active {
  transform: scale(0.95);
}

.block-image-placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.block-image-icon {
  font-size: 28px;
  line-height: 1;
  opacity: 0.6;
}

.block-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.block-image-error {
  color: #cc0000;
  font-size: 12px;
  margin-top: 4px;
  line-height: 1.3;
}

/* ============================================
   Voice Settings Panel (Req 7.1, 7.2, 7.3, 7.4)
   ============================================ */
.voice-settings-panel {
  margin-top: 16px;
  margin-bottom: 16px;
  border: 1px solid #e0e0e0;
  border-radius: 12px;
  overflow: hidden;
  background: #fafafa;
}

.voice-settings-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  padding: 12px 16px;
  font-size: 16px;
  font-weight: 600;
  background: #fafafa;
  border: none;
  border-radius: 0;
  cursor: pointer;
  min-height: 44px;
  gap: 8px;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.voice-settings-toggle:hover {
  background: #f0f0f0;
}

.voice-settings-toggle:active {
  background: #e8e8e8;
}

.voice-settings-body {
  padding: 12px 16px 16px;
  border-top: 1px solid #e0e0e0;
  transition: max-height 0.3s ease, opacity 0.3s ease, padding 0.3s ease;
  max-height: 400px;
  opacity: 1;
  overflow: hidden;
}

.voice-settings-body.collapsed {
  max-height: 0;
  opacity: 0;
  padding-top: 0;
  padding-bottom: 0;
  border-top: none;
}

.voice-settings-row {
  margin-bottom: 16px;
}

.voice-settings-label {
  display: block;
  font-size: 14px;
  font-weight: 500;
  color: #666666;
  margin-bottom: 6px;
}

.voice-settings-gender-btns {
  display: flex;
  gap: 8px;
}

.btn-gender {
  flex: 1;
  padding: 10px 16px;
  font-size: 16px;
  font-weight: 500;
  border: 2px solid #d0d0d0;
  border-radius: 8px;
  background: #ffffff;
  color: #333333;
  cursor: pointer;
  min-height: 44px;
  text-align: center;
  transition: border-color 0.2s ease, background-color 0.2s ease, color 0.2s ease;
}

.btn-gender:hover {
  border-color: #e91e63;
}

.btn-gender.active {
  border-color: #e91e63;
  background: #e91e63;
  color: #ffffff;
  font-weight: 600;
}

.voice-settings-slider-wrapper {
  display: flex;
  align-items: center;
  gap: 12px;
}

.voice-settings-range {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 6px;
  border-radius: 3px;
  background: #d0d0d0;
  outline: none;
  min-height: 44px;
  padding: 0;
  border: none;
  cursor: pointer;
}

.voice-settings-range::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #e91e63;
  cursor: pointer;
  border: 2px solid #ffffff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.voice-settings-range::-moz-range-thumb {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #e91e63;
  cursor: pointer;
  border: 2px solid #ffffff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.voice-settings-range::-webkit-slider-runnable-track {
  height: 6px;
  border-radius: 3px;
  background: #d0d0d0;
}

.voice-settings-range::-moz-range-track {
  height: 6px;
  border-radius: 3px;
  background: #d0d0d0;
}

.voice-settings-value {
  min-width: 36px;
  text-align: center;
  font-size: 16px;
  font-weight: 600;
  color: #333333;
}

/* ============================================
   Playback Controls (Req 5.5, 6.1, 6.3, 11.1, 11.4, 11.5)
   ============================================ */
.playback-controls {
  position: fixed;
  bottom: 56px;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 480px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 16px;
  background: #ffffff;
  border-top: 1px solid #e0e0e0;
  z-index: 99;
}

.playback-controls .btn {
  font-size: 14px;
  padding: 8px 14px;
  min-height: 44px;
  border-radius: 8px;
}

.playback-controls .btn-play {
  background: #34c759;
  color: #ffffff;
  font-weight: 600;
}

.playback-controls .btn-play:hover {
  background: #2db84e;
}

.playback-controls .btn-pause {
  background: #ff9500;
  color: #ffffff;
  font-weight: 600;
}

.playback-controls .btn-pause:hover {
  background: #e68600;
}

.playback-controls .btn-resume {
  background: #34c759;
  color: #ffffff;
  font-weight: 600;
}

.playback-controls .btn-resume:hover {
  background: #2db84e;
}

.playback-controls .btn-restart {
  background: #e91e63;
  color: #ffffff;
  font-weight: 600;
}

.playback-controls .btn-restart:hover {
  background: #d81b60;
}

.playback-controls .btn-next {
  background: #5856d6;
  color: #ffffff;
  font-weight: 600;
}

.playback-controls .btn-next:hover {
  background: #4b49b8;
}

/* Active block highlight during playback (Req 5.5) */
.block-active {
  border-left: 4px solid #e91e63 !important;
  box-shadow: 0 4px 20px rgba(0, 122, 255, 0.2), 0 2px 8px rgba(0, 0, 0, 0.06);
  background: linear-gradient(135deg, #f0f7ff 0%, #ffffff 100%) !important;
  transform: scale(1.01);
}

/* Inactive (dimmed) blocks during playback */
.block-inactive {
  opacity: 0.45;
  transform: scale(0.98);
}

/* Countdown display on active block */
.countdown-display {
  display: inline-block;
  margin-top: 8px;
  padding: 6px 12px;
  font-size: 14px;
  font-weight: 600;
  color: #ffffff;
  background: linear-gradient(135deg, #e91e63 0%, #5856d6 100%);
  border-radius: 20px;
  box-shadow: 0 2px 6px rgba(0, 122, 255, 0.3);
}

/* ============================================
   Prevent Horizontal Scroll (Req 8.3)
   ============================================ */
#app,
#app-content,
#app-header,
#bottom-nav {
  max-width: 100%;
  overflow-x: hidden;
}
