/* simittag creator — design follows simitrobotics.com:
   black bg, white text, IBM Plex Mono, headings 200 italic, body 300.

   App-style layout: slim topbar, controls left, live preview right.
   Every dynamic text (hints, meta, errors) has reserved space and the
   mode-input area has a fixed min-height, so nothing shifts on input. */

@font-face {
  font-family: "IBM Plex Mono";
  src: url("fonts/plex-200i.ttf") format("truetype");
  font-weight: 200; font-style: italic; font-display: swap;
}
@font-face {
  font-family: "IBM Plex Mono";
  src: url("fonts/plex-300i.ttf") format("truetype");
  font-weight: 300; font-style: italic; font-display: swap;
}
@font-face {
  font-family: "IBM Plex Mono";
  src: url("fonts/plex-400i.ttf") format("truetype");
  font-weight: 400; font-style: italic; font-display: swap;
}
@font-face {
  font-family: "IBM Plex Mono";
  src: url("fonts/plex-200.ttf") format("truetype");
  font-weight: 200; font-style: normal; font-display: swap;
}
@font-face {
  font-family: "IBM Plex Mono";
  src: url("fonts/plex-300.ttf") format("truetype");
  font-weight: 300; font-style: normal; font-display: swap;
}
@font-face {
  font-family: "IBM Plex Mono";
  src: url("fonts/plex-700.ttf") format("truetype");
  font-weight: 700; font-style: normal; font-display: swap;
}

