:root {
  --space-1: 8px;
  --space-2: 16px;
  --space-3: 24px;
  --space-4: 32px;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-subtle: #f9fafb;
  --border: #e4e7ec;
  --text: #111827;
  --text-muted: #667085;
  --primary: #2563eb;
  --primary-soft: #eff5ff;
  --radius-control: 8px;
  --radius-card: 12px;
  --shadow-soft: 0 1px 2px rgba(16, 24, 40, 0.05);
  --shadow-hover: 0 6px 18px rgba(16, 24, 40, 0.08);
  --content-max: 1040px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

h2,
p,
label {
  margin: 0;
}

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

button {
  transition: background-color 160ms ease, border-color 160ms ease, color 160ms ease, transform 160ms ease, box-shadow 160ms ease;
}

button:hover {
  box-shadow: var(--shadow-soft);
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 2px solid #7aa2ff;
  outline-offset: 1px;
}

.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 320px;
  flex: 0 0 320px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  background: #f8fafc;
  border-right: 1px solid var(--border);
  padding: var(--space-2);
}

.sidebar h1,
.sidebar h2,
.sidebar h3,
.sidebar p {
  margin: 0;
}

.section {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-soft);
  padding: var(--space-2);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.section + .section {
  margin-top: var(--space-2);
}

.section-title {
  font-size: 17px;
  line-height: 1.2;
  margin-bottom: 0;
  font-weight: 550;
  letter-spacing: 0.01em;
}

.number-formatting-controls {
  display: grid;
  grid-template-columns: 1fr 110px;
  gap: var(--space-1);
  align-items: end;
}

.inline-decimals {
  margin: 0;
}

.field {
  display: flex;
  flex-direction: column;
  margin-bottom: 0;
}

.field > span,
.inline-field > span {
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 500;
  margin-bottom: 6px;
}

.switch-field > span {
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 500;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius-control);
  padding: 10px;
  background: #fff;
  color: var(--text);
}

textarea {
  min-height: 96px;
  resize: vertical;
}

.helper-text,
.panel-subtitle {
  margin: 0;
  font-size: 12px;
  color: var(--text-muted);
}

.switch-field {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0;
}

.switch-field input {
  width: auto;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-1);
}

.segmented-3 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.segmented-4 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.segmented button {
  border: 1px solid var(--border);
  border-radius: var(--radius-control);
  background: #fff;
  color: var(--text-muted);
  padding: 8px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
}

.segmented button.active {
  background: var(--primary-soft);
  border-color: #bed2ff;
  color: #2450ab;
}

.fluid-controls,
.advanced-steps {
  border: 1px solid #e3e7ee;
  border-radius: 10px;
  background: #fcfdff;
  padding: var(--space-1);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.step-editor-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-1);
  margin-top: var(--space-1);
}

.step-row {
  display: grid;
  grid-template-columns: 1fr 90px;
  gap: var(--space-1);
  align-items: center;
}

.step-row label {
  font-size: 12px;
  color: var(--text-muted);
}

.step-row input {
  padding: 6px 8px;
}

.content {
  flex: 1;
  min-width: 0;
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  border-bottom: 1px solid var(--border);
  background: rgba(244, 246, 248, 0.96);
  backdrop-filter: blur(8px);
  width: min(var(--content-max), calc(100% - 32px));
  margin: 0 auto;
  padding: var(--space-2) 0;
}

.topbar-left,
.topbar-right {
  display: flex;
  align-items: center;
  gap: var(--space-1);
}

.inline-field {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.inline-field > span {
  margin-bottom: 0;
}

.inline-field select {
  width: 84px;
  padding: 6px 8px;
}

.current-label {
  font-size: 12px;
  color: #274c99;
  border: 1px solid #cddcfb;
  background: #eef4ff;
  border-radius: 999px;
  padding: 6px 10px;
}

.icon-btn,
.primary-btn,
.ghost-btn,
.copy-btn {
  border: 1px solid var(--border);
  border-radius: var(--radius-control);
  background: #fff;
  color: var(--text-muted);
  cursor: pointer;
  padding: 8px 10px;
  font-size: 13px;
}

.icon-btn {
  width: 36px;
  padding: 8px 0;
}

.primary-btn {
  border-color: #1f57d1;
  background: var(--primary);
  color: #fff;
  font-weight: 600;
}

.primary-btn:hover {
  box-shadow: var(--shadow-hover);
  transform: translateY(-1px);
}

.ghost-btn:hover,
.copy-btn:hover,
.icon-btn:hover {
  border-color: #c8d0da;
  transform: translateY(-1px);
}

.cards-container {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-3);
  width: min(var(--content-max), 100%);
  margin: 0 auto;
}

#cardsContainer {
  margin-top: var(--space-2);
}

.scale-overview {
  background: var(--surface);
  border: 1px solid #e8edf4;
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-soft);
  padding: 10px 12px;
}

.overview-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-1);
  margin-bottom: 10px;
}

.overview-head h3 {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
}

.overview-hint {
  font-size: 11px;
  color: var(--text-muted);
}

.overview-list {
  display: grid;
  grid-template-columns: 1fr;
  gap: 6px;
}

.overview-row {
  border-radius: 8px;
  border: 1px solid #edf1f6;
  background: #fcfdff;
  padding: 5px 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  cursor: pointer;
}

.overview-row:hover {
  border-color: #d9e3f1;
  background: #f7faff;
}

.overview-row-body {
  border-color: #bfd6ff;
  background: #edf4ff;
}

