/* EEPROM programmer page. Builds on ../../css/style.css (dark site theme). */

:root {
  --ok: #5fd47a;
  --bad: #ff6262;
  --edited: var(--signal);
  --mono: ui-monospace, "Cascadia Mono", "SFMono-Regular", Menlo, Consolas, monospace;
}

.wrap.wide { max-width: 1440px; }

.tool-main { padding: 22px 0 40px; }

.tool-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px 24px;
  margin-bottom: 16px;
}
.tool-head h1 { margin: 0; font-size: clamp(1.6rem, 3.6vw, 2.3rem); }
.tool-head p { margin: 4px 0 0; color: var(--text-dim); }

.session-box {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 8px 8px 14px;
  background: var(--surface);
  border: 1px solid var(--surface-2);
  border-radius: 999px;
  font-size: 0.88rem;
}
.session-box .label { color: var(--text-dim); }
.session-box b { color: var(--cream-soft); font-weight: 400; font-family: var(--font-display); }

.banner {
  margin: 0 0 16px;
  padding: 12px 16px;
  border-left: 4px solid var(--bad);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--bad) 10%, var(--space-deep));
}

/* ---- Buttons ---- */

.tbtn, .sbtn, .linkbtn {
  font: inherit;
  cursor: pointer;
  color: var(--cream-soft);
}
.tbtn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 8px 13px;
  border-radius: var(--radius);
  border: 1px solid var(--surface-2);
  background: var(--surface);
  font-size: 0.88rem;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s;
}
.tbtn[hidden] { display: none; }
.tbtn svg { width: 17px; height: 17px; flex: none; }
.tbtn:hover:not(:disabled) { border-color: var(--space-slate); background: var(--surface-2); }
.tbtn:focus-visible, .sbtn:focus-visible, .linkbtn:focus-visible {
  outline: 2px solid var(--glow-cyan);
  outline-offset: 2px;
}
.tbtn:disabled { opacity: 0.4; cursor: not-allowed; }
.tbtn.primary { border-color: var(--ignition); background: color-mix(in srgb, var(--ignition) 18%, var(--surface)); }
.tbtn.primary:hover:not(:disabled) { background: var(--ignition); color: var(--space-black); }
.tbtn.danger:hover:not(:disabled) { border-color: var(--bad); background: color-mix(in srgb, var(--bad) 18%, var(--surface)); }

.sbtn {
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--surface-2);
  background: var(--surface-2);
  font-size: 0.82rem;
}
.sbtn:hover { border-color: var(--space-slate); }

.linkbtn {
  all: unset;
  cursor: pointer;
  color: var(--link);
  font-size: 0.82rem;
  border-bottom: 1px dotted currentColor;
}
.linkbtn:hover { color: var(--link-hover); }

/* ---- Status cards ---- */

.status-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 12px;
  margin-bottom: 12px;
}
.status-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--surface-2);
  border-radius: var(--radius-lg);
  min-width: 0;
}
.status-card .body { flex: 1; min-width: 0; }
.status-card .title {
  display: block;
  font-family: var(--font-display);
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-dim);
}
.status-card .value { display: block; color: var(--cream-soft); overflow-wrap: anywhere; }
.status-card .sub { display: block; font-size: 0.8rem; color: var(--text-dim); overflow-wrap: anywhere; }
.status-card .actions { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }

.dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  flex: none;
  background: var(--space-divider);
}
.dot.on { background: var(--ok); box-shadow: 0 0 10px var(--ok); }
.dot.warn { background: var(--signal); box-shadow: 0 0 10px var(--signal); }
.dot.off { background: var(--bad); }

select.chip-select {
  font: inherit;
  font-size: 0.85rem;
  color: var(--cream-soft);
  background: var(--surface-2);
  border: 1px solid var(--space-slate);
  border-radius: var(--radius);
  padding: 5px 8px;
  max-width: 100%;
}

.verdict {
  font-family: var(--font-display);
  font-size: 1.35rem;
  letter-spacing: 0.06em;
  line-height: 1.2;
  color: var(--text-dim);
}
.verdict.ok { color: var(--ok); text-shadow: 0 0 14px color-mix(in srgb, var(--ok) 50%, transparent); }
.verdict.bad { color: var(--bad); text-shadow: 0 0 14px color-mix(in srgb, var(--bad) 50%, transparent); }

/* ---- Result card (left of the buttons) ---- */

