:root {
  --paper: #f3ecda;
  --card: #fff9e9;
  --ink: #1d1b19;
  --red: #b52b24;
  --yellow: #dda41c;
  --green: #326b4f;
  --muted: #756f64;
  --line: #1d1b19;
  --shadow: 8px 8px 0 #1d1b19;
}

* { box-sizing: border-box; }
html { background: var(--paper); -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at 8% 9%, rgba(221,164,28,.16) 0 70px, transparent 71px),
    var(--paper);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC", sans-serif;
}
button, input, textarea { font: inherit; }
button { cursor: pointer; }

.app-header {
  min-height: 84px;
  padding: calc(16px + env(safe-area-inset-top)) max(20px, env(safe-area-inset-right)) 14px max(20px, env(safe-area-inset-left));
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  border-bottom: 2px solid var(--ink);
}
.eyebrow { margin: 0 0 2px; color: var(--red); font-size: 11px; font-weight: 900; letter-spacing: .16em; }
h1, h2 { margin: 0; line-height: 1; }
h1 { font-size: 30px; letter-spacing: -.04em; }
h2 { font-size: 20px; letter-spacing: -.02em; }

.icon-button, .text-button, .close-button {
  border: 0;
  background: transparent;
  color: var(--ink);
  font-weight: 800;
}
.icon-button { display: flex; align-items: center; gap: 7px; min-height: 44px; padding: 8px 0 8px 12px; }
.icon-button span:first-child { display: grid; place-items: center; width: 28px; height: 28px; color: var(--card); background: var(--green); border: 2px solid var(--ink); border-radius: 7px; }
.text-button { min-height: 44px; color: var(--red); }

.app-shell { width: min(1120px, 100%); margin: 0 auto; padding: 22px 18px calc(36px + env(safe-area-inset-bottom)); display: grid; gap: 26px; }
.editor-panel, .preview-panel { min-width: 0; }
.section-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; }
.section-heading > div { display: flex; align-items: center; gap: 10px; }
.step { display: grid; place-items: center; width: 32px; height: 32px; border: 2px solid var(--ink); border-radius: 50%; color: var(--card); background: var(--red); font: 900 11px/1 monospace; }

label { display: block; margin: 0 0 8px; font-size: 14px; font-weight: 850; }
.label-row { display: flex; align-items: center; justify-content: space-between; margin-top: 18px; }
.label-row label { margin: 0 0 8px; }
#charCount { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
input, textarea {
  width: 100%;
  border: 2px solid var(--ink);
  border-radius: 14px;
  background: var(--card);
  color: var(--ink);
  font-size: 16px;
  outline: none;
  box-shadow: 4px 4px 0 var(--ink);
  transition: transform .15s, box-shadow .15s;
}
input { height: 52px; padding: 0 14px; }
textarea { min-height: 210px; padding: 14px; resize: vertical; line-height: 1.65; }
input:focus, textarea:focus { transform: translate(-2px,-2px); box-shadow: 6px 6px 0 var(--ink); border-color: var(--red); }
.fit-warning { margin: 12px 0 0; color: var(--red); font-size: 13px; font-weight: 800; }
.button-row { display: grid; grid-template-columns: 1fr 1.25fr; gap: 12px; margin-top: 20px; }
.primary-button, .secondary-button {
  min-height: 52px;
  border: 2px solid var(--ink);
  border-radius: 14px;
  font-weight: 900;
  box-shadow: 4px 4px 0 var(--ink);
}
.primary-button { color: var(--card); background: var(--red); }
.secondary-button { color: var(--ink); background: var(--yellow); }
button:active { transform: translate(3px,3px); box-shadow: 1px 1px 0 var(--ink); }
button:disabled { opacity: .45; cursor: not-allowed; }
.status-message { min-height: 21px; margin: 12px 0 0; color: var(--green); font-size: 13px; font-weight: 750; }

.size-badge { padding: 7px 9px; border: 1.5px solid var(--ink); border-radius: 99px; background: var(--card); font: 700 10px/1 monospace; white-space: nowrap; }
.canvas-frame { width: min(100%, 396px); margin: 0 auto; padding: 10px; border: 2px solid var(--ink); border-radius: 22px; background: var(--green); box-shadow: var(--shadow); }
canvas { display: block; width: 100%; height: auto; border-radius: 13px; background: var(--paper); }
.palette-note { margin: 18px auto 0; width: min(100%, 396px); color: var(--muted); font-size: 12px; text-align: center; }
.palette-note span { display: inline-block; width: 8px; height: 8px; margin-right: 6px; border-radius: 50%; background: var(--green); }

.history-drawer { position: fixed; inset: 0; z-index: 20; visibility: hidden; pointer-events: none; }
.history-drawer.open { visibility: visible; pointer-events: auto; }
.drawer-backdrop { position: absolute; inset: 0; background: rgba(29,27,25,.38); opacity: 0; transition: opacity .2s; }
.open .drawer-backdrop { opacity: 1; }
.drawer-sheet { position: absolute; inset: auto 0 0; max-height: 82vh; padding: 22px 18px calc(24px + env(safe-area-inset-bottom)); border: 2px solid var(--ink); border-bottom: 0; border-radius: 24px 24px 0 0; background: var(--paper); transform: translateY(105%); transition: transform .25s ease; overflow: auto; }
.open .drawer-sheet { transform: translateY(0); }
.drawer-header { position: sticky; top: -22px; z-index: 1; display: flex; justify-content: space-between; align-items: center; margin: -22px -18px 16px; padding: 22px 18px 14px; background: var(--paper); border-bottom: 2px solid var(--ink); }
.close-button { width: 44px; height: 44px; font-size: 30px; }
.history-list { display: grid; gap: 12px; }
.history-card { padding: 15px; border: 2px solid var(--ink); border-radius: 15px; background: var(--card); box-shadow: 3px 3px 0 var(--ink); }
.history-card h3 { margin: 0 0 7px; font-size: 17px; }
.history-card p { display: -webkit-box; margin: 0; color: var(--muted); font-size: 13px; line-height: 1.5; overflow: hidden; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.history-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; }
.history-actions button { min-height: 36px; padding: 0 12px; border: 1.5px solid var(--ink); border-radius: 9px; background: var(--paper); font-weight: 800; }
.history-actions .delete { color: var(--red); }
.empty-state { padding: 46px 20px; color: var(--muted); text-align: center; }

@media (min-width: 820px) {
  .app-header { padding-left: max(32px, calc((100vw - 1120px)/2)); padding-right: max(32px, calc((100vw - 1120px)/2)); }
  .app-shell { grid-template-columns: minmax(0, 1fr) minmax(380px, .86fr); align-items: start; padding-top: 34px; }
  .editor-panel { position: sticky; top: 24px; }
  .drawer-sheet { inset: 0 0 0 auto; width: 420px; max-height: none; border: 0 0 0 2px; border-radius: 0; transform: translateX(105%); }
  .open .drawer-sheet { transform: translateX(0); }
}

@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
