/*
 * styles.css: Responsive visual system for the browser-local image OCR application.
 * Sections: Tokens, Base, Header, Intro, Panels, Input, Preview, Languages, Status, Result, Footer, Responsive.
 */

/* ============================================================
   Design Tokens
   Design intent: Extend the portfolio's warm editorial palette with
   clear utility states and consistent control sizing.
   ============================================================ */

:root {
  /* Canvas paper — warm application background related to the portfolio. */
  --color-paper: #f4efe4;
  /* Raised paper — primary panel and control surface. */
  --color-surface: #fffaf0;
  /* Quiet paper — recessed preview and status surface. */
  --color-surface-muted: #ebe5d9;
  /* Primary ink — high-contrast headings and body text. */
  --color-ink: #292622;
  /* Secondary ink — support copy and non-primary metadata. */
  --color-ink-muted: #625d55;
  /* Rust action — primary interactive and identity accent. */
  --color-action: #8e3f2a;
  /* Dark rust action — primary hover and active treatment. */
  --color-action-dark: #652c1d;
  /* Pale rust — primary control focus-adjacent surface. */
  --color-action-soft: #ead4c8;
  /* Sage border — structural dividers and quiet outlines. */
  --color-border: #8b9481;
  /* Pale sage — ready badge and selected language background. */
  --color-ready-soft: #dce5d4;
  /* Ready ink — success text with strong contrast. */
  --color-ready: #315b3b;
  /* Focus blue — consistent high-contrast keyboard focus ring. */
  --color-focus: #174d6d;
  /* Error red — visible recoverable failure copy. */
  --color-error: #8f261f;
  /* Error surface — quiet alert background supporting dark red text. */
  --color-error-soft: #fae2df;
  /* Drop highlight — drag target background without relying on animation. */
  --color-drop-active: #f3ded3;
  /* Transparent shadow — paper elevation over the warm canvas. */
  --color-shadow: rgba(41, 38, 34, 0.14);

  /* Compact metadata — labels and small support copy. */
  --font-size-xs: 0.78rem;
  /* Control text — compact buttons and metadata. */
  --font-size-sm: 0.9rem;
  /* Reading text — application body copy. */
  --font-size-base: 1rem;
  /* Panel title — clear local hierarchy. */
  --font-size-lg: clamp(1.35rem, 1.15rem + 0.8vw, 1.8rem);
  /* Page title — responsive application identity. */
  --font-size-xl: clamp(2.4rem, 1.8rem + 3vw, 4.8rem);

  /* Hairline space — tight icon and label relationships. */
  --space-1: 0.35rem;
  /* Compact space — inline and metadata separation. */
  --space-2: 0.65rem;
  /* Control space — button padding and compact gaps. */
  --space-3: 1rem;
  /* Component space — panel internals and grouped controls. */
  --space-4: 1.5rem;
  /* Panel space — substantial card padding and grid gaps. */
  --space-5: 2rem;
  /* Section space — major page rhythm. */
  --space-6: clamp(3rem, 7vw, 6rem);

  /* Compact radius — buttons, badges, and status surfaces. */
  --radius-sm: 0.45rem;
  /* Panel radius — cards and preview frames. */
  --radius-md: 1rem;
  /* Pill radius — status badge geometry. */
  --radius-pill: 999rem;
  /* Shared border width — visible without visual heaviness. */
  --border-width: 0.08rem;
  /* Emphasized drop border — makes the input target recognizable. */
  --drop-border-width: 0.14rem;
  /* Focus width — visible keyboard outline on all surfaces. */
  --focus-width: 0.2rem;
  /* Control target — practical minimum pointer and touch height. */
  --control-height: 2.9rem;
  /* Content width — maximum application canvas. */
  --content-width: 76rem;
  /* Reading width — comfortable paragraph measure. */
  --reading-width: 68ch;
  /* Preview height — useful image inspection area on wide screens. */
  --preview-min-height: 21rem;
  /* Compact preview height — avoids excessive blank space on phones. */
  --preview-min-height-small: 14rem;
  /* Immediate feedback timing — responsive without distracting movement. */
  --transition-fast: 160ms ease;
}

