:root {
  color-scheme: light;
  --bg: #f4efe6;
  --panel: rgba(255, 252, 247, 0.92);
  --panel-border: rgba(90, 67, 33, 0.12);
  --accent: #cc7a00;
  --accent-strong: #9e5600;
  --ink: #2c241b;
  --muted: #746552;
  --shadow: 0 18px 50px rgba(77, 54, 23, 0.12);
  --grid-line: rgba(91, 112, 142, 0.28);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background:
    radial-gradient(circle at top left, rgba(255, 218, 166, 0.7), transparent 26%),
    radial-gradient(circle at bottom right, rgba(244, 196, 126, 0.55), transparent 24%),
    linear-gradient(180deg, #faf4eb 0%, #f2eadf 100%);
  color: var(--ink);
  padding-bottom: calc(22px + var(--safe-bottom));
}

button,
input,
output {
  font: inherit;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(320px, 380px) 1fr;
  gap: 24px;
  padding: 24px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 24px;
  box-shadow: var(--shadow);
}

.controls-panel {
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  position: sticky;
  top: 24px;
  max-height: calc(100vh - 48px);
  overflow: auto;
}

.panel-header h1,
.section-heading h2,
.settings-card h2,
.status-card h2 {
  margin: 0;
  font-family: "Georgia", "Times New Roman", serif;
  font-weight: 700;
}

.eyebrow {
  margin: 0 0 6px;
  font-size: 12px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--accent-strong);
}

.subtitle {
  margin: 10px 0 0;
  color: var(--muted);
  line-height: 1.55;
}

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

.shortcut-button {
  border: 1px solid rgba(158, 86, 0, 0.18);
  background: rgba(255, 255, 255, 0.76);
  color: var(--accent-strong);
  border-radius: 999px;
  min-height: 42px;
  padding: 10px 12px;
  font-weight: 700;
}

.dropzone {
  position: relative;
  display: grid;
  place-items: center;
  gap: 6px;
  min-height: 150px;
  border: 2px dashed rgba(158, 86, 0, 0.34);
  border-radius: 20px;
  padding: 20px;
  background:
    linear-gradient(135deg, rgba(255, 194, 102, 0.18), rgba(255, 255, 255, 0.65)),
    repeating-linear-gradient(
      45deg,
      rgba(255, 255, 255, 0.4) 0,
      rgba(255, 255, 255, 0.4) 10px,
      rgba(255, 246, 230, 0.4) 10px,
      rgba(255, 246, 230, 0.4) 20px
    );
  cursor: pointer;
  transition: border-color 0.18s ease, transform 0.18s ease, box-shadow 0.18s ease;
}

.dropzone:hover,
.dropzone.drag-active {
  border-color: var(--accent);
  transform: translateY(-1px);
  box-shadow: 0 14px 32px rgba(172, 100, 4, 0.12);
}

.dropzone input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.dropzone-title {
  font-size: 22px;
  font-weight: 700;
}

.dropzone-hint {
  color: var(--muted);
}

.dropzone-mobile-tip {
  display: none;
  color: var(--accent-strong);
  font-size: 13px;
}

.quick-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.primary-button,
.secondary-button {
  border: 0;
  border-radius: 14px;
  padding: 13px 16px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.15s ease, opacity 0.15s ease, background-color 0.2s ease;
}

.primary-button {
  background: linear-gradient(135deg, var(--accent), #f0a320);
  color: white;
}

.secondary-button {
  background: rgba(158, 86, 0, 0.08);
  color: var(--accent-strong);
}

.primary-button:hover:not(:disabled),
.secondary-button:hover:not(:disabled) {
  transform: translateY(-1px);
}

.primary-button:disabled,
.secondary-button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.settings-card,
.status-card {
  padding: 18px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid rgba(90, 67, 33, 0.08);
}

.settings-card h2,
.status-card h2 {
  font-size: 20px;
  margin-bottom: 12px;
}

.settings-group summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  cursor: pointer;
  list-style: none;
  margin: -2px 0 14px;
}

.settings-group summary::-webkit-details-marker {
  display: none;
}

.settings-group summary h2 {
  margin-bottom: 0;
}

.settings-group summary span {
  color: var(--muted);
  font-size: 13px;
  text-align: right;
}

.setting {
  display: grid;
  gap: 8px;
  margin-bottom: 14px;
}

.setting:last-child {
  margin-bottom: 0;
}

.setting > span {
  font-weight: 600;
}

.setting-control {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: center;
}

.setting-control output {
  color: var(--muted);
  min-width: 64px;
  text-align: right;
}

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

.status-card p {
  margin: 0;
  line-height: 1.55;
}

.summary-list {
  margin: 12px 0 0;
  padding-left: 18px;
  color: var(--muted);
}

.workspace {
  display: grid;
  grid-template-columns: minmax(320px, 0.9fr) minmax(420px, 1.1fr);
  gap: 24px;
  min-width: 0;
}

.source-panel,
.output-panel {
  display: flex;
  flex-direction: column;
  padding: 20px;
  min-width: 0;
}

.section-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.section-heading span {
  color: var(--muted);
  font-size: 14px;
}

.preview-surface {
  position: relative;
  min-height: 420px;
  border-radius: 18px;
  overflow: hidden;
  border: 1px solid rgba(90, 67, 33, 0.08);
  background: #fff;
}

.checkerboard {
  background-image:
    linear-gradient(45deg, rgba(244, 238, 229, 0.75) 25%, transparent 25%),
    linear-gradient(-45deg, rgba(244, 238, 229, 0.75) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, rgba(244, 238, 229, 0.75) 75%),
    linear-gradient(-45deg, transparent 75%, rgba(244, 238, 229, 0.75) 75%);
  background-size: 24px 24px;
  background-position: 0 0, 0 12px, 12px -12px, -12px 0;
}

