:root {
  color-scheme: light;
  --bg: #f6f6f6;
  --surface: #ffffff;
  --surface-muted: #fafafa;
  --ink: #111111;
  --muted: #666666;
  --line: #dddddd;
  --line-strong: #bdbdbd;
  --brand: #111111;
  --brand-ink: #ffffff;
  --green: #111111;
  --red: #111111;
  --blue: #111111;
  --shadow: 0 14px 30px rgba(0, 0, 0, 0.06);
  --radius: 8px;
  --focus: 0 0 0 3px rgba(17, 17, 17, 0.18);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  background: var(--bg);
  color: var(--ink);
}

body {
  margin: 0;
  min-width: 320px;
}

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

button {
  cursor: pointer;
}

a {
  color: inherit;
}

.skip-link {
  position: absolute;
  left: 16px;
  top: -80px;
  z-index: 20;
  padding: 10px 14px;
  background: var(--ink);
  color: #fff;
  border-radius: var(--radius);
}

.skip-link:focus {
  top: 16px;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 22px clamp(18px, 4vw, 44px);
  background: #111111;
  color: #fff;
  border-bottom: 4px solid var(--brand);
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.brand-mark {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--brand);
  color: var(--brand-ink);
  border: 1px solid #ffffff;
  font-weight: 800;
  font-size: 24px;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.app-header .eyebrow {
  color: #c9d0c6;
}

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

h1 {
  margin-bottom: 0;
  font-size: clamp(22px, 3vw, 34px);
  line-height: 1.18;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 4px;
  font-size: clamp(22px, 2.4vw, 30px);
  line-height: 1.2;
  letter-spacing: 0;
}

h3 {
  margin: 0;
  font-size: 18px;
  line-height: 1.3;
  letter-spacing: 0;
}

.header-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.button {
  min-height: 40px;
  padding: 10px 14px;
  border: 1px solid transparent;
  border-radius: 6px;
  font-weight: 800;
  line-height: 1;
  white-space: nowrap;
}

.button.primary {
  background: var(--ink);
  color: #fff;
}

.button.secondary {
  background: #fff;
  color: var(--ink);
  border-color: var(--line);
}

.button.danger {
  background: #111111;
  color: #ffffff;
  border-color: #111111;
}

.button:focus-visible,
.tab-button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: none;
  box-shadow: var(--focus);
}

.file-button {
  display: inline-flex;
  align-items: center;
}

input[type="file"] {
  max-width: 100%;
}

#importFile {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

.app-main {
  width: min(1480px, 100%);
  margin: 0 auto;
  padding: 22px clamp(14px, 3vw, 34px) 48px;
}

.notice-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}

.notice-bar span,
.count-pill,
.tag,
.slot-tag {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 5px 9px;
  border-radius: 999px;
  background: #f3f3f3;
  color: #333333;
  border: 1px solid #d9d9d9;
  font-size: 12px;
  font-weight: 750;
}

.notice-bar span:nth-child(2) {
  background: #f3f3f3;
  border-color: #d9d9d9;
}

.notice-bar span:nth-child(3) {
  background: #f3f3f3;
  border-color: #d9d9d9;
}

.notice-bar span:nth-child(4) {
  background: #f3f3f3;
  border-color: #d9d9d9;
}

.view-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 18px;
  border-bottom: 1px solid var(--line);
}

.tab-button {
  padding: 13px 16px;
  border: 0;
  border-bottom: 3px solid transparent;
  background: transparent;
  color: var(--muted);
  font-weight: 850;
}

.tab-button.is-active {
  color: var(--ink);
  border-bottom-color: var(--brand);
}

.view-section {
  display: none;
}

.view-section.is-active {
  display: block;
}

.section-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
}

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

.section-note {
  max-width: 520px;
  margin: 0;
  color: var(--muted);
  line-height: 1.55;
}

.panel,
.detail-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.panel {
  padding: 18px;
  margin-bottom: 18px;
}

.compact-panel {
  padding: 14px;
}

.inline-form {
  display: grid;
  grid-template-columns: minmax(220px, 1.2fr) minmax(140px, 0.65fr) minmax(260px, 1.3fr) minmax(180px, 0.8fr) auto;
  gap: 12px;
  align-items: end;
}

