@font-face {
  font-family: "Noto Sans SC";
  src: url("assets/fonts/NotoSansCJKsc-VF.ttf") format("truetype");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Noto Serif SC";
  src: url("assets/fonts/NotoSerifCJKsc-VF.ttf") format("truetype");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

:root {
  color-scheme: light;

  /* Bootstrap-like base palette */
  --bs-blue: #0d6efd;
  --bs-indigo: #6610f2;
  --bs-purple: #6f42c1;
  --bs-pink: #d63384;
  --bs-red: #dc3545;
  --bs-orange: #fd7e14;
  --bs-yellow: #ffc107;
  --bs-green: #198754;
  --bs-teal: #20c997;
  --bs-cyan: #0dcaf0;
  --bs-white: #ffffff;
  --bs-gray-100: #f8f9fa;
  --bs-gray-200: #e9ecef;
  --bs-gray-300: #dee2e6;
  --bs-gray-400: #ced4da;
  --bs-gray-500: #adb5bd;
  --bs-gray-600: #6c757d;
  --bs-gray-700: #495057;
  --bs-gray-800: #343a40;
  --bs-gray-900: #212529;

  /* App theme tokens */
  --bg: var(--bs-gray-100);
  --panel: var(--bs-white);
  --card: var(--bs-white);
  --text: var(--bs-gray-900);
  --muted: var(--bs-gray-600);
  --border: var(--bs-gray-300);
  --primary: var(--bs-blue);
  --primary-2: #0b5ed7;
  --btn: var(--bs-gray-600);
  --btn-hover: var(--bs-gray-700);
  --danger: var(--bs-red);
  --shadow: 0 10px 30px rgba(33, 37, 41, 0.08);
  --focus: 0 0 0 0.25rem rgba(13, 110, 253, 0.25);

  /* Layout */
  --panel-min-width: 800px;
  --panel-width: 945px;
  --layout-gap: 16px;
  --preview-card-width: 846px;
  --page-width: calc(
    var(--panel-width) + var(--layout-gap) + var(--preview-card-width)
  );

  /* UI sizing */
  --ui-font-width: 90px;
  --ui-size-width: 50px;
  --ui-color-width: 32px;
  --ui-inline-gap: 6px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Noto Sans SC", ui-sans-serif, system-ui, -apple-system,
    BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.topbar {
  padding: 16px;
  border-bottom: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.9);
}

.topbar__inner {
  width: min(100%, var(--page-width));
  margin: 0 auto;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.topbar__title {
  font-weight: 700;
  letter-spacing: 0.2px;
}

.topbar__meta {
  color: var(--muted);
  font-size: 13px;
}

.layout {
  display: grid;
  grid-template-columns: minmax(var(--panel-min-width), var(--panel-width))
    max-content;
  justify-content: center;
  gap: var(--layout-gap);
  padding: 16px;
  align-items: start;
}

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

.preview {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
  min-height: 480px;
  box-shadow: var(--shadow);
  width: fit-content;
  justify-self: start;
}

.preview__header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
}

.preview__title {
  font-weight: 700;
}

.preview__right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.dirtybadge {
  display: inline-flex;
  align-items: center;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid rgba(255, 193, 7, 0.55);
  background: rgba(255, 193, 7, 0.16);
  color: var(--bs-gray-900);
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.preview__meta {
  font-size: 13px;
  color: var(--muted);
}

.preview__canvaswrap {
  background: var(--bs-gray-100);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  overflow: auto;
}

#chartCanvas {
  width: 790px;
  height: auto;
  display: block;
  background: #ffffff;
  border-radius: 10px;
}

.group {
  background: var(--bs-gray-100);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  margin-bottom: 12px;
}

.group--tight {
  padding: 12px;
  margin-bottom: 10px;
}

.group__title {
  font-weight: 700;
  font-size: 13px;
  color: var(--primary-2);
  margin-bottom: 10px;
}

.group__titlerow {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.group__titlerow .group__title {
  margin-bottom: 0;
}

.group__titlerow > .tipsstyle {
  margin-left: auto;
}

.markerstylerow {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.row {
  display: grid;
  grid-template-columns: 1fr 120px;
  gap: 10px;
}

.row--compact {
  grid-template-columns: 1fr 90px;
  align-items: end;
}

.inputrow {
  display: grid;
  grid-template-columns: var(--ui-size-width) var(--ui-color-width);
  gap: var(--ui-inline-gap);
  align-items: center;
}

.grid2 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
}

.grid2--equal {
  grid-template-columns: 1fr 1fr;
}

.blockheadrow {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  gap: 12px;
  align-items: end;
  margin-bottom: 10px;
}

.blockheadrow .field {
  margin-bottom: 0;
}

.blockheadrow .field__control {
  height: 42px;
}

.basicsrow {
  display: grid;
  grid-template-columns: 1fr var(--ui-font-width)
    calc(var(--ui-size-width) + var(--ui-color-width) + var(--ui-inline-gap));
  gap: 12px;
  align-items: end;
  margin-bottom: 10px;
}

.basicsrow .field {
  margin-bottom: 0;
}

.basicsrow .field__control {
  height: 42px;
}

.basicsrow input[type="number"].field__control {
  text-align: center;
}

select.field__control {
  padding-right: 20px;
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath fill='%236c757d' d='M4.646 6.646a.5.5 0 0 1 .708 0L8 9.293l2.646-2.647a.5.5 0 0 1 .708.708l-3 3a.5.5 0 0 1-.708 0l-3-3a.5.5 0 0 1 0-.708z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  background-size: 10px 10px;
}

select.field__control::-ms-expand {
  display: none;
}

@media (max-width: 860px) {
  .blockheadrow {
    grid-template-columns: 1fr;
  }
  .blockheadrow .field {
    margin-bottom: 10px;
  }
  .basicsrow {
    grid-template-columns: 1fr;
  }
  .basicsrow .field {
    margin-bottom: 10px;
  }
}

.field {
  display: block;
  margin-bottom: 10px;
}

.field__labelrow {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 6px;
}

.field__labelactions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
  margin-left: auto;
}

.tipsstyle {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: nowrap;
  max-width: 100%;
  gap: 0;
  border: 1px solid var(--bs-gray-500);
  border-radius: 10px;
  overflow: hidden;
  background: #ffffff;
}

.tipsstyle:focus-within {
  border-color: var(--primary);
  box-shadow: var(--focus);
}

.tipsstyle .field__control {
  height: 26.39px;
  padding: 0 10px;
  border: 0;
  border-radius: 0;
  box-shadow: none;
}

.tipsstyle .field__control--size {
  padding: 0 6px;
}

.tipsstyle select.field__control {
  padding-right: 22px;
}

.tipsstyle .field__control:focus {
  border-color: transparent;
  box-shadow: none;
}

.tipsstyle .colorpicker--mini {
  height: 26.39px;
  padding: 3px;
  border: 0;
  border-radius: 0;
  box-shadow: none;
}

.tipsstyle > :not(:first-child) {
  border-left: 1px solid var(--bs-gray-500);
}

.tipsstyle--collapsible .tipsstyle__item {
  display: none;
}

.tipsstyle--collapsible[data-open="true"] .tipsstyle__item {
  display: block;
}

.tipsstyle__toggle {
  appearance: none;
  border: 0;
  border-radius: 0;
  background: var(--bs-gray-200);
  color: var(--text);
  cursor: pointer;
  height: 26.39px;
  min-width: 0;
  padding: 0 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  font-size: 10px;
  font-weight: 800;
}

.tipsstyle__toggle--label {
  width: 30px;
  min-width: 30px;
  padding: 0;
  font-size: 12px;
  border-left: 0;
}

.tipsstyle > .tipsstyle__toggle--label {
  border-left: 0;
}

.tipsstyle__toggle--chev {
  font-weight: 900;
  font-size: 12px;
}

.tipsstyle__toggle:hover {
  background: var(--bs-gray-300);
}

.tipsstyle__toggle:focus-visible {
  outline: 2px solid rgba(13, 110, 253, 0.45);
  outline-offset: -2px;
}

.tipsstyle--collapsible[data-open="false"] .tipsstyle__toggle--chev {
  border-left: 0;
}

.tipsstyle .colorpicker--mini:focus {
  border-color: transparent;
  box-shadow: none;
  outline: none;
}

.field__labelrow .field__label {
  margin-bottom: 0;
}

.field__label {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 6px;
}

.segbtn {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--bs-gray-500);
  border-radius: 10px;
  overflow: hidden;
  background: #ffffff;
}

