:root {
  --bg: #f2f2f4; --panel: #ffffff; --line: #dcdce0; --text: #1c1c1e; --muted: #6e6e73;
  --field: #f6f6f8; --accent: #0a84ff; --accent-text: #fff; --warn: #c93400; --ok: #1f8a3a;
  --checker-a: #e4e4e8; --checker-b: #f4f4f6;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161618; --panel: #1f1f22; --line: #333338; --text: #f2f2f4; --muted: #9a9aa0;
    --field: #2a2a2e; --accent: #0a84ff; --warn: #ff9f4a; --ok: #4cd06a;
    --checker-a: #26262a; --checker-b: #2e2e33;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  display: grid; grid-template-columns: 360px 1fr; background: var(--bg); color: var(--text);
  font: 13px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
}
#panel { background: var(--panel); border-right: 1px solid var(--line); overflow-y: auto; padding: 8px 18px 18px; }
section { padding: 12px 0 14px; border-bottom: 1px solid var(--line); display: flex; flex-direction: column; gap: 8px; }
h2 { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 4px 0 2px; font-weight: 600; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field > span { color: var(--muted); font-size: 12px; display: flex; justify-content: space-between; }
input[type=text], input[type=password], select {
  width: 100%; padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--field); color: var(--text); font: inherit;
}
input:focus, select:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: -1px; }
input[type=range] { width: 100%; accent-color: var(--accent); }
input[type=checkbox] { accent-color: var(--accent); margin: 0; }
.row { display: flex; gap: 6px; align-items: center; }
.row input { flex: 1; min-width: 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 6px; }
.check { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.align-end { align-self: end; padding-bottom: 7px; }
.indent, input.indent { margin-left: 22px; width: calc(100% - 22px); }
.color { display: flex; align-items: center; gap: 8px; }
.color input { width: 34px; height: 24px; padding: 0; border: 1px solid var(--line); border-radius: 5px; background: none; }
button {
  font: inherit; padding: 6px 12px; border-radius: 6px; border: 1px solid var(--line); background: var(--field); color: var(--text); cursor: pointer; white-space: nowrap;
}
button:hover { filter: brightness(0.96); }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
button.ghost { background: transparent; }
button:disabled { opacity: .5; cursor: default; }
.muted { color: var(--muted); }
.msg { margin: 0; font-size: 12px; color: var(--muted); min-height: 0; }
.msg:empty { display: none; }
.msg.err, .warn { color: var(--warn); }
.msg.ok { color: var(--ok); }
.disabled { opacity: .45; pointer-events: none; }
body:not(.native) .native-only { display: none !important; }
body.native .web-only { display: none; }
#about { padding-top: 14px; font-size: 11px; }

main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
#stage {
  flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; padding: 32px; overflow: auto;
  background-color: var(--checker-b);
  background-image: linear-gradient(45deg, var(--checker-a) 25%, transparent 25%, transparent 75%, var(--checker-a) 75%),
                    linear-gradient(45deg, var(--checker-a) 25%, transparent 25%, transparent 75%, var(--checker-a) 75%);
  background-size: 20px 20px; background-position: 0 0, 10px 10px;
}
#canvas { max-width: 100%; max-height: 100%; width: auto; height: auto; flex: none; object-fit: contain; box-shadow: 0 6px 30px rgba(0,0,0,.18); }   /* never squashed: the card keeps its shape */
#exportBar { display: flex; align-items: center; gap: 10px; padding: 10px 16px; background: var(--panel); border-top: 1px solid var(--line); }
#exportBar select { width: auto; }
.spacer { flex: 1; }