/* ============================================================
   Base and Accessibility
   Design intent: Establish readable defaults, strong focus, and a
   canvas that cannot force horizontal scrolling at narrow widths.
   ============================================================ */

* {
  box-sizing: border-box;
}

html {
  min-width: 0;
  background: var(--color-paper);
}

body {
  min-width: 0;
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
  background: var(--color-paper);
  color: var(--color-ink);
  font-family: Arial, Helvetica, sans-serif;
  font-size: var(--font-size-base);
  line-height: 1.6;
}

button,
input,
textarea {
  font: inherit;
}

button,
label[for] {
  touch-action: manipulation;
}

a {
  color: var(--color-action-dark);
  text-decoration-thickness: var(--border-width);
  text-underline-offset: var(--space-1);
}

/* Hover state: rust shift confirms pointer interaction without moving the link. */
a:hover {
  color: var(--color-action);
}

/* Keyboard focus state: strong blue outline remains visible on every application surface. */
:focus-visible {
  outline: var(--focus-width) solid var(--color-focus);
  outline-offset: var(--space-1);
}

h1,
h2,
p {
  margin-top: 0;
}

h1,
h2 {
  color: var(--color-ink);
  font-family: Georgia, "Times New Roman", serif;
  font-weight: 600;
  letter-spacing: -0.025em;
  line-height: 1.08;
  text-wrap: balance;
}

h1 {
  margin-bottom: var(--space-4);
  font-size: var(--font-size-xl);
}

h2 {
  margin-bottom: var(--space-2);
  font-size: var(--font-size-lg);
}

.page-shell {
  width: min(calc(100% - (2 * var(--space-4))), var(--content-width));
  margin-inline: auto;
}

.visually-hidden {
  position: absolute;
  width: var(--border-width);
  height: var(--border-width);
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

.skip-link {
  position: fixed;
  /* Skip-link layer sits above the sticky application header. */
  z-index: 20;
  top: var(--space-2);
  left: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  background: var(--color-ink);
  color: var(--color-surface);
  transform: translateY(-180%);
}

/* Focus state: return the skip link to the viewport for keyboard users. */
.skip-link:focus {
  color: var(--color-surface);
  transform: translateY(0);
}

/* ============================================================
   Header and Introduction
   Design intent: Use the portfolio's restrained editorial hierarchy
   before the denser utility workspace begins.
   ============================================================ */

.app-header {
  border-bottom: var(--border-width) solid var(--color-border);
  background: var(--color-paper);
}

.app-header__inner,
.app-footer__inner {
  display: flex;
  min-height: 4.5rem;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
}

.back-link {
  min-height: var(--control-height);
  display: inline-flex;
  align-items: center;
  font-weight: 700;
}

.app-header__label,
.app-footer p {
  margin-bottom: 0;
  color: var(--color-ink-muted);
  font-size: var(--font-size-sm);
}

.intro {
  padding-block: var(--space-6) var(--space-5);
}

.intro__content {
  max-width: var(--content-width);
}

.eyebrow,
.step-label {
  margin-bottom: var(--space-2);
  color: var(--color-action);
  font-size: var(--font-size-xs);
  font-weight: 700;
  letter-spacing: 0.14em;
  line-height: 1.2;
  text-transform: uppercase;
}

.intro__lede {
  max-width: 54ch;
  margin-bottom: var(--space-4);
  color: var(--color-ink-muted);
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1.2rem, 1.05rem + 0.7vw, 1.7rem);
  line-height: 1.45;
}

.privacy-note {
  max-width: var(--reading-width);
  margin-bottom: 0;
  padding: var(--space-3) var(--space-4);
  border-left: calc(3 * var(--border-width)) solid var(--color-ready);
  background: var(--color-ready-soft);
}

/* ============================================================
   Workspace and Panels
   Design intent: A two-column working surface keeps image preparation
   near recognition and gives the editable result full width.
   ============================================================ */

.workspace {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-5);
  padding-bottom: var(--space-6);
}

