:root {
  --bg: #eef1f4;
  --panel: #ffffff;
  --ink: #202428;
  --muted: #6b747d;
  --line: #d8dee4;
  --accent: #256f68;
  --accent-dark: #18534e;
  --focus: #e6f3f1;
  --paper: #fffdf8;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

button,
input {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr);
  min-height: 100vh;
}

.settings-panel {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: auto;
  padding: 24px;
  background: var(--panel);
  border-right: 1px solid var(--line);
}

.brand-block {
  margin-bottom: 26px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: 1.8rem;
  line-height: 1.08;
}

.control-group {
  display: grid;
  gap: 9px;
  margin-bottom: 18px;
}

.two-col {
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

label,
.preview-toolbar {
  color: #30363b;
  font-size: 0.92rem;
  font-weight: 700;
}

input[type="text"],
input[type="number"],
select {
  width: 100%;
  height: 42px;
  padding: 0 12px;
  color: var(--ink);
  background: #fbfcfd;
  border: 1px solid var(--line);
  border-radius: 7px;
  outline: none;
}

input[type="text"]:focus,
input[type="number"]:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--focus);
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

input[type="color"] {
  width: 48px;
  height: 42px;
  padding: 3px;
  background: #fbfcfd;
  border: 1px solid var(--line);
  border-radius: 7px;
  cursor: pointer;
}

input[type="file"] {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.file-drop {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 76px;
  padding: 14px;
  background: #f7fbfa;
  border: 1.5px dashed #8ab8b2;
  border-radius: 8px;
  cursor: pointer;
}

.file-drop__icon {
  display: grid;
  place-items: center;
  flex: 0 0 38px;
  height: 38px;
  color: #fff;
  background: var(--accent);
  border-radius: 50%;
  font-size: 1.4rem;
  font-weight: 500;
}

.file-drop small {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-weight: 500;
}

.range-row {
  display: grid;
  grid-template-columns: 1fr 54px;
  gap: 10px;
  align-items: center;
}

.color-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.color-row span {
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 800;
  text-transform: uppercase;
}

output {
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
  text-align: right;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 38px;
  font-weight: 650;
}

.checkbox-row input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.actions {
  display: grid;
  grid-template-columns: 1fr 110px;
  gap: 10px;
  padding-top: 6px;
}

button {
  min-height: 42px;
  border: 0;
  border-radius: 7px;
  cursor: pointer;
  font-weight: 800;
}

button:disabled {
  cursor: wait;
  opacity: 0.7;
}

.primary-button {
  color: #fff;
  background: var(--accent);
}

.primary-button:hover {
  background: var(--accent-dark);
}

.secondary-button {
  color: #25302f;
  background: #e9eeee;
}

.secondary-button:hover {
  background: #dde5e4;
}

.toolbar-download {
  min-height: 34px;
  padding: 0 14px;
  font-size: 0.86rem;
}

.preview-panel {
  min-width: 0;
  padding: 24px;
}

.preview-toolbar {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  max-width: 1180px;
  margin: 0 auto 16px;
  color: var(--muted);
}

.worksheet {
  position: relative;
  width: min(100%, 1180px);
  margin: 0 auto;
  padding: clamp(24px, 3.2vw, 52px);
  background: var(--paper);
  border: 1px solid #e0ddd2;
  box-shadow: 0 14px 45px rgb(28 34 38 / 14%);
}

.worksheet.landscape {
  aspect-ratio: 1.414 / 1;
}

.worksheet.portrait {
  width: min(100%, 840px);
  aspect-ratio: 1 / 1.414;
  padding: clamp(24px, 3.2vw, 44px);
}

.pdf-watermark {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 12mm;
  display: none;
  color: #575757;
  font-family: Arial, sans-serif;
  font-size: 13px;
  font-weight: 600;
  text-align: center;
}

.worksheet.exporting-pdf .pdf-watermark {
  display: block;
}

.worksheet-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 24px;
  margin-bottom: clamp(22px, 3.2vw, 44px);
}

.worksheet h2,
.name-line {
  margin: 0;
  color: #151515;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1.35rem, 2.25vw, 2.45rem);
  font-style: italic;
  font-weight: 800;
  line-height: 1.1;
}

.worksheet h2 {
  flex: 1 1 auto;
}

.name-line {
  flex: 0 0 auto;
  white-space: nowrap;
}

.grids-wrap {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: clamp(24px, 3vw, 48px);
  align-items: start;
}

.worksheet.portrait .grids-wrap {
  grid-template-columns: 1fr;
  gap: clamp(22px, 3vw, 34px);
  max-width: 560px;
  margin: 0 auto;
}

.grid-card {
  display: grid;
  place-items: center;
}

.drawing-grid {
  --cols: 10;
  --rows: 10;
  --grid-scale: 100;
  --line-weight: 2px;
  --grid-color: #222;
  position: relative;
  width: min(100%, calc(var(--grid-scale) * 1%));
  aspect-ratio: var(--cols) / var(--rows);
  overflow: hidden;
  background-color: #fffefd;
  border: var(--line-weight) solid var(--grid-color);
}

.grid-lines {
  position: absolute;
  inset: 0;
  z-index: 2;
  width: 100%;
  height: 100%;
  color: var(--grid-color);
  pointer-events: none;
}

.grid-lines line {
  stroke: currentColor;
  stroke-width: var(--line-weight);
  vector-effect: non-scaling-stroke;
  shape-rendering: crispEdges;
}

#sourceImage {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 100%;
  height: 100%;
  object-fit: contain;
  opacity: 0;
  z-index: 1;
  transform: translate(calc(-50% + var(--offset-x, 0) * 1%), calc(-50% + var(--offset-y, 0) * 1%))
    scale(calc(var(--image-scale, 92) / 100));
  transform-origin: center;
  transition: opacity 160ms ease;
}

#sourceImage.has-image {
  opacity: calc(var(--image-opacity, 82) / 100);
}

.empty-state {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  z-index: 3;
  color: #8c969e;
  font-weight: 800;
  text-align: center;
}

#sourceImage.has-image + .empty-state {
  display: none;
}

@media (max-width: 849px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .settings-panel {
    position: static;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .preview-panel {
    padding: 16px;
  }

  .worksheet {
    min-width: 680px;
  }

  .preview-panel {
    overflow-x: auto;
  }
}

@media print {
  @page {
    size: A4 landscape;
    margin: 0;
  }

  body {
    background: #fff;
  }

  .settings-panel,
  .preview-toolbar {
    display: none;
  }

  .app-shell,
  .preview-panel {
    display: block;
    min-height: 0;
    padding: 0;
  }

  .worksheet {
    margin: 0;
    padding: 17mm 18mm;
    border: 0;
    box-shadow: none;
    break-inside: avoid;
  }

  .worksheet.landscape {
    width: 297mm;
    height: 210mm;
  }

  .worksheet.portrait {
    width: 210mm;
    height: 297mm;
  }
}
