/* Mobile-first polish: keep touch controls clear, contained, and comfortable. */
.preview-wrap {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
  padding: 10px;
  border: 1px solid rgba(255, 255, 255, .78);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .76), 0 12px 30px rgba(29, 77, 77, .08);
}

.preview-actions {
  position: relative;
  inset: auto;
  z-index: 5;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  width: 100%;
  max-width: 100%;
  padding: 2px;
}

.preview-actions .remove-preview {
  position: static;
  min-width: 0;
  min-height: 44px;
  padding: 9px 6px;
  border-radius: 13px;
  font-size: 12px;
  line-height: 1.25;
  white-space: nowrap;
  transition: transform .22s cubic-bezier(.2,.8,.2,1), background .22s ease, box-shadow .22s ease;
}

.preview-wrap img {
  width: 100%;
  max-width: 100%;
  border-radius: 15px;
  background: rgba(255, 255, 255, .18);
  animation: image-arrive .38s cubic-bezier(.2,.8,.2,1) both;
}

.preview-wrap:not(.hidden) .preview-actions { animation: toolbar-arrive .32s ease both; }

.course-block {
  animation: course-arrive .46s cubic-bezier(.2,.8,.2,1) both;
  animation-delay: var(--course-delay, 0ms);
  transition: filter .35s ease, opacity .35s ease, transform .25s cubic-bezier(.2,.8,.2,1), box-shadow .3s ease;
  will-change: transform, opacity;
}

.course-block.is-past {
  filter: saturate(.42) brightness(.78);
  opacity: .62;
  box-shadow: 0 2px 7px rgba(45, 76, 74, .06), inset 0 1px 0 rgba(255, 255, 255, .48);
}

.course-block.is-live {
  position: relative;
  z-index: 3;
  filter: saturate(1.08) brightness(1.04);
  animation: course-arrive .46s cubic-bezier(.2,.8,.2,1) both, live-course-glow 2.8s 1s ease-in-out infinite;
}

.course-block.is-live::after {
  position: absolute;
  inset: 2px;
  border: 1px solid rgba(255, 255, 255, .7);
  border-radius: inherit;
  content: "";
  pointer-events: none;
}

.course-block:active { transform: scale(.975); }

.glass, .settings-card, .schedule-panel, .review-card, .import-card, .task-card {
  animation: panel-arrive .48s cubic-bezier(.2,.8,.2,1) both;
}

.ambient span:nth-child(1) { animation: light-drift-a 25s ease-in-out infinite alternate; }
.ambient span:nth-child(2) { animation: light-drift-b 31s ease-in-out infinite alternate; }
.ambient span:nth-child(3) { animation: light-drift-c 22s ease-in-out infinite alternate; }

.settings-card:nth-child(2) { animation-delay: 45ms; }
.settings-card:nth-child(3) { animation-delay: 80ms; }
.settings-card:nth-child(4) { animation-delay: 115ms; }