.wide-field {
  min-width: 0;
}

.compact-select {
  min-width: min(320px, 100%);
}

.filter-grid {
  display: grid;
  grid-template-columns: minmax(220px, 1.4fr) repeat(5, minmax(150px, 1fr));
  gap: 12px;
}

label,
.full-label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

input,
select,
textarea {
  width: 100%;
  min-height: 42px;
  padding: 10px 11px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  font-weight: 600;
}

textarea {
  min-height: 86px;
  line-height: 1.45;
  resize: vertical;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.stat-card {
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.stat-card span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
}

.stat-card strong {
  display: block;
  margin-top: 7px;
  font-size: 26px;
}

.matrix-layout {
  display: grid;
  grid-template-columns: minmax(360px, 0.95fr) minmax(420px, 1.25fr);
  gap: 18px;
  align-items: start;
}

.matrix-layout.spectrum-layout {
  grid-template-columns: 1fr;
}

.product-column,
.detail-column {
  min-width: 0;
}

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

.product-grid {
  display: grid;
  gap: 12px;
}

.product-card {
  display: grid;
  gap: 12px;
  width: 100%;
  padding: 16px;
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: 4px solid var(--brand);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.product-card.is-active {
  border-color: #9a7b17;
  border-left-color: #161812;
}

.product-card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.product-card h4 {
  margin: 0;
  color: var(--ink);
  font-size: 18px;
  line-height: 1.3;
}

.product-card p {
  margin: 0;
  color: var(--muted);
  line-height: 1.45;
}

.tag-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.step-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 18px;
}

.step-button {
  min-height: 40px;
  padding: 10px 13px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--muted);
  font-weight: 850;
}

.step-button.is-active {
  background: #111111;
  color: #ffffff;
  border-color: #111111;
}

.tag.green {
  background: #f3f3f3;
  border-color: #d9d9d9;
  color: #111111;
}

.tag.red {
  background: #111111;
  border-color: #111111;
  color: #ffffff;
}

.tag.blue {
  background: #ffffff;
  border-color: #cccccc;
  color: #111111;
}

.detail-panel {
  min-height: 360px;
  padding: 18px;
}

.detail-layout {
  display: grid;
  gap: 18px;
}

.detail-hero {
  display: grid;
  grid-template-columns: minmax(280px, 0.8fr) minmax(0, 1.2fr);
  gap: 18px;
  align-items: stretch;
}

.detail-image {
  display: grid;
  min-height: 320px;
  place-items: center;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #f3f3f3;
  color: var(--muted);
  font-weight: 850;
}

.detail-image img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  padding: 14px;
}

.detail-summary h3 {
  margin: 10px 0;
  font-size: clamp(22px, 2.2vw, 30px);
}

.detail-summary p {
  color: var(--muted);
  line-height: 1.6;
}

.empty-state {
  display: grid;
  place-items: center;
  min-height: 240px;
  color: var(--muted);
  text-align: center;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  background: var(--surface-muted);
}

.formula-line {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fafafa;
  color: #111111;
  line-height: 1.6;
  font-weight: 750;
}

.definition-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 14px;
}

.definition-item {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-muted);
}

.definition-item span {
  display: block;
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
}

.definition-item strong {
  display: block;
  overflow-wrap: anywhere;
}

.prompt-list,
.reference-wall {
  display: grid;
  gap: 12px;
}

.prompt-card,
.slot-section,
.reference-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-muted);
}

.prompt-card {
  padding: 13px;
}

.prompt-card header,
.slot-section header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.prompt-card h4,
.slot-section h4,
.reference-card h5 {
  margin: 0;
  font-size: 15px;
}

.copy-button,
.mini-button,
.link-button {
  min-height: 32px;
  padding: 7px 9px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  font-size: 12px;
  font-weight: 850;
}

.prompt-text {
  display: grid;
  gap: 8px;
  margin: 0;
  color: var(--muted);
  line-height: 1.55;
}

.prompt-text code {
  display: block;
  padding: 9px;
  white-space: normal;
  overflow-wrap: anywhere;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
}