.action-row {
  display: grid;
  grid-template-columns: minmax(230px, 300px) minmax(0, 1fr);
  gap: 12px;
  margin-bottom: 12px;
  align-items: stretch;
}
@media (max-width: 760px) {
  .action-row { grid-template-columns: minmax(0, 1fr); }
}
.action-row .toolbar { margin-bottom: 0; }
.result-card {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 2px;
  padding: 12px 16px;
  background: var(--surface);
  border: 1px solid var(--surface-2);
  border-left: 5px solid var(--space-divider);
  border-radius: var(--radius-lg);
  min-width: 0;
}
.result-card .title {
  font-family: var(--font-display);
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-dim);
}
.result-card .sub { font-size: 0.8rem; color: var(--text-dim); overflow-wrap: anywhere; }
.result-card .verdict { font-size: 1.7rem; }
.result-card.ok { border-left-color: var(--ok); background: color-mix(in srgb, var(--ok) 8%, var(--surface)); }
.result-card.bad { border-left-color: var(--bad); background: color-mix(in srgb, var(--bad) 8%, var(--surface)); }
.result-card.flash { animation: result-flash 0.9s ease-out; }
@keyframes result-flash {
  0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--signal) 70%, transparent); }
  100% { box-shadow: 0 0 0 14px transparent; }
}
@media (prefers-reduced-motion: reduce) { .result-card.flash { animation: none; } }

.view-toggle { display: inline-flex; margin-top: 8px; align-self: flex-start; border: 1px solid var(--space-slate); border-radius: 999px; overflow: hidden; }
.view-toggle[hidden] { display: none; }
.view-toggle button {
  font: inherit;
  font-size: 0.8rem;
  padding: 4px 12px;
  border: none;
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
}
.view-toggle button[aria-pressed="true"] { background: var(--surface-2); color: var(--cream-soft); }
.view-toggle button:focus-visible { outline: 2px solid var(--glow-cyan); outline-offset: -2px; }

.ref-note { color: var(--bad); }
.hexgrid.showing-ref { box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--bad) 60%, transparent); }
.hexgrid.showing-ref span.diff { background: color-mix(in srgb, var(--bad) 75%, #000); }

/* ---- Toolbar ---- */

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 18px;
  align-items: center;
  padding: 10px 12px;
  margin-bottom: 12px;
  background: var(--surface);
  border: 1px solid var(--surface-2);
  border-radius: var(--radius-lg);
}
.tool-group { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.tool-group + .tool-group { padding-left: 18px; border-left: 1px solid var(--surface-2); }
@media (max-width: 760px) {
  .tool-group + .tool-group { padding-left: 0; border-left: none; }
}

.menu { position: relative; }
.menu > summary { list-style: none; }
.menu.disabled > summary { opacity: 0.4; pointer-events: none; }
.menu > summary::-webkit-details-marker { display: none; }
.menu-items {
  position: absolute;
  z-index: 20;
  top: calc(100% + 6px);
  left: 0;
  min-width: 230px;
  padding: 6px;
  background: var(--space-navy);
  border: 1px solid var(--space-slate);
  border-radius: var(--radius);
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.5);
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.menu-items button {
  all: unset;
  cursor: pointer;
  padding: 7px 10px;
  border-radius: 4px;
  font-size: 0.88rem;
}
.menu-items button:hover, .menu-items button:focus-visible { background: var(--surface-2); }
.menu-items label { display: flex; gap: 8px; align-items: center; padding: 6px 10px; font-size: 0.88rem; cursor: pointer; }
.menu-items .sep { border-top: 1px solid var(--surface-2); margin: 4px 0; }
.menu-items select { margin-left: auto; }

/* ---- Workspace ---- */

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 380px;
  gap: 12px;
  align-items: start;
}
@media (max-width: 1080px) {
  .workspace { grid-template-columns: minmax(0, 1fr); }
}

.panel {
  background: var(--surface);
  border: 1px solid var(--surface-2);
  border-radius: var(--radius-lg);
  padding: 12px 14px;
  min-width: 0;
}
.panel + .panel { margin-top: 12px; }
.panel h2 {
  margin: 0 0 8px;
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-dim);
}
.panel p.note { font-size: 0.8rem; color: var(--text-dim); margin: 8px 0 0; }

