/* Lauregram — "Old Fashioned": a brass typewriter in sage, amber and creamsicle.
   Colors are tokens; the owner's chosen theme overrides them from the server. */

@font-face {
  font-family: "Courier Prime";
  src: url("/fonts/courier-prime-400.woff2") format("woff2");
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: "Courier Prime";
  src: url("/fonts/courier-prime-700.woff2") format("woff2");
  font-weight: 700;
  font-display: swap;
}

:root {
  --bg: #f4ecd8;
  --paper: #fbf6e6;
  --ink: #3a2e20;
  --muted: #7a6a52;
  --sage: #7f9b82;
  --sage-dark: #56705a;
  --amber: #e2a62a;
  --amber-dark: #b8801a;
  --creamsicle: #f2955a;
  --line: #d8c9a6;
  --danger: #a4452c;
  --radius: 10px;
  --gutter: 16px;
  --font: "Courier Prime", "Courier New", ui-monospace, monospace;
  color-scheme: light;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 17px;
  line-height: 1.45;
  min-height: 100vh;
  min-height: 100dvh;
}

button, input, textarea, select { font: inherit; color: inherit; }

.wrap {
  max-width: 560px;
  margin: 0 auto;
  padding: calc(var(--gutter) + env(safe-area-inset-top)) var(--gutter) calc(96px + env(safe-area-inset-bottom));
}

