:root {
  --bg-0: #f8f3e8;
  --bg-1: #e7d2a0;
  --ink: #10243d;
  --ink-soft: #446181;
  --line: #d8be88;
  --panel: rgba(255, 250, 240, 0.92);
  --primary: #c3192e;
  --primary-dark: #8f1222;
  --ghost-bg: #efe0be;
  --hero-surface: linear-gradient(180deg, #15397f 0%, #15397f 72%, #12326f 88%, #0f2e66 100%);
  --radius: 14px;
  --display: 'Archivo Black', sans-serif;
  --body: 'Space Grotesk', sans-serif;
  --page-pad-left: max(12px, env(safe-area-inset-left));
  --page-pad-right: max(12px, env(safe-area-inset-right));
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  width: 100%;
  max-width: 100%;
  min-height: 100%;
  height: 100%;
  overflow-x: hidden;
  overflow-y: hidden;
  overscroll-behavior-y: none;
}

body {
  font-family: var(--body);
  color: var(--ink);
  position: relative;
  background:
    radial-gradient(1200px 560px at -15% -20%, #fff7e4 0%, transparent 58%),
    radial-gradient(900px 480px at 112% 110%, #f1ca73 0%, transparent 50%),
    linear-gradient(162deg, var(--bg-0) 0%, var(--bg-1) 100%);
}

body::before {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: calc(env(safe-area-inset-top) + 22px);
  background: var(--hero-surface);
  pointer-events: none;
  z-index: 0;
}

.app {
  min-width: 0;
  width: 100%;
  max-width: 520px;
  margin: 0 auto;
  min-height: 100svh;
  min-height: 100dvh;
  height: 100svh;
  height: 100dvh;
  max-height: 100dvh;
  padding-top: 0;
  padding-right: var(--page-pad-right);
  padding-bottom: calc(12px + env(safe-area-inset-bottom));
  padding-left: var(--page-pad-left);
  display: flex;
  flex-direction: column;
  gap: 8px;
  position: relative;
  z-index: 1;
  overflow: hidden;
}

.hero {
  min-width: 0;
  position: relative;
  margin-left: calc(-1 * var(--page-pad-left));
  margin-right: calc(-1 * var(--page-pad-right));
  padding:
    calc(env(safe-area-inset-top) + 18px)
    max(14px, env(safe-area-inset-right))
    14px
    max(14px, env(safe-area-inset-left));
  overflow: hidden;
  background: var(--hero-surface);
}

.hero::before {
  content: none;
}

.hero::after {
  content: none;
}

.eyebrow {
  margin: 0;
  letter-spacing: 0.11em;
  text-transform: uppercase;
  color: #74511e;
  font-size: 0.68rem;
  font-weight: 600;
}

h1 {
  position: relative;
  z-index: 1;
  margin: 0.1rem 0 0;
  font-family: var(--display);
  font-size: clamp(1.95rem, 9vw, 2.7rem);
  line-height: 0.96;
  letter-spacing: 0.01em;
  text-wrap: balance;
  color: #fff;
  text-shadow:
    0 1px 2px rgba(0, 0, 0, 0.28),
    0 0 1px rgba(0, 0, 0, 0.16);
  -webkit-text-stroke: 0;
}

#homeTap {
  cursor: pointer;
}

.sub {
  margin: 0.36rem 0 0;
  color: var(--ink-soft);
  font-size: 0.9rem;
}

.field-head {
  min-width: 0;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.label {
  font-size: 0.82rem;
  font-weight: 600;
  color: #355172;
}

.meta {
  font-size: 0.72rem;
  color: #7087a0;
}

textarea {
  width: 100%;
  max-width: 100%;
  margin-top: 6px;
  border: 1px solid #ccaf77;
  border-radius: 10px;
  padding: 11px;
  font: inherit;
  font-size: 16px;
  line-height: 1.35;
  color: var(--ink);
  background: #fff;
  resize: none;
  overflow-wrap: anywhere;
  word-break: break-word;
}

#source {
  min-height: clamp(92px, 17svh, 138px);
  max-height: clamp(92px, 24svh, 180px);
  overflow-y: auto;
}

#result {
  min-height: 0;
  max-height: none;
  flex: 1 1 auto;
  overflow-y: auto;
}

textarea:focus {
  outline: 2px solid rgba(195, 25, 46, 0.3);
  outline-offset: 1px;
}

.output-surface {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
  transition: opacity 170ms ease, transform 170ms ease, max-height 220ms ease;
}

.output-surface.is-collapsed {
  flex: 0 0 auto;
  opacity: 0;
  transform: translateY(-4px);
  max-height: 0;
  overflow: hidden;
  pointer-events: none;
}

.action-row {
  min-width: 0;
}

.action-row .primary {
  width: 100%;
}

.dock {
  min-width: 0;
  position: static;
  z-index: 20;
  margin-top: auto;
  padding: 0 0 2px;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
  align-items: center;
}

button {
  border: 0;
  border-radius: 999px;
  max-width: 100%;
  min-height: 44px;
  padding: 0.62rem 0.96rem;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.primary {
  grid-column: 1 / -1;
  color: #fff;
  background: linear-gradient(132deg, var(--primary), var(--primary-dark));
  position: relative;
  overflow: hidden;
}

.secondary {
  grid-column: 1 / -1;
  background: var(--ghost-bg);
  color: #56350f;
  border: 1px solid #d5ba85;
}

.share-btn {
  background: transparent;
  color: #56350f;
  border: 0;
  min-width: 0;
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.2rem;
  border-radius: 10px;
}

.share-btn svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
  flex: 0 0 auto;
}

button:disabled {
  filter: grayscale(0.25);
  cursor: not-allowed;
}

.primary.is-busy {
  animation: busyPulse 1.1s ease-in-out infinite;
}

.primary.is-busy::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(
    110deg,
    rgba(255, 255, 255, 0) 25%,
    rgba(255, 255, 255, 0.22) 50%,
    rgba(255, 255, 255, 0) 75%
  );
  transform: translateX(-120%);
  animation: busySweep 1.15s linear infinite;
}

