/* ===== Design tokens ===== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root,
html[data-theme="light"] {
  color-scheme: light;
  --bg: #f4f7fb;
  --bg-deep: #e9eef7;
  --surface: rgba(255, 255, 255, 0.78);
  --surface-solid: #ffffff;
  --surface-strong: #fbfcff;
  --surface-muted: rgba(235, 240, 248, 0.72);
  --control-bg: rgba(247, 249, 253, 0.92);
  --text: #11141b;
  --text-secondary: #4f596a;
  --muted: #70798a;
  --border: rgba(23, 37, 61, 0.11);
  --border-strong: rgba(23, 37, 61, 0.18);
  --accent: #1769ff;
  --accent-hover: #075bea;
  --accent-soft: rgba(23, 105, 255, 0.1);
  --accent-glow: rgba(23, 105, 255, 0.2);
  --violet: #7357ff;
  --warning: #9a5b00;
  --guide-color: #e5484d;
  --header-bg: rgba(249, 251, 255, 0.76);
  --stage: rgba(231, 236, 245, 0.72);
  --page-border: rgba(16, 24, 40, 0.16);
  --shadow-card: 0 20px 55px rgba(37, 50, 75, 0.09), 0 2px 8px rgba(37, 50, 75, 0.05);
  --shadow-control: 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow-float: 0 12px 30px rgba(23, 105, 255, 0.24);
  --focus: 0 0 0 4px rgba(23, 105, 255, 0.16);
  --radius-xl: 26px;
  --radius-lg: 18px;
  --radius-md: 13px;
  --radius-sm: 10px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "Segoe UI", sans-serif;
}

html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #090b10;
  --bg-deep: #050609;
  --surface: rgba(21, 24, 32, 0.8);
  --surface-solid: #171a22;
  --surface-strong: #1c202a;
  --surface-muted: rgba(35, 40, 52, 0.72);
  --control-bg: rgba(12, 15, 21, 0.86);
  --text: #f4f6fb;
  --text-secondary: #b7bfcc;
  --muted: #8e98a8;
  --border: rgba(255, 255, 255, 0.09);
  --border-strong: rgba(255, 255, 255, 0.16);
  --accent: #6592ff;
  --accent-hover: #7ea3ff;
  --accent-soft: rgba(101, 146, 255, 0.13);
  --accent-glow: rgba(69, 117, 255, 0.26);
  --violet: #9886ff;
  --warning: #f0b35e;
  --guide-color: #ff6369;
  --header-bg: rgba(10, 12, 17, 0.76);
  --stage: rgba(4, 6, 10, 0.5);
  --page-border: rgba(255, 255, 255, 0.17);
  --shadow-card: 0 22px 60px rgba(0, 0, 0, 0.34), 0 2px 10px rgba(0, 0, 0, 0.28);
  --shadow-control: 0 1px 2px rgba(0, 0, 0, 0.35);
  --shadow-float: 0 14px 36px rgba(28, 74, 190, 0.34);
  --focus: 0 0 0 4px rgba(101, 146, 255, 0.2);
}

html {
  min-width: 320px;
  min-height: 100%;
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  background: var(--bg);
}

body {
  min-width: 320px;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  font-family: var(--font);
  line-height: 1.5;
  color: var(--text);
  background:
    radial-gradient(circle at 12% 4%, var(--accent-soft), transparent 31rem),
    radial-gradient(circle at 92% 18%, rgba(115, 87, 255, 0.1), transparent 29rem),
    linear-gradient(150deg, var(--bg), var(--bg-deep));
  transition: color 180ms ease, background-color 180ms ease;
}

body::before {
  content: "";
  position: fixed;
  z-index: -1;
  inset: 0;
  pointer-events: none;
  opacity: 0.42;
  background-image:
    linear-gradient(var(--border) 1px, transparent 1px),
    linear-gradient(90deg, var(--border) 1px, transparent 1px);
  background-size: 48px 48px;
  mask-image: linear-gradient(to bottom, rgba(0, 0, 0, 0.3), transparent 55%);
}

button,
input,
select {
  font: inherit;
}

button,
select,
input[type="range"],
input[type="checkbox"] {
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
select:focus-visible,
input:focus-visible {
  outline: none;
  box-shadow: var(--focus);
}

/* ===== Header ===== */
.app-header {
  position: sticky;
  z-index: 50;
  top: 0;
  border-bottom: 1px solid var(--border);
  background: var(--header-bg);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.04);
  backdrop-filter: saturate(150%) blur(22px);
  -webkit-backdrop-filter: saturate(150%) blur(22px);
}