.grid-panel { position: relative; padding: 0; overflow: hidden; }
.grid-status {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 4px 16px;
  padding: 9px 14px;
  border-bottom: 1px solid var(--surface-2);
  font-size: 0.82rem;
  color: var(--text-dim);
}
.grid-status b { color: var(--cream-soft); font-weight: 400; font-family: var(--mono); }
.legend { display: flex; gap: 12px; flex-wrap: wrap; }
.legend > span::before {
  content: "";
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 2px;
  margin-right: 5px;
  vertical-align: -1px;
  background: var(--sw);
}

/* ---- Hex grid ---- */

.hexgrid {
  font-family: var(--mono);
  font-size: 14px;
  line-height: 1.55;
  max-height: min(64vh, 720px);
  overflow: auto;
  padding: 0 14px 10px;
  user-select: none;
  -webkit-user-select: none;
  outline: none;
  cursor: text;
}
.hexgrid:focus-visible { box-shadow: inset 0 0 0 2px var(--glow-cyan); }
.hx-row { display: flex; gap: 14px; width: max-content; }
.hx-head {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--surface);
  color: var(--space-divider);
  padding-top: 8px;
  border-bottom: 1px solid var(--surface-2);
  margin-bottom: 2px;
}
.hx-off { width: 3ch; color: var(--space-divider); }
.hx-hex { display: flex; }
.hx-hex > span { width: 2.9ch; text-align: center; border-radius: 3px; }
.hx-hex > span:nth-child(8) { margin-right: 0.8ch; }
.hx-asc { display: flex; border-left: 1px solid var(--surface-2); padding-left: 10px; }
.hx-asc > span { width: 1.15ch; text-align: center; border-radius: 2px; white-space: pre; }
.hx-head .hx-hex > span, .hx-head .hx-asc { color: var(--space-divider); }

.hx-row:not(.hx-head) span.ff { color: color-mix(in srgb, var(--cream) 38%, transparent); }
.hx-row:not(.hx-head) span.zero { color: color-mix(in srgb, var(--cream) 55%, transparent); }
.hx-asc span.np { color: color-mix(in srgb, var(--cream) 28%, transparent); }
.hexgrid span.edited { color: var(--space-black); background: var(--edited); }
.hexgrid span.diff { color: #fff; background: var(--bad); }
.hexgrid span.edited.diff { background: linear-gradient(135deg, var(--edited) 50%, var(--bad) 50%); color: var(--space-black); }
.hexgrid span.sel { background: color-mix(in srgb, var(--glow-cyan) 32%, transparent); color: #fff; }
.hexgrid span.cur { box-shadow: inset 0 0 0 2px var(--ignition); }
.hexgrid:focus span.cur { animation: cursor-pulse 1.1s ease-in-out infinite; }
.hexgrid span.cur2 { box-shadow: inset 0 0 0 1px var(--space-slate); }
@keyframes cursor-pulse { 50% { box-shadow: inset 0 0 0 2px var(--signal); } }

/* ---- Busy overlay ---- */

.busy {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
  background: color-mix(in srgb, var(--space-black) 78%, transparent);
  backdrop-filter: blur(2px);
}
.busy[hidden] { display: none; }
.busy-card {
  width: min(420px, 90%);
  padding: 20px 22px;
  text-align: center;
  background: var(--space-navy);
  border: 1px solid var(--space-slate);
  border-radius: var(--radius-lg);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.5);
}
.busy-anim { display: flex; align-items: center; justify-content: center; gap: 10px; margin-bottom: 12px; }
.busy-anim svg { width: 46px; height: 46px; flex: none; color: var(--cream-soft); }
.bitstream {
  position: relative;
  width: 150px;
  height: 22px;
  overflow: hidden;
  font-family: var(--mono);
  font-size: 15px;
  color: var(--glow-cyan);
  mask-image: linear-gradient(90deg, transparent, #000 20%, #000 80%, transparent);
  -webkit-mask-image: linear-gradient(90deg, transparent, #000 20%, #000 80%, transparent);
}
.bitstream span {
  position: absolute;
  top: 0;
  left: 0;
  white-space: pre;
  animation: bits 1.6s linear infinite;
}
.busy[data-dir="out"] .bitstream span { animation-direction: reverse; color: var(--signal); }
@keyframes bits { from { transform: translateX(-50%); } to { transform: translateX(0); } }
.busy-label { font-family: var(--font-display); color: var(--cream-soft); }
.busy-detail { font-size: 0.82rem; color: var(--text-dim); min-height: 1.3em; }
.bar { height: 8px; border-radius: 99px; background: var(--surface); overflow: hidden; margin: 10px 0 14px; }
.bar > i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--ignition), var(--signal)); transition: width 0.12s; }
@media (prefers-reduced-motion: reduce) {
  .bitstream span, .hexgrid:focus span.cur { animation: none; }
}