#printImg { display: none; }
@media print {
  @page { margin: 12mm; }
  body { display: block; background: #fff; }
  #panel, main { display: none !important; }
  #printImg { display: block; margin: 0 auto; max-width: 100%; max-height: 95vh; }
}

/* ── Colourize theme (colourize.media look) — shared parts in colourize-theme.css. Only the app's own UI changes;
   the QR card keeps the colours chosen for it. ── */
html[data-theme=colourize] {
  --bg: #070707; --panel: rgba(17,17,17,.86); --line: #2a2a2a; --text: #fff; --muted: #8a8a8a;
  --field: #1a1a1a; --accent: #2560cb; --accent-text: #fff; --warn: #ff8a1f; --ok: #2fd27a;
  --checker-a: #141414; --checker-b: #1b1b1b;
  color-scheme: dark;
}
html[data-theme=colourize] body { font-family: Manrope, -apple-system, "Segoe UI", sans-serif; }
html[data-theme=colourize] #panel { padding-top: 56px; backdrop-filter: blur(12px); }
html[data-theme=colourize] h2 { display: inline-block; align-self: flex-start; background: #1e1e1e; color: #fff;
  font-weight: 700; letter-spacing: .08em; padding: 2px 8px; font-size: 12px; }
html[data-theme=colourize] button { border-radius: 10px; font-weight: 700; letter-spacing: .03em; }
html[data-theme=colourize] input[type=text], html[data-theme=colourize] input[type=password], html[data-theme=colourize] select { border-radius: 10px; }
html[data-theme=colourize] #exportBar { backdrop-filter: blur(12px); }
html[data-theme=colourize] #stage { background: transparent; }

/* Colourize theme: font, stage-glow background and the top-left hover menu */
@font-face { font-family: Manrope; src: url(manrope.woff2) format('woff2'); font-weight: 200 800; font-display: swap; }

html[data-theme=colourize] body {
  font-family: Manrope, -apple-system, "Segoe UI", sans-serif; letter-spacing: -.1px;
  background:
    radial-gradient(900px 520px at 85% 0%, rgba(214,31,156,.26), transparent 60%),
    radial-gradient(700px 500px at 0% 100%, rgba(37,96,203,.20), transparent 60%),
    #070707;
  background-attachment: fixed;
}

/* the theme switch button colourize-theme.js adds to the app's header */
.cz-switch { cursor: pointer; }
/* Settings popup (cm-settings.js): its panes are <section>s and its selects sit in a row, so undo the panel's rules for those */
#setDlg section { border-bottom: 0; }
#setDlg .sCtl select { width: auto; }
html[data-theme=colourize] #setDlg { --panel: #111; }

/* top-left menu: just the blue dot until hovered, then the tags fan out like the website's nav */
.cz-nav { display: none; }
html[data-theme=colourize] .cz-nav { display: block; position: fixed; left: 14px; top: 8px; z-index: 1000; width: 40px; height: 40px; -webkit-app-region: no-drag; }
html[data-theme=colourize] .cz-nav:hover { width: 250px; height: 190px; }
.cz-dot { position: absolute; left: 0; top: 0; width: 38px; height: 38px; border-radius: 50%; background: #2560cb;
  box-shadow: 0 0 22px rgba(37,96,203,.6); cursor: pointer; }
.cz-tag { position: absolute; background: #1e1e1e; color: #fff; font: 700 13px/1.3 Manrope, sans-serif; letter-spacing: .08em;
  text-transform: uppercase; padding: 3px 9px; white-space: nowrap; cursor: pointer; transform-origin: left center;
  opacity: 0; pointer-events: none; transition: opacity .18s, transform .18s; box-shadow: 0 4px 14px rgba(0,0,0,.6); }
.cz-tag:hover { background: #2560cb; }
.cz-nav:hover .cz-tag { opacity: 1; pointer-events: auto; }
.cz-tag:nth-of-type(1) { left: 50px; top: 8px; transform: translateX(-8px); }
.cz-tag:nth-of-type(2) { left: 46px; top: 35px; transform: rotate(22deg) translateX(-8px); }
.cz-tag:nth-of-type(3) { left: 32px; top: 60px; transform: rotate(56deg) translateX(-8px); }
.cz-tag:nth-of-type(4) { left: 12px; top: 72px; transform: rotate(80deg) translateX(-8px); }
.cz-nav:hover .cz-tag:nth-of-type(1) { transform: none; }
.cz-nav:hover .cz-tag:nth-of-type(2) { transform: rotate(22deg); }
.cz-nav:hover .cz-tag:nth-of-type(3) { transform: rotate(56deg); }
.cz-nav:hover .cz-tag:nth-of-type(4) { transform: rotate(80deg); }

/* ── Phones and narrow windows (the web app): the card stays in view at the top, the options scroll underneath ── */
@media screen and (max-width: 760px) {
  html, body { height: auto; }
  body { display: flex; flex-direction: column; font-size: 15px; }
  main { order: -1; position: sticky; top: 0; z-index: 5; background: var(--bg); border-bottom: 1px solid var(--line); }
  #stage { flex: none; height: 38vh; min-height: 220px; padding: 14px; }
  #exportBar { flex-wrap: wrap; gap: 8px; padding: 8px 12px; }
  #exportBar .spacer { display: none; }
  #exportBar #dims { flex: 1; }
  #exportMsg { order: 9; flex-basis: 100%; }
  #copyBtn, #printBtn, #saveBtn { flex: 1; }
  #panel { overflow: visible; border-right: 0; padding: 4px 16px 28px; }
  html[data-theme=colourize] #panel { padding-top: 4px; }
  html[data-theme=colourize] main { background: #070707; }
  html[data-theme=colourize] .cz-nav { display: none; }   /* a hover menu: no use on a touch screen */
  #webHead { display: none; }
  input[type=text], input[type=password], select { padding: 9px 10px; font-size: 16px; }   /* 16 px stops iOS zooming in */
  button { padding: 9px 13px; }
  .check, .color { min-height: 30px; }
  input[type=checkbox] { width: 18px; height: 18px; }
}

/* ── The web app on a computer (qrwifi.colourize.app): a centred page instead of an edge-to-edge window.
   Heading on top, options on the left, the card on the right at a sensible size that stays in view while the options scroll. ── */
#webHead { display: flex; align-items: center; gap: 14px; }
#webHead img { border-radius: 10px; flex: none; }
#webHead h1 { margin: 0; font-size: 22px; line-height: 1.2; font-weight: 800; letter-spacing: -.3px; }
#webHead p { margin: 2px 0 0; color: var(--muted); }
#webHead a { margin-left: auto; color: var(--muted); font-weight: 700; text-decoration: none; white-space: nowrap; }
#webHead a:hover { color: var(--text); }
@media screen and (min-width: 761px) {
  html:has(body:not(.native)), body:not(.native) { height: auto; }
  body:not(.native) {
    grid-template-columns: 372px minmax(0, 1fr); grid-template-areas: "head head" "panel main"; align-items: start;
    gap: 18px; max-width: 1120px; margin: 0 auto; padding: 24px 24px 48px; font-size: 14px;
  }
  body:not(.native) #webHead { grid-area: head; padding: 0 4px 4px; }
  body:not(.native) #panel { grid-area: panel; overflow: visible; border: 1px solid var(--line); border-radius: 18px; padding: 6px 18px 16px; }
  body:not(.native) #panel section:last-of-type { border-bottom: 0; }
  body:not(.native) main { grid-area: main; position: sticky; top: 24px; background: var(--panel); border: 1px solid var(--line); border-radius: 18px; overflow: hidden; }
  body:not(.native) #stage { flex: none; height: min(620px, calc(100vh - 190px)); min-height: 280px; padding: 28px; }
  html[data-theme=colourize] body:not(.native) .cz-nav { display: none; }   /* the page has its own heading */
  body:not(.native) #about { padding-top: 6px; }
  body:not(.native) #exportBar { flex-wrap: wrap; row-gap: 8px; }
  body:not(.native) #exportBar label, body:not(.native) #dims { white-space: nowrap; }
}
