﻿/* Colors are tokens (--t-rrggbb) so the Theme Color button can re-tint them; --theme-hexes lists them for app.js. */
:root {
  --t-14101c: #14101c;
  --t-1c1528: #1c1528;
  --t-e9d8ff: #e9d8ff;
  --t-b44cff: #b44cff;
  --t-8a3fc4: #8a3fc4;
  --t-7b2fd0: #7b2fd0;
  --t-9a4cf0: #9a4cf0;
  --t-5d1fa8: #5d1fa8;
  --t-c98bff: #c98bff;
  --t-0b0910: #0b0910;
  --t-e0b3ff: #e0b3ff;
  --t-3a2060: #3a2060;
  --t-55308a: #55308a;
  --t-d28bff: #d28bff;
  --t-1a0b2e: #1a0b2e;
  --t-d9b3ff: #d9b3ff;
  --t-6e5a8a: #6e5a8a;
  --t-2a1646: #2a1646;
  --t-1e1530: #1e1530;
  --t-5a3a85: #5a3a85;
  --theme-hexes: "14101c 1c1528 e9d8ff b44cff 8a3fc4 7b2fd0 9a4cf0 5d1fa8 c98bff 0b0910 e0b3ff 3a2060 55308a d28bff 1a0b2e d9b3ff 6e5a8a 2a1646 1e1530 5a3a85";
}
:root {
  --bg: var(--t-14101c); --panel: var(--t-1c1528); --text: var(--t-e9d8ff); --purple: var(--t-b44cff); --purple-dim: var(--t-8a3fc4);
  --btn: var(--t-7b2fd0); --btn-hover: var(--t-9a4cf0); --btn-down: var(--t-5d1fa8); --heading: var(--t-c98bff); --black: var(--t-0b0910);
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text);
  font-family: 'Segoe UI', system-ui, -apple-system, Roboto, Arial, sans-serif; font-size: 18px; }
button, select, input, textarea { font: inherit; }

.app { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 18px; max-width: 1400px;
  margin: 0 auto; padding: 14px; min-height: 100vh; }