.hidden { display: none !important; }
.sr-only {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

/* ---- header ---- */
.top {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  margin-bottom: 18px;
}
.brand {
  font-size: 1.5rem; font-weight: 700; letter-spacing: .28em; margin: 0;
  text-transform: uppercase;
}
.brand small { display: block; font-size: .68rem; letter-spacing: .12em; font-weight: 400; color: var(--muted); text-transform: none; }

.pill {
  display: inline-flex; align-items: center; gap: 7px;
  border: 1.5px solid var(--line); border-radius: 999px;
  padding: 4px 12px; font-size: .82rem; background: var(--paper); white-space: nowrap;
}
.pill::before { content: ""; width: 9px; height: 9px; border-radius: 50%; background: var(--muted); }
.pill.online::before { background: var(--sage-dark); }
.pill.resting::before { background: var(--amber); }
.pill.problem::before, .pill.offline::before { background: var(--creamsicle); }

/* ---- paper cards ---- */
.card {
  background: var(--paper);
  border: 1.5px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 14px;
  box-shadow: 0 1px 0 rgba(58,46,32,.06), 0 6px 14px -10px rgba(58,46,32,.35);
}
.card h2 { margin: 0 0 10px; font-size: 1.05rem; letter-spacing: .08em; text-transform: uppercase; }
.card h3 { margin: 0 0 6px; font-size: 1rem; }
.rule { border: 0; border-top: 1.5px dashed var(--line); margin: 12px 0; }
.muted { color: var(--muted); font-size: .88rem; }
.error { color: var(--danger); margin: 8px 0 0; font-size: .92rem; }

/* ---- form controls ---- */
textarea, input[type="text"], input[type="time"], select {
  width: 100%;
  background: #fffdf5;
  border: 1.5px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  min-height: 44px;
}
textarea { min-height: 104px; resize: vertical; }
textarea:focus, input:focus, select:focus { outline: 3px solid color-mix(in srgb, var(--amber) 55%, transparent); outline-offset: 1px; border-color: var(--amber-dark); }

.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.row.spread { justify-content: space-between; }
.grow { flex: 1 1 auto; }

/* Brass typewriter keys */
.key {
  appearance: none; cursor: pointer;
  min-height: 44px; padding: 8px 16px;
  border-radius: 9px;
  border: 1.5px solid var(--amber-dark);
  background: linear-gradient(#f0c15a, var(--amber));
  color: #3a2a0d; font-weight: 700; letter-spacing: .04em;
  box-shadow: 0 3px 0 var(--amber-dark), 0 5px 8px -4px rgba(58,46,32,.5), inset 0 1px 0 rgba(255,255,255,.55);
  transition: transform .06s ease, box-shadow .06s ease;
}
.key:active:not(:disabled) { transform: translateY(2px); box-shadow: 0 1px 0 var(--amber-dark), inset 0 1px 0 rgba(255,255,255,.4); }
.key:disabled { opacity: .55; cursor: not-allowed; }
.key:focus-visible, .tab:focus-visible, .chip:focus-visible, .react:focus-visible, .link:focus-visible {
  outline: 3px solid var(--sage-dark); outline-offset: 2px;
}
.key.send { background: linear-gradient(#f7ad78, var(--creamsicle)); border-color: #c2652a; box-shadow: 0 3px 0 #c2652a, 0 5px 8px -4px rgba(58,46,32,.5), inset 0 1px 0 rgba(255,255,255,.5); }
.key.send:active:not(:disabled) { box-shadow: 0 1px 0 #c2652a; }
.key.quiet { background: linear-gradient(#a8bfaa, var(--sage)); border-color: var(--sage-dark); color: #1f3223; box-shadow: 0 3px 0 var(--sage-dark), inset 0 1px 0 rgba(255,255,255,.4); }
.key.quiet:active:not(:disabled) { box-shadow: 0 1px 0 var(--sage-dark); }
.key.plain { background: var(--paper); border-color: var(--line); color: var(--ink); box-shadow: 0 2px 0 var(--line); font-weight: 400; }
.key.danger { color: var(--danger); }
.key.small { min-height: 36px; padding: 4px 12px; font-size: .9rem; }

.link { background: none; border: 0; padding: 4px 2px; cursor: pointer; color: var(--sage-dark); text-decoration: underline; min-height: 36px; }
.link.danger { color: var(--danger); }

/* ---- compose ---- */
.attach {
  position: relative; margin-top: 10px; border: 1.5px dashed var(--line); border-radius: 8px;
  padding: 8px; background: #fffdf5; display: flex; align-items: center; gap: 12px;
}
.attach img { max-height: 120px; max-width: 45%; border-radius: 4px; object-fit: contain; background: #fff; }
.attach .what { flex: 1; font-size: .9rem; color: var(--muted); }

.pad { margin-top: 10px; }
.pad canvas {
  display: block; width: 100%; aspect-ratio: 576 / 400; background: #fff;
  border: 1.5px solid var(--line); border-radius: 8px; touch-action: none; cursor: crosshair;
}
.pad .tools { margin-top: 8px; }
.size-dot { width: 44px; padding: 0; display: inline-flex; align-items: center; justify-content: center; }
.size-dot i { display: block; background: var(--ink); border-radius: 50%; }
.size-dot[aria-pressed="true"] { outline: 3px solid var(--sage-dark); outline-offset: 1px; }

/* ---- messages ---- */
.msg-head { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; margin-bottom: 6px; }
.msg-from { font-weight: 700; letter-spacing: .06em; text-transform: uppercase; font-size: .9rem; }
.msg-time { color: var(--muted); font-size: .82rem; white-space: nowrap; }
.msg-body { white-space: pre-wrap; overflow-wrap: anywhere; margin: 0 0 8px; }
.msg-img { display: block; max-width: 100%; max-height: 320px; border-radius: 6px; border: 1.5px solid var(--line); margin: 0 0 8px; background: #fff; }
.paper-wrap { margin: 0 0 8px; }
.paper-img { display: block; width: 100%; max-width: 340px; margin: 6px 0 8px; background: #fff; border: 1.5px solid var(--line); box-shadow: 0 2px 6px rgba(0,0,0,.15); }
.msg-img { cursor: zoom-in; }
.hdr-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 8px 0; }
.hdr-grid label { display: block; font-size: .85rem; color: var(--muted); }
.hdr-grid input, .hdr-grid select { width: 100%; }
.presets { display: flex; gap: 6px; flex-wrap: wrap; margin: 6px 0; }
.hdr-preview { display: block; width: 100%; max-width: 340px; margin: 10px auto; background: #fff; border: 1.5px solid var(--line); box-shadow: 0 2px 6px rgba(0,0,0,.15); }
.msg-foot { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }

.badge {
  display: inline-block; font-size: .8rem; padding: 2px 10px; border-radius: 6px; border: 1.5px solid var(--line);
  background: var(--bg); color: var(--muted);
}
.badge.printing { background: color-mix(in srgb, var(--amber) 30%, var(--paper)); border-color: var(--amber-dark); color: #5b3f08; }
.badge.printed { background: color-mix(in srgb, var(--sage) 28%, var(--paper)); border-color: var(--sage-dark); color: #25402a; }
.badge.problem { background: color-mix(in srgb, var(--creamsicle) 30%, var(--paper)); border-color: #c2652a; color: #6a2f0b; }
.badge.failed { background: #f3d9d0; border-color: var(--danger); color: var(--danger); }

.reaction-chip { font-size: 1.5rem; line-height: 1; }
.reacts { display: flex; gap: 4px; flex-wrap: wrap; }
.react {
  min-width: 44px; min-height: 44px; font-size: 1.35rem; background: var(--bg);
  border: 1.5px solid var(--line); border-radius: 999px; cursor: pointer;
}
.react[aria-pressed="true"] { background: color-mix(in srgb, var(--amber) 35%, var(--paper)); border-color: var(--amber-dark); }

.empty { text-align: center; color: var(--muted); padding: 22px 8px; }

/* ---- owner chrome ---- */
.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 8px; margin-bottom: 8px; scrollbar-width: thin; }
.chip {
  flex: 0 0 auto; min-height: 36px; padding: 4px 14px; border-radius: 999px; cursor: pointer;
  border: 1.5px solid var(--line); background: var(--paper);
}
.chips.nets { flex-wrap: wrap; overflow-x: visible; }
.chip[aria-selected="true"], .chip[aria-pressed="true"] { background: var(--sage); border-color: var(--sage-dark); color: #15261a; font-weight: 700; }

.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--paper); border-top: 1.5px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tab { min-height: 58px; border: 0; background: none; cursor: pointer; font-size: .82rem; letter-spacing: .06em; text-transform: uppercase; position: relative; }
.tab[aria-current="page"] { color: var(--sage-dark); font-weight: 700; }
.tab[aria-current="page"]::before { content: ""; position: absolute; top: 0; left: 24%; right: 24%; height: 4px; border-radius: 0 0 4px 4px; background: var(--amber); }
.tab .dot { display: inline-block; min-width: 18px; padding: 0 5px; margin-left: 4px; border-radius: 9px; background: var(--creamsicle); color: #fff; font-size: .72rem; }

.switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 48px; }
.switch input { flex: 0 0 26px; width: 26px; height: 26px; accent-color: var(--sage-dark); }

.invite-box { word-break: break-all; background: #fffdf5; border: 1.5px dashed var(--amber-dark); border-radius: 8px; padding: 10px; font-size: .88rem; margin: 8px 0; }

.person { display: flex; justify-content: space-between; gap: 10px; align-items: center; padding: 10px 0; border-top: 1.5px dashed var(--line); }
.person:first-of-type { border-top: 0; }

/* ---- preview overlay ---- */
.overlay {
  position: fixed; inset: 0; z-index: 20; background: rgba(40,30,18,.62);
  display: flex; flex-direction: column; align-items: center; padding: 16px; overflow-y: auto;
}
.overlay .sheet {
  background: var(--paper); border-radius: var(--radius); padding: 14px; width: min(100%, 420px); margin: auto;
}
.overlay .receipt {
  display: block; width: 100%; image-rendering: auto; background: #fff;
  border: 1px solid var(--line); box-shadow: 0 8px 18px -10px rgba(0,0,0,.6);
}

/* ---- toasts ---- */
#toasts { position: fixed; left: 0; right: 0; bottom: calc(76px + env(safe-area-inset-bottom)); z-index: 30; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; padding: 0 var(--gutter); }
.toast { background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 9px; font-size: .92rem; box-shadow: 0 6px 16px -6px rgba(0,0,0,.5); animation: rise .18s ease-out; max-width: 100%; }
.toast.bad { background: var(--danger); color: #fff; }
@keyframes rise { from { transform: translateY(8px); opacity: 0; } }

.welcome { text-align: center; padding-top: 12vh; }
.welcome .brand { font-size: 1.8rem; }
.noscript { padding: 20px; }

@media (prefers-reduced-motion: reduce) {
  .key, .toast { transition: none; animation: none; }
}
