:root{
  --footer-height: 56px;
  --panel-radius: 8px;
  --content-max-width: 1300px;
  --gutter: 20px;

  --bg-1: #070707;
  --panel-bg-1: linear-gradient(180deg,#0f1112,#131314);
  --panel-border: #1f1f1f;
  --muted: #93a3b4;
  --muted-2: #9aa6b2;
  --text: #e6eef6;
  --accent: #29a3ff;
  --button-bg: #121212;
  --button-border: #2b2b2b;
  --focus-ring: rgba(41,163,255,0.22);

  --footer-blur: 6px;
  --checkbox-size: 14px;
  --checkbox-shift: 0px;
  --transition-fast: 160ms;
  --transition-medium: 180ms;
}

/* Base */
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  padding: 20px;
  padding-bottom: var(--footer-height);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans";
  background: linear-gradient(180deg,var(--bg-1),#0b0b0b);
  color: var(--text);
  display: flex;
  flex-direction: column;
  gap: var(--gutter);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
}

/* Layout */
.container { width: 100%; max-width: var(--content-max-width); margin: 0 auto; flex: 1 1 auto; }
.row { display: flex; gap: 20px; flex: 1; min-height: 0; align-items: flex-start; }
.row > .panel:nth-child(2) { flex: 0 0 360px; min-width: 280px; max-width: 420px; }

.panel {
  flex: 1;
  background: var(--panel-bg-1);
  padding: 15px;
  border-radius: var(--panel-radius);
  border: 1px solid var(--panel-border);
  display: flex;
  flex-direction: column;
  min-width: 260px;
  min-height: 0;
  overflow: hidden;
  box-shadow: 0 1px 0 rgba(255,255,255,0.02) inset;
}

.row + .output-panel { margin-top: 14px; }

/* Header */
.panel-header-row {
  display: flex;
  align-items: center;
  gap: 12px;
  justify-content: space-between;
  position: relative;
  margin-bottom: 10px;
}

/* raise the label text in right header block by 1px; keep checkbox visually in place */
.panel-header-row > div label { transform: translateY(-1px); -webkit-transform: translateY(-1px); }
.panel-header-row > div label input[type="checkbox"] {
  transform: translateY(calc(var(--checkbox-shift, 0px) + 1px));
  -webkit-transform: translateY(calc(var(--checkbox-shift, 0px) + 1px));
}

/* Typography & form basics */
h2 { margin: 0; font-size: 14px; letter-spacing: 0.08em; text-transform: uppercase; color: #cbd5e1; font-weight: 700; }
label { display: block; margin: 8px 0 4px; font-size: 13px; color: var(--muted-2); }
input[type="file"], input[type="number"], input[type="range"], select { width: 100%; margin-bottom: 6px; }
input[type="number"], select {
  padding: 6px 8px;
  border-radius: 6px;
  border: 1px solid #222;
  background: #0b0b0b;
  color: var(--text);
  font-size: 13px;
}

/* Canvas / preview */
.canvas-holder {
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000;
  border-radius: 4px;
  border: 1px solid #111;
  overflow: hidden;
  height: 360px;
  max-height: 45vh;
  flex: 0 0 auto;
  align-self: flex-start;
  width: 100%;
}
canvas { display: block; max-width: 100%; max-height: 100%; image-rendering: pixelated; box-sizing: border-box; }

pre#preview {
  flex: 0 0 auto;
  width: 100%;
  background: #000;
  color: var(--text);
  padding: 10px;
  border-radius: 4px;
  border: 1px solid #111;
  overflow: auto;
  font-family: "Courier New", monospace;
  font-size: 11px;
  line-height: 1.2;
  white-space: pre;
  max-height: min(calc(44 * 1.2em), calc(100vh - var(--footer-height) - 180px));
  -webkit-overflow-scrolling: touch;
  scrollbar-gutter: stable;
}

/* Counters & output (compact) */
/* Default layout for counters when outputCounter is in its original location */
#previewCounter,
#outputCounter {
  font-size: 12px;
  color: var(--muted);
  margin: 6px 0 6px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  line-height: 1;
}

/* prevent flicker by taking element out of flow until moved */
#outputCounter.will-move {
  position: fixed !important;
  left: -10000px !important;
  top: -10000px !important;
  width: 1px !important;
  height: 1px !important;
  overflow: hidden !important;
  opacity: 0 !important;
  pointer-events: none !important;
  /* visually hidden off-screen; aria-hidden should be set in JS */
}

/* base for moved counter: in-flow but start invisible and slightly up (to animate) */
.output-panel .panel-header-row > div #outputCounter,
.output-panel .panel-header-row > div .moved-to-header-right {
  display: inline-flex !important;
  align-items: center !important;
  margin: 0 10px 0 0 !important;
  padding: 0 !important;
  font-size: 12px !important;
  color: var(--muted) !important;
  line-height: 1 !important;
  height: 100% !important;
  white-space: nowrap;
  transition: opacity 220ms ease, transform 220ms cubic-bezier(.2,.9,.2,1);
  opacity: 0;
  transform: translateY(-6px);
}