.header-inner {
  width: min(100%, 1580px);
  min-height: 76px;
  margin: 0 auto;
  padding: 12px clamp(16px, 3vw, 34px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}

.brand {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 13px;
}

.brand-mark {
  width: 44px;
  height: 44px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 14px;
  color: #fff;
  background: linear-gradient(145deg, #1878ff, #6558f5);
  box-shadow: 0 10px 24px rgba(40, 103, 238, 0.28), inset 0 1px 0 rgba(255, 255, 255, 0.35);
}

.brand-mark svg {
  width: 24px;
  height: 24px;
  stroke: currentColor;
  stroke-width: 1.7;
}

.brand-copy {
  min-width: 0;
}

.brand-copy h1 {
  font-size: clamp(1.25rem, 2vw, 1.55rem);
  line-height: 1.1;
  font-weight: 720;
  letter-spacing: -0.035em;
}

.subtitle {
  margin-top: 3px;
  overflow: hidden;
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.3;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.header-actions {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 9px;
}

.related-sites-menu {
  position: relative;
}

.related-sites-trigger {
  min-height: 44px;
  padding: 8px 13px;
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text-secondary);
  background: var(--surface);
  box-shadow: var(--shadow-control);
  font-size: 0.82rem;
  font-weight: 650;
  list-style: none;
  cursor: pointer;
  user-select: none;
  transition: transform 160ms ease, color 160ms ease, border-color 160ms ease, background 160ms ease, box-shadow 160ms ease;
}

.related-sites-trigger::-webkit-details-marker {
  display: none;
}

.related-sites-trigger:hover {
  transform: translateY(-1px);
  border-color: var(--border-strong);
  color: var(--accent);
  background: var(--surface-strong);
}

.related-sites-menu[open] .related-sites-trigger {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-soft);
  box-shadow: var(--focus);
}

.related-sites-icon {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
}

.related-sites-chevron {
  width: 14px;
  height: 14px;
  flex: 0 0 auto;
  transition: transform 180ms ease;
}

.related-sites-menu[open] .related-sites-chevron {
  transform: rotate(180deg);
}

.related-sites-label-short {
  display: none;
}

.related-sites-panel {
  position: absolute;
  z-index: 80;
  top: calc(100% + 12px);
  right: 0;
  width: 238px;
  padding: 8px;
  display: grid;
  gap: 3px;
  border: 1px solid var(--border-strong);
  border-radius: 17px;
  background: var(--surface-solid);
  box-shadow: 0 22px 55px rgba(10, 18, 32, 0.2), 0 4px 14px rgba(10, 18, 32, 0.1);
  backdrop-filter: blur(24px) saturate(140%);
  -webkit-backdrop-filter: blur(24px) saturate(140%);
  overflow: hidden;
}

html[data-theme="dark"] .related-sites-panel {
  box-shadow: 0 26px 60px rgba(0, 0, 0, 0.5), 0 4px 16px rgba(0, 0, 0, 0.35);
}

.related-sites-panel a {
  min-height: 42px;
  padding: 9px 12px;
  display: flex;
  align-items: center;
  border-radius: 11px;
  color: var(--text-secondary);
  font-size: 0.84rem;
  font-weight: 580;
  text-decoration: none;
  transition: color 150ms ease, background 150ms ease, transform 150ms ease;
}

.related-sites-panel a:hover,
.related-sites-panel a:focus-visible {
  color: var(--accent);
  background: var(--accent-soft);
  transform: translateX(2px);
  outline: none;
}

.theme-toggle {
  width: 44px;
  height: 44px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: 50%;
  color: var(--text-secondary);
  background: var(--surface);
  box-shadow: var(--shadow-control);
  cursor: pointer;
  transition: transform 160ms ease, color 160ms ease, border-color 160ms ease, background 160ms ease;
}

.theme-toggle:hover {
  transform: translateY(-1px);
  border-color: var(--border-strong);
  color: var(--accent);
  background: var(--surface-strong);
}

.theme-toggle:active {
  transform: translateY(0) scale(0.96);
}

.theme-icon {
  width: 21px;
  height: 21px;
}

.theme-icon-sun {
  display: none;
}

html[data-theme="dark"] .theme-icon-moon {
  display: none;
}

html[data-theme="dark"] .theme-icon-sun {
  display: block;
}

/* ===== Main surfaces ===== */
main {
  width: min(100%, 1580px);
  flex: 1;
  margin: 0 auto;
  padding: clamp(18px, 2.6vw, 36px);
}

.card {
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  background: var(--surface);
  box-shadow: var(--shadow-card);
  backdrop-filter: blur(24px) saturate(125%);
  -webkit-backdrop-filter: blur(24px) saturate(125%);
}

#upload-section {
  width: min(920px, 100%);
  margin: clamp(30px, 8vh, 86px) auto 40px;
  padding: clamp(12px, 2vw, 18px);
}