.slot-section {
  padding: 14px;
}

.reference-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 12px;
}

.reference-card {
  overflow: hidden;
  background: #fff;
}

.reference-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 12px;
}

.reference-grid .reference-card {
  display: grid;
  grid-template-columns: 128px minmax(0, 1fr);
  gap: 12px;
  padding: 12px;
}

.reference-thumb {
  display: grid;
  width: 100%;
  aspect-ratio: 16 / 10;
  place-items: center;
  background: linear-gradient(135deg, #f1f2ef, #e4e8e1);
  color: var(--muted);
  font-weight: 850;
}

.reference-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.reference-card h4 {
  margin: 9px 0 6px;
  font-size: 16px;
}

.reference-card a,
.reference-card p {
  display: block;
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.reference-body {
  display: grid;
  gap: 8px;
  padding: 12px;
}

.reference-body p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.reference-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.studio-layout {
  display: grid;
  grid-template-columns: minmax(310px, 0.9fr) minmax(460px, 1.25fr);
  gap: 18px;
  align-items: start;
}

.studio-layout.single-column {
  grid-template-columns: 1fr;
}

.studio-step {
  display: none;
}

.studio-step.is-active {
  display: block;
}

.studio-layout .panel:nth-child(3),
.studio-layout .panel:nth-child(4) {
  grid-column: span 1;
}

.stacked-form,
.formula-grid {
  display: grid;
  gap: 12px;
  margin-top: 14px;
}

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

.full-span {
  grid-column: 1 / -1;
}

.formula-preview {
  margin-top: 14px;
}

.status-line {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.inline-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.inline-meta,
.locked-note {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-muted);
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.locked-note {
  border-color: #111111;
  color: #111111;
  font-weight: 800;
}

.ai-prompt {
  min-height: 160px;
  margin: 0;
  padding: 12px;
  overflow: auto;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
  color: #111111;
  line-height: 1.6;
}

.ai-prompt-card {
  margin-top: 12px;
}

.link-preview-box {
  display: grid;
  min-height: 82px;
}

.link-preview-thumb {
  display: grid;
  grid-template-columns: 120px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-muted);
  color: var(--muted);
  font-size: 13px;
  font-weight: 750;
}

.link-preview-thumb img {
  width: 120px;
  aspect-ratio: 16 / 10;
  object-fit: cover;
  border: 1px solid var(--line);
  border-radius: 4px;
}

.rule-list {
  display: grid;
  gap: 8px;
  margin: 14px 0 0;
  padding: 0;
  list-style: none;
}

.rule-list li {
  padding: 10px 12px;
  border-left: 3px solid var(--brand);
  background: var(--surface-muted);
  color: var(--muted);
  line-height: 1.5;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 30;
  max-width: min(420px, calc(100vw - 36px));
  padding: 12px 14px;
  border-radius: var(--radius);
  background: #151812;
  color: #fff;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
}

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

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 1180px) {
  .filter-grid,
  .stats-grid,
  .matrix-layout,
  .studio-layout {
    grid-template-columns: 1fr 1fr;
  }

  .filter-grid label:first-child,
  .detail-column,
  .studio-layout .panel:nth-child(2),
  .studio-layout .panel:nth-child(3),
  .studio-layout .panel:nth-child(4) {
    grid-column: 1 / -1;
  }
}

@media (max-width: 760px) {
  .app-header,
  .section-heading {
    align-items: flex-start;
    flex-direction: column;
  }

  .header-actions {
    width: 100%;
    justify-content: flex-start;
  }

  .button,
  .file-button {
    justify-content: center;
    min-width: 0;
    white-space: normal;
  }

  .filter-grid,
  .stats-grid,
  .matrix-layout,
  .studio-layout,
  .inline-form,
  .detail-hero,
  .formula-grid,
  .definition-list {
    grid-template-columns: 1fr;
  }

  .view-tabs {
    overflow-x: auto;
  }

  .tab-button {
    flex: 1 0 auto;
  }

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

  .reference-grid .reference-card,
  .link-preview-thumb {
    grid-template-columns: 1fr;
  }

}