.segbtn__btn {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  padding: 6px 10px;
  min-width: 40px;
  font-size: 12px;
  line-height: 1.2;
}

.segbtn__btn + .segbtn__btn {
  border-left: 1px solid var(--bs-gray-500);
}

.segbtn__btn:hover {
  background: var(--bs-gray-100);
  color: var(--text);
}

.segbtn__btn--active {
  background: var(--primary);
  color: #ffffff;
  font-weight: 700;
}

.segbtn__btn--active:hover {
  background: var(--primary-2);
}

.segbtn__btn:focus-visible {
  outline: 2px solid rgba(13, 110, 253, 0.45);
  outline-offset: -2px;
}

.field__control {
  width: 100%;
  background: #ffffff;
  border: 1px solid var(--bs-gray-400);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 10px;
  outline: none;
}

.field__control--size {
  width: var(--ui-size-width);
  text-align: center;
}

.field__control--font {
  width: var(--ui-font-width);
  min-width: 0;
}

.field__control:focus {
  border-color: var(--primary);
  box-shadow: var(--focus);
}

.colorpicker {
  width: 100%;
  height: 42px;
  border-radius: 10px;
  border: 1px solid var(--bs-gray-400);
  background: #ffffff;
  padding: 6px;
  cursor: pointer;
}