.pane { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.left { justify-content: flex-start; }
.right { align-items: center; justify-content: center; position: sticky; top: 0; align-self: start; padding-top: 4px; }

button { background: var(--btn); color: #fff; border: 0; border-radius: 12px; padding: 10px 18px;
  font-weight: 700; font-size: 1.05rem; cursor: pointer; transition: background .12s, transform .05s; }
button:hover { background: var(--btn-hover); }
button:active { background: var(--btn-down); transform: scale(.97); }
button:focus-visible, canvas:focus-visible, textarea:focus-visible, select:focus-visible { outline: 3px solid var(--t-e0b3ff); outline-offset: 2px; }
button.small { background: var(--t-3a2060); padding: 6px 12px; font-size: .9rem; }
button.small:hover { background: var(--t-55308a); }
button.on, button[aria-pressed=true].arrow { background: var(--t-d28bff); color: var(--t-1a0b2e); }
button.arrow { font-size: 1.5rem; padding: 6px 22px; }

.toprow { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.modes { display: flex; gap: 6px; }
.mode { width: 86px; height: 42px; padding: 0 8px; font-size: .95rem; }
.mode.on { background: var(--t-d28bff); color: var(--t-1a0b2e); }

.box { display: flex; flex-direction: column; gap: 6px; }
.boxhead { display: flex; align-items: center; gap: 8px; }
.boxhead h2 { margin: 0 auto 0 0; font-size: 1.1rem; color: var(--heading); }
textarea { width: 100%; min-height: 170px; resize: vertical; background: var(--black); color: var(--t-d9b3ff);
  border: 2px solid var(--purple-dim); border-radius: 12px; padding: 10px; font-size: 1.35rem; font-weight: 600;
  line-height: 1.35; }
textarea:focus { border-color: var(--t-d28bff); }
textarea::selection { background: var(--purple); color: #fff; }
textarea::placeholder { color: var(--t-6e5a8a); }

.actions { display: contents; }   /* the buttons flow in the same row as Encrypt / Decrypt */
button.act { height: 42px; padding: 0 10px; font-size: .95rem; }
button.act:not(.wide):not(.icon) { width: 80px; }
button.act.icon { width: 46px; padding: 0; display: flex; align-items: center; justify-content: center; }
button.copyicon { display: flex; align-items: center; justify-content: center; padding: 4px 10px; }
[hidden] { display: none !important; }
.toast { min-height: 1.4em; margin: 0; color: var(--heading); font-weight: 600; }

#ring { width: min(100%, 72vh, 640px); aspect-ratio: 1; touch-action: none; cursor: grab; border-radius: 50%; }
#ring:active { cursor: grabbing; }
.keybox { width: min(100%, 640px); display: flex; align-items: center; gap: 6px; background: var(--t-2a1646); border: 2px solid var(--purple); border-radius: 14px; padding: 6px 8px; }
.keygap { flex: 0 0 44px; }
.keylabel { flex: 1; text-align: center; font-size: clamp(1.5rem, 4vw, 2.2rem); font-weight: 800; color: #fff; }
.iconbtn { flex: 0 0 44px; height: 44px; padding: 0; background: transparent; color: var(--t-e9d8ff); display: flex; align-items: center; justify-content: center; border-radius: 10px; }
.iconbtn:hover { background: var(--t-55308a); }
.iconbtn.done { color: #7dffa8; }
.ringbtns { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }

/* ---- preview ---- */
.overlay { position: fixed; inset: 0; background: rgba(8, 5, 14, .86); z-index: 10; display: flex; align-items: center; justify-content: center; padding: 10px; }
.overlay[hidden] { display: none; }
.dialog { background: var(--bg); border: 2px solid var(--purple-dim); border-radius: 16px; padding: 12px; display: flex; flex-direction: column;
  gap: 10px; max-height: 100%; width: min(100%, 760px); }
.controls { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; }
.controls label { display: flex; align-items: center; gap: 6px; font-weight: 600; }
.controls.bottom { justify-content: flex-end; }
select, input[type=number] { background: var(--black); color: var(--text); border: 2px solid var(--purple-dim); border-radius: 10px; padding: 6px 8px; }
select { max-width: 240px; }
input[type=number] { width: 5em; }
input[type=color] { width: 54px; height: 38px; padding: 0; border: 2px solid var(--purple-dim); border-radius: 10px; background: var(--black); }

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .right { position: static; order: -1; }
  #ring { width: min(100%, 520px); }
}

/* ---- printing: see the body.ws-open rules at the end (the Preview's pages are what gets printed) ---- */
@page { size: letter; margin: 0; }

@media (max-width: 520px) {
  .ringbtns { gap: 6px; flex-wrap: nowrap; }
  .ringbtns button { padding: 8px 10px; font-size: 1rem; }
  .ringbtns button.arrow { padding: 6px 12px; font-size: 1.3rem; }
}

/* ---- background picker ---- */
.bgrow { display: flex; align-items: center; gap: 8px; position: relative; font-weight: 600; }
.bgpick { position: relative; }
.bgcur { display: flex; align-items: center; gap: 8px; background: var(--black); color: var(--text); border: 2px solid var(--purple-dim);
  border-radius: 10px; padding: 3px 10px 3px 4px; font-size: 1rem; font-weight: 600; min-width: 190px; }
.bgcur:hover { background: var(--t-1e1530); }
.bgcur span:nth-child(2) { flex: 1; text-align: left; }
.bgcur img, .bglist img { width: 34px; height: 42px; object-fit: cover; border-radius: 4px; border: 1px solid var(--t-5a3a85); background: #fff; display: block; }
.bglist { position: absolute; top: calc(100% + 4px); left: 0; z-index: 20; margin: 0; padding: 4px; list-style: none; min-width: 100%;
  max-height: 260px; overflow-y: auto; background: var(--panel); border: 2px solid var(--purple-dim); border-radius: 10px; }
.bglist li { display: flex; align-items: center; gap: 8px; padding: 4px 8px; border-radius: 8px; cursor: pointer; font-weight: 600; white-space: nowrap; }
.bglist li:hover, .bglist li[aria-selected=true] { background: var(--t-3a2060); }

/* ---- preview window: every control is the same height ---- */
.dialog button, .dialog select, .dialog input[type=number], .dialog input[type=color], .dialog .bgcur { height: 34px; }
.dialog button { padding: 0 14px; font-size: .95rem; border-radius: 10px; }
.dialog button.small, .dialog button.dim { background: var(--t-3a2060); }
.dialog button.small:hover, .dialog button.dim:hover { background: var(--t-55308a); }
.dialog button.w100 { width: 100px; }
.dialog .iconsq { width: 46px; padding: 0; display: flex; align-items: center; justify-content: center; background: var(--t-3a2060); }
.dialog .iconsq:hover { background: var(--t-55308a); }
.dialog button[aria-pressed=true] { background: var(--t-d28bff); color: var(--t-1a0b2e); }
.dialog .bgcur { padding: 0 10px 0 4px; background: var(--black); border-radius: 10px; }
.dialog .bgcur:hover { background: var(--t-1e1530); }
.bgcur img { width: 22px; height: 28px; }
.dialog select, .dialog input[type=number] { padding-top: 0; padding-bottom: 0; }
.controls.bottom { justify-content: flex-end; align-items: center; gap: 8px; }

/* ---- Readable Message box (rich text) ---- */
.rtbar { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
.rtbar select { height: 32px; background: var(--black); color: var(--text); border: 2px solid var(--purple-dim); border-radius: 8px; padding: 0 6px; font-size: .9rem; max-width: 150px; }
.rtbar button.rt { width: 34px; height: 32px; padding: 0; background: var(--t-3a2060); font-size: 1rem; border-radius: 8px; display: flex; align-items: center; justify-content: center; }
.rtbar button.rt:hover { background: var(--t-55308a); }
.rtbar button.rt.on { background: var(--t-d28bff); color: var(--t-1a0b2e); }
.rtcolor { position: relative; width: 34px; height: 32px; border-radius: 8px; background: var(--t-3a2060); cursor: pointer; display: flex; align-items: center; justify-content: center; }
.rtcolor:hover { background: var(--t-55308a); }
.rtcolor input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }
.rtcolor .sw { font-weight: 900; font-size: .95rem; line-height: 1; padding-bottom: 3px; border-bottom: 4px solid var(--c, #fff); }
.rtbox { min-height: 150px; max-height: 360px; overflow: auto; background: var(--black); color: var(--t-d9b3ff); border: 2px solid var(--purple-dim); border-radius: 12px;
  padding: 10px; font-size: 1.35rem; font-weight: 500; line-height: 1.35; outline: none; }
.rtbox:focus { border-color: var(--t-d28bff); }
.rtbox:empty::before { content: attr(data-placeholder); color: var(--t-6e5a8a); pointer-events: none; }
.rtbox img { max-width: 100%; height: auto; border-radius: 6px; }

/* ---- color buttons + custom color picker ---- */
.colorbtn { display: flex; align-items: center; gap: 8px; }
.dot { width: 18px; height: 18px; border-radius: 50%; background: var(--dot, #3b1f0a); border: 2px solid #fff; display: inline-block; }
.rtcolor { border: 0; padding: 0; }
.rtcolor .sw { color: #fff; }
.cdlg { z-index: 40; }
.cd { width: min(100%, 640px); }
.cd h2 { margin: 0; font-size: 1.15rem; color: var(--heading); }
.cdbody { display: flex; flex-wrap: wrap; gap: 16px; }
.cdleft { flex: 1 1 250px; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.cdright { flex: 0 1 240px; display: flex; flex-direction: column; gap: 8px; align-items: stretch; }
.cdlabel { font-weight: 600; font-size: .95rem; }
.cdgrid { display: grid; grid-template-columns: repeat(8, 1fr); gap: 4px; }
.cdgrid button { height: auto !important; aspect-ratio: 1; padding: 0 !important; border-radius: 4px !important; border: 2px solid transparent; background: var(--c); }
.cdgrid button:hover, .cdgrid button.sel { border-color: #fff; }
.cdgrid button.empty { background: var(--t-1e1530); border: 1px dashed var(--t-5a3a85); cursor: default; }
.cdbtns { display: flex; flex-direction: column; gap: 6px; align-items: flex-start; }
#cdSpec { width: 100%; height: auto; border: 2px solid var(--purple-dim); border-radius: 8px; cursor: crosshair; touch-action: none; display: block; }
#cdVal { width: 100%; accent-color: var(--purple); }
.cdrow { display: flex; }
.cdswatch { flex: 1; height: 34px; border-radius: 8px; border: 2px solid #fff; background: #000; }
.cdfields { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 10px; }
.cdfields label { display: flex; align-items: center; justify-content: space-between; gap: 6px; font-size: .9rem; }
.cdfields input { width: 4.4em; background: var(--black); color: var(--text); border: 2px solid var(--purple-dim); border-radius: 8px; padding: 0 6px; height: 30px; }
.cdfields .hexl { grid-column: 1 / -1; }
.cdfields .hexl input { width: 100%; }
@media print { .cdlg { display: none !important; } }

/* ---- monospace boxes: the same look as the printed worksheet; long lines scroll sideways ---- */
textarea { font-family: Consolas, 'Courier New', monospace; white-space: pre; overflow: auto; tab-size: 4; }
button.act.mid { width: 96px; }

/* ---- worksheet (on-page print preview; these very pages are what the browser prints) ---- */
.wsov { z-index: 20; }
.wsdlg { width: min(100%, 1340px); height: min(100%, 92vh); max-height: none; }
.wsbody { display: flex; gap: 14px; min-height: 0; flex: 1; }
.wsctl { flex: 0 0 360px; overflow-x: hidden; overflow-y: auto; display: flex; flex-direction: column; gap: 5px; padding-right: 6px; }
.wsctl h3 { margin: 3px 0 0; font-size: 1rem; color: var(--heading); }
.wsrow { display: flex; align-items: center; gap: 6px; }
.wsrow input[type=range] { flex: 1; min-width: 0; accent-color: var(--purple); }
.wsrow select, .wsctl > select { flex: 1; min-width: 0; max-width: none; }
.wsdlg input[type=number] { width: 5.4em; background: var(--black); color: var(--text); border: 2px solid var(--purple-dim); border-radius: 8px; padding: 0 6px; }
.wsmargins { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 10px; }
.wsmargins label { display: flex; justify-content: space-between; align-items: center; gap: 6px; font-size: .9rem; }
.wsmargins input { width: 4.8em; }
.wscheck { display: flex; gap: 8px; align-items: center; font-size: .95rem; }
.wscheck input { width: 18px; height: 18px; accent-color: var(--purple); }
.wsbtns { margin-top: auto; padding-top: 8px; }
.wsbtns button { flex: 1; }
.wsnote { margin: 0; font-size: .8rem; opacity: .8; }
.wsctl > button { width: 100%; }
.wsstage { flex: 1; overflow: auto; background: #5d5d66; padding: 12px; border-radius: 10px; min-height: 0; min-width: 0; }
#wsScaler { margin: 0 auto; }
#wsPages { transform-origin: top left; width: max-content; display: flex; flex-direction: column; gap: 14px; }
.ws-page { position: relative; flex: none; background: #fff; color: var(--ink, #000); box-shadow: 0 2px 10px rgba(0, 0, 0, .5); overflow: hidden;
  font-family: var(--font, Consolas, 'Courier New', monospace); break-inside: avoid; }
.ws-bg { position: absolute; left: 0; top: 0; width: 100%; height: 100%; object-fit: cover; z-index: 0; }
.ws-scan { position: absolute; inset: 0; width: 100%; height: 100%; opacity: .55; z-index: 1; }
.ws-content { position: absolute; z-index: 2; }
.ws-head { padding-bottom: calc(var(--em) * 0.3); }
.ws-key { font-family: 'Comic Sans MS', 'Comic Sans', 'Chalkboard SE', 'Comic Neue', cursive; font-size: calc(var(--em) * 0.85); line-height: 1.25; white-space: pre-line; }
.ws-row { display: flex; position: relative; white-space: pre; break-inside: avoid; page-break-inside: avoid; }
.ws-row .c { flex: none; width: var(--cw); display: flex; flex-direction: column; }
.ws-note { position: absolute; z-index: 3; text-align: center; color: var(--ink, #000); font: 500 18px 'Segoe UI', Arial, sans-serif; line-height: 1.3; }
/* the soft white backdrop: solid white 3 mm around the text, fading out over about 6 mm more (same look as the app) */
.ws-note-in { display: inline-block; max-width: 100%; background: rgba(255, 255, 255, .9); box-shadow: 0 0 6mm 3mm rgba(255, 255, 255, .9); }
.ws-note-in * { text-align: center !important; max-width: 100%; }
.ws-note img { height: auto; }
.ws-note.ws-probe-note { position: static; visibility: hidden; }
.ws-row .ch { font-family: var(--font); display: block; height: var(--code-h); line-height: var(--code-h); text-align: center; font-size: var(--em); white-space: pre; }
.ws-row.label .ch { font-weight: 700; }
.ws-row .ans { display: block; position: relative; height: var(--write-h); }
.ws-row .ans.ln { border-bottom: var(--line-w) solid currentColor; }
.ws-row .ans.ln::before, .ws-row .ans.ln::after { content: ""; position: absolute; bottom: 0; height: var(--tick); border-left: calc(var(--line-w) * 0.7) solid currentColor; }
.ws-row .ans.ln::before { left: 0; }
.ws-row .ans.ln::after { right: 0; }
.ws-row.cont::before { content: "\21AA"; position: absolute; left: calc(var(--cw) * -1.6); width: calc(var(--cw) * 1.5); text-align: right; color: #666; font-size: calc(var(--em) * 0.8); line-height: var(--code-h); }
@media (max-width: 760px) { .wsbody { flex-direction: column; } .wsctl { flex: none; max-height: 42vh; } }

/* Ctrl+P / the Print button while the worksheet is open prints only its pages, exactly as shown */
@media print {
  body.ws-open .app, body.ws-open #colorDlg { display: none !important; }
  body.ws-open #preview { display: block !important; position: static; padding: 0; background: none; }
  body.ws-open .wsdlg { display: block; width: auto; height: auto; border: 0; padding: 0; background: none; }
  body.ws-open .wsctl { display: none !important; }
  body.ws-open .wsbody { display: block; }
  body.ws-open .wsstage { overflow: visible; padding: 0; background: none; }
  body.ws-open #wsScaler { width: auto !important; height: auto !important; margin: 0; }
  body.ws-open #wsPages { transform: none !important; display: block; width: auto; }
  body.ws-open .ws-page { box-shadow: none; margin: 0; break-after: page; page-break-after: always; }
  body.ws-open .ws-page:last-child { break-after: auto; page-break-after: auto; }
  body.ws-open .ws-scan { display: none !important; }   /* the paper scan is for lining up only */
  body.ws-open .ws-page { print-color-adjust: exact; -webkit-print-color-adjust: exact; }
}