#status {
  grid-column: 1 / -1;
  color: #45627f;
  font-size: 0.8rem;
}

.is-hidden {
  display: none;
}

#status:empty {
  display: none;
}

@media (min-width: 740px) {
  html,
  body {
    height: auto;
    min-height: 100%;
    overflow-y: auto;
  }

  body::before {
    display: none;
  }

  .app {
    max-width: min(920px, calc(100% - 40px));
    min-height: calc(100dvh - 20px);
    height: auto;
    max-height: none;
    padding-right: 20px;
    padding-bottom: 24px;
    padding-left: 20px;
    gap: 12px;
  }

  .hero {
    margin-left: -20px;
    margin-right: -20px;
    padding-top: 26px;
    padding-right: 20px;
    padding-left: 20px;
  }

  h1 {
    font-size: clamp(2.3rem, 4.8vw, 3.4rem);
  }

  #source {
    min-height: 120px;
    max-height: 220px;
  }

  #result {
    min-height: 240px;
    max-height: 46dvh;
  }

  .dock {
    grid-template-columns: auto auto auto 1fr;
    gap: 8px;
    padding-bottom: 4px;
  }

  .secondary {
    grid-column: auto;
    justify-self: start;
    min-width: 128px;
  }

  #status {
    grid-column: 4;
    justify-self: end;
    text-align: right;
  }
}

@media (min-width: 1100px) {
  .app {
    max-width: 980px;
  }
}

@keyframes busyPulse {
  0% {
    filter: brightness(1);
  }
  50% {
    filter: brightness(1.09);
  }
  100% {
    filter: brightness(1);
  }
}

@keyframes busySweep {
  100% {
    transform: translateX(120%);
  }
}
