:root {
  color-scheme: light;
  --ink: #191a1f;
  --muted: #666a73;
  --line: #dadde3;
  --soft: #f5f6f8;
  --soft-2: #eef1f5;
  --accent: #244cc8;
  --accent-ink: #ffffff;
  --good: #146c43;
  --warn: #8b4b00;
  --radius: 8px;
  --shadow: 0 16px 40px rgba(25, 26, 31, 0.08);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  background: #ffffff;
}

body {
  margin: 0;
  min-width: 320px;
  color: var(--ink);
  background:
    linear-gradient(180deg, #f8f9fb 0, #ffffff 280px),
    #ffffff;
}

button,
input,
select {
  font: inherit;
}

button {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 7px;
  cursor: pointer;
  transition:
    background-color 160ms ease,
    border-color 160ms ease,
    transform 160ms ease;
}

button:hover {
  transform: translateY(-1px);
}

.app {
  width: min(1480px, calc(100% - 32px));
  margin: 0 auto;
  padding: 26px 0 48px;
}

.topbar {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) auto;
  align-items: end;
  gap: 24px;
  padding: 6px 0 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.site-logo {
  width: 44px;
  height: 44px;
  flex: 0 0 auto;
  object-fit: contain;
}

.eyebrow {
  margin: 0 0 6px;
  color: #5c6675;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 2.1rem;
  line-height: 0.95;
  letter-spacing: 0;
}

.title-row {
  display: flex;
  align-items: end;
  gap: 14px;
  flex-wrap: wrap;
}

.title-note {
  margin: 0 0 2px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  line-height: 1.3;
}

h2 {
  margin-bottom: 0;
  font-size: 1rem;
  letter-spacing: 0;
}

h3 {
  margin-bottom: 0;
  font-size: 0.86rem;
  letter-spacing: 0;
}

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

.mode-toggle {
  gap: 0;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #ffffff;
  box-shadow: 0 1px 0 rgba(25, 26, 31, 0.04);
}

.mode-button {
  min-height: 34px;
  padding: 0 12px;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 800;
  white-space: nowrap;
}

.mode-button.is-active {
  background: var(--ink);
  color: #ffffff;
}

.mode-button:hover {
  transform: none;
}

.control {
  display: grid;
  grid-template-columns: auto minmax(150px, 210px);
  align-items: center;
  gap: 10px;
  min-height: 40px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #ffffff;
  color: var(--muted);
  font-size: 0.86rem;
  box-shadow: 0 1px 0 rgba(25, 26, 31, 0.04);
}

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

.control select {
  min-height: 32px;
  border: 0;
  background: transparent;
  color: var(--ink);
  font-weight: 760;
  outline: none;
}

.control output {
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.primary-button {
  border-color: #1d43b3;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 700;
  padding: 0 14px;
}

.ghost-button {
  background: #ffffff;
  color: var(--ink);
  padding: 0 12px;
}

.summary-band {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #ffffff;
  box-shadow: var(--shadow);
}

.ratio-list {
  display: grid;
  grid-template-columns: repeat(3, minmax(180px, 1fr));
  gap: 10px;
}

.ratio-card {
  display: grid;
  gap: 8px;
  min-height: 190px;
  padding: 16px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: var(--radius);
  background: var(--ratio-bg, #f7f7f7);
  color: var(--ratio-text, #ffffff);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.04);
  cursor: pointer;
}

.ratio-card.is-active {
  outline: 2px solid #111318;
  outline-offset: 2px;
}

.ratio-card .copy-button {
  border-color: var(--ratio-copy-border, rgba(255, 255, 255, 0.38));
  background: var(--ratio-copy-bg, rgba(255, 255, 255, 0.13));
  color: currentColor;
}

.ratio-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.ratio-value {
  font-size: 1.8rem;
  font-weight: 850;
  line-height: 1;
  letter-spacing: 0;
}

.ratio-label {
  font-size: 0.74rem;
  font-weight: 800;
  text-transform: uppercase;
}

.ratio-use {
  margin: 0;
  color: currentColor;
  font-size: 0.82rem;
  line-height: 1.35;
  opacity: 0.78;
}

.ratio-sample {
  margin: 18px 0 4px;
  color: currentColor;
  font-size: 1.22rem;
  font-weight: 830;
  line-height: 1.18;
}

.ratio-bottom {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 10px;
  margin-top: auto;
  color: currentColor;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.86rem;
  font-weight: 760;
}

.workspace {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  gap: 14px;
  margin-top: 14px;
}

.side-panel,
.palette-panel,
.line-panel,
.list-panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #ffffff;
  box-shadow: var(--shadow);
}

.side-panel {
  align-self: start;
  width: fit-content;
  min-height: 0;
  padding: 14px;
}

.palette-panel {
  min-height: 540px;
  padding: 14px;
}

.line-panel {
  margin-top: 14px;
  padding: 14px;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 40px;
  margin-bottom: 12px;
}

.panel-header span {
  color: var(--muted);
  font-size: 0.82rem;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.side-panel .panel-header span {
  display: none;
}

.family-list,
.stack-list {
  display: grid;
  gap: 8px;
}

.family-list {
  grid-template-columns: repeat(3, 51px);
  align-items: start;
}

.family-button {
  display: block;
  width: 51px;
  height: 51px;
  min-height: 51px;
  aspect-ratio: 1;
  padding: 0;
  border: 0;
  border-radius: 7px;
  background: var(--family-bg);
  color: var(--ink);
  box-shadow: none;
}

.family-button.is-active {
  outline: 2px solid #111318;
  outline-offset: 2px;
}

.preview-overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(65, 68, 76, 0.48);
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms ease;
}

.preview-overlay.is-open {
  opacity: 1;
  pointer-events: auto;
}

.preview-dialog {
  position: relative;
  display: grid;
  place-items: center;
  width: min(560px, calc(100vw - 40px));
  min-height: min(420px, calc(100vh - 80px));
  padding: 56px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #ffffff;
  box-shadow: 0 24px 70px rgba(25, 26, 31, 0.24);
}

.close-preview {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 36px;
  height: 36px;
  min-height: 36px;
  padding: 0;
  border-color: var(--line);
  background: #ffffff;
  color: var(--ink);
  font-weight: 850;
}

.modal-swatch {
  display: grid;
  place-items: center;
  width: min(320px, 72vw);
  aspect-ratio: 1.75;
  border-radius: var(--radius);
  color: #ffffff;
  font-size: 1.9rem;
  font-weight: 850;
  letter-spacing: 0;
}

.line-list {
  display: grid;
  grid-template-columns: repeat(6, minmax(134px, 1fr));
  gap: 10px;
}

.line-card {
  display: grid;
  gap: 10px;
  min-height: 150px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #ffffff;
  cursor: pointer;
}

.line-card:hover {
  border-color: #b9bec8;
}

.line-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.line-ratio {
  color: var(--ink);
  font-size: 1rem;
  font-weight: 850;
}

.line-hex {
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.76rem;
  font-weight: 760;
}

.line-preview {
  display: grid;
  align-content: center;
  gap: 16px;
  min-height: 92px;
  padding: 18px 14px;
  border: 1px solid #eef0f3;
  border-radius: 7px;
  background: #ffffff;
}

.line-sample {
  display: block;
  width: 100%;
  height: 0;
  border-top-color: var(--line-sample);
}

.line-sample.solid {
  border-top-style: solid;
  border-top-width: 2px;
}

.line-sample.dashed {
  border-top-style: dashed;
  border-top-width: 2px;
}

.line-sample.dotted {
  border-top-style: dotted;
  border-top-width: 2px;
}

.stack-item {
  display: grid;
  grid-template-columns: 42px 1fr auto;
  align-items: center;
  gap: 10px;
  min-height: 56px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #ffffff;
}

.stack-swatch {
  width: 42px;
  height: 42px;
  border: 1px solid rgba(0, 0, 0, 0.12);
  border-radius: 6px;
}

.stack-name {
  color: var(--ink);
  font-size: 0.86rem;
  font-weight: 750;
}

.stack-ratio {
  color: var(--muted);
  font-size: 0.78rem;
  font-variant-numeric: tabular-nums;
}

.stack-hex {
  color: var(--ink);
  font-size: 0.78rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.palette-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(156px, 1fr));
  gap: 10px;
}

.swatch-card {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #ffffff;
}

.swatch-fill {
  position: relative;
  display: grid;
  min-height: 116px;
  padding: 12px;
  color: var(--text-on-swatch);
}

.swatch-fill::after {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.12), transparent 46%),
    linear-gradient(180deg, transparent, rgba(0, 0, 0, 0.12));
  pointer-events: none;
}