/* ---- Pictures (checker panel preview) ---- */

.led-panel {
  display: block;
  width: 100%;
  height: auto;
  background: #000;
  border-radius: 6px;
  image-rendering: auto;
}
.palettes { display: flex; flex-wrap: wrap; gap: 10px 22px; margin-top: 10px; }
.palette b {
  display: block;
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  margin-bottom: 4px;
}
.palette .sw { display: flex; flex-wrap: wrap; gap: 4px; }
.palette .sw span {
  display: inline-flex;
  align-items: flex-end;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 4px;
  font-family: var(--mono);
  font-size: 0.68rem;
  color: #fff;
  text-shadow: 0 0 3px #000, 0 0 2px #000;
  border: 1px solid var(--surface-2);
}
.pixel-info { font-family: var(--mono); font-size: 0.8rem; color: var(--text-dim); min-height: 1.4em; margin-top: 6px; }

/* ---- Log ---- */

.log {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 260px;
  overflow: auto;
  font-family: var(--mono);
  font-size: 0.78rem;
  line-height: 1.45;
}
.log li { padding: 2px 0; border-bottom: 1px dashed color-mix(in srgb, var(--surface-2) 70%, transparent); overflow-wrap: anywhere; }
.log time { color: var(--space-divider); margin-right: 6px; }
.log .ok { color: var(--ok); }
.log .warn { color: var(--signal); }
.log .error { color: var(--bad); }

/* ---- Dialogs ---- */

dialog.modal {
  width: min(560px, calc(100vw - 32px));
  max-height: calc(100vh - 48px);
  padding: 0;
  color: var(--text);
  background: var(--space-deep);
  border: 1px solid var(--space-slate);
  border-radius: var(--radius-lg);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.6);
}
dialog.modal.wide { width: min(760px, calc(100vw - 32px)); }
dialog.modal::backdrop { background: rgba(5, 8, 12, 0.72); backdrop-filter: blur(2px); }
.modal-body { padding: 20px 22px 8px; }
.modal-body h2 { margin: 0 0 10px; font-size: 1.3rem; }
.modal-body ul, .modal-body ol { padding-left: 1.3em; margin: 0 0 1em; }
.modal-body li { margin-bottom: 0.45em; }
.modal-body pre {
  font-family: var(--mono);
  font-size: 0.8rem;
  background: var(--surface-2);
  padding: 8px 10px;
  border-radius: var(--radius);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  max-height: 160px;
  overflow: auto;
}
.modal-body code { font-family: var(--mono); color: var(--signal); }
.modal-body svg.figure { width: 100%; height: auto; display: block; margin: 6px 0 12px; }
.modal-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 22px 18px;
}
.modal-check { display: flex; gap: 8px; align-items: center; font-size: 0.88rem; color: var(--text-dim); margin: 6px 0 4px; }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.field label { font-size: 0.82rem; color: var(--text-dim); }
.field input[type="text"], .field select {
  font: inherit;
  font-family: var(--mono);
  color: var(--cream-soft);
  background: var(--surface);
  border: 1px solid var(--space-slate);
  border-radius: var(--radius);
  padding: 8px 10px;
}
.field input:focus { outline: 2px solid var(--glow-cyan); outline-offset: 1px; }
.field-row { display: flex; gap: 12px; flex-wrap: wrap; }
.field-row .field { flex: 1; min-width: 120px; }
.error-text { color: var(--bad); font-size: 0.85rem; min-height: 1.3em; margin: 0; }
kbd {
  font-family: var(--mono);
  font-size: 0.8em;
  padding: 1px 5px;
  border-radius: 4px;
  border: 1px solid var(--space-slate);
  background: var(--surface-2);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 60;
  transform: translateX(-50%);
  padding: 10px 18px;
  border-radius: 999px;
  background: var(--space-navy);
  border: 1px solid var(--space-slate);
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.5);
  font-size: 0.9rem;
  max-width: calc(100vw - 32px);
}
.toast[hidden] { display: none; }

.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}