.panel {
  min-width: 0;
  padding: var(--space-5);
  border: var(--border-width) solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  box-shadow: 0 var(--space-2) var(--space-5) var(--color-shadow);
}

.panel--result {
  grid-column: 1 / -1;
}

.panel__heading {
  margin-bottom: var(--space-4);
}

.panel__heading p:last-child {
  max-width: var(--reading-width);
  margin-bottom: 0;
  color: var(--color-ink-muted);
}

.panel__heading--inline,
.panel__heading--result,
.result-actions {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-4);
}

.rotation-label {
  flex: 0 0 auto;
  margin-bottom: 0;
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-pill);
  background: var(--color-surface-muted);
  color: var(--color-ink-muted);
  font-size: var(--font-size-xs);
  font-weight: 700;
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
}

.button-row--centered {
  justify-content: center;
}

.button {
  display: inline-flex;
  min-height: var(--control-height);
  align-items: center;
  justify-content: center;
  padding: var(--space-2) var(--space-4);
  border: var(--border-width) solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-weight: 700;
  text-align: center;
  /* 160ms color feedback is immediate and avoids decorative movement. */
  transition: background-color var(--transition-fast), border-color var(--transition-fast), color var(--transition-fast);
}

.button--primary {
  border-color: var(--color-action);
  background: var(--color-action);
  color: var(--color-surface);
}

/* Primary hover state: darker rust confirms the available action. */
.button--primary:hover:not(:disabled),
.file-input-label:hover {
  border-color: var(--color-action-dark);
  background: var(--color-action-dark);
  color: var(--color-surface);
}

.button--secondary {
  border-color: var(--color-action);
  background: transparent;
  color: var(--color-action-dark);
}

/* Secondary hover state: pale rust supplies pointer feedback while retaining hierarchy. */
.button--secondary:hover:not(:disabled) {
  background: var(--color-action-soft);
}

.button--quiet {
  border-color: var(--color-border);
  background: transparent;
  color: var(--color-ink-muted);
}

/* Quiet hover state: muted surface confirms the lower-priority action. */
.button--quiet:hover:not(:disabled) {
  background: var(--color-surface-muted);
  color: var(--color-ink);
}

.button--large {
  width: 100%;
  min-height: calc(var(--control-height) + var(--space-2));
  margin-top: var(--space-4);
}

/* Disabled state: reduced contrast and default cursor communicate non-interactivity. */
.button:disabled,
.text-button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

/* File-input focus state: the visible label mirrors focus on the visually hidden native control. */
.file-input:focus-visible + .file-input-label {
  outline: var(--focus-width) solid var(--color-focus);
  outline-offset: var(--space-1);
}

/* Disabled file state: mirror the hidden native control's state on its visible label. */
.file-input:disabled + .file-input-label {
  cursor: not-allowed;
  opacity: 0.48;
}

/* ============================================================
   Image Input
   Design intent: A generous dashed area makes drag-and-drop obvious
   while visible buttons keep file and clipboard methods explicit.
   ============================================================ */

.dropzone {
  display: grid;
  min-height: 17rem;
  place-content: center;
  padding: var(--space-5);
  border: var(--drop-border-width) dashed var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-paper);
  text-align: center;
  /* 160ms color feedback supports drag targeting without shifting layout. */
  transition: background-color var(--transition-fast), border-color var(--transition-fast);
}

/* Drag-active state: warm highlight confirms that releasing will select the image. */
.dropzone.is-dragging {
  border-color: var(--color-action);
  background: var(--color-drop-active);
}

/* Processing state: mute the drop surface while replacement input is temporarily guarded. */
.dropzone.is-disabled {
  cursor: not-allowed;
  opacity: 0.6;
}

.dropzone__icon {
  width: 3.25rem;
  height: 3.25rem;
  display: grid;
  place-items: center;
  margin: 0 auto var(--space-3);
  border: var(--border-width) solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  color: var(--color-action);
  font-size: 1.8rem;
  line-height: 1;
}

.dropzone__title {
  margin-bottom: var(--space-1);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.2rem;
  font-weight: 700;
}

