:root {
  color-scheme: light;
  --bg: #d7e2e8;
  --panel: #f7f6f2;
  --ink: #1c2830;
  --muted: #5c6d78;
  --line: #ddd6c8;
  --teal: #0f6e6e;
  --teal-dark: #0b5555;
  --paper: #ffffff;
  --stage: #e7f0f4;
  --bad: #8a2424;
  --warn: #8a4b08;
  --ok: #0f513c;
  font-family: "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
}

button, input, select { font: inherit; color: inherit; }

button {
  border: 1px solid var(--line);
  background: var(--paper);
  border-radius: 10px;
  padding: 8px 10px;
  cursor: pointer;
}

button:hover { border-color: #c9c0ae; }

button:focus-visible, input:focus-visible, select:focus-visible {
  outline: 2px solid var(--teal);
  outline-offset: 2px;
}

button:disabled { opacity: 0.45; cursor: not-allowed; }

.app {
  display: grid;
  height: 100vh;
  grid-template-columns: 280px minmax(0, 1fr) 320px;
  grid-template-rows: 62px minmax(0, 1fr) 36px;
  grid-template-areas:
    "top top top"
    "left stage right"
    "status status status";
}

.top {
  grid-area: top;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.brand { min-width: 0; }

.brand h1 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 0;
  white-space: nowrap;
}

.brand p {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.zoom { display: flex; gap: 6px; }

.zoom button { min-width: 42px; }

#zoomLabel { min-width: 64px; font-variant-numeric: tabular-nums; }

.side {
  background: var(--panel);
  min-height: 0;
  overflow: auto;
  padding: 14px;
}

.side-left { grid-area: left; border-right: 1px solid var(--line); }
.side-right { grid-area: right; border-left: 1px solid var(--line); }

#stage {
  grid-area: stage;
  min-width: 0;
  min-height: 0;
  margin: 12px;
  border-radius: 14px;
  overflow: hidden;
  background: var(--stage);
  box-shadow: 0 10px 28px rgba(28, 40, 48, 0.08);
}

#board {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

.status {
  grid-area: status;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding: 0 14px;
  background: #24343d;
  color: #e7eef2;
  font-size: 13px;
}

#statusText { min-width: 0; }

#countsText {
  flex: none;
  color: #b7c6ce;
  font-variant-numeric: tabular-nums;
}

h2 {
  margin: 18px 0 8px;
  font-size: 14px;
  letter-spacing: 0.01em;
}

.side h2:first-child, #props h2:first-child { margin-top: 0; }

