:root {
  color-scheme: light;
  --panel-bg: #faf8f5;
  --surface: #ffffff;
  --ink: #1d2430;
  --muted: #697281;
  --line: #d9d4cc;
  --accent: #cf3f36;
  --accent-dark: #9f2f2a;
  --focus: #1c7c8c;
  --preview-bg: #ece7de;
  --shadow: 0 12px 30px rgba(35, 31, 27, 0.12);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "Noto Sans SC", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--preview-bg);
  color: var(--ink);
}

button,
input,
select {
  font: inherit;
}

button,
select,
input[type="color"],
input[type="number"],
input[type="file"] {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink);
}

button {
  min-height: 40px;
  padding: 0 14px;
  cursor: pointer;
  font-weight: 650;
}

button:hover {
  border-color: #b9afa3;
}

button:focus-visible,
select:focus-visible,
input:focus-visible,
summary:focus-visible {
  outline: 3px solid rgba(28, 124, 140, 0.22);
  outline-offset: 2px;
}

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

.control-panel {
  display: flex;
  min-width: 0;
  flex-direction: column;
  border-right: 1px solid var(--line);
  background: var(--panel-bg);
}

.puzzle-name {
  flex: 0 0 auto;
  margin: 0;
  padding: 22px 24px 18px;
  border-bottom: 1px solid var(--line);
  font-size: 24px;
  line-height: 1.1;
  letter-spacing: 0;
}

.control-scroll {
  display: flex;
  min-height: 0;
  flex: 1 1 auto;
  flex-direction: column;
  gap: 18px;
  overflow-y: auto;
  padding: 20px 24px 24px;
}

.control-section,
.advanced-panel,
.app-status {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.72);
}

.control-section {
  display: grid;
  gap: 16px;
  padding: 16px;
}

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

.field label,
.section-title {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.field input,
.field select {
  min-height: 38px;
  width: 100%;
  padding: 0 10px;
}

.field input[type="color"] {
  padding: 4px;
}

.field input[type="file"] {
  min-height: auto;
  padding: 8px;
}

.section-row,
.button-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.small-button {
  min-height: 34px;
  padding: 0 10px;
  font-size: 13px;
}

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

.pair-item {
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  min-height: 48px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.pair-color {
  appearance: none;
  background-color: var(--pair-color);
  background-image: none;
  color: transparent;
  cursor: pointer;
  width: 34px;
  height: 34px;
  padding: 0;
}

.pair-color option {
  color: var(--ink);
}

.pair-name {
  min-width: 0;
  overflow: hidden;
  font-weight: 650;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.delete-pair {
  min-height: 34px;
  padding: 0 10px;
  color: #7c2c26;
}

.empty-state {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.advanced-panel {
  margin-top: auto;
  overflow: hidden;
}

.advanced-panel summary {
  cursor: pointer;
  padding: 14px 16px;
  color: var(--ink);
  font-weight: 750;
}

.advanced-panel[open] summary {
  border-bottom: 1px solid var(--line);
}

.advanced-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  padding: 16px;
}

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

.export-section {
  grid-template-columns: 1fr;
}

.export-section button {
  border-color: transparent;
  background: var(--accent);
  color: #fff;
}

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

.app-status {
  min-height: 42px;
  padding: 12px 14px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.4;
}

.app-status.is-error,
.preview-status.is-error {
  color: #9f2f2a;
}

.app-status.is-ok,
.preview-status.is-ok {
  color: #287266;
}

.preview-pane {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  min-width: 0;
  border-right: 1px solid var(--line);
  background: #f3efe8;
}

.preview-pane:last-child {
  border-right: 0;
}

.preview-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  min-height: 66px;
  padding: 18px 24px 14px;
}

.preview-header h2 {
  margin: 0;
  font-size: 18px;
  line-height: 1.2;
  letter-spacing: 0;
}

.preview-meta {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.preview-surface {
  display: grid;
  min-height: 0;
  place-items: center;
  overflow: auto;
  padding: 20px 24px;
}

.preview-surface svg {
  display: block;
  width: min(82%, 420px);
  max-height: 100%;
  filter: drop-shadow(var(--shadow));
  touch-action: none;
}

.preview-status {
  min-height: 44px;
  padding: 10px 24px 18px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.4;
}

.dot {
  cursor: grab;
}

.dot:active {
  cursor: grabbing;
}

.circle-boundary {
  pointer-events: none;
}

.answer-path {
  pointer-events: none;
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
    height: auto;
    min-height: 100vh;
  }

  .control-panel,
  .preview-pane {
    min-height: 640px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .preview-surface svg {
    width: min(78vw, 420px);
  }
}
