/* =========================================================
   cf·translate — warm editorial translator
   Type: Fraunces (display + output) + Geist (UI) + JetBrains Mono (chrome)
   Palette: cream paper · deep warm ink · poppy red accent · emerald success
   ========================================================= */

:root {
  --bg:           #F4EDE0;
  --paper:        #FBF6EC;
  --paper-2:      #F0E7D5;
  --ink:          #1D1612;
  --ink-2:        #5B4F44;
  --ink-3:        #8A7A6B;
  --line:         #E4D9C5;
  --line-strong:  #C7B79A;
  --accent:       #E5462A;
  --accent-ink:   #FBF6EC;
  --accent-soft:  #FBD9CE;
  --success:      #1E6B4F;
  --success-soft: #CFE4D7;
  --danger:       #B23A1F;

  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 14px;
  --r-xl: 20px;

  --serif: "Fraunces", "Iowan Old Style", "Georgia", serif;
  --sans:  "Geist", -apple-system, BlinkMacSystemFont, "Helvetica Neue", sans-serif;
  --mono:  "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:           #1A1411;
    --paper:        #221A15;
    --paper-2:      #2B201A;
    --ink:          #F0E8DA;
    --ink-2:        #BFB29F;
    --ink-3:        #80735F;
    --line:         #3A2E25;
    --line-strong:  #524236;
    --accent:       #FF6F4E;
    --accent-ink:   #1A1411;
    --accent-soft:  #4A2418;
    --success:      #5BC9A0;
    --success-soft: #1E3D2F;
    --danger:       #FF8266;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  min-height: 100dvh;
}

body {
  display: flex;
  justify-content: center;
  position: relative;
  padding:
    env(safe-area-inset-top, 0)
    env(safe-area-inset-right, 0)
    env(safe-area-inset-bottom, 0)
    env(safe-area-inset-left, 0);
  overflow-x: hidden;
}

/* Paper grain — adds warmth without imagery */
.grain {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  opacity: 0.32;
  mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='220' height='220' viewBox='0 0 220 220'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0.12 0 0 0 0 0.09 0 0 0 0 0.07 0 0 0 0.55 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
}

@media (prefers-color-scheme: dark) {
  .grain { opacity: 0.55; mix-blend-mode: screen; }
}

/* ============================ layout ============================ */
.app {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 620px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 22px 18px 36px;
}

/* ============================ masthead ============================ */
.masthead {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  padding: 2px 2px 0;
  flex-wrap: wrap;
}

.masthead-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

/* ============================ language flags ============================ */
.lang-toggle {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--paper);
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  padding: 3px;
}

.lang-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 22px;
  padding: 0;
  background: transparent;
  border: 0;
  border-radius: 999px;
  cursor: pointer;
  opacity: 0.42;
  filter: saturate(0.6);
  transition: opacity 0.18s ease, filter 0.18s ease, transform 0.1s ease,
    background-color 0.18s ease;
  -webkit-tap-highlight-color: transparent;
}

.lang-btn:hover {
  opacity: 0.85;
  filter: saturate(0.9);
}

.lang-btn:active {
  transform: scale(0.92);
}

.lang-btn.active {
  opacity: 1;
  filter: saturate(1);
  background: var(--bg);
  box-shadow: 0 0 0 1px var(--line-strong) inset;
}

.flag {
  width: 22px;
  height: auto;
  display: block;
  border-radius: 2px;
  overflow: hidden;
  box-shadow: 0 0 0 0.5px rgba(0, 0, 0, 0.18);
}

.brand {
  display: inline-flex;
  align-items: baseline;
  gap: 8px;
}

.brand-mark {
  font-family: var(--serif);
  font-size: 22px;
  color: var(--accent);
  transform: translateY(2px);
  display: inline-block;
}

.brand-name {
  font-family: var(--serif);
  font-style: italic;
  font-weight: 500;
  font-size: 24px;
  letter-spacing: -0.01em;
  color: var(--ink);
  font-variation-settings: "SOFT" 60;
}

.brand-name .dot-sep {
  color: var(--accent);
  font-style: normal;
  margin: 0 1px;
}

.direction {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  background: transparent;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  padding: 8px 14px;
  font-family: var(--serif);
  font-style: italic;
  font-weight: 400;
  font-size: 14px;
  color: var(--ink);
  cursor: pointer;
  transition: background-color 0.18s ease, border-color 0.18s ease, transform 0.12s ease;
  font-variation-settings: "SOFT" 60;
  white-space: nowrap;
}

.direction:hover { background: var(--paper); border-color: var(--ink-2); }
.direction:active { transform: scale(0.97); }

