* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: system-ui, -apple-system, sans-serif;
  background: #f4f4f6;
  color: #222;
  padding: 12px;
}

header { text-align: center; margin-bottom: 12px; }
header h1 { font-size: 1.4rem; font-weight: 600; }
header p { color: #666; font-size: 0.85rem; margin-top: 4px; }

.container {
  max-width: 1400px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 1fr 1.5fr;
  gap: 14px;
}

.panel {
  background: #fff;
  border: 1px solid #ddd;
  border-radius: 8px;
  padding: 12px;
  display: flex;
  flex-direction: column;
}
.panel h2 {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #888;
  margin-bottom: 8px;
}

.drop-zone {
  border: 2px dashed #bbb;
  border-radius: 6px;
  padding: 18px 14px;
  text-align: center;
  color: #888;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  font-size: 0.9rem;
}
.drop-zone:hover, .drop-zone.dragover {
  border-color: #4a90d9;
  background: #f0f6fd;
}
.drop-zone input { display: none; }
.drop-zone label { cursor: pointer; display: block; }
.drop-zone strong { color: #4a90d9; }

.file-info {
  margin-top: 10px;
  font-size: 0.8rem;
  color: #555;
}
.file-info .label { color: #999; }

.preview-box {
  background: #fafafa;
  border: 1px solid #e5e5e5;
  border-radius: 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: #bbb;
  font-size: 0.85rem;
  overflow: hidden;
  height: 22vh;
  min-height: 140px;
  flex: 0 0 auto;
}

/* Corrected preview: same starting size as the original layout (42% of the
   window height), but allowed to grow into any spare room at the bottom of the
   right-hand panel. It never makes the page taller. */
#previewCorrected {
  height: 42vh;
  min-height: 240px;
  flex: 1 1 auto;
}

.preview-box canvas {
  max-width: 100%;
  max-height: calc(100% - 28px);
  width: auto;
  height: auto;
  display: block;
  object-fit: contain;
}
.preview-box.draggable canvas { cursor: grab; }
.preview-box.dragging canvas   { cursor: grabbing; }

.plotter-select {
  width: 100%;
  padding: 8px 10px;
  font-size: 0.9rem;
  border: 1px solid #ccc;
  border-radius: 6px;
  background: #fff;
  margin-bottom: 8px;
}
.plotter-select:disabled {
  background: #f0f0f4;
  color: #999;
  cursor: not-allowed;
}

.plotter-info {
  font-size: 0.78rem;
  color: #777;
  text-align: center;
  margin-top: 2px;
  margin-bottom: 4px;
  line-height: 1.4;
}

.control-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  padding: 6px 10px;
  background: #f7f7fa;
  border: 1px solid #e5e5e5;
  border-radius: 6px;
  font-size: 0.82rem;
  color: #555;
  flex-wrap: wrap;
}
.control-label {
  font-weight: 500;
  color: #666;
  min-width: 48px;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.rotate-angle,
.zoom-pct {
  font-family: ui-monospace, monospace;
  font-size: 0.78rem;
  color: #333;
  min-width: 44px;
  text-align: center;
}
.offset-val {
  font-family: ui-monospace, monospace;
  font-size: 0.78rem;
  color: #333;
}
/* Rotate / Size / Offset groups sit side by side on one line */
.control-row { gap: 6px 14px; }
.ctl-group {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: nowrap;
}
.ctl-group .control-label { min-width: 0; }
.control-row .icon-btn { padding: 4px 8px; }
.control-row .icon-btn.subtle { padding: 3px 6px; }
.control-row input[type="range"] { width: 80px; }
.control-row .rotate-angle,
.control-row .zoom-pct { min-width: 36px; }

.btn-row .hint {
  margin-left: auto;
  color: #999;
  font-size: 0.72rem;
}

.icon-btn {
  padding: 5px 10px;
  font-size: 0.82rem;
  font-weight: 500;
  background: #e8e8ec;
  color: #333;
  border: 1px solid #d0d0d6;
  border-radius: 6px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  transition: background 0.1s, border-color 0.1s, transform 0.05s;
}
.icon-btn:hover { background: #dcdce2; border-color: #b8b8c0; }
.icon-btn:active { background: #c8c8cc; transform: translateY(1px); }
.icon-btn .icon { font-size: 0.95rem; line-height: 1; }
.icon-btn.subtle {
  background: transparent;
  border-color: transparent;
  color: #888;
  font-size: 0.72rem;
  padding: 3px 7px;
}
.icon-btn.subtle:hover {
  background: #e8e8ec;
  border-color: #d0d0d6;
  color: #333;
}
/* Flip buttons stay highlighted while a flip is switched on */
.icon-btn.active,
.icon-btn[aria-pressed="true"] {
  background: #4a90d9;
  border-color: #3a7bc8;
  color: #fff;
}
.icon-btn.active:hover,
.icon-btn[aria-pressed="true"]:hover { background: #3a7bc8; }

.btn-row {
  margin-top: 10px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
button.btn-primary {
  padding: 10px 20px;
  font-size: 0.9rem;
  font-weight: 600;
  background: #4a90d9;
  color: #fff;
  border: 1px solid #3a7bc8;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.12s;
}
button.btn-primary:hover { background: #3a7bc8; }
button.btn-primary:disabled {
  background: #b0c8e0;
  border-color: #b0c8e0;
  cursor: not-allowed;
}

input[type="range"] {
  width: 130px;
  cursor: pointer;
  accent-color: #4a90d9;
}

.status {
  font-size: 0.8rem;
  color: #666;
  min-height: 1.2em;
}
.status.warn { color: #b8801a; }

.loading {
  text-align: center;
  padding: 40px 20px;
  color: #888;
  font-size: 0.9rem;
}

@media (max-width: 900px) {
  .container { grid-template-columns: 1fr; }
}

/* Fit the whole app in the window (no page scrolling) on wider screens.
   The two preview boxes now share whatever height is left over after the
   other controls, so selecting a file (which adds the file-info lines) makes
   the previews a little shorter instead of pushing the page off screen. */
@media (min-width: 901px) {
  html, body { height: 100%; }
  body {
    height: 100vh;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }
  header { flex: 0 0 auto; margin-bottom: 8px; }
  .container {
    flex: 1 1 0;
    min-height: 0;
    width: 100%;
    grid-template-rows: minmax(0, 1fr);
  }
  .panel { min-height: 0; overflow-y: auto; }
  .preview-box,
  #previewCorrected {
    flex: 1 1 0;
    height: auto;
    min-height: 120px;
  }
}