:root {
  --ink: #221e18;
  --ink-soft: #4a4335;
  --paper: #efe7d3;
  --paper-deep: #e4d9bf;
  --paper-edge: #d8caa8;
  --shell: #15130f;
  --shell-deep: #0c0b09;
  --shell-line: #322c22;
  --shell-text: #d9d0bd;
  --shell-text-dim: #8d8370;
  --red: #b23a24;
  --red-deep: #8f2c1a;
  --red-ink: #a3341f;

  --font-display: "Oswald", "Arial Narrow", sans-serif;
  --font-type: "Courier Prime", "Courier New", monospace;

  --space-1: 0.4rem;
  --space-2: 0.8rem;
  --space-3: 1.4rem;
  --space-4: 2.2rem;
  --space-5: 3.2rem;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

.icon-sprite {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

html {
  color-scheme: dark;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--shell);
  color: var(--shell-text);
  font-family: var(--font-type);
  -webkit-font-smoothing: antialiased;
}

::selection {
  background: var(--red);
  color: var(--paper);
}

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

/* thin custom scrollbar carrying the palette, not the browser default */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--shell-line) var(--shell-deep);
}
::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}
::-webkit-scrollbar-track {
  background: var(--shell-deep);
}
::-webkit-scrollbar-thumb {
  background: var(--shell-line);
  border-radius: 0;
  border: 2px solid var(--shell-deep);
}

.icon {
  width: 1.15em;
  height: 1.15em;
  display: inline-block;
  vertical-align: -0.2em;
}

/* ---- labels & type primitives ---- */

.field-label {
  display: block;
  font-family: var(--font-display);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--ink-soft);
  margin-bottom: var(--space-1);
}

.section-label {
  font-family: var(--font-display);
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink);
  margin: 0 0 var(--space-3);
  padding-bottom: var(--space-1);
  border-bottom: 1px solid var(--paper-edge);
}

.typed-input,
.typed-textarea {
  width: 100%;
  font-family: var(--font-type);
  font-size: 0.98rem;
  line-height: 1.6;
  color: var(--ink);
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--paper-edge);
  padding: var(--space-2) 0.1rem;
  resize: vertical;
  caret-color: var(--red);
}

.typed-input::placeholder,
.typed-textarea::placeholder {
  color: var(--ink-soft);
  font-style: italic;
}

.typed-textarea {
  border: 1px solid var(--paper-edge);
  background: linear-gradient(var(--paper-edge) 1px, transparent 1px);
  background-size: 100% 1.85em;
  background-position: 0 0.2em;
  padding: var(--space-2) var(--space-2) var(--space-2) 2.6rem;
  min-height: 5.5em;
}

.result-text {
  min-height: 12em;
  font-size: 1rem;
}

.text-link {
  font-family: var(--font-display);
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  background: none;
  border: none;
  padding: 0;
  color: var(--red-ink);
  text-decoration: underline;
  text-decoration-style: dotted;
  text-underline-offset: 3px;
  cursor: pointer;
}

.text-link--muted {
  color: var(--ink-soft);
}

.wire-status {
  font-family: var(--font-type);
  font-size: 0.85rem;
  color: var(--ink-soft);
  min-height: 1.2em;
}
.wire-status:not(:empty)::after {
  content: "_";
  animation: wire-blink 1s steps(1) infinite;
}

@keyframes wire-blink {
  50% {
    opacity: 0;
  }
}

.marginal-note {
  font-family: var(--font-type);
  font-size: 0.88rem;
  color: var(--red-deep);
  background: color-mix(in srgb, var(--red) 8%, var(--paper));
  border: 1px solid var(--red);
  padding: var(--space-2) var(--space-2);
  margin: var(--space-3) 0 0;
}
.marginal-note::before {
  content: "ERRO — ";
  font-family: var(--font-display);
  font-weight: 700;
  letter-spacing: 0.06em;
}

/* ---- stamp buttons: the one signature interaction ---- */