.dropzone__separator,
.dropzone__hint {
  color: var(--color-ink-muted);
  font-size: var(--font-size-sm);
}

.dropzone__separator {
  margin-bottom: var(--space-2);
}

.dropzone__hint {
  margin: var(--space-3) 0 0;
}

.file-summary {
  display: flex;
  min-width: 0;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin-top: var(--space-3);
  padding: var(--space-3);
  border: var(--border-width) solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface-muted);
}

.file-summary[hidden] {
  display: none;
}

.file-summary > div {
  min-width: 0;
}

.file-summary__name,
.file-summary__detail {
  overflow-wrap: anywhere;
}

.file-summary__name {
  margin-bottom: var(--space-1);
  font-weight: 700;
}

.file-summary__detail {
  margin-bottom: 0;
  color: var(--color-ink-muted);
  font-size: var(--font-size-xs);
}

.ready-badge {
  flex: 0 0 auto;
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-pill);
  background: var(--color-ready-soft);
  color: var(--color-ready);
  font-size: var(--font-size-xs);
  font-weight: 700;
}

/* ============================================================
   Preview and Orientation
   Design intent: A neutral frame shows the full decoded image rather
   than cropping, and keeps orientation controls immediately below it.
   ============================================================ */

.preview-frame {
  display: grid;
  min-height: var(--preview-min-height);
  place-items: center;
  overflow: auto;
  padding: var(--space-3);
  border: var(--border-width) solid var(--color-border);
  border-radius: var(--radius-md);
  background-color: var(--color-surface-muted);
  background-image:
    linear-gradient(45deg, var(--color-paper) 25%, transparent 25%),
    linear-gradient(-45deg, var(--color-paper) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, var(--color-paper) 75%),
    linear-gradient(-45deg, transparent 75%, var(--color-paper) 75%);
  background-position: 0 0, 0 var(--space-2), var(--space-2) calc(-1 * var(--space-2)), calc(-1 * var(--space-2)) 0;
  background-size: calc(2 * var(--space-2)) calc(2 * var(--space-2));
}

.preview-placeholder {
  max-width: 28ch;
  margin: 0;
  color: var(--color-ink-muted);
  text-align: center;
}

.preview-canvas {
  width: auto;
  max-width: 100%;
  height: auto;
  max-height: 34rem;
  background: var(--color-surface);
  box-shadow: 0 var(--space-1) var(--space-3) var(--color-shadow);
}

.preview-canvas[hidden] {
  display: none;
}

.orientation-actions {
  margin-top: var(--space-3);
}

/* ============================================================
   Language Selection and Status
   Design intent: Present language choices as compact explicit rows and
   keep network/recognition progress continuously visible below the action.
   ============================================================ */

.language-fieldset {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.language-fieldset legend {
  margin-bottom: var(--space-1);
  font-weight: 700;
}

.language-fieldset > p {
  margin-bottom: var(--space-3);
  color: var(--color-ink-muted);
  font-size: var(--font-size-sm);
}

.language-options {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--space-2);
}

.check-option {
  display: grid;
  min-width: 0;
  min-height: var(--control-height);
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2);
  border: var(--border-width) solid var(--color-border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  background: var(--color-surface);
}

/* Selected state: pale sage confirms inclusion without relying on the checkbox alone. */
.check-option:has(input:checked) {
  background: var(--color-ready-soft);
}

/* Disabled state: cursor communicates that language changes wait for the active OCR job. */
.check-option:has(input:disabled) {
  cursor: not-allowed;
  opacity: 0.6;
}

.check-option input {
  width: 1.15rem;
  height: 1.15rem;
  accent-color: var(--color-action);
}

.check-option code {
  color: var(--color-ink-muted);
  font-size: var(--font-size-xs);
}

.text-button {
  min-height: var(--control-height);
  margin-top: var(--space-2);
  padding: var(--space-1) 0;
  border: 0;
  background: transparent;
  color: var(--color-action-dark);
  cursor: pointer;
  font-weight: 700;
  text-decoration: underline;
  text-decoration-thickness: var(--border-width);
  text-underline-offset: var(--space-1);
}

