:root {
  --color-bg: #f1eee7;
  --color-paper: #fbfaf5;
  --color-paper-deep: #ebe5da;
  --color-ink: #111111;
  --color-muted: #58534b;
  --color-line: #151515;
  --color-soft-line: #cfc7b8;
  --color-warm: #ded6c7;
  --color-accent: #1f6f8b;
  --color-accent-dark: #16556c;
  --color-accent-soft: #dceff5;
  --color-alert-bg: #f8ece8;
  --color-alert: #7a2424;
  --shadow-paper: 0 14px 34px rgba(17, 17, 17, 0.08);
  --shadow-soft: 0 8px 24px rgba(17, 17, 17, 0.07);
  --radius-lg: 24px;
  --radius-md: 18px;
  --radius-sm: 14px;
  --space-page: clamp(16px, 5vw, 28px);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--color-bg);
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--color-ink);
  background:
    linear-gradient(180deg, rgba(251, 250, 245, 0.92), rgba(241, 238, 231, 0.86) 300px),
    var(--color-bg);
  font-family: "Roboto Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button,
input {
  font: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.is-hidden {
  display: none !important;
}

.splash {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: var(--space-page);
  background: var(--color-paper);
  transition: opacity 240ms ease, visibility 240ms ease;
}

.splash.is-fading {
  opacity: 0;
  visibility: hidden;
}

.crest {
  width: min(42vw, 168px);
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  background: transparent;
  border: 0;
  overflow: visible;
}

.crest img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.crest-fallback {
  display: none;
  width: 108px;
  height: 108px;
  place-items: center;
  color: var(--color-ink);
  border: 1.5px solid var(--color-line);
  border-radius: 999px;
  background: var(--color-paper);
  font-size: 2.3rem;
  font-weight: 700;
  letter-spacing: 0;
}

.crest.has-fallback img {
  display: none;
}

.crest.has-fallback .crest-fallback {
  display: grid;
}

.app-shell {
  width: min(100%, 760px);
  min-height: 100vh;
  margin: 0 auto;
  padding:
    max(22px, env(safe-area-inset-top))
    var(--space-page)
    max(24px, env(safe-area-inset-bottom));
}

.app-header {
  padding: 8px 0 18px;
  border-bottom: 1px solid rgba(21, 21, 21, 0.16);
}

.masthead {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 14px;
}

.brand-mark {
  width: 62px;
  height: 78px;
  display: grid;
  place-items: center;
}

.brand-mark img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.brand-mark span {
  width: 52px;
  height: 52px;
  display: none;
  place-items: center;
  border: 1.5px solid var(--color-line);
  border-radius: 999px;
  background: var(--color-paper);
  font-weight: 700;
}

.brand-mark.has-fallback img,
.brand-mark img[src=""],
.brand-mark img:not([src]) {
  display: none;
}

.brand-mark.has-fallback span,
.brand-mark img[src=""] + span,
.brand-mark img:not([src]) + span {
  display: grid;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--color-muted);
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
}

.app-header h1 {
  margin: 0;
  font-size: 2rem;
  line-height: 1.05;
  font-weight: 700;
  letter-spacing: 0;
}

.capture-section {
  margin-top: 22px;
}

.app-shell.has-result-focus .capture-section,
.app-shell.has-result-focus .preview-section,
.app-shell.has-result-focus .actions {
  display: none;
}

.capture-box {
  width: 100%;
  min-height: 268px;
  padding: 28px 18px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 8px;
  color: var(--color-ink);
  background: var(--color-paper);
  border: 1px solid rgba(21, 21, 21, 0.08);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-paper);
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 120ms ease, box-shadow 120ms ease, opacity 120ms ease, background-color 120ms ease;
}

.capture-box:active {
  transform: translateY(2px);
  background: #ffffff;
  box-shadow: 0 8px 18px rgba(17, 17, 17, 0.06);
}

.capture-box:disabled {
  cursor: not-allowed;
  opacity: 0.66;
  transform: none;
}

.plus {
  width: 84px;
  height: 84px;
  display: grid;
  place-items: center;
  color: var(--color-accent-dark);
  border: 0;
  border-radius: 999px;
  background: var(--color-accent-soft);
  font-size: 3.2rem;
  line-height: 1;
  font-weight: 400;
}

.capture-title {
  margin-top: 8px;
  color: var(--color-ink);
  font-size: 1.18rem;
  font-weight: 700;
}

.file-input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.preview-section {
  margin-top: 20px;
}

