@font-face {
  font-family: "WorksheetBody";
  src: url("/static/fonts/omyu-pretty.ttf") format("truetype");
  font-weight: 300 800;
  font-style: normal;
  font-display: swap;
}

:root {
  --font-body: "WorksheetBody", "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  --game-blue: #0066cc;
  --game-blue-focus: #0071e3;
  --game-ink: #1d1d1f;
  --game-muted: #737377;
  --game-page: #f5f5f7;
  --game-canvas: #ffffff;
  --game-field: #fbfbfd;
  --game-line: #dedee3;
  --game-danger: #c2410c;
  --game-success: #0f766e;
  --game-pill: 9999px;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--game-ink);
  font-family: var(--font-body);
  background: var(--game-page);
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 14px 0 72px;
}

.topbar,
.panel,
.worksheet-page,
.empty-state {
  border: 1px solid var(--game-line);
  border-radius: 24px;
  background: var(--game-canvas);
}

.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  min-height: 68px;
  margin-bottom: 24px;
  padding: 12px 18px;
}

.topbar h1,
.panel-heading h2,
.empty-state h3,
.worksheet-title {
  margin: 0;
  color: var(--game-ink);
  font-family: var(--font-body);
  font-weight: 800;
  letter-spacing: 0;
}

.topbar h1 {
  flex: 1 1 auto;
  font-size: clamp(1.15rem, 2.4vw, 1.45rem);
}

.topbar__actions,
.action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 0 20px;
  border: 1px solid var(--game-line);
  border-radius: var(--game-pill);
  color: var(--game-ink);
  background: var(--game-canvas);
  transition: color 0.18s ease, border-color 0.18s ease, background 0.18s ease;
}

.button:hover:not(:disabled) {
  color: var(--game-blue);
  border-color: var(--game-blue);
}

.button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

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

.button--primary:hover:not(:disabled) {
  color: #ffffff;
  background: var(--game-blue-focus);
}

.layout {
  display: grid;
  grid-template-columns: minmax(340px, 420px) minmax(0, 1fr);
  gap: 22px;
  align-items: start;
}

.panel {
  padding: 28px;
}

.panel-heading {
  margin-bottom: 20px;
}

.panel-heading h2 {
  font-size: clamp(1.5rem, 3vw, 2.2rem);
}

.preview-heading {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: start;
}

.step-label {
  margin: 0 0 10px;
  color: var(--game-muted);
  font-size: 0.82rem;
  font-weight: 800;
  letter-spacing: 0.14em;
}

.summary,
.empty-state p,
.worksheet-meta {
  color: var(--game-muted);
}

.summary {
  max-width: 28ch;
  margin: 4px 0 0;
  font-size: 0.95rem;
  text-align: right;
}

.maker-form {
  display: grid;
  gap: 16px;
}

.field {
  display: grid;
  gap: 8px;
}

.field span,
.option-card legend {
  font-weight: 800;
}

.field input,
.field select {
  width: 100%;
  min-height: 52px;
  padding: 0 16px;
  border: 1px solid var(--game-line);
  border-radius: 16px;
  color: var(--game-ink);
  background: var(--game-field);
}

.field input[type="file"] {
  padding: 13px 16px;
}

.field input:focus,
.field select:focus {
  outline: 3px solid rgba(0, 102, 204, 0.16);
  border-color: var(--game-blue);
}

.field-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.option-card {
  margin: 0;
  padding: 18px;
  border: 1px solid var(--game-line);
  border-radius: 20px;
  background: var(--game-field);
}

.option-card legend {
  padding: 0 8px;
}

.toggle-stack {
  display: grid;
  gap: 12px;
}

.toggle-stack label {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid var(--game-line);
  border-radius: 14px;
  background: #ffffff;
}

.feedback {
  min-height: 1.5em;
  margin: 0;
  color: var(--game-muted);
}

.feedback.is-error {
  color: var(--game-danger);
}

.feedback.is-success {
  color: var(--game-success);
}

.feedback.is-warning {
  color: #9a5b00;
}

.empty-state {
  min-height: 300px;
  display: grid;
  place-items: center;
  padding: 42px;
  text-align: center;
  border-style: dashed;
}

.empty-state h3 {
  margin-bottom: 12px;
  font-size: 1.55rem;
}

.empty-state p {
  max-width: 42ch;
  margin: 0;
  line-height: 1.65;
}

.prompt-tools {
  display: grid;
  gap: 14px;
  padding: 16px;
  border: 1px solid var(--game-line);
  border-radius: 18px;
  background: var(--game-field);
}

.prompt-tools > div:first-child {
  display: grid;
  gap: 6px;
}

.prompt-tools strong {
  color: var(--game-ink);
  font-weight: 800;
}