/* visible state: fade + slide into place */
#outputCounter.visible {
  opacity: 1 !important;
  transform: translateY(0) !important;
  pointer-events: auto !important;
}

/* Ensure internal children of the counter don't add extra spacing */
.output-panel .panel-header-row > div #outputCounter * {
  margin: 0;
  padding: 0;
}

/* textarea / output area */
textarea#output {
  width: 100%;
  resize: none;
  overflow: hidden;
  min-height: 120px;
  max-height: 60vh;
  background: #000;
  color: var(--text);
  border-radius: 4px;
  border: 1px solid #111;
  padding: 8px;
  font-family: "Courier New", monospace;
  font-size: 11px;
  line-height: 1.1;
}

/* Header-right group */
.output-panel .panel-header-row > div { display: inline-flex; align-items: center; gap: 8px; margin-left: 0; }

/* Buttons */
button {
  padding: 8px 12px;
  margin: 0 8px 0 0;
  border-radius: 6px;
  border: 1px solid var(--button-border);
  background: linear-gradient(180deg, rgba(255,255,255,0.01), var(--button-bg));
  color: var(--text);
  cursor: pointer;
  font-size: 13px;
  transition: transform var(--transition-fast) ease, box-shadow var(--transition-fast) ease, background var(--transition-fast) ease;
  box-shadow: 0 2px 6px rgba(0,0,0,0.45);
}
button:hover { background: linear-gradient(180deg, rgba(255,255,255,0.02), #1a1a1a); transform: translateY(-1px); }
button:active { transform: translateY(0); }
button:focus-visible { outline: none; box-shadow: 0 0 0 4px var(--focus-ring); border-color: var(--accent); }

button.primary {
  background: linear-gradient(180deg, rgba(41,163,255,0.12), rgba(41,163,255,0.06));
  color: #fff;
  border-color: rgba(41,163,255,0.22);
}

#copyBtn, #downloadBtn { display: inline-block; transform: translateX(6px); transition: transform var(--transition-medium) cubic-bezier(.2,.9,.2,1); }
#copyBtn:hover, #downloadBtn:hover { transform: translateX(6px) translateY(-1px); }

/* Small helpers */
.small { font-size: 12px; color: var(--muted); }
.inline { display: inline-flex; align-items: center; gap: 8px; margin-top: 6px; font-size: 13px; color: #b8c6d4; }

/* Footer */
.site-footer {
  position: fixed; left: 0; right: 0; bottom: 0; height: var(--footer-height);
  display: flex; align-items: center; justify-content: center; z-index: 9999;
  background: linear-gradient(180deg, rgba(255,255,255,0.02), rgba(17,24,39,0.88));
  color: var(--text); backdrop-filter: blur(var(--footer-blur)); -webkit-backdrop-filter: blur(var(--footer-blur));
  box-shadow: 0 -2px 10px rgba(0,0,0,0.45); padding: 6px 12px; font-size: 14px; transition: height var(--transition-fast) ease, padding var(--transition-fast) ease;
}
.site-footer__inner { display: flex; align-items: center; gap: 12px; max-width: 1100px; width: 100%; justify-content: space-between; }
.site-footer__brand { display:flex; align-items:center; gap:10px; }
.site-footer__logo { display: block; height: 40px; min-width: 40px; overflow: hidden; flex: 0 0 auto; }
.site-footer__logo-img { display: block; height: 100%; object-fit: contain; }

/* restore footer link hover (lift + shadow) */
.site-footer__links a:hover,
.site-footer__links a:focus {
  transform: translateY(-3px);
  box-shadow: 0 6px 18px rgba(0,0,0,0.5);
  border-color: rgba(255,255,255,0.06);
  outline: none;
}

/* Footer links & donate */
.site-footer__links { display:flex; gap:10px; align-items:center; }
.site-footer__links a {
  color: var(--text);
  text-decoration: none;
  padding: 6px 10px;
  border-radius: 8px;
  background: rgba(255,255,255,0.02);
  border: 1px solid transparent;
  font-weight: 600;
  letter-spacing: 0.2px;
  transition: transform var(--transition-fast) ease, box-shadow var(--transition-fast) ease, background var(--transition-fast) ease, border-color var(--transition-fast) ease;
  display:inline-flex; align-items:center;
}
.site-footer__links .link-icon { margin-right: 8px; flex-shrink: 0; display: inline-block; vertical-align: middle; }

.site-footer__links a.donate {
  background: linear-gradient(90deg, rgba(40,167,69,0.12), rgba(46,204,113,0.06));
  color: #f8fff8;
  border-color: rgba(46,204,113,0.14);
  transition: background 200ms ease, box-shadow 200ms ease, border-color 200ms ease, color 200ms ease;
}
.site-footer__links a.donate:hover,
.site-footer__links a.donate:focus {
  background: linear-gradient(180deg, rgba(46,204,113,0.16), rgba(40,167,69,0.10));
  box-shadow: 0 8px 24px rgba(46,204,113,0.18);
  color: #ffffff;
  transform: none;
  outline: none;
}

/* Checkbox alignment */
.panel-header-row, .panel-header-row > div { line-height: 1; }
.panel-header-row label { display: inline-flex; align-items: baseline; gap: 8px; font-size: 13px; color: var(--muted); }
.panel-header-row label input[type="checkbox"] {
  width: var(--checkbox-size); height: var(--checkbox-size); margin: 0; padding: 0;
  vertical-align: baseline;
  transform: translateY(var(--checkbox-shift));
  -webkit-transform: translateY(var(--checkbox-shift));
  appearance: auto;
}

/* Responsive */
@media (max-width:1000px) {
  .row { flex-direction: column; align-items: stretch; }
  .panel:first-child { max-width: none; width: 100%; }
  .row > .panel:nth-child(2) { flex: 0 0 auto; min-width: 0; max-width: none; }
  #copyBtn, #downloadBtn { transform: none; -webkit-transform: none; }
  .panel-header-row label input[type="checkbox"] { transform: none; -webkit-transform: none; }
  /* fallback: don't attempt animation on tiny screens */
  .output-panel .panel-header-row > div #outputCounter,
  .output-panel .panel-header-row > div .moved-to-header-right {
    transition: none;
    transform: none;
    opacity: 1;
  }
}

/* Accessibility & print */
:focus { outline: none; }
a:focus, button:focus, input:focus, select:focus, textarea:focus { box-shadow: 0 0 0 4px var(--focus-ring); }
@media print { .site-footer { display: none !important; } }

/* ---------- Responsive footer: unified & tightened (S20, iPhone 17) ---------- */
@media (max-width: 460px) {
  /* reserve enough space for the footer including the safe-area on devices with home indicator/notch */
  :root {
    --footer-height: calc(clamp(72px, 18vw, 110px) + env(safe-area-inset-bottom));
  }

  /* ensure page content has room (body in your main CSS already uses var(--footer-height), but keep a safety fallback) */
  body {
    padding-bottom: var(--footer-height);
  }

  .site-footer {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    height: auto;
    padding: 10px calc(12px + env(safe-area-inset-left)) calc(10px + env(safe-area-inset-bottom));
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    box-shadow: 0 -1px 10px rgba(0,0,0,0.40);
    background: linear-gradient(180deg, rgba(255,255,255,0.02), rgba(17,24,39,0.92));
    backdrop-filter: blur(calc(var(--footer-blur) * 0.9));
    -webkit-backdrop-filter: blur(calc(var(--footer-blur) * 0.9));
    touch-action: manipulation;
  }

  .site-footer__inner {
    width: 100%;
    max-width: 1100px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    justify-content: center;
    padding: 0;
  }

  /* Brand/logo on top, centered */
  .site-footer__brand {
    display: flex;
    align-items: center;
    gap: 8px;
    justify-content: center;
    order: 0;
    width: 100%;
  }

  /* Container for logo: responsive width (caps chosen to keep 560x52 image small) */
  .site-footer__logo {
    width: clamp(64px, 18vw, 140px); /* primary width cap */
    max-width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    line-height: 0;
  }

  /* The image itself: fill container, preserve aspect ratio, hard caps on height */
  .site-footer__logo-img {
    width: 100%;
    height: auto;
    max-height: clamp(28px, 9vw, 56px); /* prevents very tall rendering */
    object-fit: contain;
    display: block;
  }

  /* Short brand text beside logo (ellipsis to avoid wrapping) */
  .site-footer__text {
    font-size: 13px;
    color: var(--text);
    margin-left: 8px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 60%;
  }

  /* Links under the logo, centered and wrapping if needed */
  .site-footer__links {
    display: flex;
    gap: 8px;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    width: 100%;
    order: 1;
    padding-top: 4px;
  }
  .site-footer__links a {
    padding: 6px 10px;
    font-size: 13px;
    border-radius: 8px;
  }
  .site-footer__links a.donate {
    padding-left: 10px;
    padding-right: 10px;
  }

  /* keep hover/focus subtle on small screens to avoid layout shift */
  .site-footer__links a:hover,
  .site-footer__links a:focus {
    transform: none;
    box-shadow: 0 6px 18px rgba(0,0,0,0.35);
  }

  /* ensure focus rings remain visible on small devices */
  .site-footer a:focus, .site-footer button:focus {
    box-shadow: 0 0 0 4px var(--focus-ring);
  }
}

/* Very narrow phones: hide long brand text and reduce logo more */
@media (max-width: 360px) {
  .site-footer__text { display: none; }
  .site-footer__logo {
    width: clamp(48px, 20vw, 120px);
  }
  .site-footer__logo-img {
    max-width: 120px;
    max-height: 48px;
  }
}

/* Medium narrow screens: prevent oversized logo between phone/tablet widths */
@media (min-width: 461px) and (max-width: 900px) {
  .site-footer__logo {
    width: clamp(80px, 10vw, 180px);
  }
  .site-footer__logo-img {
    width: 100%;
    max-width: 180px;
    max-height: 56px;
  }
}