.colorpicker--mini {
  width: var(--ui-color-width);
  height: 42px;
  border-radius: 10px;
  padding: 4px;
  flex: 0 0 auto;
}

.colorpicker:focus {
  border-color: var(--primary);
  box-shadow: var(--focus);
  outline: none;
}

.colorpicker::-webkit-color-swatch-wrapper {
  padding: 0;
}

.colorpicker::-webkit-color-swatch {
  border: 1px solid var(--bs-gray-400);
  border-radius: 8px;
}

.colorpicker::-moz-color-swatch {
  border: 1px solid var(--bs-gray-400);
  border-radius: 8px;
}

.field__control--textarea {
  resize: vertical;
  line-height: 1.35;
}

.list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 10px;
}

.listitem {
  display: grid;
  grid-template-columns: 1fr 34px;
  gap: 8px;
  align-items: center;
}

.iconbtn {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #ffffff;
  color: var(--text);
  cursor: pointer;
}

.iconbtn--sm {
  width: 30px;
  height: 30px;
}

.stylebtn {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-direction: row;
  gap: 4px;
  line-height: 1;
  font-size: 12px;
  font-weight: 800;
  width: auto;
  min-width: 54px;
  padding: 0 8px;
}

.stylebtn::after {
  content: ">>";
  font-size: 10px;
  line-height: 1;
  opacity: 0.7;
  transform: scaleX(0.92);
}

.stylebtn[aria-expanded="true"]::after {
  content: "<<";
}

.stylebtn--active {
  border-color: rgba(13, 110, 253, 0.7);
  box-shadow: var(--focus);
}

.stylepanel {
  display: flex;
  justify-content: flex-end;
  margin-top: -6px;
  margin-bottom: 10px;
}

.stylepanel[hidden] {
  display: none;
}

.iconbtn:hover {
  background: var(--bs-gray-100);
}

.iconbtn--danger {
  color: var(--danger);
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.btn {
  border: 1px solid var(--primary);
  background: var(--primary);
  color: #ffffff;
  padding: 10px 12px;
  border-radius: 12px;
  cursor: pointer;
  font-weight: 700;
}

.btn--sm {
  padding: 8px 10px;
  border-radius: 10px;
  font-size: 13px;
}

.btn:hover {
  border-color: var(--primary-2);
  background: var(--primary-2);
}

.btn--secondary {
  border-color: var(--btn);
  background: var(--btn);
  color: #ffffff;
  font-weight: 600;
}

.btn--secondary:hover {
  background: var(--btn-hover);
  border-color: var(--btn-hover);
}

.btn--file {
  position: relative;
  overflow: hidden;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.btn--file input[type="file"] {
  position: absolute;
  left: -9999px;
}

.check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--muted);
  margin: 8px 0 12px;
  user-select: none;
}

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

.checkgrid .check {
  margin: 0;
}

.checkgrid .check span {
  min-width: 0;
}

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

.check input {
  accent-color: var(--primary);
}

.hint {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.35;
  margin-top: 8px;
}

.tablewrap {
  overflow: auto;
  border-radius: 12px;
  border: 1px solid var(--border);
}

table.data {
  width: 100%;
  border-collapse: collapse;
  min-width: 420px;
  background: #ffffff;
}

table.data th,
table.data td {
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
  padding: 8px;
  text-align: center;
  font-size: 13px;
}

table.data th {
  position: sticky;
  top: 0;
  background: var(--bs-gray-100);
  z-index: 1;
}

table.data th:first-child,
table.data td:first-child {
  position: sticky;
  left: 0;
  background: var(--bs-gray-100);
  z-index: 2;
}

table.data input {
  width: 100%;
  background: #ffffff;
  border: 1px solid var(--bs-gray-400);
  color: var(--text);
  border-radius: 10px;
  padding: 8px 8px;
  text-align: center;
  outline: none;
}

table.data input:focus {
  border-color: var(--primary);
  box-shadow: var(--focus);
}

.dialog {
  border: none;
  padding: 0;
  background: transparent;
}

.dialog::backdrop {
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(6px);
}

.dialog__content {
  width: min(1100px, calc(100vw - 32px));
  max-height: min(88vh, 820px);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow);
}

#annotationEditorDialog .dialog__content {
  width: min(1520px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
}

#annotationEditorDialog .dialog__body {
  grid-template-columns: minmax(380px, 1fr) max-content;
}

#annotationEditorDialog .dialog__main {
  justify-self: start;
}

