:root {
  --build: "6af9f483";
  --paper: #f6f3ec;
  --card: #fffdf8;
  --ink: #1d1a16;
  --muted: #6d675c;
  --line: #e2dccf;
  --accent: #c4372b;
  --focus: #1b5fd1;
  --radius: 20px;
  --shadow: 0 1px 2px rgba(40, 30, 10, 0.05), 0 8px 24px rgba(40, 30, 10, 0.06);
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --bar-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: calc(var(--bar-h) + 12px); }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 16px/1.5 var(--sans);
  overscroll-behavior-y: none;
}
button, select, input[type="range"], summary { touch-action: manipulation; }
button { font-family: inherit; color: inherit; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
svg:not(.keep) { flex: none; }
button svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ------------------------------------------------------------ app bar */
.appbar {
  position: sticky;
  top: 0;
  z-index: 15;
  padding-top: env(safe-area-inset-top, 0px);
  background: rgba(246, 243, 236, 0.86);
  -webkit-backdrop-filter: saturate(1.4) blur(14px);
  backdrop-filter: saturate(1.4) blur(14px);
  border-bottom: 1px solid var(--line);
}
.appbar-in {
  max-width: 1120px;
  margin: 0 auto;
  min-height: var(--bar-h);
  padding: 8px max(16px, env(safe-area-inset-right, 0px)) 8px max(16px, env(safe-area-inset-left, 0px));
  display: flex;
  align-items: center;
  gap: 12px;
}
.logo { border-radius: 9px; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2); }
.brand { min-width: 0; flex: 1; }
h1 { margin: 0; font: 700 19px/1.15 var(--sans); letter-spacing: -0.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tagline { margin: 1px 0 0; font-size: 12.5px; line-height: 1.25; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }



/* ------------------------------------------------------------ layout */
main {
  max-width: 1120px;
  margin: 0 auto;
  padding: 16px max(16px, env(safe-area-inset-right, 0px)) 8px max(16px, env(safe-area-inset-left, 0px));
  display: grid;
  gap: 16px;
}
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); min-width: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 32px; margin-bottom: 8px; }
.label { display: block; margin: 0; font: 700 12px/1.2 var(--sans); letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.label.small { margin: 16px 0 8px; }

.icon-btn { display: grid; place-items: center; width: 32px; height: 32px; border: 0; border-radius: 50%; background: rgba(29, 26, 22, 0.07); color: var(--muted); cursor: pointer; }
.icon-btn[hidden] { display: none; }
.icon-btn svg { width: 16px; height: 16px; stroke-width: 2.2; }
.icon-btn:active { background: rgba(29, 26, 22, 0.14); }

textarea {
  display: block;
  width: 100%;
  resize: none;
  min-height: 80px;
  max-height: 40vh;
  overflow-y: auto;
  padding: 14px 16px;
  font: 19px/1.45 var(--sans);
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 14px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
textarea:focus { outline: none; border-color: var(--ink); box-shadow: 0 0 0 3px rgba(29, 26, 22, 0.1); }
button:focus-visible, input:focus-visible, select:focus-visible, summary:focus-visible, .hit:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

/* ------------------------------------------------------------ language menu (top right): text language + interface language */
.langmenu { position: relative; flex-shrink: 0; }
#lang-btn { display: inline-flex; align-items: center; gap: 6px; min-height: 40px; padding: 0 10px 0 12px; border: 1px solid var(--line); border-radius: 999px; background: #fff; font: 700 13.5px var(--sans); color: var(--ink); cursor: pointer; }
#lang-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
#lang-btn .caret { width: 16px; height: 16px; color: var(--muted); }
#lang-btn[aria-expanded="true"] { border-color: var(--ink); }
.menu { position: absolute; right: 0; top: calc(100% + 8px); z-index: 40; width: 232px; max-height: min(78vh, 560px); overflow-y: auto; padding: 8px; border: 1px solid var(--line); border-radius: 16px; background: #fff; box-shadow: 0 14px 40px rgba(0, 0, 0, 0.22); }
.menu[hidden] { display: none; }
.menu-h { padding: 8px 10px 4px; font: 700 11.5px var(--sans); letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.langs { display: flex; flex-direction: column; gap: 1px; }
.langs button { display: flex; align-items: center; justify-content: space-between; min-height: 40px; padding: 0 10px; border: 0; border-radius: 10px; background: none; font: 600 15px var(--sans); text-align: left; cursor: pointer; }
.langs button:hover { background: rgba(29, 26, 22, 0.06); }
.langs button[aria-checked="true"] { background: rgba(29, 26, 22, 0.08); }
.langs button[aria-checked="true"]::after { content: "✓"; font-weight: 700; }
.langs button.auto { color: var(--accent); }

/* ------------------------------------------------------------ options (collapsible) */
.opts { margin-top: 12px; border-top: 1px solid var(--line); }
.opts summary { list-style: none; display: flex; align-items: center; justify-content: space-between; min-height: 48px; font: 600 14px var(--sans); color: var(--ink); cursor: pointer; }
.opts summary::-webkit-details-marker { display: none; }
.opts summary::after { content: ""; width: 9px; height: 9px; border: solid var(--muted); border-width: 0 2px 2px 0; transform: rotate(45deg); transition: transform 0.2s; margin-right: 4px; }
.opts[open] summary::after { transform: rotate(-135deg); }
.opts .toggles { margin-top: 2px; }
.opts .examples .label.small { margin-top: 18px; }

.toggles { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.tog { position: relative; cursor: pointer; }
.tog input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.tog span {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  padding: 0 14px 0 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  font: 500 14px var(--sans);
  transition: background 0.15s, border-color 0.15s;
}
.tog span::before { content: ""; width: 18px; height: 18px; border-radius: 50%; border: 2px solid #c9c2b3; transition: all 0.15s; }
.tog input:checked + span { border-color: var(--ink); background: #f4efe3; }
.tog input:checked + span::before { border-color: var(--ink); background: var(--ink) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23fff' stroke-width='3.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 12.5 4 4 8-9'/%3E%3C/svg%3E") center / 12px no-repeat; }
.tog input:focus-visible + span { outline: 3px solid var(--focus); outline-offset: 2px; }

.size { display: flex; align-items: center; gap: 10px; margin-top: 12px; font: 500 14px var(--sans); color: var(--muted); }
.size > span:first-child { min-width: 54px; }
.size input { flex: 1; min-width: 0; height: 28px; accent-color: var(--ink); }
.size-a { font-weight: 700; color: var(--muted); line-height: 1; }
.size-a.small { font-size: 12px; }
.size-a.big { font-size: 20px; }

.examples { min-width: 0; }
.chips { display: flex; gap: 8px; margin: 0 -18px; padding: 0 18px 4px; overflow-x: auto; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-height: 36px; padding: 0 14px; border: 1px solid var(--line); border-radius: 999px; background: #fff; font: 14px var(--sans); cursor: pointer; }
.chip:active { background: #f1ecdf; }

/* ------------------------------------------------------------ output */
.actions { display: flex; gap: 6px; }
.actions button { display: inline-flex; align-items: center; gap: 6px; min-height: 36px; padding: 0 12px; border: 1px solid var(--line); border-radius: 999px; background: #fff; font: 600 13px var(--sans); cursor: pointer; transition: background 0.15s, transform 0.1s; }
.actions button svg { width: 18px; height: 18px; }
.actions button:hover:not(:disabled) { border-color: var(--ink); }
.actions button:active:not(:disabled) { transform: scale(0.96); }
.actions button:disabled { opacity: 0.4; cursor: default; }
.actions button[hidden] { display: none; }
/* install: very bottom right on desktop (inside the tab bar on phones, see below) */
#btn-install { position: fixed; right: max(16px, env(safe-area-inset-right, 0px)); bottom: calc(16px + var(--safe-b)); z-index: 30; background: var(--accent) !important; color: #fff; border-color: transparent !important; box-shadow: 0 6px 18px rgba(0, 0, 0, 0.22); }

.canvas { background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 10px; min-height: 96px; overflow-x: auto; }
.canvas svg { display: block; max-width: none; }
.canvas .hit { cursor: pointer; }
.canvas .hit:hover { fill: rgba(196, 55, 43, 0.08); }
.canvas .hit.unk:hover { fill: rgba(0, 0, 0, 0.05); }
.muted { color: var(--muted); }
.status { margin: 12px 2px 0; font-size: 14px; color: var(--muted); }
.status b { color: var(--ink); font-weight: 600; }
.hint { margin: 4px 2px 0; font-size: 13px; color: var(--muted); }

/* ------------------------------------------------------------ alternatives popover */
.pop {
  position: absolute;
  z-index: 30;
  width: min(380px, calc(100vw - 24px));
  max-height: 70vh;
  overflow: auto;
  background: var(--card);
  border: 1px solid var(--ink);
  border-radius: 16px;
  padding: 14px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.22);
}
.pop[hidden] { display: none; }
.pop h3 { margin: 0 0 10px; font: 700 15px var(--sans); }
.pop p { margin: 0; font-size: 14px; color: var(--muted); }
.alts { display: grid; gap: 6px; }
.alt { display: grid; grid-template-columns: 72px 1fr; gap: 10px; align-items: center; text-align: left; min-height: 64px; border: 1px solid var(--line); border-radius: 12px; padding: 6px 8px; background: #fff; cursor: pointer; font: 14px/1.3 var(--sans); }
.alt:hover { border-color: var(--ink); }
.alt[aria-current="true"] { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.alt img { height: 56px; max-width: 72px; object-fit: contain; }
.alt small { display: block; color: var(--muted); }

/* ------------------------------------------------------------ footer / about */
.credit { margin: 18px 2px 0; text-align: center; font-size: 13px; color: var(--muted); }
footer { max-width: 1120px; margin: 0 auto; padding: 8px max(16px, env(safe-area-inset-right, 0px)) calc(32px + var(--safe-b)) max(16px, env(safe-area-inset-left, 0px)); font-size: 13px; color: var(--muted); }
.about { border: 1px solid var(--line); border-radius: 16px; background: rgba(255, 253, 248, 0.6); padding: 0 16px; }
.about summary { list-style: none; display: flex; align-items: center; justify-content: space-between; min-height: 48px; font: 600 14px var(--sans); color: var(--ink); cursor: pointer; }
.about summary::-webkit-details-marker { display: none; }
.about summary::after { content: ""; width: 9px; height: 9px; border: solid var(--muted); border-width: 0 2px 2px 0; transform: rotate(45deg); transition: transform 0.2s; margin-right: 4px; }
.about[open] summary::after { transform: rotate(-135deg); }
.about[open] { padding-bottom: 12px; }
.about p { margin: 0 0 8px; }
.about a { color: var(--ink); }
.pwa { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin: 10px 0 0; }
.pwa button { min-height: 40px; padding: 0 14px; border: 1px solid var(--line); border-radius: 999px; background: #fff; font: 600 13px var(--sans); cursor: pointer; }
.pwa button[hidden] { display: none; }
.pwa button:disabled { opacity: 0.55; cursor: default; }

/* ------------------------------------------------------------ wide screens: input on the left, result on the right */
@media (min-width: 960px) {
  main { grid-template-columns: minmax(340px, 400px) minmax(0, 1fr); align-items: start; gap: 20px; padding-top: 22px; }
  .card.input { position: sticky; top: calc(var(--bar-h) + 16px); }
  .card { padding: 22px; }
  .chips { flex-wrap: wrap; margin: 0; padding: 0; overflow: visible; }
  .chip { max-width: 100%; }
  .canvas { min-height: 200px; }
}
@media (min-width: 960px) and (max-height: 760px) {
  .card.input { position: static; }
}

/* ------------------------------------------------------------ phones: actions become a tab bar, popover a bottom sheet */
@media (max-width: 719px) {
  :root { --bar-h: 58px; }
  .tagline { font-size: 12px; white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
  h1 { font-size: 18px; }
  .card { padding: 14px; border-radius: 18px; }
  .chips { margin: 0 -14px; padding-left: 14px; padding-right: 14px; }
  textarea { font-size: 18px; min-height: 72px; }
  .output .card-head { margin-bottom: 10px; }

  body { padding-bottom: calc(68px + var(--safe-b)); }
  .actions {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 25;
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: 1fr;
    gap: 0;
    padding: 6px 8px calc(6px + var(--safe-b));
    background: rgba(255, 253, 248, 0.92);
    -webkit-backdrop-filter: saturate(1.4) blur(14px);
    backdrop-filter: saturate(1.4) blur(14px);
    border-top: 1px solid var(--line);
  }
  .actions button { flex-direction: column; justify-content: center; gap: 2px; min-height: 52px; padding: 4px 2px; border: 0; border-radius: 12px; background: none; font: 600 11.5px var(--sans); color: var(--ink); }
  .actions button svg { width: 22px; height: 22px; }
  .actions button:active:not(:disabled) { background: rgba(29, 26, 22, 0.08); transform: none; }
  /* while typing the keyboard needs the room */
  .typing .actions { display: none; }
  #btn-install { position: static; box-shadow: none; background: none !important; color: var(--accent); }
  .typing { padding-bottom: 0; }
  .output .card-head { min-height: 0; }

  .pop {
    position: fixed;
    left: 0 !important;
    right: 0;
    top: auto !important;
    bottom: 0;
    width: auto;
    max-height: 62vh;
    border: 0;
    border-radius: 22px 22px 0 0;
    padding: 18px 14px calc(18px + var(--safe-b));
    box-shadow: 0 -12px 40px rgba(0, 0, 0, 0.25);
  }
  .pop::before { content: ""; display: block; width: 40px; height: 4px; margin: -8px auto 12px; border-radius: 2px; background: var(--line); }
  .pop h3 { margin-top: 2px; }
}
@media (max-width: 360px) {
  .tagline { display: none; }
}

/* installed app: no browser chrome, so give the bar a little more presence */
@media (display-mode: standalone) {
  .appbar { background: rgba(246, 243, 236, 0.94); }
  #btn-install { display: none !important; }
}

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

@media print {
  body { background: #fff; padding: 0; }
  .appbar, .card.input, .card-head, .status, .hint, footer, .pop, .actions { display: none !important; }
  main { display: block; padding: 0; }
  .card, .canvas { border: 0; box-shadow: none; padding: 0; }
  .canvas { overflow: visible; }
  .canvas svg { width: 100% !important; height: auto !important; }
  .canvas .hit { display: none; }
}