.drop-zone {
  position: relative;
  min-height: clamp(310px, 48vh, 470px);
  padding: clamp(40px, 8vw, 88px) 24px;
  display: grid;
  align-content: center;
  justify-items: center;
  overflow: hidden;
  border: 1.5px dashed var(--border-strong);
  border-radius: calc(var(--radius-xl) - 7px);
  text-align: center;
  background:
    radial-gradient(circle at 50% 26%, var(--accent-soft), transparent 14rem),
    var(--control-bg);
  cursor: pointer;
  transition: transform 180ms ease, border-color 180ms ease, background 180ms ease, box-shadow 180ms ease;
}

.drop-zone::after {
  content: "";
  position: absolute;
  width: 240px;
  height: 240px;
  left: 50%;
  top: 50%;
  border: 1px solid var(--border);
  border-radius: 50%;
  opacity: 0.5;
  transform: translate(-50%, -62%);
  pointer-events: none;
}

.drop-zone:hover,
.drop-zone.drag-over {
  transform: translateY(-2px);
  border-color: var(--accent);
  background:
    radial-gradient(circle at 50% 26%, var(--accent-glow), transparent 15rem),
    var(--control-bg);
  box-shadow: inset 0 0 0 1px var(--accent-soft);
}

.upload-icon,
.upload-text,
.upload-hint {
  position: relative;
  z-index: 1;
}

.upload-icon {
  width: 58px;
  height: 58px;
  margin-bottom: 18px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 18px;
  color: #fff;
  background: linear-gradient(145deg, var(--accent), var(--violet));
  box-shadow: var(--shadow-float);
}

.upload-text {
  font-size: clamp(1.2rem, 3vw, 1.6rem);
  font-weight: 680;
  letter-spacing: -0.025em;
}

.upload-hint {
  margin-top: 7px;
  color: var(--muted);
  font-size: 0.9rem;
}

/* ===== Workspace ===== */
#workspace {
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(290px, 330px) minmax(0, 1fr);
  align-items: start;
  gap: clamp(18px, 2vw, 28px);
}

.controls-panel {
  position: sticky;
  top: 98px;
  max-height: calc(100dvh - 120px);
  padding: 22px;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}

.controls-panel h2,
.preview-header h2 {
  font-size: 1.08rem;
  line-height: 1.2;
  font-weight: 690;
  letter-spacing: -0.02em;
}