.prompt-tools span {
  color: var(--game-muted);
  font-size: 0.95rem;
  line-height: 1.5;
}

.prompt-copy-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
}

.prompt-copy-button {
  min-height: 42px;
  padding: 0 16px;
  white-space: nowrap;
}

.print-area {
  display: grid;
  gap: 24px;
}

.worksheet-page {
  width: min(100%, 794px);
  margin: 0 auto;
  padding: 36px 40px;
  aspect-ratio: 210 / 297;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 18px;
  overflow: hidden;
}

.worksheet-header {
  display: grid;
  gap: 16px;
  border-bottom: 1px solid var(--game-line);
  padding-bottom: 24px;
}

.worksheet-title {
  font-size: clamp(1.55rem, 3vw, 2.2rem);
}

.worksheet-meta {
  display: flex;
  justify-content: flex-end;
  align-items: flex-end;
  gap: 12px;
  margin: 0;
  padding-top: 6px;
  font-size: 1rem;
}

.worksheet-name-line {
  display: inline-block;
  width: 168px;
  height: 1.3em;
  border-bottom: 1.5px solid #1d1d1f;
}

.dot-sheet {
  width: 100%;
  height: 100%;
  min-height: 0;
  display: grid;
}

.dot-svg {
  width: 100%;
  height: 100%;
  display: block;
  background: #ffffff;
}

.dot-source-image {
  opacity: 0.16;
}

.dot-guide {
  fill: none;
  stroke: #c7c7cc;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.dot-point {
  fill: #1f2937;
}

.dot-label {
  fill: #111827;
  font-family: var(--font-body);
  font-weight: 800;
}

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

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .topbar__actions {
    width: 100%;
  }

  .topbar__actions .button {
    flex: 1 1 auto;
  }
}

@media (max-width: 620px) {
  .app-shell {
    width: min(100% - 20px, 1180px);
  }

  .panel,
  .worksheet-page {
    padding: 22px;
    border-radius: 20px;
  }

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

  .preview-heading {
    display: block;
  }

  .summary {
    text-align: left;
  }
}

@page {
  size: A4 portrait;
  margin: 10mm;
}

@media print {
  html,
  body {
    min-height: 0;
    background: #ffffff;
  }

  .topbar,
  .controls-panel,
  .preview-heading,
  .empty-state,
  .feedback {
    display: none !important;
  }

  .app-shell {
    width: 100%;
    padding: 0;
  }

  .layout,
  .preview-panel,
  .print-area {
    display: block;
    margin: 0;
    padding: 0;
    border: 0;
  }

  .worksheet-page {
    width: 190mm;
    height: 275mm;
    min-height: 0;
    max-height: 275mm;
    aspect-ratio: auto;
    padding: 0;
    border: 0;
    overflow: hidden;
    break-after: auto;
    break-inside: avoid;
    page-break-after: auto;
    page-break-inside: avoid;
  }

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

.sample-tools {
  display: grid;
  gap: 12px;
}

.sample-panel {
  padding: 14px;
  border: 1px solid var(--game-line);
  border-radius: 18px;
  background: var(--game-field);
}

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

.sample-card {
  display: grid;
  gap: 8px;
  width: 100%;
  padding: 10px;
  border: 1px solid var(--game-line);
  border-radius: 16px;
  color: var(--game-ink);
  background: #fff;
  text-align: left;
}

.sample-card:hover {
  border-color: var(--game-blue);
}

.sample-card img {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: contain;
  border-radius: 12px;
  background: #fff;
}

.sample-card span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.92rem;
  font-weight: 800;
}

.sample-message {
  grid-column: 1 / -1;
  margin: 0;
  color: var(--game-muted);
}

.sample-message--error {
  color: var(--game-danger);
}

.source-preview {
  display: grid;
  grid-template-columns: 96px minmax(0, 1fr);
  gap: 14px;
  align-items: center;
  padding: 12px;
  border: 1px solid var(--game-line);
  border-radius: 18px;
  background: #fff;
}

.source-preview img {
  width: 96px;
  height: 72px;
  object-fit: contain;
  border: 1px solid var(--game-line);
  border-radius: 14px;
  background: #fff;
}

.source-preview--no-image {
  grid-template-columns: minmax(0, 1fr);
}

.source-preview--no-image img {
  display: none;
}

.source-preview strong,
.source-preview span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.source-preview span {
  color: var(--game-muted);
  font-size: 0.95rem;
}

@media (max-width: 520px) {
  .sample-list {
    grid-template-columns: 1fr;
  }

  .source-preview {
    grid-template-columns: 82px minmax(0, 1fr);
  }

  .source-preview img {
    width: 82px;
    height: 62px;
  }
}