.intro {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.tools, .legend, .actions { display: grid; gap: 8px; }

.tool {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  padding: 8px;
}

.tool[draggable="true"] { cursor: grab; }
.tool strong { display: block; font-size: 14px; }
.tool small { display: block; color: var(--muted); font-weight: 400; }
.tool svg { width: 34px; height: 28px; flex: none; }
.tool.active {
  border-color: var(--teal);
  background: #e7f4f4;
  box-shadow: inset 3px 0 0 var(--teal);
}

.legend {
  grid-template-columns: 1fr 1fr;
  margin: 14px 0;
  font-size: 12px;
}

.lg { display: flex; align-items: center; gap: 6px; min-height: 26px; }

.sh {
  width: 28px;
  height: 16px;
  flex: none;
  border: 1.6px solid #1c3d5a;
  background: white;
  display: grid;
  place-items: center;
}

.sh.attr, .sh.derived, .sh.multi, .sh.keyline {
  border-color: #1d6b45;
  background: #f5fbf7;
  border-radius: 50%;
}

.sh.weak { box-shadow: inset 0 0 0 1.4px #1c3d5a; }
.sh.multi { box-shadow: inset 0 0 0 1.4px #1d6b45; }
.sh.derived { border-style: dashed; }
.sh.keyline {
  width: auto;
  min-width: 26px;
  padding: 0 5px;
  font-size: 10px;
  text-decoration: underline;
}
.sh.rel {
  width: 13px;
  height: 13px;
  margin: 0 7px;
  border-color: #a15c07;
  background: #fff8ef;
  transform: rotate(45deg);
}

.steps {
  margin: 0 0 14px;
  padding-left: 18px;
  color: var(--ink);
  font-size: 13px;
  line-height: 1.45;
}

.actions { grid-template-columns: 1fr 1fr; }
.actions .wide { grid-column: 1 / -1; }
.actions.starter { margin-top: 12px; }

.primary {
  background: var(--teal);
  border-color: var(--teal);
  color: white;
  font-weight: 600;
}
.primary:hover { background: var(--teal-dark); }

.ghost { background: white; }
.danger { color: var(--bad); }

.snap {
  display: flex;
  gap: 8px;
  align-items: center;
  margin: 12px 0;
  font-size: 13px;
}

details { font-size: 13px; }
summary { cursor: pointer; color: var(--teal-dark); }
kbd {
  font-family: inherit;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 4px;
  padding: 0 4px;
  background: white;
  font-size: 12px;
}
.keys { margin: 8px 0 0; padding-left: 18px; }
.keys li { margin: 4px 0; }

.muted { color: var(--muted); font-size: 13px; line-height: 1.45; }
.field { display: flex; flex-direction: column; gap: 4px; margin: 0 0 10px; font-size: 13px; }
.field input, .field select {
  width: 100%;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
}
.check { display: flex; gap: 8px; align-items: flex-start; margin: 8px 0; font-size: 14px; }
.check input { margin-top: 2px; }

.feedback { margin-top: 18px; padding-top: 8px; border-top: 1px solid var(--line); }
.banner { padding: 8px 10px; border-radius: 8px; font-size: 13px; line-height: 1.4; }
.banner.ok { background: #e5f5ee; color: var(--ok); }
.banner.bad { background: #fdecec; color: var(--bad); }
.banner.warn { background: #fff4e5; color: var(--warn); }
.banner.empty { background: #eef3f6; color: #34505c; }
.issue { margin: 8px 0 0; padding: 2px 0 2px 10px; border-left: 3px solid var(--line); font-size: 13px; line-height: 1.4; }
.issue.bad { border-color: #d16464; }
.issue.warn { border-color: #e0a15a; }
.issue.tip { border-color: #7eb8d4; }

dialog {
  width: min(960px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  border: 0;
  border-radius: 14px;
  padding: 0;
  color: var(--ink);
}
dialog::backdrop { background: rgba(20, 32, 40, 0.48); }
.schema-card { margin: 0; padding: 18px 18px 22px; overflow: auto; max-height: calc(100vh - 32px); }
.schema-head, .sql-bar { display: flex; justify-content: space-between; gap: 12px; align-items: center; }
.schema-head h2, .sql-bar h3 { margin: 0; }
.rules { margin: 12px 0; padding-left: 18px; font-size: 14px; line-height: 1.45; }
#schemaNotes { margin: 0 0 12px; padding-left: 18px; color: var(--warn); font-size: 13px; }
.schema-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; }
.rel-table { border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: white; }
.rel-table h3 { margin: 0; padding: 8px 10px; background: #1c3d5a; color: white; font-size: 14px; }
.rel-table ul { list-style: none; margin: 0; padding: 0; }
.rel-table li { display: flex; justify-content: space-between; gap: 8px; padding: 6px 10px; border-top: 1px solid var(--line); font-size: 13px; }
.pk { color: var(--teal-dark); font-weight: 700; }
.fk { color: #8a4b08; }
.sql-bar { margin-top: 16px; }
.sql-bar div { display: flex; gap: 8px; }
#schemaSql {
  margin: 10px 0 0;
  padding: 12px;
  overflow: auto;
  max-height: 280px;
  background: #142028;
  color: #e7eef2;
  border-radius: 10px;
  font-family: Consolas, "Courier New", monospace;
  font-size: 13px;
  line-height: 1.45;
}

@media (max-width: 1100px) {
  body { overflow: auto; }
  .app {
    height: auto;
    min-height: 100vh;
    grid-template-columns: 1fr;
    grid-template-rows: auto auto minmax(70vh, 1fr) auto auto;
    grid-template-areas:
      "top"
      "left"
      "stage"
      "right"
      "status";
  }
  #stage { height: 70vh; }
  .status { align-items: flex-start; flex-direction: column; padding: 8px 14px; }
}