/* Text-button hover state: rust shift confirms the compact action. */
.text-button:hover:not(:disabled) {
  color: var(--color-action);
}

.status-card {
  margin-top: var(--space-3);
  padding: var(--space-3);
  border: var(--border-width) solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface-muted);
}

.status-card__row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-3);
}

.status-card__label {
  flex: 0 0 auto;
  color: var(--color-ink-muted);
  font-size: var(--font-size-sm);
}

.status-card__value {
  min-width: 0;
  overflow-wrap: anywhere;
  font-weight: 700;
  text-align: right;
}

.progress {
  width: 100%;
  height: var(--space-2);
  display: block;
  margin-top: var(--space-3);
  accent-color: var(--color-action);
}

.progress[hidden] {
  display: none;
}

.message {
  margin: var(--space-3) 0 0;
  padding: var(--space-3);
  border-radius: var(--radius-sm);
  overflow-wrap: anywhere;
}

.message:empty,
.message[hidden] {
  display: none;
}

/* Error state: dark red text and pale surface identify a recoverable alert. */
.message--error {
  border: var(--border-width) solid var(--color-error);
  background: var(--color-error-soft);
  color: var(--color-error);
}

.message--feedback {
  border-left: calc(3 * var(--border-width)) solid var(--color-ready);
  background: var(--color-ready-soft);
  color: var(--color-ready);
}

/* ============================================================
   Editable Result
   Design intent: A generous plain-text field keeps review and correction
   central, with export actions directly beneath the edited value.
   ============================================================ */

.result-label {
  display: inline-block;
  margin-bottom: var(--space-2);
  font-weight: 700;
}

#result-text {
  width: 100%;
  min-height: 18rem;
  display: block;
  resize: vertical;
  padding: var(--space-3);
  border: var(--border-width) solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  color: var(--color-ink);
  line-height: 1.55;
}

/* Result focus state: blue inset shadow reinforces the global keyboard outline on the large field. */
#result-text:focus {
  border-color: var(--color-focus);
  box-shadow: inset 0 0 0 var(--border-width) var(--color-focus);
}

.result-actions {
  margin-top: var(--space-3);
}

/* ============================================================
   Footer
   Design intent: A quiet closing rule echoes the portfolio and provides
   a reliable return route after completing the OCR task.
   ============================================================ */

.app-footer {
  border-top: var(--border-width) solid var(--color-border);
}

.app-footer a {
  min-height: var(--control-height);
  display: inline-flex;
  align-items: center;
  font-weight: 700;
}

/* ============================================================
   Responsive and Reduced Motion
   ============================================================ */

/* Tablet and below (max 832px): stack panels to preserve the task sequence and reading width. */
@media (max-width: 52rem) {
  .workspace {
    grid-template-columns: 1fr;
  }

  .panel--result {
    grid-column: auto;
  }

  .language-options {
    grid-template-columns: 1fr;
  }
}

/* Narrow phones (max 480px): reduce page gutters and stack controls to prevent horizontal scrolling. */
@media (max-width: 30rem) {
  :root {
    --preview-min-height: var(--preview-min-height-small);
  }

  .page-shell {
    width: min(calc(100% - (2 * var(--space-3))), var(--content-width));
  }

  .panel {
    padding: var(--space-4);
  }

  .app-header__inner,
  .app-footer__inner,
  .panel__heading--inline,
  .panel__heading--result,
  .result-actions {
    align-items: flex-start;
    flex-direction: column;
    gap: var(--space-2);
  }

  .button-row,
  .button,
  .file-input-label {
    width: 100%;
  }

  .dropzone {
    min-height: 0;
    padding: var(--space-4);
  }

  .status-card__row {
    align-items: flex-start;
    flex-direction: column;
    gap: var(--space-1);
  }

  .status-card__value {
    text-align: left;
  }
}

/* Reduced motion: remove non-essential transitions while preserving every instruction and control. */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto;
    transition-duration: 0.01ms;
    animation-duration: 0.01ms;
    animation-iteration-count: 1;
  }
}