:root {
  --bg: #000;
  --fg: #fff;
  --dim: #8a8a8a;
  --faint: #262626;
  --panel: #0a0a0a;
  --accent: #5b9dd9;   /* terminal blue — sits with the warn/error palette */
  --warn: #c9a13b;
  --err: #d05a5a;
  --bar-h: 52px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { height: 100%; }
body {
  background: var(--bg);
  color: var(--fg);
  font-family: "IBM Plex Mono", monospace;
  font-weight: 300;
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
::selection { background: var(--fg); color: var(--bg); }
* { scrollbar-width: thin; scrollbar-color: var(--faint) transparent; }

/* ---------- topbar ---------- */
.topbar {
  flex: none;
  height: var(--bar-h);
  display: flex;
  align-items: center;
  gap: 1.5rem;
  padding: 0 1.25rem;
  border-bottom: 1px solid var(--faint);
}
.brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  color: var(--fg);
  text-decoration: none;
}
.brand img { display: block; }
.brand span {
  font-weight: 200;
  font-style: italic;
  font-size: 1.05rem;
  letter-spacing: -0.02em;
}
.tabs {
  flex: 1;
  display: flex;
  justify-content: space-evenly;
  align-items: stretch;
  height: 100%;
}
.tabs button {
  background: none;
  border: none;
  color: var(--dim);
  font: inherit;
  font-weight: 400;
  font-style: italic;
  font-size: 0.85rem;
  padding: 0 1rem;
  cursor: pointer;
  border-bottom: 1px solid transparent;
  margin-bottom: -1px;
}
.tabs button::before { content: "// "; color: #3a3a3a; font-weight: 700; font-style: normal; }
.tabs button:hover { color: var(--fg); }
.tabs button.active { color: var(--fg); border-bottom-color: var(--fg); }
.toplink {
  color: var(--dim);
  font-size: 0.8rem;
  font-style: italic;
  text-decoration: none;
}
.toplink:hover { color: var(--fg); }

/* ---------- layout ---------- */
main { flex: 1; min-height: 0; display: flex; }
section { display: none; flex: 1; min-height: 0; }
section.active {
  display: grid;
  grid-template-columns: minmax(340px, 420px) 1fr;
}
.controls {
  overflow-y: auto;
  padding: 0.4rem 1.5rem 2rem;
  border-right: 1px solid var(--faint);
}
.view {
  overflow-y: auto;
  padding: 1.25rem 1.75rem;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.view.center { align-items: center; justify-content: center; }
.view-head { flex: none; margin-bottom: 0.75rem; }

.group { padding: 1.2rem 0; border-bottom: 1px solid var(--faint); }
.group:last-child { border-bottom: none; }
.group-title {
  display: block;
  font-size: 0.68rem;
  color: #5c5c5c;
  font-style: italic;
  letter-spacing: 0.04em;
}
.group-title::before { content: "// "; color: #333; font-weight: 700; font-style: normal; }
#c-label-style { transition: opacity .2s; }
#c-label-style.inactive { opacity: 0.35; pointer-events: none; }
#c-label-style > * + * { margin-top: 1.1rem; }

p.note, .note {
  color: var(--dim);
  font-size: 0.72rem;
  font-weight: 300;
  max-width: 60ch;
  line-height: 1.6;
}
.note.warn { color: var(--warn); }
.note.error { color: var(--err); }

/* reserved-height text slots — typing never shifts the layout */
.one-line { display: block; min-height: 1.25rem; }
.hint:empty { display: none; }

/* ---------- forms ---------- */
.fieldrow {
  display: flex;
  flex-wrap: wrap;
  gap: 0.9rem 1.5rem;
  align-items: flex-start;
}
.field {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  min-width: 0;
}
.group > * + * { margin-top: 1.1rem; }
.field.narrow { flex: 0 1 auto; min-width: 10ch; }
/* narrow fields size to their one-line caption so inputs always align */
.field.narrow > span:first-child { white-space: nowrap; }
.field.grow { flex: 1 1 12ch; }
.field.third { flex: 1 1 8ch; }
.field > span:first-child {
  font-size: 0.72rem;
  color: var(--dim);
  font-style: italic;
}

input[type="text"], input[type="number"], textarea, select {
  background: var(--panel);
  border: 1px solid var(--faint);
  color: var(--fg);
  font: inherit;
  font-weight: 300;
  font-size: 0.85rem;
  padding: 0.45rem 0.65rem;
  border-radius: 0;
  width: 100%;
  min-width: 0;
}
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; }
input[type="number"] { appearance: textfield; -moz-appearance: textfield; }
textarea {
  min-height: 7.5rem;
  resize: vertical;
  line-height: 1.6;
}
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--dim); }
input:disabled, select:disabled { opacity: 0.35; }

/* ---------- segmented controls ---------- */
.seg {
  display: inline-flex;
  border: 1px solid var(--faint);
  align-self: flex-start;
}
.seg label {
  position: relative;
  padding: 0.42rem 1.05rem;
  font-size: 0.82rem;
  color: var(--dim);
  cursor: pointer;
  border-right: 1px solid var(--faint);
  transition: color .15s, background .15s;
  white-space: nowrap;
  line-height: 1.3;
}
.seg label:last-child { border-right: none; }
.seg label:hover { color: var(--fg); }
.seg label:has(input:checked) { background: var(--fg); color: var(--bg); }
.seg label:has(input:focus-visible) { outline: 1px solid var(--dim); outline-offset: 2px; }
.seg label.disabled, .seg label:has(input:disabled) {
  opacity: 0.3;
  cursor: not-allowed;
  color: var(--dim);
}
.seg label.disabled:hover { opacity: 0.6; color: #ddd; }

/* tooltip on disabled options: "needs D" / "needs M or D" */
.seg label[data-tip]:hover::after {
  content: attr(data-tip);
  position: absolute;
  bottom: calc(100% + 0.55rem);
  left: 50%;
  transform: translateX(-50%);
  background: #101010;
  border: 1px solid #3a3a3a;
  color: var(--fg);
  font-size: 0.68rem;
  font-style: italic;
  padding: 0.24rem 0.65rem;
  white-space: nowrap;
  pointer-events: none;
  animation: tip-in .16s ease both;
  z-index: 5;
}
@keyframes tip-in {
  from { opacity: 0; transform: translateX(-50%) translateY(5px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* variant(s) that would enable the hovered mode */
.seg label.suggest {
  color: var(--fg);
  animation: suggest-pulse 1.1s ease-in-out infinite;
}
@keyframes suggest-pulse {
  0%, 100% { box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.95); }
  50%      { box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.25); }
}
.seg input {
  position: absolute;
  opacity: 0;
  width: 100%; height: 100%;
  left: 0; top: 0;
  margin: 0;
  cursor: inherit;
}
.seg.mini label { padding: 0.28rem 0.8rem; font-size: 0.74rem; }

/* ---------- checkboxes: bordered box with an × ---------- */
.check-row { display: flex; gap: 0.5rem 1.4rem; flex-wrap: wrap; align-items: center; }
.check-row label {
  display: flex; align-items: center; gap: 0.45rem;
  font-size: 0.82rem; cursor: pointer; color: #ccc;
  white-space: nowrap;
}
input[type="checkbox"]:not(.switch input) {
  appearance: none;
  -webkit-appearance: none;
  width: 1rem; height: 1rem;
  border: 1px solid var(--faint);
  background: var(--panel);
  display: inline-grid;
  place-content: center;
  cursor: pointer;
  flex: none;
  margin: 0;
}
input[type="checkbox"]:not(.switch input):hover { border-color: var(--dim); }
input[type="checkbox"]:not(.switch input):checked::before {
  content: "×";
  color: var(--fg);
  font-size: 0.95rem;
  font-weight: 400;
  line-height: 1;
}
input[type="checkbox"]:focus-visible { outline: 1px solid var(--dim); outline-offset: 2px; }

/* ---------- toggle switch ---------- */
.switch {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  cursor: pointer;
  font-size: 0.82rem;
  font-style: italic;
  color: #ccc;
  white-space: nowrap;
  position: relative;
}
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch .track {
  width: 34px; height: 18px;
  border: 1px solid var(--faint);
  position: relative;
  flex: none;
  transition: background .18s, border-color .18s;
}
.switch .track::after {
  content: "";
  position: absolute;
  top: 2px; left: 2px;
  width: 12px; height: 12px;
  background: var(--dim);
  transition: transform .18s, background .18s;
}
.switch:hover .track { border-color: var(--dim); }
.switch input:checked + .track {
  background: var(--accent);
  border-color: var(--accent);
}
.switch input:checked + .track::after {
  transform: translateX(16px);
  background: var(--bg);
}
.switch input:focus-visible + .track { outline: 1px solid var(--dim); outline-offset: 2px; }

.row-split {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
}
.row-split > .switch { margin-top: 1.5rem; }
.poster-switch { margin-top: 1.55rem; }

.hint { font-size: 0.68rem; color: var(--dim); line-height: 1.55; }
.hint b { color: #aaa; font-weight: 400; }

/* ---------- buttons ---------- */
.btn-row { display: flex; gap: 0.7rem; flex-wrap: wrap; margin-bottom: 0.9rem; }
button.btn, a.btn {
  background: none;
  border: 1px solid var(--faint);
  color: var(--fg);
  font: inherit;
  font-style: italic;
  font-size: 0.8rem;
  padding: 0.45rem 1.1rem;
  cursor: pointer;
  text-decoration: none;
  transition: border-color .2s, background .2s, color .2s;
}
button.btn:hover:not(:disabled), a.btn:hover {
  border-color: var(--fg);
  background: var(--fg);
  color: var(--bg);
}
button.btn:disabled { opacity: 0.35; cursor: not-allowed; }

/* ---------- creator preview ---------- */
.stage {
  width: min(100%, 60vh, 520px);
  aspect-ratio: 1 / 1.12;
  display: flex;
  align-items: center;
  justify-content: center;
  flex: none;
}
.preview-box {
  background: #fff;
  line-height: 0;
  width: min(100%, 54vh);
  max-height: 100%;
}
.preview-box svg {
  display: block;
  width: 100%;
  height: auto;
  max-height: 100%;
}
.preview-box:empty { display: none; }
.meta {
  font-size: 0.75rem;
  color: var(--dim);
  word-break: break-all;
  line-height: 1.7;
}
.meta.one-line { min-height: 1.4rem; }
.view.center .meta {
  margin-top: 0.8rem;
  text-align: center;
  white-space: nowrap;
  word-break: normal;
  min-height: 1.4rem;
}
.stage .error { text-align: center; max-width: 44ch; }
.stage .error:empty { display: none; }
.meta b { color: #ccc; font-weight: 400; }
.meta .warn-note { color: var(--warn); }

/* ---------- sheet preview ---------- */
#sheet-preview, #calib-preview {
  flex: 1 1 0;
  min-height: 0;
  display: flex;
  justify-content: center;
}
#sheet-preview svg, #calib-preview svg {
  height: 100%;
  width: auto;
  max-width: 100%;
  border: 1px solid var(--faint);
  background: #fff;
}
.page-thumbs {
  flex: none;
  height: 122px;
  display: flex;
  gap: 0.8rem;
  overflow-x: auto;
  margin-top: 0.9rem;
}
.page-thumb {
  border: 1px solid var(--faint);
  line-height: 0;
  cursor: pointer;
  position: relative;
  flex: none;
  align-self: flex-start;
}
.page-thumb:hover { border-color: var(--dim); }
.page-thumb.current { border-color: var(--accent); }
.page-thumb.current span { color: var(--accent); }
.page-thumb svg { width: 76px; height: auto; display: block; }
.page-thumb span {
  position: absolute; bottom: 2px; right: 4px;
  font-size: 0.6rem; color: var(--dim); line-height: 1.2;
}

/* ---------- creator batch mode ---------- */
#tab-creator.batch-on .view {
  align-items: stretch;
  justify-content: flex-start;
}
#tab-creator.batch-on .stage { display: none; }
#tab-creator.batch-on .meta {
  text-align: left;
  max-width: none;
  margin: 0 0 0.9rem;
  order: -1;
}
#tab-creator.batch-on.batch-err .view { align-items: center; justify-content: center; }
#tab-creator.batch-on.batch-err .stage { display: flex; }

/* ---------- batch preview ---------- */
.batch-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(112px, 1fr));
  gap: 0.8rem;
  align-content: start;
}
.batch-grid svg { width: 100%; height: auto; display: block; background: #fff; }
.batch-grid .more {
  align-self: center;
  justify-self: start;
  font-size: 0.75rem;
  color: var(--dim);
  font-style: italic;
}

/* ---------- print ---------- */
#print-area { display: none; }
@media print {
  body { display: block; overflow: visible; }
  body > *:not(#print-area) { display: none !important; }
  #print-area { display: block !important; }
  #print-area svg { page-break-after: always; display: block; }
  #print-area svg:last-child { page-break-after: auto; }
}

/* ---------- motion / mobile ---------- */
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
@media (max-width: 860px) {
  body { overflow: auto; }
  main { display: block; }
  section.active { display: block; }
  .controls { border-right: none; border-bottom: 1px solid var(--faint); }
  .view.center { align-items: flex-start; }
  .stage { width: 100%; aspect-ratio: auto; }
  #sheet-preview svg, #calib-preview svg { height: auto; width: 100%; }
  .topbar { gap: 0.8rem; padding: 0 0.9rem; }
  .tabs button { padding: 0 0.4rem; font-size: 0.8rem; }
  .brand span { display: none; }
}