#sourceCanvas {
  display: block;
  width: 100%;
  height: auto;
}

.empty-state {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  text-align: center;
  padding: 20px;
  color: var(--muted);
}

.empty-state strong {
  display: block;
  color: var(--ink);
  font-size: 20px;
  margin-bottom: 8px;
}

.empty-state p {
  margin: 0;
}

.empty-state.roomy {
  position: relative;
  min-height: 480px;
}

.pages-container {
  flex: 1;
  display: grid;
  gap: 24px;
  align-content: start;
}

.print-page {
  width: min(100%, 210mm);
  min-height: 297mm;
  padding: var(--page-margin, 12mm);
  margin: 0 auto;
  background: white;
  border-radius: 10px;
  box-shadow: 0 14px 36px rgba(76, 58, 34, 0.16);
  border: 1px solid rgba(90, 67, 33, 0.08);
  overflow: hidden;
}

.page-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  grid-auto-rows: var(--row-height, 32mm);
  gap: var(--row-gap, 4mm) var(--column-gap, 7mm);
  width: 100%;
}

.problem-card {
  min-height: 0;
  border-radius: 10px;
  padding: 2.5mm 2.5mm 1.8mm;
  display: flex;
  flex-direction: column;
  background:
    linear-gradient(180deg, rgba(255, 248, 240, 0.76), rgba(255, 255, 255, 0.98));
  border: 1px solid rgba(216, 198, 170, 0.7);
}

.problem-image-wrap {
  flex: 1;
  width: 100%;
  min-height: 0;
  display: flex;
  align-items: flex-start;
  justify-content: flex-start;
  overflow: hidden;
}

.problem-image {
  display: block;
  flex: 0 0 auto;
  width: auto;
  height: auto;
  max-width: calc(82% * var(--problem-scale-factor, 1));
  max-height: calc((var(--row-height, 32mm) - var(--answer-height, 17mm) - 8mm) * var(--problem-scale-factor, 1));
  margin-left: 0;
  margin-right: auto;
  align-self: flex-start;
}

.answer-area {
  height: var(--answer-height, 17mm);
  border-radius: 6px;
}

.mobile-action-bar {
  display: none;
}

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

  .controls-panel {
    position: static;
    max-height: none;
  }

  .workspace {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 820px) {
  body {
    padding-bottom: calc(96px + var(--safe-bottom));
  }

  .app-shell {
    gap: 16px;
    padding: 14px;
  }

  .panel {
    border-radius: 18px;
  }

  .controls-panel,
  .source-panel,
  .output-panel {
    padding: 16px;
  }

  .controls-panel {
    gap: 14px;
  }

  .eyebrow {
    font-size: 11px;
  }

  .panel-header h1 {
    font-size: 30px;
    line-height: 1.05;
  }

  .subtitle {
    font-size: 14px;
  }

  .mobile-shortcuts {
    position: sticky;
    top: 8px;
    z-index: 4;
    background: rgba(250, 244, 235, 0.9);
    backdrop-filter: blur(10px);
    padding: 6px 0;
  }

  .dropzone {
    min-height: 122px;
    padding: 18px 16px;
  }

  .dropzone-title {
    font-size: 20px;
  }

  .dropzone-mobile-tip {
    display: inline;
  }

  .quick-actions {
    display: none;
  }

  .settings-group summary {
    margin-bottom: 10px;
  }

  .setting {
    gap: 6px;
    margin-bottom: 12px;
  }

  .setting > span {
    font-size: 15px;
  }

  .setting-control {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .setting-control output {
    min-width: 0;
    text-align: left;
    font-size: 13px;
  }

  .section-heading {
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
  }

  .preview-surface {
    min-height: 250px;
  }

  .empty-state.roomy {
    min-height: 280px;
  }

  .pages-container {
    gap: 16px;
  }

  .print-page {
    border-radius: 14px;
    min-height: auto;
  }

  .mobile-action-bar {
    position: fixed;
    left: 12px;
    right: 12px;
    bottom: calc(10px + var(--safe-bottom));
    z-index: 20;
    display: grid;
    grid-template-columns: 1.2fr 1fr 1fr;
    gap: 10px;
    padding: 10px;
    border-radius: 18px;
    background: rgba(255, 252, 247, 0.92);
    border: 1px solid rgba(90, 67, 33, 0.08);
    box-shadow: 0 18px 40px rgba(77, 54, 23, 0.16);
    backdrop-filter: blur(12px);
  }

  .mobile-action-bar .primary-button,
  .mobile-action-bar .secondary-button {
    min-height: 48px;
    padding: 12px 10px;
    border-radius: 14px;
    font-size: 15px;
  }
}

@media print {
  body {
    background: white;
    padding-bottom: 0;
  }

  .controls-panel,
  .source-panel,
  .mobile-action-bar {
    display: none !important;
  }

  .app-shell,
  .workspace,
  .output-panel {
    display: block;
    padding: 0;
    margin: 0;
    background: white;
  }

  .output-panel {
    box-shadow: none;
    border: 0;
    padding: 0;
  }

  .section-heading {
    display: none;
  }

  .pages-container {
    gap: 0;
  }

  .print-page {
    margin: 0;
    width: 210mm;
    min-height: 297mm;
    box-shadow: none;
    border: 0;
    border-radius: 0;
    page-break-after: always;
  }

  .print-page:last-child {
    page-break-after: auto;
  }

  @page {
    size: A4 portrait;
    margin: 0;
  }
}