.controls-panel h2 {
  margin-bottom: 20px;
  padding-bottom: 15px;
  border-bottom: 1px solid var(--border);
}

.control-group {
  min-width: 0;
  margin-bottom: 19px;
}

.control-group:last-child {
  margin-bottom: 0;
}

.control-group > label,
#trim-style-control > label {
  display: block;
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 0.72rem;
  line-height: 1.25;
  font-weight: 680;
  letter-spacing: 0.075em;
  text-transform: uppercase;
}

.control-help {
  margin-top: 7px;
  color: var(--muted);
  font-size: 0.76rem;
  line-height: 1.45;
}

.control-help.warning {
  color: var(--warning);
}

/* ===== Form controls ===== */
select,
input[type="number"] {
  width: 100%;
  min-width: 0;
  min-height: 44px;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  outline: none;
  color: var(--text);
  background: var(--control-bg);
  box-shadow: var(--shadow-control), inset 0 1px 0 rgba(255, 255, 255, 0.03);
  font-size: 0.88rem;
  transition: border-color 160ms ease, background 160ms ease, box-shadow 160ms ease;
}

select {
  padding-right: 34px;
  cursor: pointer;
}

select:hover,
input[type="number"]:hover {
  border-color: var(--border-strong);
  background: var(--surface-strong);
}

select:focus,
input[type="number"]:focus {
  border-color: var(--accent);
  background: var(--surface-solid);
  box-shadow: var(--focus);
}

input[type="number"] {
  -moz-appearance: textfield;
}

input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
  margin: 0;
  -webkit-appearance: none;
}

.unit-toggle {
  display: flex;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--control-bg);
}

.unit-btn {
  min-height: 36px;
  flex: 1;
  padding: 6px 9px;
  border: 0;
  border-radius: 9px;
  color: var(--muted);
  background: transparent;
  font-size: 0.81rem;
  font-weight: 620;
  cursor: pointer;
  transition: color 160ms ease, background 160ms ease, box-shadow 160ms ease, transform 160ms ease;
}

.unit-btn:hover {
  color: var(--text);
}

.unit-btn:active {
  transform: scale(0.98);
}

.unit-btn.active {
  color: var(--text);
  background: var(--surface-solid);
  box-shadow: 0 2px 8px rgba(14, 23, 40, 0.1), inset 0 0 0 1px var(--border);
}

.size-grid,
.margin-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.size-grid label,
.margin-grid label {
  color: var(--text-secondary);
  font-size: 0.76rem;
  font-weight: 520;
  letter-spacing: 0;
  text-transform: none;
}

.image-info {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--muted);
  background: var(--surface-muted);
  font-size: 0.75rem;
  line-height: 1.4;
}

.image-info strong {
  color: var(--text-secondary);
  font-weight: 650;
}

input[type="range"] {
  width: 100%;
  height: 7px;
  border: 0;
  border-radius: 999px;
  outline: 0;
  appearance: none;
  -webkit-appearance: none;
  background: linear-gradient(90deg, var(--accent-soft), var(--border-strong));
  cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
  width: 21px;
  height: 21px;
  border: 3px solid var(--surface-solid);
  border-radius: 50%;
  appearance: none;
  -webkit-appearance: none;
  background: var(--accent);
  box-shadow: 0 3px 10px var(--accent-glow);
}

input[type="range"]::-moz-range-thumb {
  width: 17px;
  height: 17px;
  border: 3px solid var(--surface-solid);
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 3px 10px var(--accent-glow);
}

.input-with-unit {
  display: flex;
  align-items: center;
  gap: 9px;
}

.input-with-unit input {
  flex: 1;
}

.unit-label {
  min-width: 2ch;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 620;
}

.checkbox-label {
  min-height: 44px;
  display: flex !important;
  align-items: center;
  gap: 9px;
  margin-bottom: 0 !important;
  color: var(--text-secondary) !important;
  font-size: 0.86rem !important;
  font-weight: 540 !important;
  letter-spacing: 0 !important;
  text-transform: none !important;
  cursor: pointer;
}