.overview-label {
  font-size: 12px;
  color: #344054;
  font-weight: 600;
}

.overview-value-btn {
  border: 0;
  background: transparent;
  color: #1f4b98;
  font-size: 12px;
  padding: 2px 0;
  cursor: copy;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 70%;
}

.type-card {
  background: var(--surface);
  border: 1px solid #e9edf3;
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-soft);
  padding: 12px;
  transition: box-shadow 160ms ease, transform 160ms ease;
}

.type-card + .type-card {
  margin-top: var(--space-3);
}

.type-card:hover {
  box-shadow: var(--shadow-hover);
  transform: translateY(-1px);
}

.card-header {
  display: flex;
  align-items: flex-start;
  justify-content: flex-start;
  margin-bottom: 4px;
}

.card-title {
  font-size: 14px;
  font-weight: 620;
  color: #1d2939;
}

.body-card {
  border-color: #bfd6ff;
  background: linear-gradient(180deg, #ffffff 0%, #f8fbff 100%);
}

.code-pill {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-1);
  border: 1px solid #dbe3f1;
  background: #f8fbff;
  border-radius: 10px;
  padding: 7px 9px;
  margin-bottom: 10px;
  overflow-x: auto;
  cursor: pointer;
}

.code-pill code {
  flex: 1 1 auto;
  min-width: max-content;
  color: #143462;
  font-size: 13px;
  font-weight: 600;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  white-space: nowrap;
}

.copy-btn {
  padding: 6px 10px;
  font-size: 12px;
  flex-shrink: 0;
}

.code-pill-actions {
  display: inline-flex;
  gap: 6px;
  margin-left: 8px;
}

.copy-icon-btn {
  width: 28px;
  height: 28px;
  padding: 0;
  position: relative;
}

.copy-icon-btn::before,
.copy-icon-btn::after {
  content: "";
  position: absolute;
  width: 10px;
  height: 10px;
  border: 1.5px solid #4a6fae;
  border-radius: 2px;
  background: transparent;
}

.copy-icon-btn::before {
  top: 7px;
  left: 9px;
}

.copy-icon-btn::after {
  top: 10px;
  left: 6px;
  background: #eff5ff;
}

.code-decl-btn {
  height: 28px;
  padding: 4px 8px;
  font-size: 11px;
  border-color: #d4dce9;
  color: #4d6286;
  background: #f9fbff;
}

.card-preview {
  margin: 0;
  display: block;
  background: transparent;
  color: #111827;
  max-width: 58ch;
  text-align: left;
  word-break: normal;
  overflow-wrap: anywhere;
}

.card-preview::before,
.card-preview::after {
  content: none !important;
  display: none !important;
}

.type-card.compact-preview {
  padding: 8px 10px;
}

.type-card.compact-preview .card-preview {
  max-width: 46ch;
}

.preview-stack {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.preview-heading {
  margin: 0;
}

.preview-paragraph {
  margin: 0;
}

.card-meta-line {
  margin: 8px 0 0;
  font-size: 11px;
  color: #7a8698;
  line-height: 1.35;
}

.modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  z-index: 20;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
}

.modal-panel {
  position: relative;
  width: min(980px, calc(100vw - 24px));
  max-height: min(88vh, 900px);
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: 0 18px 48px rgba(16, 24, 40, 0.22);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border);
  padding: var(--space-2);
}

.modal-header h3 {
  margin: 0;
  font-size: 18px;
  font-weight: 550;
}

.modal-tabs {
  padding: var(--space-1) var(--space-2);
  display: flex;
  gap: var(--space-1);
  border-bottom: 1px solid var(--border);
}

.tab-btn {
  border: 1px solid var(--border);
  border-radius: var(--radius-control);
  background: #fff;
  color: var(--text-muted);
  font-size: 13px;
  padding: 8px 10px;
  cursor: pointer;
}

.tab-btn.active {
  border-color: #bed2ff;
  background: var(--primary-soft);
  color: #2450ab;
  font-weight: 600;
}

.export-panel {
  padding: var(--space-2);
  overflow: auto;
}

.export-actions {
  display: flex;
  justify-content: flex-end;
  margin-bottom: var(--space-1);
}

.token-copy-list {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-1);
  margin-bottom: var(--space-2);
}

.token-copy-item {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fbfcfe;
  padding: 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-1);
}

.token-copy-item code {
  font-size: 12px;
  color: #344054;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.export-output {
  margin: 0;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #f8fafc;
  padding: var(--space-2);
  white-space: pre;
  overflow: auto;
  font-size: 12px;
  line-height: 1.5;
  color: #243447;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
}

.copy-toast {
  position: fixed;
  right: var(--space-3);
  bottom: var(--space-3);
  border: 1px solid #bdd3ff;
  background: #eaf2ff;
  color: #1f4ca3;
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 13px;
  box-shadow: var(--shadow-soft);
  z-index: 40;
}

.copy-toast.error {
  border-color: #f7c0c0;
  background: #fff1f1;
  color: #a13737;
}

.hidden {
  display: none !important;
}

@media (max-width: 1080px) {
  .topbar {
    padding: var(--space-2);
  }

  .cards-container {
    padding: var(--space-2);
  }

  .card-header {
    flex-direction: column;
  }

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

@media (max-width: 900px) {
  .app-shell {
    flex-direction: column;
  }

  .sidebar {
    width: 100%;
    flex: 0 0 auto;
    position: static;
    height: auto;
    max-height: 48vh;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }

  .content {
    height: auto;
    min-height: 52vh;
  }

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