.stamp-btn {
  position: relative;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.8rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--red-ink);
  background: transparent;
  border: 2px solid var(--red-ink);
  border-radius: 999px;
  padding: 0.75rem 1.9rem;
  cursor: pointer;
  transform: rotate(-2deg);
  transition: transform 0.18s cubic-bezier(0.16, 1, 0.3, 1), box-shadow 0.18s ease, background-color 0.15s ease;
  box-shadow: 0 0 0 0 rgba(178, 58, 36, 0);
}

/* inner ring — the double-line rubber-stamp impression */
.stamp-btn::before {
  content: "";
  position: absolute;
  inset: 3px;
  border: 1px solid var(--red-ink);
  border-radius: 999px;
  opacity: 0.55;
  pointer-events: none;
}

.stamp-btn:hover:not(:disabled) {
  background: color-mix(in srgb, var(--red) 8%, transparent);
}

.stamp-btn:active:not(:disabled) {
  transform: rotate(0deg) scale(0.94);
  box-shadow: 0 0 0 6px rgba(178, 58, 36, 0.12);
}

.stamp-btn:disabled {
  color: var(--ink-soft);
  border-color: var(--paper-edge);
  cursor: not-allowed;
  transform: none;
}
.stamp-btn:disabled::before {
  border-color: var(--paper-edge);
}

.stamp-btn--lg {
  font-size: 0.92rem;
  padding: 0.95rem 2.6rem;
  transform: rotate(-1.4deg);
}

/* ---- dark shell / desk ---- */

.shell {
  min-height: 100vh;
  position: relative;
  padding: var(--space-5) var(--space-3);
  background:
    radial-gradient(ellipse 60% 45% at 50% 8%, rgba(255, 220, 170, 0.05), transparent 70%),
    var(--shell);
}

.desk {
  max-width: 980px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.paper {
  position: relative;
  background-color: var(--paper);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix type='matrix' values='0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.05 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  padding: var(--space-4) var(--space-4) var(--space-4) calc(var(--space-4) + 1.4rem);
  box-shadow: 0 24px 48px -28px rgba(0, 0, 0, 0.75), 0 4px 10px -4px rgba(0, 0, 0, 0.5);
}

/* the printed red margin rule — steno/legal-pad convention, not a UI accent */
.paper::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: calc(var(--space-4) + 0.55rem);
  width: 1px;
  background: rgba(178, 58, 36, 0.35);
}

.paper--result {
  transform: rotate(-0.35deg);
}

.masthead {
  border-bottom: 2px solid var(--ink);
  padding-bottom: var(--space-2);
  margin-bottom: var(--space-4);
}

.masthead-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-2);
}

.masthead-meta {
  display: flex;
  align-items: baseline;
  gap: var(--space-3);
}

.wire-clock {
  font-family: var(--font-type);
  font-size: 0.82rem;
  color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
}

.masthead-mark {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(1.9rem, 4vw, 2.6rem);
  letter-spacing: 0.01em;
  text-transform: uppercase;
  color: var(--ink);
  margin: 0;
}

.masthead-sub {
  font-family: var(--font-display);
  font-size: 0.8rem;
  font-weight: 500;
  letter-spacing: 0.02em;
  color: var(--ink-soft);
  margin: var(--space-1) 0 0;
}

.desk-grid {
  display: grid;
  grid-template-columns: 1.6fr 1fr;
  gap: var(--space-4) var(--space-4);
}

.desk-col--wide .field-block + .field-block {
  margin-top: var(--space-4);
}

.note-card + .note-card {
  margin-top: var(--space-3);
}

/* ---- dropzone: cut-line, not a rounded upload well ---- */

.dropzone {
  border: 1.5px dashed var(--ink-soft);
  padding: var(--space-4) var(--space-3);
  text-align: center;
  color: var(--ink-soft);
  cursor: pointer;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}

.dropzone:hover,
.dropzone:focus-visible {
  border-color: var(--red-ink);
  background: color-mix(in srgb, var(--red) 5%, transparent);
}

.dropzone.dragover {
  border-color: var(--red-ink);
  border-style: solid;
  background: color-mix(in srgb, var(--red) 8%, transparent);
}

.dropzone-text {
  margin: var(--space-2) 0 0;
  font-family: var(--font-type);
  font-size: 0.92rem;
}

.icon-upload {
  width: 1.6em;
  height: 1.6em;
  color: var(--ink-soft);
}

