:root {
  color-scheme: light;
  --bg: #eef2f7;
  --panel: #ffffff;
  --panel-soft: #f8fafc;
  --ink: #111827;
  --muted: #64748b;
  --line: #d7dee8;
  --line-strong: #aeb8c7;
  --accent: #0f766e;
  --accent-dark: #115e59;
  --accent-soft: #d7f4ef;
  --danger: #b42318;
  --shadow: 0 18px 44px rgba(15, 23, 42, 0.12);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.78), rgba(238, 242, 247, 0.96)),
    var(--bg);
}

button,
input,
select {
  font: inherit;
}

.app-shell {
  width: min(1480px, calc(100% - 28px));
  margin: 0 auto;
  padding: 18px 0 34px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  padding: 14px 0 18px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(1.9rem, 4vw, 3.1rem);
  line-height: 1;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 4px;
  font-size: 0.95rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.topbar-actions,
.preview-toolbar,
.section-heading {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
}

.button {
  min-height: 40px;
  padding: 0 13px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  color: var(--ink);
  background: #ffffff;
  cursor: pointer;
}

.button:hover {
  border-color: #7b8797;
}

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

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

.button.compact {
  min-height: 34px;
}

.button.subtle {
  width: 100%;
  color: var(--muted);
  background: var(--panel-soft);
}

.topbar-preset {
  display: grid;
  gap: 4px;
  min-width: 176px;
}

.topbar-template {
  min-width: 148px;
}

.topbar-guide {
  min-width: 188px;
}

.topbar-preset span {
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.topbar-preset select {
  min-height: 40px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  padding: 0 10px;
  color: var(--ink);
  background: #ffffff;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(330px, 420px) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.control-panel,
.preview-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.control-panel {
  display: grid;
  gap: 12px;
  padding: 12px;
}

.panel-section {
  display: grid;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
}

.panel-section summary {
  list-style: none;
  cursor: pointer;
}

.panel-section summary::-webkit-details-marker {
  display: none;
}

.panel-body {
  display: grid;
  gap: 12px;
}

.section-heading-copy {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.section-heading p,
.preview-toolbar p,
.control-note {
  margin: 0;
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.5;
}

.control-note {
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.panel-section > .section-heading {
  margin: 0;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 10px 12px;
  align-items: center;
}

.panel-section > .section-heading::after {
  content: "▾";
  order: 3;
  color: var(--muted);
  font-size: 0.92rem;
}

.panel-section > .section-heading > .button {
  position: relative;
  z-index: 1;
}

.panel-section:not([open]) {
  gap: 0;
}

.panel-section:not([open]) > .section-heading::after {
  content: "▸";
}

.crop-canvas {
  width: 100%;
  height: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #e5e7eb;
  touch-action: none;
}

.crop-canvas.is-empty {
  cursor: pointer;
}

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

.field,
.toggle-field {
  display: grid;
  gap: 6px;
}

.field.wide {
  grid-column: 1 / -1;
}

.field span,
.toggle-field span,
.slider-list span {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.07em;
  text-transform: uppercase;
}

.field input,
.field select {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  padding: 0 10px;
  color: var(--ink);
  background: #ffffff;
  outline: none;
}

.field input:focus,
.field select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.12);
}

.button-field {
  justify-content: end;
}

.toggle-field {
  align-content: end;
  grid-template-columns: auto 1fr;
  align-items: center;
  min-height: 62px;
  padding-bottom: 8px;
}

.toggle-field input,
.toggle-grid input {
  accent-color: var(--accent);
}

.size-list {
  display: grid;
  gap: 8px;
}

.size-item {
  display: grid;
  gap: 10px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.size-item-title {
  display: grid;
  gap: 3px;
}

.size-item strong {
  display: block;
  font-size: 0.92rem;
}

.size-item span {
  color: var(--muted);
  font-size: 0.83rem;
}

.size-item button {
  min-height: 32px;
  padding: 0 9px;
}

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

.size-edit-grid label {
  display: grid;
  gap: 4px;
}

.size-edit-grid label span {
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.size-edit-grid input {
  width: 100%;
  min-height: 34px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  padding: 0 8px;
}

.size-item-actions,
.guide-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.slider-list {
  display: grid;
  gap: 10px;
}

.slider-list label {
  display: grid;
  gap: 6px;
}

.slider-list input {
  width: 100%;
  accent-color: var(--accent);
}

.color-field {
  max-width: 160px;
}

.color-field input {
  padding: 3px;
}

.toggle-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px 12px;
  color: var(--ink);
  font-size: 0.92rem;
}

.preview-panel {
  display: grid;
  gap: 12px;
  padding: 14px;
  min-width: 0;
}

.preview-toolbar {
  align-items: start;
}

.print-note {
  max-width: 280px;
  padding: 9px 10px;
  border: 1px solid #f4c27a;
  border-radius: 8px;
  color: #7a4a00;
  background: #fff7df;
}

.canvas-stage {
  display: grid;
  place-items: center;
  min-height: 70vh;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(45deg, #e8edf4 25%, transparent 25%),
    linear-gradient(-45deg, #e8edf4 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #e8edf4 75%),
    linear-gradient(-45deg, transparent 75%, #e8edf4 75%),
    #f8fafc;
  background-size: 22px 22px;
  background-position: 0 0, 0 11px, 11px -11px, -11px 0;
  overflow: auto;
}

#sheetCanvas {
  display: block;
  width: min(100%, var(--screen-canvas-width, 760px));
  height: auto;
  border: 1px solid #a8b1c0;
  background: #ffffff;
  box-shadow: 0 18px 40px rgba(15, 23, 42, 0.18);
}

.status-box {
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: var(--panel-soft);
  line-height: 1.5;
}

.status-box.is-error {
  border-color: #f3b2aa;
  color: var(--danger);
  background: #fff4f2;
}

.tool-footer {
  display: flex;
  justify-content: flex-start;
  gap: 12px;
  align-items: center;
  padding: 0 2px;
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.4;
}

.tool-footer a {
  color: var(--accent);
  font-weight: 700;
  text-decoration: none;
}

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

  .control-panel {
    order: 2;
  }
}

@media (max-width: 640px) {
  .app-shell {
    width: min(100%, calc(100% - 16px));
    padding-top: 8px;
  }

  .topbar,
  .topbar-actions,
  .preview-toolbar,
  .section-heading {
    display: grid;
    justify-content: stretch;
  }

  .topbar-actions {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .topbar-preset {
    grid-column: auto;
    min-width: 0;
  }

  .panel-section > .section-heading {
    align-items: start;
  }

  .topbar-template,
  .topbar-guide {
    min-width: 0;
  }

  .form-grid,
  .toggle-grid,
  .size-edit-grid {
    grid-template-columns: 1fr;
  }

  .canvas-stage {
    min-height: 48vh;
    padding: 10px;
  }

  .tool-footer {
    flex-wrap: wrap;
  }
}

@media print {
  :root {
    --shadow: none;
  }

  html,
  body {
    width: var(--print-width, auto);
    height: var(--print-height, auto);
    margin: 0;
    background: #ffffff;
  }

  .no-print,
  .control-panel,
  .topbar {
    display: none !important;
  }

  .app-shell,
  .workspace,
  .preview-panel,
  .canvas-stage {
    display: block;
    width: auto;
    margin: 0;
    padding: 0;
    border: 0;
    box-shadow: none;
    background: #ffffff;
  }

  #sheetCanvas {
    width: var(--print-width, auto) !important;
    height: var(--print-height, auto) !important;
    max-width: none !important;
    border: 0;
    box-shadow: none;
  }
}