.swatch-name {
  position: relative;
  z-index: 1;
  align-self: start;
  font-size: 0.9rem;
  font-weight: 820;
}

.swatch-ratio {
  position: relative;
  z-index: 1;
  align-self: end;
  font-size: 0.8rem;
  font-weight: 720;
  font-variant-numeric: tabular-nums;
}

.swatch-body {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 8px;
  min-height: 58px;
  padding: 10px 12px;
}

.hex {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.88rem;
  font-weight: 750;
}

.small-meta {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.74rem;
  font-variant-numeric: tabular-nums;
}

.copy-button {
  width: 38px;
  height: 38px;
  min-height: 38px;
  padding: 0;
  background: var(--soft);
  color: var(--ink);
  font-size: 0.82rem;
  font-weight: 850;
}

.copy-button:hover,
.ghost-button:hover {
  border-color: #b7bdc8;
  background: var(--soft-2);
}

.list-panel {
  margin-top: 14px;
  padding: 14px;
}

.hex-lists {
  display: grid;
  gap: 10px;
}

.hex-list {
  display: grid;
  grid-template-columns: 110px 1fr;
  gap: 10px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #ffffff;
}

.hex-list.is-active {
  border-color: #111318;
  background: #fafafa;
}

.hex-list-title {
  display: grid;
  align-content: center;
  gap: 3px;
  min-height: 44px;
  font-size: 0.85rem;
  font-weight: 850;
}

