@import url("https://fonts.googleapis.com/css2?family=Fraunces:opsz,wght@9..144,500;9..144,700&family=Inter:wght@400;500;600&family=Caveat:wght@500&family=Dancing+Script:wght@500&family=Homemade+Apple&display=swap");

:root {
  color-scheme: light;
  --bg: #f4efe6;
  --fg: #14213d;
  --muted: #6b6a75;
  --accent: #c2410c;
  --border: #e2d9c8;
  --radius: 12px;
  --font: "Inter", system-ui, sans-serif;
  --paper: #fffdf8;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--fg); font-family: var(--font); }
button { font: inherit; cursor: pointer; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.stack { display: flex; flex-direction: column; gap: 0.75rem; }

.topbar { display: flex; align-items: center; gap: 1rem; padding: 0.9rem 1.5rem; background: var(--fg); color: #f4efe6; flex-wrap: wrap; }
.brand { font-family: "Fraunces", serif; font-weight: 700; font-size: 1.4rem; letter-spacing: -0.01em; }
.brand::before { content: "✒ "; color: #fb923c; }
.fname { flex: 1; min-width: 0; opacity: 0.75; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar .btn.ghost { color: #f4efe6; border-color: rgba(255,255,255,0.3); background: transparent; }

.btn { border-radius: 999px; padding: 0.7rem 1.3rem; border: 1px solid var(--border); background: var(--paper); color: var(--fg); font-weight: 600; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; width: 100%; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.link { background: none; border: none; color: var(--accent); font-weight: 600; }
.input { width: 100%; padding: 0.7rem 0.9rem; border: 1px solid var(--border); border-radius: 10px; background: #fff; font: inherit; color: var(--fg); }
.alert { padding: 0.75rem 1rem; border-radius: 10px; margin-top: 1rem; }
.alert-error { background: #fde8e4; color: #9a1f0b; border: 1px solid #f5c2b8; }

.landing { min-height: 100vh; }
.hero { max-width: 76rem; margin: 0 auto; padding: 4rem 1.5rem; display: grid; gap: 3rem; align-items: center; }
@media (min-width: 860px) { .hero { grid-template-columns: 1.1fr 1fr; padding-top: 6rem; } }
.hero h1 { font-family: "Fraunces", serif; font-size: clamp(2.4rem, 5vw, 4rem); line-height: 1.05; margin: 0 0 1rem; letter-spacing: -0.02em; }
.hero p { font-size: 1.15rem; line-height: 1.6; color: var(--muted); max-width: 34rem; }
.steps { list-style: none; padding: 0; margin: 2rem 0 0; display: flex; flex-wrap: wrap; gap: 0.6rem; }
.steps li { background: var(--paper); border: 1px solid var(--border); border-radius: 999px; padding: 0.5rem 1rem 0.5rem 0.5rem; display: flex; gap: 0.6rem; align-items: center; font-weight: 500; }
.steps b { background: var(--fg); color: #fff; width: 1.6rem; height: 1.6rem; border-radius: 50%; display: grid; place-items: center; font-size: 0.8rem; }
.drop { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0.5rem; min-height: 320px; padding: 2rem;
  background: var(--paper); border: 2px dashed #d4c4a6; border-radius: 24px; cursor: pointer; color: var(--accent); text-align: center;
  box-shadow: 0 20px 50px -30px rgba(20,33,61,0.4); transition: 0.15s; }
.drop:hover, .drop.over { border-color: var(--accent); transform: translateY(-2px); }
.drop input { display: none; }
.drop-title { font-family: "Fraunces", serif; font-size: 1.5rem; color: var(--fg); }
.drop-sub { color: var(--muted); }

.layout { display: grid; gap: 1.5rem; padding: 1.5rem; max-width: 80rem; margin: 0 auto; }
@media (min-width: 900px) { .layout { grid-template-columns: 320px 1fr; align-items: start; } .panel { position: sticky; top: 1.5rem; } }
.panel { background: var(--paper); border: 1px solid var(--border); border-radius: 18px; padding: 1.25rem; display: flex; flex-direction: column; gap: 1.4rem; }
.panel h2 { font-family: "Fraunces", serif; font-size: 1.1rem; margin: 0 0 0.6rem; }
.panel p { margin: 0 0 0.6rem; line-height: 1.5; }
.sig-preview { background: #fff; border: 1px solid var(--border); border-radius: 10px; padding: 0.75rem; margin-bottom: 0.6rem; display: grid; place-items: center; }
.sig-preview img { max-width: 100%; max-height: 70px; }
.tools { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-bottom: 0.6rem; }
.tool { flex: 1; padding: 0.65rem 0.8rem; border-radius: 10px; border: 1px solid var(--border); background: #fff; color: var(--fg); font-weight: 500; white-space: nowrap; }
.tool.on { background: var(--fg); color: #fff; border-color: var(--fg); }
.tool:disabled { opacity: 0.45; cursor: not-allowed; }
.field { display: flex; flex-direction: column; gap: 0.5rem; }
.hint { background: #ffedd5; color: #9a3412; padding: 0.6rem 0.8rem; border-radius: 10px; font-weight: 500; margin-top: 0.6rem !important; }
.dl { border-top: 1px solid var(--border); padding-top: 1.2rem; }
.dl .muted { text-align: center; margin-top: 0.5rem; }

.pages { display: flex; flex-direction: column; gap: 1.5rem; align-items: center; min-width: 0; }
.page-block { width: 100%; max-width: 820px; }
.page-label { font-size: 0.8rem; color: var(--muted); margin-bottom: 0.4rem; font-weight: 500; }
.page { position: relative; width: 100%; background: #fff; box-shadow: 0 10px 30px -12px rgba(20,33,61,0.35); border-radius: 4px; overflow: hidden; touch-action: none; }
.page.armed { cursor: crosshair; outline: 2px dashed var(--accent); }
.page canvas { display: block; width: 100%; height: 100%; }
.stamp { position: absolute; cursor: move; touch-action: none; }
.stamp img { width: 100%; height: 100%; display: block; pointer-events: none; user-select: none; }
.stamp.sel { outline: 2px solid var(--accent); outline-offset: 2px; }
.stamp-del { position: absolute; top: -14px; right: -14px; width: 26px; height: 26px; border-radius: 50%; border: none; background: var(--accent); color: #fff; line-height: 1; font-size: 1.1rem; }
.stamp-resize { position: absolute; right: -8px; bottom: -8px; width: 16px; height: 16px; background: #fff; border: 2px solid var(--accent); border-radius: 4px; cursor: nwse-resize; }

.modal-bg { position: fixed; inset: 0; background: rgba(20,33,61,0.55); display: grid; place-items: center; padding: 1rem; z-index: 10; }
.modal { background: var(--paper); border-radius: 20px; padding: 1.5rem; width: 100%; max-width: 640px; display: flex; flex-direction: column; gap: 1rem; }
.modal h2 { font-family: "Fraunces", serif; margin: 0; }
.tabs { display: flex; background: var(--bg); border-radius: 999px; padding: 4px; width: fit-content; }
.tabs button { border: none; background: none; padding: 0.45rem 1.2rem; border-radius: 999px; color: var(--fg); font-weight: 500; }
.tabs button.on { background: var(--fg); color: #fff; }
.pad-wrap { position: relative; }
.pad { width: 100%; aspect-ratio: 3 / 1; background: #fff; border: 1px solid var(--border); border-radius: 12px; touch-action: none; cursor: crosshair; display: block; }
.pad-line { position: absolute; left: 8%; right: 8%; bottom: 22%; border-top: 1px solid #d6cfc2; font-size: 0.75rem; color: var(--muted); padding-top: 4px; pointer-events: none; }
.pad-wrap .link { position: absolute; top: 8px; right: 10px; }
.font-list { display: grid; gap: 0.5rem; }
.font-opt { background: #fff; border: 1px solid var(--border); border-radius: 10px; padding: 0.6rem 1rem; font-size: 2rem; text-align: left; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.font-opt.on { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent) inset; }
.inks { display: flex; align-items: center; gap: 0.6rem; }
.ink { width: 26px; height: 26px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 0 0 1px var(--border); }
.ink.on { box-shadow: 0 0 0 2px var(--accent); }
.modal-actions { display: flex; gap: 0.6rem; justify-content: flex-end; flex-wrap: wrap; }
.modal-actions .btn.primary { width: auto; }

.loading { display: flex; justify-content: center; padding: 2rem; }
.spinner { width: 24px; height: 24px; border: 3px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.skeleton { background: var(--border); border-radius: 8px; }
.empty { text-align: center; padding: 2rem; color: var(--muted); }
.empty-title { font-weight: 600; color: var(--fg); }
.badge { display: inline-block; padding: 0.2rem 0.6rem; border-radius: 999px; background: var(--bg); font-size: 0.8rem; }
.list { list-style: none; padding: 0; margin: 0; }
.list-item { padding: 0.75rem 0; border-bottom: 1px solid var(--border); }
.shell { max-width: 76rem; margin: 0 auto; padding: 1.5rem; }
.card { background: var(--paper); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; }
.row { display: flex; gap: 0.75rem; flex-wrap: wrap; }
.grid { display: grid; gap: 1rem; }
.table { width: 100%; border-collapse: collapse; }
