/* Stitch Digitizer for Web: the same look as the Windows app (light studio, colour-by-job icons, blue status bar) */
:root {
  --accent: #1e6fd9;
  --accent-dark: #175bb3;
  --chrome: #f4f6f9;
  --card: #ffffff;
  --line: #e1e6ec;
  --text: #1f2933;
  --muted: #677384;
  --highlight: #eaf2fd;
  --around: #e9edf2;
  --options: #f8fafc;
  --alarm: #c0392b;
  --font: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { font: 13px/1.35 var(--font); color: var(--text); background: var(--chrome); overflow: hidden; }
button, input, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.spacer { flex: 1; }

#app { display: grid; height: 100vh; grid-template-rows: auto auto auto 1fr auto auto; }

/* ---------- menus ---------- */
#menubar { display: flex; align-items: center; gap: 4px; padding: 0 8px; background: var(--card); border-bottom: 1px solid var(--line); height: 30px; }
#menus { display: flex; }
#menus > button { background: none; border: 0; padding: 4px 9px; border-radius: 4px; cursor: default; }
#menus > button:hover, #menus > button.open { background: var(--highlight); }
#quick { display: flex; align-items: center; gap: 1px; margin-left: 6px; }
#quick .sep { width: 1px; height: 18px; background: var(--line); margin: 0 5px; }
#edition { color: var(--muted); font-size: 12px; }
#site { display: flex; gap: 2px; margin-right: 10px; }
#site a { color: var(--muted); text-decoration: none; font-size: 12px; padding: 3px 8px; border-radius: 4px; }
#site a:hover { background: var(--highlight); color: var(--accent); }
@media (max-width: 900px) { #site, #edition { display: none; } }
#phoneNote { position: fixed; left: 8px; right: 8px; bottom: 8px; z-index: 25; background: #fff8e1; border: 1px solid #f3d58a; border-radius: 8px; padding: 8px 36px 8px 12px; font-size: 13px; box-shadow: 0 6px 20px rgba(16,24,40,.15); }
#phoneNote[hidden] { display: none; }
#phoneNote button { position: absolute; right: 6px; top: 6px; border: 0; background: none; font-size: 15px; cursor: pointer; }

/* buttons with icons */
.tb { display: inline-flex; align-items: center; gap: 6px; background: transparent; border: 1px solid transparent; border-radius: 6px; padding: 4px; cursor: pointer; white-space: nowrap; }
.tb:hover:not(:disabled) { background: var(--highlight); border-color: #cfe0f8; }
.tb:disabled { opacity: .4; cursor: default; }
.tb.on { background: #dbe8fb; border-color: #a9c7f2; }
.tb svg { display: block; flex: none; }
#quick .tb { padding: 3px 4px; }
#quick .tb svg { width: 18px; height: 18px; }

/* ---------- top bar ---------- */
#toolbar { display: flex; align-items: center; padding: 5px 8px; background: var(--card); border-bottom: 1px solid var(--line); gap: 8px; }
#toolbar .left { display: flex; flex-wrap: wrap; align-items: center; gap: 2px; flex: 1; min-width: 0; }
#toolbar .right { display: flex; align-items: center; gap: 2px; }
#toolbar .div { width: 1px; height: 24px; background: var(--line); margin: 0 8px; }
.accent { background: var(--accent); color: #fff; border: 0; border-radius: 6px; padding: 7px 14px; font-weight: 600; display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }
.accent:hover { background: var(--accent-dark); }
.accent svg path[stroke] { stroke: #fff; }
.pill { display: inline-flex; align-items: center; gap: 7px; border: 1px solid #b8dfc4; background: #eaf7ee; color: #1d6b37; border-radius: 999px; padding: 5px 12px 5px 8px; font-weight: 600; cursor: pointer; }
.pill.Warning { background: #fff4dc; border-color: #f0cf8a; color: #8a5a00; }
.pill.Problem { background: #fdecea; border-color: #f2b8b2; color: #a1281d; }

/* ---------- tool settings bar ---------- */
#options { display: flex; align-items: center; gap: 12px; height: 40px; padding: 3px 10px; background: var(--options); border-bottom: 1px solid var(--line); overflow: hidden; }
#toolName { min-width: 64px; }
.option { display: flex; align-items: center; gap: 6px; }
.strip { display: flex; background: var(--card); border: 1px solid var(--line); border-radius: 6px; padding: 1px; overflow-x: auto; scrollbar-width: none; }
.strip .tb { padding: 3px; border-radius: 4px; }
#toolBrief { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- the work area ---------- */
#work { display: grid; grid-template-columns: auto 1fr 300px; min-height: 0; }
#rail { background: var(--card); border-right: 1px solid var(--line); overflow-y: auto; scrollbar-width: none; padding: 6px 4px; display: flex; flex-direction: column; align-items: center; }
#rail .gap { width: 36px; height: 1px; background: var(--line); margin: 4px 0; flex: none; }
.railTool { width: 60px; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 5px 2px; border: 1px solid transparent; border-radius: 7px; background: none; cursor: pointer; font-size: 10.5px; text-align: center; flex: none; }
.railTool:hover { background: var(--highlight); }
.railTool.on { background: #dbe8fb; border-color: #a9c7f2; }
.railTool.soon { opacity: .45; }
#rail.short .railTool span { display: none; }
#rail.short .railTool { width: 44px; }

#middle { display: grid; grid-template-rows: 1fr auto; min-width: 0; min-height: 0; }
#canvasBox { position: relative; min-height: 0; overflow: hidden; background: var(--around); }
#canvas { position: absolute; inset: 0; width: 100%; height: 100%; outline: none; touch-action: none; }
#designBar { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 18px; padding: 8px 12px; background: var(--card); border-top: 1px solid var(--line); }
#designBar label { display: flex; align-items: center; gap: 6px; color: var(--muted); }
#designBar label.check { color: var(--text); }
#designBar input[type=text] { width: 150px; }
#fabricAdvice { margin: 0; flex-basis: 100%; font-size: 12px; }
input[type=text], input[type=number], select { border: 1px solid #cdd5df; border-radius: 5px; padding: 4px 7px; background: #fff; min-height: 28px; }
input[type=text]:focus, input[type=number]:focus, select:focus { outline: 2px solid #a9c7f2; border-color: var(--accent); }

/* ---------- the side panel ---------- */
#side { display: grid; grid-template-rows: minmax(140px, 42%) 1fr; background: var(--card); border-left: 1px solid var(--line); min-height: 0; }
.panel { display: flex; flex-direction: column; min-height: 0; }
#settingsPanel { border-top: 1px solid var(--line); }
.panelHead { display: flex; align-items: center; padding: 10px 12px 6px; }
.panelHead h2 { font-size: 11.5px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); font-weight: 600; margin: 0; flex: 1; }
.panelButtons button { background: none; border: 1px solid transparent; border-radius: 4px; width: 24px; height: 24px; cursor: pointer; padding: 0; color: var(--text); }
.panelButtons button:hover { background: var(--highlight); }
.panelButtons svg { width: 16px; height: 16px; vertical-align: middle; }
#order { list-style: none; margin: 0; padding: 0 6px 8px; overflow-y: auto; flex: 1; }
#order li { display: flex; align-items: center; gap: 7px; padding: 3px 6px; border-radius: 4px; cursor: pointer; user-select: none; }
#order li:hover { background: #f3f7fd; }
#order li.sel { background: var(--highlight); outline: 1px solid #cfe0f8; }
#order li.hidden { opacity: .45; }
#order .n { color: var(--muted); width: 20px; text-align: right; font-size: 12px; }
#order .sw, .sw { width: 13px; height: 13px; border-radius: 3px; border: 1px solid rgba(0,0,0,.25); flex: none; display: inline-block; }
#order svg { flex: none; }
#order .empty { color: var(--muted); padding: 6px; cursor: default; }
#settings { padding: 0 12px 16px; overflow-y: auto; flex: 1; }
#settings .kind { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 15px; margin-bottom: 8px; }
#settings .row { display: grid; grid-template-columns: 104px 1fr; align-items: center; gap: 8px; margin: 6px 0; }
#settings .row > span { color: var(--muted); }
#settings .row.top { align-items: start; }
#settings select, #settings input[type=text], #settings input[type=number] { width: 100%; }
#settings details { margin-top: 12px; }
#settings summary { cursor: pointer; padding: 4px 0; }
#settings .flags label { display: block; margin: 2px 0; }
.notice { background: #fff4dc; border: 1px solid #e0a840; border-radius: 4px; padding: 6px 8px; margin-bottom: 8px; }
.notice button { margin-top: 6px; }
.threadPick { display: flex; align-items: center; gap: 6px; }
.threadPick select { flex: 1; }

/* ---------- hint and status ---------- */
#hint { display: flex; align-items: center; gap: 10px; padding: 7px 14px; background: #e6f0fd; border-top: 1px solid #b9d3f5; font-size: 14px; color: #12355f; }
#hint .q { flex: none; width: 22px; height: 22px; border-radius: 50%; background: var(--accent); color: #fff; display: grid; place-items: center; font-weight: 700; }
#hint.alarm { background: #fdecea; border-color: #f2b8b2; color: #7d1d14; }
#hint.alarm .q { background: var(--alarm); }
#status { display: flex; align-items: center; gap: 16px; padding: 4px 10px; background: var(--accent); color: #e6f0fd; font-size: 12.5px; }
#status.alarm { background: var(--alarm); }
#verdict { display: inline-flex; align-items: center; gap: 6px; background: none; border: 0; color: #fff; font-weight: 600; cursor: pointer; padding: 0; }
#verdict i { width: 10px; height: 10px; border-radius: 50%; border: 1.5px solid #fff; background: #2e9c55; }
#verdict.Warning i { background: #f2a516; }
#verdict.Problem i { background: #e0483d; }

/* ---------- the simulator ---------- */
#simBar { position: absolute; left: 50%; bottom: 16px; transform: translateX(-50%); display: flex; align-items: center; gap: 10px; background: #1f2a3a; color: #e8eef5; padding: 8px 12px; border-radius: 10px; box-shadow: 0 6px 20px rgba(0,0,0,.25); z-index: 5; }
#simBar button, #simBar select { background: #2f3d52; color: #fff; border: 1px solid #45566f; border-radius: 6px; padding: 4px 10px; }
#simScrub { width: min(40vw, 420px); }

/* ---------- menus, dialogs, loading ---------- */
.menu { position: fixed; z-index: 20; background: #fff; border: 1px solid #cdd5df; border-radius: 6px; box-shadow: 0 8px 24px rgba(16,24,40,.16); padding: 4px; min-width: 210px; }
.menu button { display: flex; width: 100%; align-items: center; gap: 10px; background: none; border: 0; padding: 6px 10px 6px 26px; text-align: left; border-radius: 4px; cursor: default; position: relative; white-space: nowrap; }
.menu button:hover:not(:disabled), .menu button.open { background: var(--highlight); }
.menu button:disabled { color: #a0a9b6; }
.menu button .keys { margin-left: auto; padding-left: 24px; color: var(--muted); font-size: 12px; }
.menu button.check::before { content: "✓"; position: absolute; left: 9px; }
.menu button.sub::after { content: "›"; margin-left: auto; padding-left: 16px; color: var(--muted); }
.menu hr { border: 0; border-top: 1px solid var(--line); margin: 4px 6px; }
dialog { border: 0; border-radius: 10px; padding: 0; box-shadow: 0 16px 48px rgba(16,24,40,.28); max-width: min(560px, 92vw); }
dialog form { padding: 18px 20px 14px; }
dialog h2 { margin: 0 0 10px; font-size: 17px; }
dialog.wide { max-width: min(860px, 96vw); width: 860px; }
dialog .dlgError { color: #c0392b; margin: 10px 0 0; white-space: pre-line; }
dialog .dlgBody { white-space: pre-line; max-height: 60vh; overflow-y: auto; }
dialog .dlgBody .finding { border-left: 4px solid #2e9c55; padding: 4px 10px; margin: 8px 0; white-space: normal; }
dialog .dlgBody .finding.Warning { border-color: #f2a516; }
dialog .dlgBody .finding.Problem { border-color: #e0483d; }
dialog .dlgBody .finding.Note { border-color: #9aa6b4; }
dialog .dlgBody .grid2 { display: grid; grid-template-columns: auto 1fr; gap: 8px 12px; align-items: center; white-space: normal; }
dialog .dlgButtons { display: flex; justify-content: flex-end; gap: 8px; margin: 16px 0 0; padding: 0; }
dialog .dlgButtons button { border: 1px solid #cdd5df; background: #fff; border-radius: 6px; padding: 6px 16px; cursor: pointer; }
dialog .dlgButtons button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.threadGrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 4px; max-height: 50vh; overflow-y: auto; white-space: normal; }
.threadGrid button { display: flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: #fff; border-radius: 5px; padding: 4px 6px; text-align: left; cursor: pointer; font-size: 12px; }
.threadGrid button.on { outline: 2px solid var(--accent); }

#loadingCard { position: fixed; inset: 0; display: grid; place-content: center; justify-items: center; gap: 10px; background: rgba(244,246,249,.92); z-index: 30; color: var(--muted); font-size: 15px; }
#app:not(.loading) #loadingCard { display: none; }
.spinner { width: 34px; height: 34px; border: 4px solid #cfe0f8; border-top-color: var(--accent); border-radius: 50%; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* narrower screens: the side panel gets smaller, words on the top bar go */
@media (max-width: 1150px) { .words { display: none; } #work { grid-template-columns: auto 1fr 260px; } }
@media (max-width: 820px) { #work { grid-template-columns: auto 1fr; } #side { display: none; } #designBar label:nth-child(n+4) { display: none; } }

/* ---------- lettering ---------- */
.textForm { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; white-space: normal; }
.textForm .col { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.textForm .row { display: grid; grid-template-columns: 140px 1fr; align-items: center; gap: 8px; }
.textForm .row[hidden] { display: none; }
.textForm .inline { display: flex; align-items: center; gap: 8px; }
.textForm .inline input[type=range] { flex: 1; }
.textForm .inline input[type=number] { width: 70px; }
.textForm .stack { display: flex; flex-direction: column; gap: 4px; }
.textForm textarea { font-size: 17px; padding: 6px 8px; border: 1px solid #cdd5df; border-radius: 6px; resize: vertical; font-family: inherit; }
.textForm .lbl { color: var(--muted); }
.textForm input.big { font-size: 18px; width: 90px; text-transform: uppercase; }
.textForm .note { margin: 0; font-size: 12px; color: #6b5a12; background: #fff8e1; border-radius: 6px; padding: 6px 8px; }
.textForm .note[hidden] { display: none; }
.textForm .notice { margin: 0; font-size: 12px; background: #fdecea; border-radius: 6px; padding: 6px 8px; }
canvas.preview { width: 100%; height: 150px; border: 1px solid var(--line); border-radius: 6px; background: #fff; }
.fontPicker { display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.fontPicker .tabs { display: flex; background: var(--around); }
.fontPicker .tabs button { flex: 1; border: 0; background: none; padding: 7px 4px; cursor: pointer; font-size: 12px; border-bottom: 2px solid transparent; }
.fontPicker .tabs button.on { border-bottom-color: var(--accent); background: #fff; font-weight: 600; }
.fontList { height: 260px; overflow-y: auto; padding: 4px; }
.fontList button { display: flex; flex-direction: column; align-items: flex-start; width: 100%; border: 0; background: none; padding: 6px 28px 6px 8px; text-align: left; border-radius: 5px; cursor: pointer; position: relative; }
.fontList button:hover { background: var(--highlight); }
.fontList button.on { background: #d5e5fa; }
.fontList button .muted { font-size: 11px; }
.fontList .remove { position: absolute; right: 8px; top: 8px; color: var(--muted); }
.fontList .remove:hover { color: #c0392b; }
.fontList p { padding: 8px; margin: 0; font-size: 12px; }
.fontFoot { display: flex; flex-wrap: wrap; gap: 6px; padding: 6px; border-top: 1px solid var(--line); }
.fontFoot:empty { display: none; }
button.plain { border: 1px solid #cdd5df; background: #fff; border-radius: 6px; padding: 5px 10px; cursor: pointer; font-size: 12px; }
button.plain:hover { background: var(--highlight); }
button.wideButton { width: 100%; margin: 4px 0 8px; font-size: 13px; }
.letterGrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 4px 10px; max-height: 40vh; overflow-y: auto; margin-top: 10px; }
.letterGrid label { display: flex; align-items: center; gap: 6px; font-size: 12px; min-width: 0; }
.letterGrid input { width: 34px; text-align: center; font-size: 15px; }
.letterGrid span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (max-width: 700px) { .textForm { grid-template-columns: 1fr; } }
.textForm select { min-width: 0; max-width: 100%; }
.textForm .row > select, .textForm .row > .threadPick { width: 100%; }

/* ---------- pictures ---------- */
#busyCard { position: fixed; inset: 0; z-index: 40; display: grid; place-content: center; background: rgba(244,246,249,.7); }
#busyCard[hidden] { display: none; }
#busyCard .card { background: #fff; border-radius: 10px; box-shadow: 0 16px 48px rgba(16,24,40,.2); padding: 22px 26px; width: 360px; display: grid; justify-items: center; gap: 8px; text-align: center; }
#busyCard p { margin: 0; font-weight: 600; }
.picForm { display: grid; grid-template-columns: 280px 1fr; gap: 16px; white-space: normal; }
.picSide { display: flex; flex-direction: column; gap: 6px; }
.picSide > b { margin-top: 8px; }
.picSide .inline { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.picSide input[type=number] { width: 70px; }
.picSide .bad { color: #c0392b; }
.picSide p { margin: 0; }
.small { font-size: 12px; }
.noAi { background: #e4eefb; border-radius: 6px; padding: 6px 8px; font-size: 12px; }
.palette { display: flex; flex-direction: column; gap: 2px; max-height: 200px; overflow-y: auto; }
.palette label { display: flex; align-items: center; gap: 6px; font-size: 12px; }
.palette .sw, .threadPick .sw { flex: none; }
.palette .sw { width: 14px; height: 14px; border: 1px solid #9aa6b4; border-radius: 3px; }
.palette .muted { margin-left: auto; }
.pics { display: grid; grid-template-columns: 1fr 1fr; grid-template-rows: auto 1fr; gap: 6px 12px; min-height: 340px; }
.pic { border: 1px solid var(--line); border-radius: 6px; display: grid; place-items: center; overflow: hidden; min-height: 300px; position: relative; }
.pic.working::after { content: "Working…"; position: absolute; inset: 0; display: grid; place-items: center; background: rgba(255,255,255,.7); color: var(--muted); }
.checker { background: #fff repeating-conic-gradient(#eee 0 25%, #fff 0 50%) 0 0 / 16px 16px; }
.fitPic { max-width: 100%; max-height: 380px; width: auto; height: auto; object-fit: contain; image-rendering: auto; }
.gapTop { margin-top: 12px; display: flex; gap: 8px; }
@media (max-width: 760px) { .picForm { grid-template-columns: 1fr; } .pics { grid-template-columns: 1fr; } }

/* ---------- colours ---------- */
.colourList { display: flex; flex-direction: column; gap: 2px; max-height: 300px; overflow-y: auto; border: 1px solid var(--line); border-radius: 6px; padding: 4px; white-space: normal; }
.colourList button { display: flex; align-items: center; gap: 10px; border: 0; background: none; padding: 5px 8px; border-radius: 5px; text-align: left; cursor: pointer; }
.colourList button:hover { background: var(--highlight); }
.colourList button.on { background: #d5e5fa; }
.colourList .sw { width: 22px; height: 22px; border: 1px solid #9aa6b4; border-radius: 4px; flex: none; }
.colourList b { display: block; font-weight: 600; }
.inline { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

/* the way out of the simulator, on the top bar while it runs */
.exitSim { display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 12px; margin-right: 6px; border: 1px solid #f2b8b2; background: #fde8e6; color: #b42318; border-radius: 17px; font-weight: 600; cursor: pointer; }
.exitSim:hover { background: #fbd5d1; }
.exitSim[hidden] { display: none; }

/* ---------- your account (on the website) ---------- */
#acctBtn { display: flex; align-items: center; gap: 6px; border: 1px solid var(--line, #d9dee5); background: #fff; border-radius: 999px; padding: 2px 10px 2px 2px; margin-right: 8px; cursor: pointer; font: inherit; color: inherit; text-align: left; line-height: 1.1; }
#acctBtn[hidden] { display: none; }
#acctBtn:hover { border-color: var(--accent); }
#acctBtn img { width: 24px; height: 24px; flex: none; }
#acctBtn b { display: block; font-size: 11.5px; }
#acctBtn small { display: block; font-size: 10.5px; color: var(--muted); max-width: 170px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (max-width: 900px) { #acctBtn small { display: none; } }
dialog.account { width: min(440px, 92vw); }
dialog.account .dlgForm { padding: 18px 20px 14px; }
dialog.account .dlgBody { white-space: normal; }
dialog.account .badge { float: right; width: 96px; height: 96px; margin: -6px 0 6px 10px; }
dialog.account p { margin: 0 0 10px; }
dialog.account .acctForm { display: grid; gap: 6px; margin: 0 0 10px; }
dialog.account input { border: 1px solid #cdd5df; border-radius: 6px; padding: 8px 10px; font: inherit; }
dialog.account button { border: 1px solid #cdd5df; background: #fff; border-radius: 6px; padding: 7px 16px; cursor: pointer; font: inherit; }
dialog.account button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
dialog.account .dlgButtons .left { margin-right: auto; }
dialog.account .offer { clear: both; border: 1px solid #cdd5df; border-radius: 8px; padding: 10px 12px; margin: 0 0 10px; }
dialog.account .offerHead { display: flex; justify-content: space-between; margin-bottom: 4px; }
dialog.account .offer ul { margin: 0 0 10px; padding-left: 18px; }
#toast { position: fixed; left: 50%; bottom: 56px; transform: translateX(-50%); z-index: 50; background: #1f2a3a; color: #fff; padding: 9px 16px; border-radius: 8px; box-shadow: 0 6px 20px rgba(0,0,0,.25); font-size: 13px; max-width: 90vw; }
#toast[hidden] { display: none; }
dialog.account .acctForm { padding: 0; }
