/* TranscriptDrop — utility UI styles.
   Goals: quiet/tool-first, WCAG 2.1 AA (contrast >= 4.5:1 for text, visible
   focus, responsive). Light + dark via prefers-color-scheme. */

:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --text: #14181f;          /* ~16:1 on surface */
  --text-muted: #4b5563;    /* ~7:1 on surface  */
  --border: #d6dbe2;
  --primary: #1d4ed8;       /* white text ~6.3:1 */
  --primary-hover: #1a43b8;
  --primary-text: #ffffff;
  --focus: #1d4ed8;
  --code-bg: #eef1f5;
  --code-text: #1f2733;
  --danger-bg: #fef3f2;
  --danger-border: #f1b4ae;
  --danger-text: #b42318;   /* ~6:1 on danger bg */
  --radius: 10px;
  --radius-sm: 7px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.1);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1216;
    --surface: #171b21;
    --text: #e7eaef;
    --text-muted: #a6aebd;  /* ~7:1 on surface */
    --border: #2a313c;
    --primary: #2563eb;     /* white text ~5.1:1 */
    --primary-hover: #1d4ed8;
    --primary-text: #ffffff;
    --focus: #7aa2ff;
    --code-bg: #11151b;
    --code-text: #d6dbe4;
    --danger-bg: #2a1614;
    --danger-border: #5a2a25;
    --danger-text: #ffb4ab;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial,
    sans-serif;
  font-size: 16px;
  line-height: 1.5;
}

/* Accessibility helpers ---------------------------------------------------- */

.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  background: var(--surface);
  color: var(--text);
  padding: 0.6rem 1rem;
  border: 2px solid var(--focus);
  border-radius: var(--radius-sm);
  z-index: 10;
}

.skip-link:focus {
  left: 1rem;
  top: 1rem;
}

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

/* Layout ------------------------------------------------------------------- */

.page {
  max-width: 720px;
  margin: 0 auto;
  padding: clamp(1.25rem, 4vw, 3rem) clamp(1rem, 4vw, 1.5rem) 3rem;
}

.page__header {
  margin-bottom: 1.5rem;
}

.page__title {
  margin: 0 0 0.35rem;
  font-size: clamp(1.6rem, 5vw, 2rem);
  letter-spacing: -0.02em;
}

.page__subtitle {
  margin: 0;
  color: var(--text-muted);
  max-width: 48ch;
}

.page__footer {
  margin-top: 2rem;
  color: var(--text-muted);
  font-size: 0.85rem;
}

.page__footer p {
  margin: 0;
}

/* Card --------------------------------------------------------------------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: clamp(1rem, 4vw, 1.5rem);
}

.card + .card,
.status + .card,
.alert + .card {
  margin-top: 1.25rem;
}

/* Form fields -------------------------------------------------------------- */

.mode {
  display: inline-grid;
  grid-template-columns: repeat(2, minmax(5rem, 1fr));
  gap: 0.25rem;
  margin: 0 0 1rem;
  padding: 0.2rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.mode__option {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 2.4rem;
  padding: 0.35rem 0.85rem;
  border-radius: 5px;
  color: var(--text-muted);
  font-weight: 600;
  cursor: pointer;
}

.mode__option:has(input:checked) {
  background: var(--primary);
  color: var(--primary-text);
}

.mode__option input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.field {
  margin-bottom: 1.1rem;
}

.field__label {
  display: block;
  font-weight: 600;
  margin-bottom: 0.35rem;
}

.field__input {
  width: 100%;
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.6rem 0.7rem;
}

.field__input--short {
  max-width: 12rem;
}

.field__input::placeholder {
  color: var(--text-muted);
  opacity: 1;
}

.field__help {
  margin: 0.4rem 0 0;
  color: var(--text-muted);
  font-size: 0.85rem;
}

.field__help code,
code {
  background: var(--code-bg);
  color: var(--code-text);
  padding: 0.05rem 0.3rem;
  border-radius: 4px;
  font-size: 0.85em;
}

/* Buttons ------------------------------------------------------------------ */

.btn {
  font: inherit;
  font-weight: 600;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  padding: 0.6rem 1rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: 44px; /* comfortable touch target */
}

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

.btn--primary {
  background: var(--primary);
  color: var(--primary-text);
}

.btn--primary:hover:not(:disabled) {
  background: var(--primary-hover);
}

.btn--ghost {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
}

.btn--ghost:hover:not(:disabled) {
  border-color: var(--text-muted);
}

/* Spinner (only shown while form is busy) */
.btn__spinner {
  display: none;
  width: 1rem;
  height: 1rem;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

form[aria-busy="true"] .btn__spinner {
  display: inline-block;
}

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

@media (prefers-reduced-motion: reduce) {
  .btn__spinner {
    animation: none;
  }
}

/* Status + alert ----------------------------------------------------------- */

.status {
  margin: 1.25rem 0 0;
  color: var(--text-muted);
  min-height: 1.25rem;
}

.status:empty {
  margin: 0;
  min-height: 0;
}

.alert {
  margin-top: 1.25rem;
  background: var(--danger-bg);
  border: 1px solid var(--danger-border);
  color: var(--danger-text);
  border-radius: var(--radius-sm);
  padding: 0.85rem 1rem;
}

.alert__title {
  display: block;
  margin-bottom: 0.15rem;
}

.alert__message {
  color: var(--danger-text);
}

/* Result ------------------------------------------------------------------- */

.result__heading {
  margin: 0 0 1rem;
  font-size: 1.2rem;
}

.meta {
  margin: 0 0 1.25rem;
  display: grid;
  gap: 0.5rem;
}

.meta__row {
  display: grid;
  grid-template-columns: 7.5rem 1fr;
  gap: 0.5rem 1rem;
  align-items: baseline;
}

.meta__term {
  color: var(--text-muted);
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.meta__desc {
  margin: 0;
  word-break: break-word;
  overflow-wrap: anywhere;
}

.meta__desc a {
  color: var(--primary);
}

.empty {
  margin: 0;
  color: var(--text-muted);
}

/* Markdown preview --------------------------------------------------------- */

.preview-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.preview-toolbar__title {
  margin: 0;
  font-size: 1rem;
}

.preview-toolbar__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.preview {
  margin: 0;
  background: var(--code-bg);
  color: var(--code-text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 1rem;
  max-height: 22rem;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas,
    "Liberation Mono", monospace;
  font-size: 0.85rem;
  line-height: 1.55;
  tab-size: 2;
}

/* Save-to-library form ----------------------------------------------------- */

.save-form {
  margin-top: 1.25rem;
}

.save-form__title {
  margin: 0 0 1rem;
  font-size: 1rem;
}

.save-form__actions {
  display: flex;
  gap: 0.5rem;
}

.save-form__feedback {
  margin: 0.75rem 0 0;
  color: var(--text-muted);
  font-size: 0.9rem;
  min-height: 1.25rem;
}

.save-form__feedback:empty {
  min-height: 0;
}

.save-hint {
  margin: 0.75rem 0 0;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.platform-hint {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  align-items: flex-start;
}

.platform-hint p {
  margin: 0;
  color: var(--text-muted);
}

/* Small screens ------------------------------------------------------------ */

@media (max-width: 480px) {
  .meta__row {
    grid-template-columns: 1fr;
    gap: 0.1rem;
  }

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

  .preview-toolbar__actions {
    width: 100%;
  }

  .preview-toolbar__actions .btn {
    flex: 1;
  }
}