.image-preview-list {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  margin-top: var(--space-3);
}

.image-preview {
  position: relative;
  width: 92px;
  height: 92px;
  background: #fff;
  padding: 4px 4px 14px;
  box-shadow: 0 6px 14px -6px rgba(0, 0, 0, 0.5);
}

.image-preview .icon-clip {
  position: absolute;
  top: -9px;
  left: 50%;
  transform: translateX(-50%) rotate(-8deg);
  width: 1.3em;
  height: 1.3em;
  color: var(--shell-line);
  filter: drop-shadow(0 2px 1px rgba(0, 0, 0, 0.35));
}

.image-preview:nth-child(3n) {
  transform: rotate(-2.5deg);
}
.image-preview:nth-child(3n + 1) {
  transform: rotate(1.8deg);
}
.image-preview:nth-child(3n + 2) {
  transform: rotate(-1deg);
}

.image-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.remove-btn {
  position: absolute;
  top: -8px;
  right: -8px;
  width: 22px;
  height: 22px;
  padding: 0;
  border: 1.5px solid var(--red-ink);
  border-radius: 50%;
  background: var(--paper);
  color: var(--red-ink);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.remove-btn .icon {
  width: 0.75em;
  height: 0.75em;
}

.file-attach {
  margin-top: var(--space-2);
}

.file-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  margin-top: var(--space-2);
  padding: var(--space-1) var(--space-2);
  border: 1px solid var(--ink-soft);
  background: color-mix(in srgb, var(--ink) 4%, var(--paper));
}

.file-chip-name {
  font-family: var(--font-type);
  font-size: 0.85rem;
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 220px;
}

.file-chip .remove-btn {
  position: static;
}

/* ---- action row / result ---- */

.action-bar {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-wrap: wrap;
  margin-top: var(--space-5);
  padding-top: var(--space-3);
  border-top: 1px solid var(--paper-edge);
}

.result-header {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-bottom: var(--space-3);
  color: var(--red-ink);
}
.result-header .section-label {
  margin: 0;
  border: none;
  padding: 0;
  color: var(--ink);
}

.result-actions {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin-top: var(--space-3);
}

/* ---- login / credential ---- */

.login-screen,
#login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
}

.credential {
  position: relative;
  width: min(360px, 100%);
  background-color: var(--paper);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix type='matrix' values='0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.05 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  padding: var(--space-5) var(--space-4) var(--space-4);
  box-shadow: 0 28px 56px -30px rgba(0, 0, 0, 0.8), 0 6px 14px -6px rgba(0, 0, 0, 0.5);
  text-align: left;
}

.credential-stamp {
  position: absolute;
  top: var(--space-3);
  right: var(--space-3);
  font-family: var(--font-display);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  color: var(--red-ink);
  border: 2px solid var(--red-ink);
  border-radius: 50%;
  width: 4.4rem;
  height: 4.4rem;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  transform: rotate(9deg);
}
.credential-stamp::after {
  content: "";
  position: absolute;
  inset: 5px;
  border: 1px solid var(--red-ink);
  border-radius: 50%;
}

.credential-mark {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.7rem;
  letter-spacing: 0.01em;
  text-transform: uppercase;
  color: var(--ink);
  margin: 0 0 var(--space-1);
}

.credential-sub {
  font-family: var(--font-display);
  font-size: 0.78rem;
  font-weight: 500;
  letter-spacing: 0.02em;
  color: var(--ink-soft);
  margin: 0 0 var(--space-4);
  padding-bottom: var(--space-3);
  border-bottom: 2px solid var(--ink);
}

.credential-form {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.credential-form .stamp-btn {
  margin-top: var(--space-2);
  align-self: flex-start;
}

/* ---- responsive: stack the desk on narrow screens ---- */

@media (max-width: 860px) {
  .desk-grid {
    grid-template-columns: 1fr;
  }
  .shell {
    padding: var(--space-4) var(--space-2);
  }
  .paper {
    padding: var(--space-3) var(--space-3) var(--space-3) calc(var(--space-3) + 1.2rem);
  }
  .paper::after {
    left: calc(var(--space-3) + 0.5rem);
  }
}