.direction .lang { color: var(--ink); }
.direction .arrow {
  font-family: var(--sans);
  font-style: normal;
  color: var(--accent);
  font-weight: 500;
  font-size: 14px;
}

.hairline {
  width: 100%;
  height: 0;
  border: 0;
  border-top: 1px solid var(--line);
  margin: 4px 0 2px;
}

/* ============================ panels ============================ */
.panel {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--r-xl);
  padding: 16px 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  position: relative;
  opacity: 0;
  transform: translateY(8px);
  animation: rise 520ms cubic-bezier(0.2, 0.7, 0.2, 1) forwards;
}

.panel[data-stagger="1"] { animation-delay: 60ms; }
.translate-btn[data-stagger="2"] { animation-delay: 140ms; }
.panel[data-stagger="3"] { animation-delay: 220ms; }

@keyframes rise {
  to { opacity: 1; transform: translateY(0); }
}

.panel-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.panel-label {
  font-family: var(--mono);
  font-size: 10.5px;
  font-weight: 500;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-3);
}

/* ============================ input ============================ */
.input {
  width: 100%;
  resize: vertical;
  min-height: 110px;
  border: 0;
  background: transparent;
  color: var(--ink);
  font-family: var(--sans);
  font-size: 18px;
  line-height: 1.5;
  font-weight: 400;
  outline: none;
  padding: 2px 0;
  caret-color: var(--accent);
}

.input::placeholder {
  color: var(--ink-3);
  font-style: italic;
  font-family: var(--serif);
}

.input::selection { background: var(--accent-soft); color: var(--ink); }

.panel-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 4px;
  border-top: 1px dashed var(--line);
  margin-top: 4px;
}

.count {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ink-3);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.04em;
}

.ghost {
  background: transparent;
  border: 0;
  color: var(--ink-2);
  padding: 6px 0 6px 10px;
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border-radius: var(--r-sm);
  transition: color 0.15s ease;
}

.ghost:hover { color: var(--accent); }

/* ============================ translate button ============================ */
.translate-btn {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  background: var(--accent);
  color: var(--accent-ink);
  border: 0;
  border-radius: var(--r-xl);
  padding: 16px 22px;
  font-family: var(--serif);
  font-style: italic;
  font-weight: 600;
  font-size: 19px;
  letter-spacing: -0.01em;
  cursor: pointer;
  overflow: hidden;
  min-height: 56px;
  transition: transform 0.1s ease, filter 0.18s ease, opacity 0.2s ease,
    background-color 0.2s ease;
  -webkit-tap-highlight-color: transparent;
  font-variation-settings: "SOFT" 80;
  opacity: 0;
  transform: translateY(8px);
  animation: rise 520ms cubic-bezier(0.2, 0.7, 0.2, 1) forwards;
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.08) inset, 0 10px 24px -14px rgba(229, 70, 42, 0.5);
}

.translate-btn:hover:not(:disabled) { filter: brightness(1.04); }
.translate-btn:active:not(:disabled) { transform: translateY(1px) scale(0.995); }

.translate-btn:disabled {
  background: var(--paper-2);
  color: var(--ink-3);
  cursor: not-allowed;
  box-shadow: 0 1px 0 var(--line) inset;
}

.translate-btn .translate-label {
  position: relative;
  z-index: 1;
}

.translate-kbd {
  position: relative;
  z-index: 1;
  font-family: var(--mono);
  font-style: normal;
  font-size: 11px;
  font-weight: 500;
  padding: 4px 8px;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.18);
  letter-spacing: 0.05em;
  color: inherit;
}

.translate-btn:disabled .translate-kbd {
  background: var(--line);
  color: var(--ink-3);
}

@media (max-width: 480px) {
  .translate-kbd { display: none; }
}

.translate-sweep {
  position: absolute;
  inset: 0;
  background: linear-gradient(
    90deg,
    transparent 0%,
    rgba(255, 255, 255, 0.22) 50%,
    transparent 100%
  );
  transform: translateX(-100%);
  opacity: 0;
  pointer-events: none;
}

.translate-btn.busy .translate-sweep {
  opacity: 1;
  animation: sweep 1.4s linear infinite;
}

@keyframes sweep {
  from { transform: translateX(-100%); }
  to   { transform: translateX(100%); }
}

/* ============================ output ============================ */
.output-panel {
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  min-height: 150px;
  transition: background-color 0.25s ease, color 0.25s ease,
    border-color 0.25s ease, transform 0.1s ease;
}

.output-panel:hover { border-color: var(--line-strong); }
.output-panel:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}
.output-panel:active { transform: scale(0.997); }