.hex-list-title span {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 650;
}

.hex-code-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.hex-code-list li {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--soft);
  color: #2c3038;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.76rem;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  max-width: min(320px, calc(100vw - 40px));
  padding: 11px 14px;
  border: 1px solid #b8c2d2;
  border-radius: 7px;
  background: #ffffff;
  color: var(--ink);
  box-shadow: 0 12px 28px rgba(25, 26, 31, 0.18);
  font-size: 0.88rem;
  opacity: 0;
  transform: translateY(8px);
  transition:
    opacity 180ms ease,
    transform 180ms ease;
  pointer-events: none;
}

.toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 1120px) {
  .ratio-list {
    grid-template-columns: repeat(2, minmax(160px, 1fr));
  }

  .palette-grid {
    grid-template-columns: repeat(3, minmax(150px, 1fr));
  }

  .line-list {
    grid-template-columns: repeat(3, minmax(150px, 1fr));
  }
}

@media (max-width: 840px) {
  .app {
    width: min(100% - 22px, 760px);
    padding-top: 14px;
  }

  .topbar {
    grid-template-columns: 1fr;
    align-items: start;
  }

  .site-logo {
    width: 38px;
    height: 38px;
  }

  h1 {
    font-size: 1.8rem;
  }

  .title-note {
    margin-bottom: 2px;
  }

  .tools {
    justify-content: start;
  }

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

  .side-panel,
  .palette-panel {
    min-height: 0;
  }

  .palette-grid {
    grid-template-columns: repeat(2, minmax(140px, 1fr));
  }

  .line-list {
    grid-template-columns: repeat(2, minmax(140px, 1fr));
  }
}

@media (max-width: 560px) {
  h1 {
    font-size: 1.55rem;
  }

  .tools,
  .control {
    width: 100%;
  }

  .mode-button {
    flex: 1 1 0;
  }

  .control {
    grid-template-columns: auto minmax(0, 1fr);
  }

  .primary-button {
    width: 100%;
  }

  .ratio-list,
  .palette-grid,
  .line-list {
    grid-template-columns: 1fr;
  }

  .hex-list {
    grid-template-columns: 1fr;
  }
}
