/* MORSE: a crude paint program. Grey bevelled chrome on a teal desktop, a white sheet where everything is drawn with the mouse. */
:root {
  --desk: #008080; --chrome: #c0c0c0; --hi: #ffffff; --lo: #808080; --dk: #000000; --navy: #000080; --paper: #ffffff; --ink: #111111;
  --red: #ff0000; --yel: #ffff00; --blu: #0000ff; --lim: #00ff00; --mag: #ff00ff; --cya: #00ffff; --org: #ff8000; --grn: #008000; --mar: #800000;
  --hand: 'Comic Neue', 'Comic Sans MS', cursive; --pix: 'Pixelify Sans', system-ui, sans-serif; --num: 'VT323', ui-monospace, monospace;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--desk); color: var(--ink); font: 400 16px/1.4 var(--hand); overflow: hidden; -webkit-tap-highlight-color: transparent; }
a { color: var(--blu); }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* ---------- bevels ---------- */
.out { background: var(--chrome); box-shadow: inset -1px -1px var(--dk), inset 1px 1px var(--hi), inset -2px -2px var(--lo), inset 2px 2px #dfdfdf; }
.in { background: var(--hi); box-shadow: inset -1px -1px var(--hi), inset 1px 1px var(--lo), inset -2px -2px #dfdfdf, inset 2px 2px var(--dk); }
.btn { font: 500 15px/1 var(--pix); padding: 8px 14px; min-height: 34px; border: 0; border-radius: 0; cursor: pointer; background: var(--chrome); color: var(--dk);
  box-shadow: inset -1px -1px var(--dk), inset 1px 1px var(--hi), inset -2px -2px var(--lo), inset 2px 2px #dfdfdf; display: inline-flex; align-items: center; justify-content: center; gap: 6px; text-decoration: none; white-space: nowrap; }
.btn:active, .btn.on { box-shadow: inset 1px 1px var(--dk), inset -1px -1px var(--hi), inset 2px 2px var(--lo), inset -2px -2px #dfdfdf; padding: 9px 13px 7px 15px; }
.btn:focus-visible { outline: 1px dotted var(--dk); outline-offset: -5px; }
.btn[disabled] { color: var(--lo); text-shadow: 1px 1px var(--hi); cursor: default; }
.btn.big { font-size: 20px; padding: 14px 22px; min-height: 52px; }
.btn.big:active { padding: 15px 21px 13px 23px; }
.field { font: 400 17px/1.2 var(--hand); padding: 8px 9px; border: 0; border-radius: 0; width: 100%; background: var(--hi);
  box-shadow: inset -1px -1px var(--hi), inset 1px 1px var(--lo), inset -2px -2px #dfdfdf, inset 2px 2px var(--dk); }
.field:focus { outline: 1px dotted var(--dk); outline-offset: -4px; }
textarea.field { resize: vertical; min-height: 70px; }
.mono { font-family: var(--num); font-size: 1.3em; line-height: 1; letter-spacing: .02em; }

/* ---------- the window ---------- */
.win { position: fixed; inset: 10px; display: flex; flex-direction: column; background: var(--chrome); padding: 3px;
  box-shadow: inset -1px -1px var(--dk), inset 1px 1px #dfdfdf, inset -2px -2px var(--lo), inset 2px 2px var(--hi); max-width: 1400px; margin: 0 auto; }
.title { background: var(--navy); color: #fff; display: flex; align-items: center; gap: 6px; padding: 3px 3px 3px 5px; font: 600 15px/1 var(--pix); min-height: 28px; user-select: none; }
.title .ticon { width: 18px; height: 18px; flex: none; }
.title .ttext { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.title .tb { width: 24px; height: 22px; min-height: 0; padding: 0; font: 700 14px/1 var(--pix); }
.title .tb:active { padding: 1px 0 0 1px; }
.menu { display: flex; align-items: center; gap: 0; padding: 2px 0; font: 400 15px/1 var(--pix); position: relative; z-index: 30; user-select: none; }
.menu > .mi { position: relative; }
.menu > .mi > button, .menu > a.mi { background: none; border: 0; padding: 6px 9px; cursor: pointer; font: inherit; color: var(--dk); text-decoration: none; display: block; }
.menu u { text-decoration-thickness: 1px; text-underline-offset: 2px; }
.menu > .mi.open > button, .menu > .mi > button:hover, .menu > a.mi:hover { background: var(--navy); color: #fff; }
.menu .drop { position: absolute; top: 100%; left: 0; min-width: 220px; padding: 3px; display: none; z-index: 40; }
.menu .mi.open .drop { display: block; }
.menu .drop a, .menu .drop button { display: flex; justify-content: space-between; gap: 20px; width: 100%; text-align: left; background: none; border: 0; padding: 8px 18px; color: var(--dk); text-decoration: none; cursor: pointer; font: inherit; white-space: nowrap; }
.menu .drop a:hover, .menu .drop button:hover { background: var(--navy); color: #fff; }
.menu .drop button[disabled] { color: var(--lo); text-shadow: 1px 1px var(--hi); background: none; cursor: default; }
.menu .drop hr { border: 0; border-top: 1px solid var(--lo); border-bottom: 1px solid var(--hi); margin: 3px 2px; }
.menu .drop .chk::before { content: ''; display: inline-block; width: 14px; }
.menu .drop .chk.on::before { content: '\2713'; }
.menu .spacer { flex: 1; }
.menu .wallet { margin: 0 3px; min-height: 28px; padding: 5px 10px; font-size: 14px; }
.menu .wallet:active { padding: 6px 9px 4px 11px; }
.menu .wallet.on::before { content: ''; width: 8px; height: 8px; background: var(--lim); box-shadow: 0 0 0 1px var(--dk); }

.body { flex: 1; min-height: 0; display: flex; gap: 3px; }
.tools { flex: none; width: 62px; padding: 4px 3px; display: flex; flex-direction: column; gap: 6px; }
.tools .grid { display: grid; grid-template-columns: 26px 26px; gap: 0; justify-content: center; }
.tools .t { width: 26px; height: 26px; min-height: 0; padding: 0; }
.tools .t:active, .tools .t.on { padding: 1px 0 0 1px; background: repeating-conic-gradient(var(--hi) 0 25%, var(--chrome) 0 50%) 0 0 / 2px 2px; }
.tools .t svg { width: 16px; height: 16px; display: block; margin: auto; shape-rendering: crispEdges; }
.tools .opt { width: 44px; margin: 0 auto; min-height: 66px; display: flex; flex-direction: column; justify-content: center; align-items: center; gap: 4px; padding: 4px 0; }
.tools .opt i { display: block; background: var(--dk); border-radius: 1px; }
.tools .opt b { display: block; cursor: pointer; padding: 2px 4px; width: 36px; }
.tools .opt b.on { background: var(--navy); }
.tools .opt b.on i { background: #fff; }

.cw { flex: 1; min-width: 0; overflow: auto; background: var(--lo); position: relative; overscroll-behavior: contain; }
.cw::-webkit-scrollbar { width: 17px; height: 17px; }
.cw::-webkit-scrollbar-track { background: repeating-conic-gradient(var(--hi) 0 25%, var(--chrome) 0 50%) 0 0 / 2px 2px; }
.cw::-webkit-scrollbar-thumb { background: var(--chrome); box-shadow: inset -1px -1px var(--dk), inset 1px 1px var(--hi), inset -2px -2px var(--lo), inset 2px 2px #dfdfdf; }
.cw::-webkit-scrollbar-corner { background: var(--chrome); }
.sheet { position: relative; background: var(--paper); margin: 6px; min-height: calc(100% - 12px); padding: 26px 30px 60px; overflow: hidden; }
.sheet .grip { position: absolute; width: 5px; height: 5px; background: var(--navy); }
.sheet .grip.r { right: 0; top: 50%; } .sheet .grip.b { bottom: 0; left: 50%; } .sheet .grip.rb { right: 0; bottom: 0; }
#doodle { position: absolute; left: 0; top: 0; pointer-events: none; z-index: 20; touch-action: none; }
#doodle.live { pointer-events: auto; cursor: crosshair; }

.swatches { display: flex; align-items: center; gap: 6px; padding: 4px 3px 3px; user-select: none; }
.cur { position: relative; width: 34px; height: 34px; flex: none; }
.cur i { position: absolute; width: 15px; height: 15px; box-shadow: 0 0 0 1px var(--lo), 0 0 0 2px var(--hi); }
.cur i.fg { left: 5px; top: 5px; z-index: 2; } .cur i.bg { right: 5px; bottom: 5px; }
.pal { display: grid; grid-template-columns: repeat(14, 18px); grid-template-rows: 18px 18px; gap: 0; }
.pal button { width: 18px; height: 18px; border: 0; padding: 0; cursor: pointer; box-shadow: inset 1px 1px var(--lo), inset -1px -1px var(--hi), inset 2px 2px var(--dk), inset -2px -2px #dfdfdf; }
.status { display: flex; gap: 3px; font: 400 14px/1 var(--pix); }
.status > span { padding: 5px 7px; box-shadow: inset 1px 1px var(--lo), inset -1px -1px var(--hi); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.status #st-help { flex: 1; min-width: 0; }
.status #st-xy { width: 110px; font-family: var(--num); font-size: 18px; }
.status #st-sz { width: 120px; font-family: var(--num); font-size: 18px; }

/* ---------- message boxes (toasts, dialogs) ---------- */
#toasts { position: fixed; right: 16px; bottom: 16px; z-index: 90; display: flex; flex-direction: column; gap: 8px; max-width: min(380px, calc(100vw - 32px)); }
.msg { padding: 3px; }
.msg .title { font-size: 14px; min-height: 24px; }
.msg .mb { display: flex; gap: 12px; align-items: flex-start; padding: 12px 12px 10px; font: 400 15px/1.35 var(--pix); }
.msg .mb svg { flex: none; width: 30px; height: 30px; }
.msg.ok .title { background: var(--grn); }
.dlg-back { position: fixed; inset: 0; z-index: 80; display: grid; place-items: center; padding: 16px; background: transparent; }
.dlg { width: min(560px, 100%); max-height: calc(100dvh - 40px); display: flex; flex-direction: column; padding: 3px; }
.dlg .db { background: var(--chrome); padding: 14px; overflow: auto; font: 400 15px/1.45 var(--pix); }
.dlg .db p { margin: 0 0 10px; }
.dlg .db .row { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; }

/* ---------- hand-drawn things on the sheet ---------- */
.h1 { font: 700 clamp(44px, 7vw, 92px)/.92 var(--hand); margin: 0; letter-spacing: -.01em; transform: rotate(-2deg); transform-origin: left center; }
.h2 { font: 700 clamp(26px, 3.2vw, 38px)/1.05 var(--hand); margin: 0 0 10px; }
.h3 { font: 700 22px/1.1 var(--hand); margin: 0 0 8px; }
.lede { font: 400 20px/1.35 var(--hand); margin: 12px 0 0; max-width: 34em; }
.scrawl { position: relative; }
.scrawl::before { content: ''; position: absolute; inset: 0; border: 3px solid var(--line, var(--ink)); border-radius: 3px 9px 4px 11px / 9px 4px 10px 3px; filter: url(#wob); pointer-events: none; }
.sprayed { background-repeat: repeat; }
.hl { padding: 0 .12em; background-image: var(--spray-yel); }
.hl-r { padding: 0 .12em; background-image: var(--spray-red); color: #fff; }
.hl-c { padding: 0 .12em; background-image: var(--spray-cya); }
.note { font: 400 16px/1.35 var(--hand); }
.small { font-size: 15px; }
.tilt-l { transform: rotate(-1.5deg); } .tilt-r { transform: rotate(1.2deg); }
.arrow { position: absolute; pointer-events: none; overflow: visible; }
.lbl { font: 700 18px/1.1 var(--hand); }
.err { color: var(--red); font-weight: 700; min-height: 1.4em; }
.ok-t { color: var(--grn); font-weight: 700; }
.sym { font-family: var(--num); font-size: 30px; letter-spacing: .08em; line-height: 1; }

/* morse strips drawn as svg */
.morse-svg { display: block; overflow: visible; }

/* the telegraph key */
.key { position: relative; cursor: pointer; touch-action: none; user-select: none; -webkit-user-select: none; outline: none; }
.key svg { display: block; width: 100%; height: auto; overflow: visible; }
.key .lever { transition: transform 40ms linear; transform-origin: 18% 62%; transform-box: view-box; }
.key.down .lever { transform: rotate(4deg); }
.key .spark { opacity: 0; }
.key.down .spark { opacity: 1; }
.key:focus-visible { outline: 2px dotted var(--ink); outline-offset: 6px; }

/* timing bar */
.tbar { position: relative; height: 40px; margin-top: 6px; }
.tbar .zones { position: absolute; inset: 0; display: flex; }
.tbar .zones span { position: relative; display: flex; align-items: flex-end; justify-content: center; font: 700 15px/1 var(--hand); padding-bottom: 4px; border-right: 2px dashed #999; }
.tbar .zones span:last-child { border-right: 0; }
.tbar .fill { position: absolute; left: 0; top: 4px; height: 14px; width: 0; background-image: var(--spray-blu); }
.tbar .fill.gap { background-image: var(--spray-org); }
.tbar .fill.dash { background-image: var(--spray-red); }
.tbar .fill.erase { background-image: var(--spray-mag); }

/* layout helpers */
.cols { display: grid; gap: 28px; }
.stack > * + * { margin-top: 14px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.kv { display: flex; justify-content: space-between; gap: 12px; padding: 6px 0; border-bottom: 2px dotted #bbb; }
.kv:last-child { border-bottom: 0; }
.kv b { font-family: var(--num); font-size: 22px; font-weight: 400; line-height: 1; }
.list { list-style: none; margin: 0; padding: 0; }

/* doodled morse chart */
.chart { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); column-gap: 14px; row-gap: 0; font: 700 18px/1 var(--hand); }
.chart div { display: flex; align-items: center; gap: 8px; padding: 3px 4px; border-radius: 4px 9px 3px 8px; min-width: 0; }
.chart div b { width: 18px; flex: none; }
.chart div i { font: 400 22px/1 var(--num); font-style: normal; letter-spacing: .12em; white-space: nowrap; }
.chart div.maybe { background-image: var(--spray-yel); }
.chart div.hit { background-image: var(--spray-lim); }

@media (max-width: 760px) {
  body { font-size: 16px; }
  .win { inset: 0; padding: 2px; }
  .title { font-size: 14px; }
  .tools { width: 34px; padding: 3px 2px; }
  .tools .grid { grid-template-columns: 26px; }
  .tools .opt { display: none; }
  .sheet { margin: 4px; padding: 18px 14px 50px; min-height: calc(100% - 8px); }
  .menu > .mi > button, .menu > a.mi { padding: 6px 7px; }
  .menu .hide-m { display: none; }
  .swatches .pal { grid-template-columns: repeat(14, 17px); grid-template-rows: 17px 17px; }
  .swatches .pal button { width: 17px; height: 17px; }
  .status #st-sz { display: none; }
  .status #st-xy { width: 92px; }
  .chart { grid-template-columns: repeat(2, minmax(0, 1fr)); font-size: 17px; }
  .menu .drop { min-width: 200px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