.preview-header {
  min-height: 30px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.preview-header h2,
.result-section h2 {
  margin: 0;
  font-size: 0.9rem;
  font-weight: 700;
  text-transform: uppercase;
}

.preview-header span {
  min-width: 36px;
  min-height: 30px;
  padding: 4px 10px;
  display: inline-grid;
  place-items: center;
  color: var(--color-ink);
  background: var(--color-paper);
  border: 0;
  border-radius: 999px;
  box-shadow: inset 0 0 0 1px rgba(21, 21, 21, 0.14);
  font-weight: 700;
}

.preview-list {
  margin-top: 10px;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.preview-item {
  position: relative;
  aspect-ratio: 1;
  overflow: hidden;
  border: 0;
  border-radius: var(--radius-sm);
  background: var(--color-paper);
  box-shadow: var(--shadow-soft);
}

.preview-item img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  filter: grayscale(0.12);
}

.preview-remove {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 999px;
  color: #ffffff;
  background: rgba(17, 17, 17, 0.72);
  font-size: 1.35rem;
  line-height: 1;
  cursor: pointer;
  touch-action: manipulation;
}

.preview-remove:active {
  transform: scale(0.94);
}

.actions {
  position: sticky;
  bottom: 0;
  margin: 24px calc(var(--space-page) * -1) 0;
  padding: 14px var(--space-page) max(14px, env(safe-area-inset-bottom));
  display: grid;
  gap: 12px;
  background: linear-gradient(180deg, rgba(241, 238, 231, 0), var(--color-bg) 24px);
}

.button {
  width: 100%;
  min-height: 70px;
  padding: 18px 22px;
  border: 0;
  border-radius: 999px;
  color: var(--color-ink);
  background: var(--color-paper);
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
  box-shadow: var(--shadow-soft);
  transition: transform 120ms ease, box-shadow 120ms ease, background-color 120ms ease, color 120ms ease, opacity 120ms ease;
}

.button-primary {
  background: var(--color-accent);
  color: var(--color-paper);
  box-shadow: 0 10px 24px rgba(31, 111, 139, 0.2);
}

.button-primary:active:not(:disabled),
.button-secondary:active:not(:disabled) {
  transform: translateY(2px);
  box-shadow: 0 5px 14px rgba(17, 17, 17, 0.1);
}

.button-secondary {
  background: var(--color-paper);
  color: var(--color-ink);
  box-shadow: inset 0 0 0 1px rgba(21, 21, 21, 0.1), var(--shadow-soft);
}

.restart-button {
  margin-top: 18px;
}

.button:focus-visible,
.capture-box:focus-visible,
.preview-remove:focus-visible {
  outline: 3px solid rgba(17, 17, 17, 0.28);
  outline-offset: 3px;
}

.button:disabled {
  color: #615f5a;
  background: #e1d9cc;
  box-shadow: none;
  cursor: not-allowed;
  opacity: 1;
}

.button-primary:disabled {
  color: var(--color-accent-dark);
  background: var(--color-accent-soft);
}

.result-section {
  margin-top: 22px;
  padding-bottom: 18px;
}

.app-shell.has-final-result .result-section {
  margin-top: 26px;
}

.result-section h2 {
  margin-bottom: 10px;
}

.result-box {
  max-height: 48vh;
  min-height: 144px;
  padding: 16px;
  border: 1px solid rgba(21, 21, 21, 0.1);
  border-radius: var(--radius-md);
  color: var(--color-ink);
  background: rgba(251, 250, 245, 0.94);
  box-shadow: var(--shadow-paper);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  overflow-y: auto;
  font-size: 0.98rem;
  line-height: 1.65;
  -webkit-overflow-scrolling: touch;
}

.app-shell.has-final-result .result-box {
  max-height: none;
  min-height: 38vh;
}

.result-box.is-loading {
  color: var(--color-muted);
}

.result-box.is-error {
  color: var(--color-alert);
  background: var(--color-alert-bg);
}

.result-box.is-success {
  background: var(--color-paper);
}

.result-actions {
  margin-top: 12px;
  display: grid;
  gap: 12px;
}

.button.is-done {
  color: var(--color-paper);
  background: var(--color-ink);
}

.result-status {
  min-height: 28px;
  margin: 10px 0 0;
  color: var(--color-muted);
  font-size: 0.9rem;
}

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

@media (min-width: 560px) {
  .capture-box {
    min-height: 320px;
  }

  .app-header h1 {
    font-size: 3rem;
  }

  .brand-mark {
    width: 76px;
    height: 96px;
  }

  .crest-fallback {
    font-size: 2.8rem;
  }

  .result-actions {
    grid-template-columns: repeat(3, 1fr);
  }
}