.checkbox-label input[type="checkbox"] {
  width: 19px;
  height: 19px;
  flex: 0 0 auto;
  accent-color: var(--accent);
  cursor: pointer;
}

.assembly-key-option {
  margin-top: 12px;
}

/* ===== Buttons ===== */
.btn {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 9px 15px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  color: var(--text);
  background: transparent;
  font-size: 0.84rem;
  font-weight: 640;
  line-height: 1.2;
  cursor: pointer;
  transition: transform 160ms ease, border-color 160ms ease, color 160ms ease, background 160ms ease, box-shadow 160ms ease;
}

.btn:hover {
  transform: translateY(-1px);
}

.btn:active {
  transform: translateY(0) scale(0.985);
}

.btn svg {
  width: 17px;
  height: 17px;
  flex: 0 0 auto;
}

.btn-primary {
  border-color: rgba(255, 255, 255, 0.12);
  color: #fff;
  background: linear-gradient(145deg, var(--accent), #4d61ee);
  box-shadow: var(--shadow-float), inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

.btn-primary:hover {
  background: linear-gradient(145deg, var(--accent-hover), #6259f0);
  box-shadow: 0 16px 34px var(--accent-glow);
}

.btn-outline {
  border-color: var(--border);
  color: var(--text-secondary);
  background: var(--control-bg);
  box-shadow: var(--shadow-control);
}

.btn-outline:hover {
  border-color: var(--border-strong);
  color: var(--accent);
  background: var(--surface-strong);
}

.btn-ghost {
  min-height: 38px;
  padding: 6px 10px;
  color: var(--accent);
}

.btn-ghost:hover {
  background: var(--accent-soft);
}

.btn-large {
  min-height: 50px;
  padding: 12px 24px;
  border-radius: var(--radius-md);
  font-size: 0.93rem;
}

.btn-large svg {
  width: 19px;
  height: 19px;
}

.btn-full {
  width: 100%;
}

.action-buttons {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

/* ===== Preview ===== */
.preview-card {
  min-width: 0;
  min-height: min(760px, calc(100dvh - 120px));
  padding: clamp(18px, 2.3vw, 30px);
  display: flex;
  flex-direction: column;
}

.preview-header {
  margin-bottom: 17px;
  padding-bottom: 15px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--border);
}

.preview-header-tools {
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
}

.page-info {
  max-width: min(760px, 72%);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px 12px;
  color: var(--muted);
  font-size: 0.76rem;
  line-height: 1.4;
  text-align: right;
}

.zoom-controls {
  flex: 0 0 auto;
  min-height: 40px;
  padding: 3px;
  display: flex;
  align-items: center;
  gap: 2px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--control-bg);
  box-shadow: var(--shadow-control);
}

.zoom-btn,
.zoom-readout {
  height: 32px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 999px;
  color: var(--text-secondary);
  background: transparent;
  cursor: pointer;
  transition: color 150ms ease, background 150ms ease, transform 150ms ease, opacity 150ms ease;
}

.zoom-btn {
  width: 32px;
}

.zoom-btn svg {
  width: 18px;
  height: 18px;
}

.zoom-readout {
  min-width: 55px;
  padding: 0 7px;
  font-size: 0.72rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.zoom-btn:hover:not(:disabled),
.zoom-readout:hover {
  color: var(--accent);
  background: var(--accent-soft);
}

.zoom-btn:active:not(:disabled),
.zoom-readout:active {
  transform: scale(0.94);
}

.zoom-btn:disabled {
  opacity: 0.34;
  cursor: not-allowed;
}

.preview-container {
  min-width: 0;
  min-height: 420px;
  max-height: 72dvh;
  flex: 1;
  padding: clamp(14px, 2vw, 24px);
  overflow: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background:
    radial-gradient(circle at 50% 0%, var(--accent-soft), transparent 28rem),
    var(--stage);
  box-shadow: inset 0 1px 4px rgba(20, 28, 43, 0.06);
}

.preview-grid {
  width: max-content;
  min-width: min-content;
  margin: 0 auto;
  display: grid;
  gap: 10px;
}

.preview-tile {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--page-border);
  border-radius: 3px;
  background: #fff;
  box-shadow: 0 9px 24px rgba(18, 24, 37, 0.15), 0 1px 3px rgba(18, 24, 37, 0.14);
}

.preview-tile canvas {
  display: block;
}

.preview-tile .cutting-guides,
.preview-tile .trim-marks {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.preview-tile .cutting-guides::before,
.preview-tile .cutting-guides::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  height: 1px;
  border-top: 1.5px dashed var(--guide-color);
}

.preview-tile .cutting-guides::before {
  top: var(--guide-top);
}

.preview-tile .cutting-guides::after {
  bottom: var(--guide-bottom);
}

.preview-tile .cutting-guides-left,
.preview-tile .cutting-guides-right {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 1px;
}

.preview-tile .cutting-guides-left {
  left: var(--guide-left);
  border-left: 1.5px dashed var(--guide-color);
}

.preview-tile .cutting-guides-right {
  right: var(--guide-left);
  border-right: 1.5px dashed var(--guide-color);
}

.preview-tile .trim-mark {
  position: absolute;
  display: block;
  background: var(--guide-color);
}

.preview-tile .trim-mark.horizontal {
  width: 9px;
  height: 1.5px;
}

.preview-tile .trim-mark.vertical {
  width: 1.5px;
  height: 9px;
}

.preview-tile .page-badge {
  position: absolute;
  right: 5px;
  bottom: 5px;
  padding: 2px 6px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 6px;
  color: #fff;
  background: rgba(15, 18, 24, 0.72);
  box-shadow: 0 2px 7px rgba(0, 0, 0, 0.2);
  backdrop-filter: blur(8px);
  font-size: 0.62rem;
  font-weight: 700;
}

.preview-footer {
  margin-top: 18px;
  text-align: center;
}

.export-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
}

.export-controls select {
  width: auto;
  min-width: 142px;
  min-height: 50px;
}

.preview-footer .control-help {
  margin-top: 8px;
}

/* ===== Footer / utility ===== */
footer {
  padding: 10px 20px 26px;
  color: var(--muted);
  font-size: 0.76rem;
  text-align: center;
}

footer .site-credit {
  max-width: 720px;
  margin: 7px auto 0;
  line-height: 1.55;
}

footer a {
  color: var(--text-secondary);
  font-weight: 620;
  text-decoration-color: var(--border-strong);
  text-underline-offset: 3px;
  transition: color 150ms ease, text-decoration-color 150ms ease;
}

footer a:hover,
footer a:focus-visible {
  color: var(--accent);
  text-decoration-color: currentColor;
}

.hidden {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

.btn.loading {
  opacity: 0.62;
  pointer-events: none;
}

/* ===== Scrollbars ===== */
.preview-container::-webkit-scrollbar,
.controls-panel::-webkit-scrollbar {
  width: 9px;
  height: 9px;
}

.preview-container::-webkit-scrollbar-track,
.controls-panel::-webkit-scrollbar-track {
  background: transparent;
}

.preview-container::-webkit-scrollbar-thumb,
.controls-panel::-webkit-scrollbar-thumb {
  border: 2px solid transparent;
  border-radius: 999px;
  background: var(--border-strong);
  background-clip: padding-box;
}

.preview-container::-webkit-scrollbar-thumb:hover,
.controls-panel::-webkit-scrollbar-thumb:hover {
  background: var(--muted);
  background-clip: padding-box;
}

/* ===== Tablet ===== */
@media (max-width: 900px) {
  .header-inner {
    min-height: 70px;
  }

  main {
    padding: 18px;
  }

  #workspace {
    grid-template-columns: minmax(0, 1fr);
  }

  .controls-panel {
    position: static;
    max-height: none;
    padding: 20px;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: start;
    gap: 18px;
    overflow: visible;
  }

  .controls-panel h2 {
    grid-column: 1 / -1;
    margin-bottom: 0;
  }

  .controls-panel .control-group {
    margin-bottom: 0;
  }

  .preview-card {
    min-height: 620px;
  }

  .preview-container {
    max-height: 68dvh;
  }
}

/* ===== Phone ===== */
@media (max-width: 600px) {
  body::before {
    background-size: 36px 36px;
  }

  .header-inner {
    min-height: 64px;
    padding: 10px 14px;
  }

  .brand {
    gap: 10px;
  }

  .brand-mark {
    width: 40px;
    height: 40px;
    border-radius: 12px;
  }

  .brand-mark svg {
    width: 21px;
    height: 21px;
  }

  .brand-copy h1 {
    font-size: 1.18rem;
  }

  .subtitle {
    max-width: 58vw;
    font-size: 0.73rem;
  }

  .theme-toggle {
    width: 42px;
    height: 42px;
  }

  .header-actions {
    gap: 7px;
  }

  .related-sites-trigger {
    min-height: 42px;
    padding: 7px 11px;
  }

  .related-sites-panel {
    top: calc(100% + 10px);
    width: min(238px, calc(100vw - 28px));
  }

  main {
    padding: 12px;
  }

  .card {
    border-radius: 20px;
  }

  #upload-section {
    margin: 20px auto;
    padding: 8px;
  }

  .drop-zone {
    min-height: 340px;
    padding: 44px 16px;
    border-radius: 14px;
  }

  .drop-zone::after {
    width: 205px;
    height: 205px;
  }

  .upload-icon {
    width: 52px;
    height: 52px;
    padding: 13px;
  }

  .upload-text {
    font-size: 1.15rem;
  }

  #workspace {
    gap: 14px;
  }

  .controls-panel {
    padding: 17px;
    grid-template-columns: minmax(0, 1fr);
    gap: 17px;
  }

  .controls-panel h2 {
    padding-bottom: 13px;
  }

  .unit-btn {
    min-height: 40px;
  }

  .preview-card {
    min-height: 520px;
    padding: 15px;
  }

  .preview-header {
    margin-bottom: 13px;
    padding-bottom: 13px;
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }

  .page-info {
    max-width: none;
    justify-content: flex-start;
    text-align: left;
  }

  .preview-header-tools {
    flex-direction: column;
    align-items: flex-start;
    gap: 9px;
  }

  .page-info span {
    margin-left: 0 !important;
  }

  .preview-container {
    min-height: 300px;
    max-height: 64dvh;
    padding: 12px;
    border-radius: 14px;
  }

  .preview-grid {
    gap: 7px;
  }

  .preview-footer {
    margin-top: 14px;
  }

  .export-controls {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
  }

  .export-controls select,
  .export-controls .btn-large {
    width: 100%;
  }

  footer {
    padding-bottom: calc(22px + env(safe-area-inset-bottom));
  }
}

@media (max-width: 380px) {
  .subtitle {
    display: none;
  }

  .related-sites-label-full {
    display: none;
  }

  .related-sites-label-short {
    display: inline;
  }

  .size-grid,
  .margin-grid {
    gap: 7px;
  }

  .action-buttons {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (pointer: coarse) {
  .btn,
  select,
  input[type="number"] {
    min-height: 48px;
  }

  .unit-btn {
    min-height: 44px;
  }

  .zoom-controls {
    min-height: 46px;
  }

  .zoom-btn,
  .zoom-readout {
    height: 38px;
  }

  .zoom-btn {
    width: 38px;
  }

  input[type="range"]::-webkit-slider-thumb {
    width: 25px;
    height: 25px;
  }

  input[type="range"]::-moz-range-thumb {
    width: 21px;
    height: 21px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}
