@font-face { font-family: "Schibsted Grotesk"; font-weight: 500; font-display: swap; src: url("fonts/schibsted-grotesk-latin-500-normal.woff2") format("woff2"); }
@font-face { font-family: "Schibsted Grotesk"; font-weight: 700; font-display: swap; src: url("fonts/schibsted-grotesk-latin-700-normal.woff2") format("woff2"); }
@font-face { font-family: "IBM Plex Mono"; font-weight: 400; font-display: swap; src: url("fonts/ibm-plex-mono-latin-400-normal.woff2") format("woff2"); }
@font-face { font-family: "IBM Plex Mono"; font-weight: 500; font-display: swap; src: url("fonts/ibm-plex-mono-latin-500-normal.woff2") format("woff2"); }

:root {
  --table: #e6e9ed;      /* the light table the plate sits on */
  --table-dot: #c9ced6;
  --panel: #ffffff;
  --ink: #15171c;
  --muted: #5f6673;
  --line: #d6dae1;
  --cobalt: #2a3bd1;     /* actions */
  --cobalt-soft: #e8eafb;
  --reg: #d92d77;        /* registration marks: only around the plate */
  --display: "Schibsted Grotesk", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  --body: system-ui, -apple-system, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: var(--body); color: var(--ink); background: var(--table); font-size: 15px; line-height: 1.5; }
button, textarea, input { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--cobalt); outline-offset: 2px; }
[hidden] { display: none !important; }

.app { height: 100vh; height: 100dvh; display: grid; grid-template-columns: 216px minmax(0, 1fr) 392px; }