.output-text {
  font-family: var(--serif);
  font-weight: 500;
  font-size: 21px;
  line-height: 1.45;
  letter-spacing: -0.005em;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  padding: 8px 0 32px;
  min-height: 60px;
  color: var(--ink);
  font-variation-settings: "SOFT" 40;
}

.output-text.empty {
  color: var(--ink-3);
  font-style: italic;
  font-size: 16px;
  font-family: var(--serif);
}

.hint {
  position: absolute;
  bottom: 12px;
  right: 16px;
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-3);
  background: var(--paper-2);
  padding: 4px 9px;
  border-radius: 999px;
  pointer-events: none;
  border: 1px solid var(--line);
}

.output-panel.empty-output .hint { display: none; }

/* COPY FLASH — full card inversion, very memorable */
.output-panel.copied {
  background: var(--ink);
  color: var(--paper);
  border-color: var(--ink);
}
.output-panel.copied .panel-label { color: var(--paper-2); }
.output-panel.copied .output-text { color: var(--paper); }
.output-panel.copied .hint {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

/* ============================ status ============================ */
.status {
  font-family: var(--mono);
  font-size: 10.5px;
  font-weight: 500;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-3);
}

.status.error { color: var(--danger); }

.status .dot {
  display: inline-block;
  width: 6px;
  height: 6px;
  background: var(--accent);
  border-radius: 50%;
  margin-right: 7px;
  animation: pulse 1s ease-in-out infinite;
  vertical-align: middle;
}

@keyframes pulse {
  0%, 100% { opacity: 0.3; transform: scale(0.85); }
  50%      { opacity: 1;   transform: scale(1);    }
}

/* ============================ colophon ============================ */
.colophon {
  text-align: center;
  font-size: 11px;
  color: var(--ink-3);
  letter-spacing: 0.02em;
  padding: 10px 0 0;
}

.colophon .mono {
  font-family: var(--mono);
  font-size: 10.5px;
}

.colophon .dot-sep {
  margin: 0 6px;
  color: var(--line-strong);
}

/* ============================ picker dialog ============================ */
.picker {
  border: 0;
  border-radius: var(--r-xl);
  background: var(--paper);
  color: var(--ink);
  padding: 22px;
  max-width: 400px;
  width: calc(100% - 32px);
  box-shadow:
    0 1px 0 var(--line) inset,
    0 24px 60px -20px rgba(0, 0, 0, 0.35);
  border: 1px solid var(--line);
}

.picker::backdrop {
  background: rgba(29, 22, 18, 0.55);
  backdrop-filter: blur(6px);
}

.picker-eyebrow {
  margin: 0 0 8px;
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--accent);
}

.picker-title {
  margin: 0 0 6px;
  font-family: var(--serif);
  font-weight: 600;
  font-size: 26px;
  line-height: 1.15;
  letter-spacing: -0.015em;
  font-variation-settings: "SOFT" 50;
}

.picker-title em {
  font-style: italic;
  color: var(--accent);
  font-weight: 500;
}

.picker-sub {
  margin: 0 0 18px;
  color: var(--ink-2);
  font-size: 14px;
}

.picker-buttons {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.picker-option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-lg);
  padding: 14px 16px;
  font-family: var(--serif);
  font-style: italic;
  font-weight: 500;
  font-size: 15px;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
  text-align: left;
  font-variation-settings: "SOFT" 60;
}

.picker-option:hover {
  background: var(--paper-2);
  border-color: var(--ink-2);
}

.picker-option:active { transform: scale(0.99); }

.picker-arrow {
  color: var(--accent);
  font-family: var(--sans);
  font-style: normal;
  font-weight: 500;
  font-size: 18px;
  flex-shrink: 0;
  padding: 0 6px;
}

.picker-from, .picker-to {
  flex: 1;
  min-width: 0;
}
.picker-to { text-align: right; }

/* ============================ desktop ============================ */
@media (min-width: 760px) {
  .app {
    padding-top: 36px;
    gap: 22px;
  }
  .brand-name { font-size: 28px; }
  .brand-mark { font-size: 26px; }
  .direction { font-size: 15px; padding: 9px 16px; }
  .input { font-size: 19px; min-height: 130px; }
  .output-text { font-size: 23px; padding: 10px 0 40px; }
  .translate-btn { font-size: 20px; padding: 18px 22px; min-height: 60px; }
}

/* ============================ reduced motion ============================ */
@media (prefers-reduced-motion: reduce) {
  .panel, .translate-btn {
    opacity: 1 !important;
    transform: none !important;
    animation: none !important;
  }
  .translate-btn.busy .translate-sweep { animation: none; }
  .status .dot { animation: none; }
  .output-panel { transition: background-color 0.001s, color 0.001s; }
}