@keyframes course-arrive {
  from { opacity: 0; transform: translateY(8px) scale(.985); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes panel-arrive {
  from { opacity: .65; transform: translateY(7px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes image-arrive {
  from { opacity: .45; transform: scale(.99); }
  to { opacity: 1; transform: scale(1); }
}

@keyframes toolbar-arrive {
  from { opacity: 0; transform: translateY(-5px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes live-course-glow {
  0%, 100% { box-shadow: 0 7px 18px rgba(24, 115, 108, .17), 0 0 0 0 rgba(36, 143, 133, .18), inset 0 1px 0 rgba(255, 255, 255, .75); }
  50% { box-shadow: 0 9px 24px rgba(24, 115, 108, .22), 0 0 0 3px rgba(36, 143, 133, .13), inset 0 1px 0 rgba(255, 255, 255, .82); }
}

@keyframes light-drift-a { to { transform: translate3d(-2vw, 2vh, 0) scale(1.06); } }
@keyframes light-drift-b { to { transform: translate3d(3vw, -2vh, 0) scale(1.04); } }
@keyframes light-drift-c { to { transform: translate3d(0, 3vh, 0) scale(.96); } }

@media (hover: hover) and (pointer: fine) {
  .course-block:hover { transform: translateY(-2px) scale(1.015); }
  .preview-actions .remove-preview:hover { transform: translateY(-2px); background: rgba(255,255,255,.92); box-shadow: 0 7px 18px rgba(29,77,77,.1); }
  .primary:hover, .secondary:hover, .icon-btn:hover, .week-switch button:hover { transform: translateY(-2px); }
}

@media (max-width: 760px) {
  html, body { width: 100%; max-width: 100%; overflow-x: hidden; }
  .app-shell {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    padding: max(8px, env(safe-area-inset-top)) 10px calc(100px + env(safe-area-inset-bottom));
  }

  .topbar { width: 100%; max-width: 100%; }
  .topbar nav { min-width: 0; }
  .topbar .nav-link { min-height: 44px; touch-action: manipulation; }
  main, .view, .import-layout, .settings-grid, .dashboard-grid { width: 100%; max-width: 100%; min-width: 0; }
  .settings-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    justify-content: stretch;
    gap: 14px;
    margin: 0;
  }

  .settings-grid > *, .settings-card, .settings-card.glass {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    margin-inline: 0;
    padding: 20px 16px;
    overflow: hidden;
  }

  .settings-card *, .settings-card .section-head, .settings-card .setting-row,
  .settings-card .field, .settings-card .button-stack { min-width: 0; max-width: 100%; }
  .settings-card h2 { font-size: 20px; overflow-wrap: anywhere; }
  .settings-card .section-head { flex-wrap: wrap; gap: 10px; }
  .settings-card input, .settings-card select, .settings-card textarea,
  .task-form input, .task-form select, .form-grid input, .form-grid select {
    box-sizing: border-box;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    min-height: 44px;
    font-size: 16px;
  }
  .settings-card .period-list { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .settings-card .period-list > * { min-width: 0; overflow-wrap: anywhere; }
  .settings-card .button-stack button, .settings-card > button { min-height: 46px; white-space: normal; overflow-wrap: anywhere; }
  .settings-card .setting-row { gap: 10px; }
  .settings-card .setting-row > div { min-width: 0; }
  .settings-card #syncCode { overflow-wrap: anywhere; }
  .inline-controls { min-width: 0; }
  .inline-controls input { width: 0; }

  .preview-wrap { width: 100%; max-width: 100%; padding: 8px; gap: 8px; border-radius: 19px; }
  .preview-actions { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
  .preview-actions .remove-preview { min-height: 44px; padding: 8px 3px; border-radius: 12px; font-size: clamp(10px, 3vw, 12px); }
  .preview-wrap img { height: min(58svh, 500px); min-height: 240px; object-fit: contain; }
  .crop-hint { bottom: 10px; left: 10px; right: 10px; font-size: 12px; }

  .schedule-panel { width: 100%; max-width: 100%; min-width: 0; padding: 16px 10px; }
  .schedule-panel .section-head { align-items: flex-start; gap: 8px; }
  .schedule-actions { min-width: 0; max-width: 67%; gap: 6px; }
  .schedule-actions button, .week-switch button { min-height: 40px; touch-action: manipulation; }
  .week-strip { gap: 0; }
  .week-day { min-height: 42px; }
  .schedule-grid { touch-action: pan-y; }
  .course-block { touch-action: manipulation; }
  .course-detail {
    width: calc(100vw - 20px);
    max-width: 430px;
    max-height: calc(100dvh - env(safe-area-inset-top) - env(safe-area-inset-bottom) - 24px);
    padding: 22px 16px;
    border-radius: 22px;
  }
  .form-grid { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 9px; }
  .form-grid label { min-width: 0; overflow-wrap: anywhere; }
  .dialog-actions { position: sticky; bottom: -16px; padding: 10px 0 2px; background: rgba(232,247,244,.94); }
  button, .nav-link, select { touch-action: manipulation; }
}

@media (max-width: 380px) {
  .app-shell { padding-inline: 7px; }
  .settings-card, .settings-card.glass { padding-inline: 13px; }
  .preview-actions { gap: 4px; }
  .preview-actions .remove-preview { padding-inline: 2px; font-size: 10px; }
  .period-list { gap: 6px; }
  .schedule-panel { padding-inline: 7px; }
  .hero-row h1 { font-size: clamp(30px, 9vw, 36px); }
}

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