@import url('https://fonts.googleapis.com/css2?family=DM+Mono:wght@400;500&family=Nunito:wght@500;700;900&display=swap');

:root {
  --ink: #29252f;
  --paper: #fffaf0;
  --pink: #f6bad2;
  --pink-deep: #e878a5;
  --purple: #8472af;
  --mint: #a7d6c8;
  --yellow: #f7d75b;
  --line: 3px solid var(--ink);
  font-family: "Nunito", system-ui, sans-serif;
  color: var(--ink);
  background: #dcd7ea;
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; background-image: radial-gradient(#ffffff80 1px, transparent 1px), linear-gradient(135deg, #e7e1ef, #d4e8e1); background-size: 19px 19px, auto; }
button, input, textarea { font: inherit; }
button { color: inherit; }
.page-shell { width: min(1180px, calc(100% - 28px)); margin: 18px auto; }
.site-header { display: flex; align-items: center; justify-content: space-between; padding: 13px 18px; background: #fffdf7dd; border: var(--line); border-radius: 17px; box-shadow: 5px 6px 0 #3e3948; }
.brand { color: var(--ink); text-decoration: none; font-size: 1.25rem; font-weight: 900; letter-spacing: -.03em; }
.brand span { color: var(--pink-deep); }
.header-user { display: flex; gap: 14px; align-items: center; font-family: "DM Mono", monospace; font-size: .78rem; }
.header-user form { margin: 0; }
.text-button { border: 0; background: transparent; text-decoration: underline; cursor: pointer; }
main { margin-top: 28px; }
.main-grid { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(340px, .75fr); gap: 28px; align-items: start; }
.section-heading { display: flex; align-items: end; justify-content: space-between; gap: 20px; margin-bottom: 14px; }
h1, h2 { margin: 3px 0 0; line-height: 1.05; letter-spacing: -.045em; }
h1 { font-size: clamp(2rem, 4vw, 3.6rem); }
h2 { font-size: 2rem; }
.eyebrow { font: 500 .72rem/1 "DM Mono", monospace; letter-spacing: .14em; text-transform: uppercase; }
.sender-tag { background: var(--yellow); border: 2px solid var(--ink); border-radius: 999px; padding: 6px 11px; transform: rotate(2deg); }
.frame-display { position: relative; aspect-ratio: 5 / 3; padding: 14px; background: #765c48; border: 5px solid #342a27; box-shadow: inset 0 0 0 5px #b08b63, 9px 11px 0 #514a5b55; }
.frame-display::after { content: ""; position: absolute; inset: 10px; border: 8px solid #f5ead0; pointer-events: none; }
.frame-display img, .empty-display { width: 100%; height: 100%; object-fit: cover; display: block; }
.empty-display { display: grid; place-content: center; text-align: center; background: var(--paper); }
.empty-display span { font-size: 3rem; color: var(--purple); }
.timestamp { font: .72rem "DM Mono", monospace; text-align: right; }
.paper-card { background: var(--paper); border: var(--line); border-radius: 4px 22px 7px 18px; box-shadow: 8px 9px 0 #81778e66; padding: 25px; position: relative; }
.paper-card::before { content: ""; position: absolute; width: 86px; height: 23px; background: #f6bad2aa; top: -10px; left: 42%; transform: rotate(-2deg); }
.centered-card { max-width: 620px; margin: 90px auto; text-align: center; padding: 48px; }
.login-form { display: grid; gap: 14px; max-width: 440px; margin: 28px auto 0; text-align: left; }
.login-form > label { font-weight: 900; }
.login-code-field { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.login-code-field input { min-width: 0; border: 2px solid var(--ink); border-radius: 9px; padding: 11px; font-family: "DM Mono", monospace; }
.login-form > .primary-button { justify-self: center; }
.type-tabs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; margin: 22px 0 18px; }
.type-tabs input { position: absolute; opacity: 0; }
.type-tabs span { display: block; text-align: center; border: 2px solid var(--ink); border-radius: 999px; padding: 8px 4px; cursor: pointer; background: white; }
.type-tabs input:checked + span { background: var(--pink); box-shadow: 3px 3px 0 var(--ink); transform: translate(-2px, -2px); }
.upload-zone { min-height: 140px; border: 3px dashed var(--purple); display: grid; place-content: center; text-align: center; border-radius: 15px; cursor: pointer; background: #f0ebfa; }
.upload-zone input { position: absolute; opacity: 0; }
.upload-zone span { font-weight: 900; }
.upload-zone small { display: block; margin-top: 4px; }
.photo-preview { aspect-ratio: 5 / 3; overflow: hidden; margin-top: 14px; border: 2px solid var(--ink); }
.photo-preview img { width: 100%; height: 100%; object-fit: cover; display: block; }
.crop-controls { display: grid; gap: 5px; margin-top: 10px; font-size: .78rem; }
.crop-controls label { display: grid; grid-template-columns: 80px 1fr; align-items: center; }
textarea { width: 100%; resize: vertical; border: 2px solid var(--ink); background: #fff; border-radius: 9px; padding: 12px; }
.drawing-tools { display: flex; gap: 7px; flex-wrap: wrap; align-items: center; font-size: .75rem; margin-bottom: 9px; }
.drawing-tools label { display: flex; align-items: center; gap: 5px; }
.small-button { background: white; border: 2px solid var(--ink); border-radius: 7px; cursor: pointer; }
.small-button.active { background: var(--mint); }
.canvas-wrap { border: 2px solid var(--ink); line-height: 0; touch-action: none; }
canvas { width: 100%; height: auto; background: var(--paper); cursor: crosshair; }
.primary-button { display: inline-block; background: var(--pink-deep); border: var(--line); box-shadow: 4px 4px 0 var(--ink); padding: 11px 18px; border-radius: 9px; font-weight: 900; cursor: pointer; }
.primary-button:hover { transform: translate(2px, 2px); box-shadow: 2px 2px 0 var(--ink); }
.send-button { width: 100%; margin-top: 17px; }
.form-error { color: #9b173f; font-weight: 700; }
.toast { position: fixed; z-index: 5; top: 20px; left: 50%; transform: translateX(-50%); background: var(--mint); border: var(--line); box-shadow: 4px 4px 0 var(--ink); padding: 9px 18px; border-radius: 999px; }
.history-section { margin-top: 55px; }
.history-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
.history-item { margin: 0; background: white; padding: 8px 8px 4px; border: 2px solid var(--ink); transform: rotate(var(--tilt, -1deg)); box-shadow: 4px 5px 0 #5e586555; }
.history-item:nth-child(even) { --tilt: 1.2deg; }
.history-item img { width: 100%; aspect-ratio: 5/3; object-fit: cover; }
.history-item p { margin: 5px 2px; font: .68rem "DM Mono", monospace; }
footer { text-align: center; padding: 42px 0 22px; font: .72rem "DM Mono", monospace; }

@media (max-width: 820px) {
  .main-grid { grid-template-columns: 1fr; }
  .history-grid { grid-template-columns: repeat(2, 1fr); }
  .header-user > span { display: none; }
}
@media (max-width: 480px) {
  .page-shell { width: min(100% - 16px, 1180px); margin-top: 8px; }
  .site-header { box-shadow: 3px 4px 0 #3e3948; }
  .paper-card { padding: 18px; }
  .history-grid { grid-template-columns: 1fr 1fr; gap: 9px; }
  .section-heading { align-items: start; }
}

@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; } }
