:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --panel: #ffffff;
  --ink: #1f2933;
  --muted: #687586;
  --line: #d9e0e8;
  --accent: #176b87;
  --accent-strong: #0f4f66;
  --soft: #e9f4f7;
  --warn: #b7791f;
  --danger: #b42318;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Segoe UI", "Noto Sans KR", Arial, sans-serif;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  border: 0;
  border-radius: 6px;
  background: var(--accent);
  color: white;
  cursor: pointer;
  min-height: 38px;
  padding: 0 14px;
  font-weight: 700;
}

button:hover {
  background: var(--accent-strong);
}

button.secondary {
  background: #3f5968;
}

button.ghost {
  background: #eef3f6;
  color: var(--ink);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 22px 28px;
  background: #fbfcfd;
  border-bottom: 1px solid var(--line);
}

.app-header h1 {
  margin: 0 0 6px;
  font-size: 24px;
}

.app-header p {
  margin: 0;
  color: var(--muted);
}

.header-actions,
.button-row,
.editor-toolbar,
.inline-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.inline-actions button {
  flex: 1 1 0;
}

.workspace {
  display: grid;
  grid-template-columns: 280px 250px minmax(360px, 1fr) minmax(360px, 1fr);
  gap: 14px;
  min-height: calc(100vh - 95px);
  padding: 14px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  min-width: 0;
  overflow: hidden;
}

.panel h2 {
  margin: 0;
  font-size: 17px;
}

.controls-panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 18px;
}

.drop-zone {
  display: grid;
  place-items: center;
  min-height: 132px;
  border: 2px dashed #a9bac7;
  border-radius: 8px;
  background: #f8fbfc;
  cursor: pointer;
  text-align: center;
  padding: 16px;
}

.drop-zone.drag-over {
  border-color: var(--accent);
  background: var(--soft);
  box-shadow: inset 0 0 0 2px rgba(23, 107, 135, 0.16);
}

.drop-zone input {
  display: none;
}

.drop-zone span {
  font-weight: 800;
}

.drop-zone small {
  color: var(--muted);
}

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

.control-grid label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

.control-grid select,
.control-grid input {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  padding: 0 10px;
}

.status-box {
  display: grid;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
  padding: 12px;
  color: var(--muted);
}

progress {
  width: 100%;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

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

.page-list,
.problem-list {
  display: grid;
  gap: 10px;
  max-height: calc(100vh - 160px);
  overflow: auto;
  padding: 12px;
}

.page-card,
.problem-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 10px;
}

.page-card {
  display: grid;
  grid-template-columns: 70px 1fr;
  gap: 10px;
  align-items: center;
}

.page-card.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--soft);
}

.page-card.done {
  border-color: #15803d;
}

.page-card.failed {
  border-color: var(--danger);
}

.page-card img {
  width: 70px;
  height: 92px;
  object-fit: contain;
  background: #eef2f5;
  border-radius: 4px;
}

.page-card strong,
.problem-card strong {
  display: block;
  margin-bottom: 4px;
}

.page-card small,
.problem-card small {
  color: var(--muted);
}

.preview-panel {
  display: flex;
  flex-direction: column;
}

.canvas-wrap {
  position: relative;
  flex: 1;
  overflow: auto;
  padding: 16px;
  background: #dfe5ea;
}

#pageCanvas {
  display: block;
  max-width: 100%;
  background: white;
  box-shadow: 0 4px 16px rgba(20, 30, 40, 0.18);
}

.overlay-layer {
  position: absolute;
  left: 16px;
  top: 16px;
  pointer-events: none;
}

.overlay-box {
  position: absolute;
  border: 2px solid rgba(23, 107, 135, 0.85);
  background: rgba(23, 107, 135, 0.08);
}

.overlay-box.figure {
  border-color: rgba(183, 121, 31, 0.9);
  background: rgba(183, 121, 31, 0.12);
}

.editor-panel {
  display: flex;
  flex-direction: column;
}

.editor-toolbar {
  border-bottom: 1px solid var(--line);
  padding: 10px 12px;
}

.problem-card header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.problem-card input.problem-number {
  width: 70px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px;
  font-weight: 800;
}

.problem-card textarea {
  width: 100%;
  min-height: 132px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px;
  line-height: 1.55;
}

.asset-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.asset-list img {
  width: 96px;
  height: 72px;
  object-fit: contain;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #f5f7f9;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  background: var(--soft);
  color: var(--accent-strong);
  padding: 0 9px;
  font-size: 12px;
  font-weight: 800;
}

.warning {
  color: var(--warn);
}

dialog {
  border: 1px solid var(--line);
  border-radius: 8px;
  width: min(560px, calc(100vw - 32px));
}

#savedProjects {
  display: grid;
  gap: 8px;
  margin: 16px 0;
}

.saved-project {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px;
}

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

  .pages-panel {
    display: none;
  }
}

@media (max-width: 920px) {
  .app-header {
    align-items: stretch;
    flex-direction: column;
  }

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

  .page-list,
  .problem-list {
    max-height: none;
  }
}
