/* Professional interaction layer.
 * Keeps module layouts intact while making feedback decisive and inexpensive.
 */

:root {
  --ui-motion-instant: 90ms;
  --ui-motion-fast: 130ms;
  --ui-motion-page: 170ms;
  --ui-ease-out: cubic-bezier(0.2, 0.75, 0.25, 1);
  --ui-focus-ring: color-mix(in srgb, var(--accent) 36%, transparent);
  --ui-shadow-rest: 0 1px 2px rgba(18, 24, 21, 0.04), 0 8px 24px rgba(18, 24, 21, 0.055);
  --ui-shadow-hover: 0 2px 4px rgba(18, 24, 21, 0.045), 0 12px 28px rgba(18, 24, 21, 0.075);
}

html {
  scroll-behavior: auto;
  text-rendering: optimizeLegibility;
}

body::before {
  opacity: 0.45;
}

/* Expensive backdrop blur is unnecessary on a fixed opaque navigation rail. */
.sidebar,
.sidebar-toggle {
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
}

.sidebar {
  box-shadow: 8px 0 28px rgba(18, 24, 21, 0.055);
}

.sidebar-brand {
  padding-bottom: 17px;
}

.sidebar-logo-icon {
  border-radius: 10px;
}

.sidebar-link {
  min-height: 46px;
  transition:
    color var(--ui-motion-fast) ease,
    background-color var(--ui-motion-fast) ease,
    border-color var(--ui-motion-fast) ease;
}

.sidebar-link-icon {
  transition:
    color var(--ui-motion-fast) ease,
    background-color var(--ui-motion-fast) ease;
}

.sidebar-link.active::before {
  top: 9px;
  bottom: 9px;
  width: 2px;
}

.theme-toggle,
.account-badge,
.sidebar-toggle {
  transition:
    color var(--ui-motion-fast) ease,
    background-color var(--ui-motion-fast) ease,
    border-color var(--ui-motion-fast) ease,
    transform var(--ui-motion-instant) ease;
}

/* One consistent, keyboard-visible focus treatment across all modules. */
:where(a, button, input, textarea, select, summary, [tabindex]):focus-visible {
  outline: 3px solid var(--ui-focus-ring) !important;
  outline-offset: 2px !important;
}

:where(input, textarea, select):focus {
  box-shadow: 0 0 0 3px var(--ui-focus-ring);
}

/* Controls respond quickly and never use an open-ended transition: all. */
:where(
  .btn,
  .learning-header-link,
  .learning-primary-action,
  .learning-secondary-action,
  .learning-tool-grid button,
  .study-studio-button,
  .study-studio-tabs button,
  .tenses-tab,
  .toeic-option,
  .quiz-option
) {
  transition:
    color var(--ui-motion-fast) ease,
    background-color var(--ui-motion-fast) ease,
    border-color var(--ui-motion-fast) ease,
    box-shadow var(--ui-motion-fast) ease,
    transform var(--ui-motion-instant) ease;
}

:where(
    .btn,
    .learning-header-link,
    .learning-primary-action,
    .learning-secondary-action,
    .learning-tool-grid button,
    .study-studio-button,
    .study-studio-tabs button
  ):active:not(:disabled) {
  transform: translateY(0) scale(0.985) !important;
}

:where(.btn, .study-studio-button, .study-studio-tabs button):disabled {
  cursor: not-allowed;
  transform: none !important;
  box-shadow: none !important;
}

/* Raised surfaces share quiet depth without decorative glow. */
:where(
  .card,
  .learning-section,
  .learning-stat,
  .tenses-card,
  .toeic-card,
  .resource-card,
  .ielts-resource-card,
  .study-studio-panel,
  .study-studio-next,
  .coach-kpi
) {
  box-shadow: var(--ui-shadow-rest);
  transition:
    border-color var(--ui-motion-fast) ease,
    background-color var(--ui-motion-fast) ease,
    box-shadow var(--ui-motion-fast) ease,
    transform var(--ui-motion-instant) ease;
}

.learning-focus {
  box-shadow: 0 14px 34px rgba(15, 41, 66, 0.15);
}

.progress-bar,
.toeic-progress-fill,
.tenses-progress-fill {
  transition: width var(--ui-motion-page) var(--ui-ease-out) !important;
}

/* Short page entrance: enough context to perceive navigation, never floaty. */
@keyframes ui-page-enter {
  from {
    opacity: 0.65;
    transform: translateY(3px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes ui-dialog-enter {
  from {
    opacity: 0.72;
    transform: translateY(5px) scale(0.995);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@media (prefers-reduced-motion: no-preference) {
  .page.active {
    animation: ui-page-enter var(--ui-motion-page) var(--ui-ease-out) both;
  }

  .account-modal:not([hidden]) .account-dialog,
  .modal-overlay:not([hidden]) .modal,
  dialog[open] {
    animation: ui-dialog-enter var(--ui-motion-page) var(--ui-ease-out) both;
  }
}

/* Hover elevation only exists when the device really has hover. */
@media (hover: hover) and (pointer: fine) {
  :where(
    .card,
    .learning-section,
    .learning-stat,
    .tenses-card,
    .resource-card,
    .ielts-resource-card,
    .study-studio-panel,
    .coach-kpi
  ):hover {
    border-color: color-mix(in srgb, var(--accent) 27%, var(--border));
    box-shadow: var(--ui-shadow-hover);
  }

  :where(
      .btn,
      .learning-header-link,
      .learning-primary-action,
      .learning-secondary-action,
      .learning-tool-grid button,
      .study-studio-button
    ):hover:not(:disabled) {
    transform: translateY(-1px);
  }
}

/* Loading feedback does not change element dimensions or flash continuously. */
[aria-busy='true'] {
  cursor: progress;
}

[aria-busy='true'] > * {
  opacity: 0.72;
}

html[data-theme='light'] .sidebar {
  box-shadow: 8px 0 28px rgba(31, 41, 37, 0.055) !important;
}

html[data-theme='light']
  :where(
    .card,
    .learning-section,
    .learning-stat,
    .tenses-card,
    .resource-card,
    .ielts-resource-card,
    .study-studio-panel,
    .study-studio-next,
    .coach-kpi
  ) {
  box-shadow: var(--ui-shadow-rest);
}

@media (max-width: 760px) {
  .sidebar {
    box-shadow: 12px 0 30px rgba(18, 24, 21, 0.12);
  }

  .sidebar-toggle {
    min-width: 44px;
    min-height: 44px;
  }

  :where(button, .btn, [role='button']) {
    min-height: 44px;
  }
}

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