/* ---------- navigation ---------- */
.nav { background: var(--panel); border-right: 1px solid var(--line); padding: 20px 14px; overflow-y: auto; }
.nav-top { display: flex; align-items: center; justify-content: space-between; padding: 0 8px 20px; }
.wordmark { font-family: var(--display); font-weight: 700; font-size: 25px; letter-spacing: -.03em; color: var(--ink); text-decoration: none; }
.nav-label { margin: 0 8px 6px; font-family: var(--mono); font-size: 11.5px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.nav-group { margin: 14px 0 0; }
.nav-group h3 { margin: 0 8px 4px; font-size: 13px; font-weight: 600; color: var(--muted); }
.nav-item { display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px 10px; border: 0; border-radius: 8px; background: none; text-align: left; font-size: 15px; }
.nav-item:hover { background: #f1f3f6; }
.nav-item[aria-current="page"] { background: var(--cobalt-soft); color: var(--cobalt); font-weight: 600; }
.dot { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.nav .nav-close, .scrim, .bar .bar-mark, .bar .format-btn { display: none; }

/* ---------- stage ---------- */
.stage { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.bar { display: flex; align-items: center; gap: 12px; padding: 14px 20px; }
.format-title { margin: 0; font-family: var(--display); font-weight: 700; font-size: 22px; letter-spacing: -.02em; }
.bar-tools { margin-left: auto; display: flex; align-items: center; gap: 4px; }
.icon-btn { display: inline-flex; align-items: center; justify-content: center; width: 38px; height: 38px; border: 0; border-radius: 9px; background: none; color: var(--ink); }
.icon-btn:hover:not(:disabled) { background: rgba(21,23,28,.07); }
.icon-btn:disabled { opacity: .32; cursor: default; }
.primary-btn { display: inline-flex; align-items: center; gap: 7px; height: 40px; margin-left: 8px; padding: 0 16px; border: 0; border-radius: 10px; background: var(--cobalt); color: #fff; font-weight: 600; }
.primary-btn:hover:not(:disabled) { background: #2231b8; }
.primary-btn:disabled { opacity: .6; cursor: progress; }

.table {
  flex: 1; min-height: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; padding: 18px 28px 22px;
  background-image: radial-gradient(var(--table-dot) 1px, transparent 1.2px); background-size: 18px 18px;
}
.plate { position: relative; padding: 22px; }
.plate-inner { box-shadow: 0 1px 2px rgba(20,24,40,.12), 0 18px 48px -18px rgba(20,24,40,.35); border-radius: 4px; overflow: hidden; background: #fff; }
.canvas-scale { transform-origin: 0 0; }
.crop { position: absolute; width: 16px; height: 16px; }
.crop::before, .crop::after { content: ""; position: absolute; background: var(--reg); }
.crop::before { width: 16px; height: 1.5px; } .crop::after { width: 1.5px; height: 16px; }
.crop.tl { left: 0; top: 0; } .crop.tl::before { top: 22px; } .crop.tl::after { left: 22px; }
.crop.tr { right: 0; top: 0; } .crop.tr::before { top: 22px; right: 0; } .crop.tr::after { right: 22px; }
.crop.bl { left: 0; bottom: 0; } .crop.bl::before { bottom: 22px; } .crop.bl::after { left: 22px; bottom: 0; }
.crop.br { right: 0; bottom: 0; } .crop.br::before { bottom: 22px; right: 0; } .crop.br::after { right: 22px; bottom: 0; }
.size-note { margin: 0; font-family: var(--mono); font-size: 12px; color: var(--muted); letter-spacing: .02em; }

/* ---------- assistant ---------- */
.assistant { display: flex; flex-direction: column; min-height: 0; background: var(--panel); border-left: 1px solid var(--line); }
.assistant-title { margin: 0; padding: 18px 20px 10px; font-family: var(--display); font-size: 17px; font-weight: 700; }
.log { flex: 1; min-height: 0; overflow-y: auto; padding: 6px 20px 16px; display: flex; flex-direction: column; gap: 12px; }
.intro { color: var(--muted); font-size: 14.5px; margin: 0; }
.try { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; }
.try p { margin: 6px 0 2px; font-family: var(--mono); font-size: 11.5px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.try button { border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 6px 12px; font-size: 14px; text-align: left; }
.try button:hover { border-color: var(--cobalt); color: var(--cobalt); }
.msg { max-width: 92%; font-size: 14.5px; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.user { align-self: flex-end; background: var(--ink); color: #fff; padding: 8px 12px; border-radius: 14px 14px 4px 14px; }
.msg.user img { display: block; max-width: 140px; max-height: 180px; border-radius: 8px; margin-bottom: 6px; }
.msg.user img:only-child { margin-bottom: 0; }
.msg.assistant { align-self: flex-start; padding-left: 12px; border-left: 2px solid var(--cobalt); }
.msg.error { align-self: flex-start; padding: 8px 12px; border-radius: 10px; background: #fdecef; color: #8f1d3c; }
.msg.working { align-self: flex-start; color: var(--muted); padding-left: 12px; border-left: 2px solid var(--line); }
.msg.working::after { content: ""; display: inline-block; width: 1.2em; text-align: left; animation: dots 1.2s steps(4) infinite; }
@keyframes dots { 0% { content: ""; } 25% { content: "."; } 50% { content: ".."; } 75% { content: "..."; } }

.composer { padding: 10px 14px 12px; border-top: 1px solid var(--line); }
.attachment { position: relative; display: inline-block; margin: 0 0 8px 4px; }
.attachment img { display: block; height: 64px; border-radius: 8px; border: 1px solid var(--line); }
.attachment-x { position: absolute; top: -8px; right: -8px; width: 24px; height: 24px; border-radius: 50%; border: 0; background: var(--ink); color: #fff; display: flex; align-items: center; justify-content: center; }
.composer-row { display: flex; align-items: flex-end; gap: 6px; border: 1px solid var(--line); border-radius: 14px; padding: 5px; background: #fff; }
.composer-row:focus-within { border-color: var(--cobalt); }
.composer textarea { flex: 1; min-height: 38px; max-height: 160px; border: 0; outline: none; resize: none; padding: 8px 4px; font-size: 15px; line-height: 1.45; background: none; }
.send-btn { width: 38px; height: 38px; border: 0; border-radius: 10px; background: var(--cobalt); color: #fff; display: flex; align-items: center; justify-content: center; flex: none; }
.send-btn:disabled { background: #b9bfe9; cursor: default; }
.composer-hint { margin: 6px 4px 0; font-size: 12px; color: var(--muted); }

.drop { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; background: rgba(42,59,209,.12); border: 3px dashed var(--cobalt); font-size: 18px; font-weight: 600; color: var(--cobalt); pointer-events: none; }

/* ---------- saving on a phone ---------- */
.save { width: min(420px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); padding: 14px 16px 16px; border: 0; border-radius: 16px; background: var(--panel); color: var(--ink); box-shadow: 0 24px 64px -16px rgba(20,24,40,.45); }
.save::backdrop { background: rgba(21,23,28,.5); }
.save[open] { display: flex; flex-direction: column; align-items: stretch; gap: 10px; }
.save-head { display: flex; align-items: center; justify-content: space-between; }
.save-head h2 { margin: 0; font-size: 17px; font-weight: 700; }
.save-img { display: block; align-self: center; max-width: 100%; max-height: 52dvh; object-fit: contain; border-radius: 8px; border: 1px solid var(--line); -webkit-touch-callout: default; }
.save-hint { margin: 0; font-size: 13.5px; color: var(--muted); }
.save .save-share { margin: 0; justify-content: center; height: 46px; font-size: 16px; }
.text-btn { border: 0; background: none; color: var(--cobalt); font-weight: 600; padding: 8px; }

/* ---------- narrower screens ---------- */
@media (max-width: 1180px) { .app { grid-template-columns: 196px minmax(0, 1fr) 340px; } }

@media (max-width: 900px) {
  .app { display: block; height: auto; min-height: 100dvh; }
  .nav { position: fixed; z-index: 40; inset: 0 auto 0 0; width: min(300px, 84vw); transform: translateX(-102%); transition: transform .22s ease; }
  .nav { visibility: hidden; }
  .app.nav-open .nav { transform: none; visibility: visible; }
  .nav .nav-close { display: inline-flex; }
  .app.nav-open .scrim { display: block; position: fixed; inset: 0; z-index: 30; background: rgba(21,23,28,.35); }
  .bar { position: sticky; top: 0; z-index: 10; padding: 10px 12px; gap: 8px; background: var(--panel); border-bottom: 1px solid var(--line); }
  .bar .bar-mark { display: block; font-size: 21px; }
  .bar .format-btn { display: inline-flex; align-items: center; gap: 7px; height: 36px; padding: 0 12px; border: 1px solid var(--line); border-radius: 999px; background: #fff; font-weight: 600; font-size: 14px; }
  .format-title { display: none; }
  .bar-tools { gap: 0; }
  .bar-tools .icon-btn { width: 34px; }
  .primary-btn { margin-left: 4px; padding: 0 12px; }
  .primary-btn span { display: none; }
  .table { height: 62vh; height: 62svh; flex: none; padding: 10px 12px 12px; gap: 8px; }
  .plate { padding: 16px; }
  .crop.tl::before, .crop.tr::before { top: 16px; } .crop.bl::before, .crop.br::before { bottom: 16px; }
  .crop.tl::after, .crop.bl::after { left: 16px; } .crop.tr::after, .crop.br::after { right: 16px; }
  .assistant { border-left: 0; border-top: 1px solid var(--line); min-height: 38vh; }
  .log { overflow: visible; }
  .composer { position: sticky; bottom: 0; background: var(--panel); padding-bottom: calc(12px + env(safe-area-inset-bottom)); }
  .composer-hint { display: none; }
}
@media (max-width: 380px) { .bar .bar-mark { display: none; } }

@media (prefers-reduced-motion: reduce) {
  .nav { transition: none; }
  .msg.working::after { animation: none; content: "…"; }
}