#annotationEditorDialog .svgsplit {
  flex-direction: column;
}

.dialog__header {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--bs-gray-100);
}

.dialog__title {
  font-weight: 800;
  letter-spacing: 0.2px;
}

.dialog__body {
  display: grid;
  grid-template-columns: 360px 1fr;
  gap: 12px;
  padding: 12px;
  overflow: hidden;
  flex: 1;
}

.dialog__sidebar {
  overflow: auto;
  padding-right: 6px;
}

.dialog__main {
  overflow: hidden;
}

.dialog__footer {
  padding: 12px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
}

.svgwrap {
  background: var(--bs-gray-100);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px;
  height: auto;
  width: fit-content;
  max-width: 100%;
  max-height: 100%;
  display: flex;
  position: relative;
  overflow: auto;
  align-items: flex-start;
  justify-content: flex-start;
}

.svgsplit {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  justify-content: flex-start;
  flex: 0 0 auto;
}

.svgsplit__title {
  font-size: 12px;
  color: var(--muted);
  margin: 0 0 8px;
  font-weight: 700;
}

.svgsplit__preview {
  width: 240px;
  flex: 0 0 auto;
}

.svgsplit__editor {
  width: 720px;
  flex: 0 0 auto;
}

.annbasegrid {
  display: flex;
  gap: 12px;
  align-items: stretch;
  justify-content: flex-start;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.annbasegrid .group--tight {
  margin-bottom: 0;
}

.annbasegrid__base {
  flex: 1 1 380px;
  min-width: 280px;
}

.annbasegrid__preview {
  flex: 0 0 auto;
}

.annpreviewcanvas {
  width: 240px;
  max-width: 100%;
}

#annSvg,
#annPreviewSvg {
  width: 100%;
  height: auto;
  flex: 0 0 auto;
  display: block;
  background: #ffffff;
  border-radius: 12px;
  box-shadow: 0 0 0 1px var(--border);
}

#annPreviewSvg {
  pointer-events: none;
}

.markerlist {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 10px;
}

.markeritem {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #ffffff;
  cursor: pointer;
}

.markeritem:hover {
  background: var(--bs-gray-100);
}

.markeritem--active {
  border-color: rgba(13, 110, 253, 0.7);
  box-shadow: var(--focus);
}

.markeritem__name {
  font-size: 13px;
}

.markeritem__toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--muted);
  user-select: none;
}

.markeritem__toggle input {
  accent-color: var(--primary);
}

.markeritem__controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  justify-content: flex-end;
}

.markeritem__style,
.markeritem__mode,
.markeritem__angle {
  height: 24px;
  padding: 2px 8px;
  border-radius: 10px;
  border: 1px solid var(--bs-gray-400);
  background: #ffffff;
  color: var(--text);
  font-size: 12px;
  outline: none;
}

.markeritem__style:disabled {
  opacity: 0.6;
}

.markeritem__mode:disabled,
.markeritem__angle:disabled {
  opacity: 0.6;
}

.markeritem__style,
.markeritem__mode {
  min-width: 70px;
}

.markeritem__anglewrap {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.markeritem__angle {
  width: 62px;
}

.markeritem__deg {
  font-size: 12px;
  color: var(--muted);
}

@media (max-width: 980px) {
  .topbar__inner {
    flex-wrap: wrap;
    align-items: center;
  }

  .topbar__meta {
    width: 100%;
  }

  .layout {
    grid-template-columns: 1fr;
    padding: 12px;
  }

  .panel,
  .preview {
    padding: 12px;
  }

  .preview {
    width: 100%;
    justify-self: stretch;
    min-height: 0;
  }

  .preview__header {
    flex-wrap: wrap;
    align-items: flex-start;
  }

  .preview__right {
    width: 100%;
    flex-wrap: wrap;
  }

  #previewMeta {
    flex: 1 1 220px;
    min-width: 0;
  }

  #exportPng {
    margin-left: auto;
  }

  .preview__canvaswrap {
    padding: 10px;
    overflow-x: hidden;
  }

  #chartCanvas {
    width: 100%;
    max-width: 790px;
  }

  .field__labelrow {
    flex-wrap: wrap;
    align-items: flex-start;
  }

  .field__labelactions {
    width: 100%;
    justify-content: flex-end;
  }

  table.data {
    min-width: 0;
  }

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

  #annotationEditorDialog .dialog__body {
    grid-template-columns: 1fr;
  }

  .svgwrap {
    min-height: 360px;
  }

  .svgsplit {
    flex-direction: column;
  }

  .svgsplit__editor {
    width: min(720px, 100%);
  }
}

@media (max-width: 1699px) and (min-width: 981px) {
  .layout {
    grid-template-columns: minmax(0, var(--panel-width));
  }

  .topbar__inner {
    width: min(100%, var(--panel-width));
  }
}
