:root {
  color-scheme: light;
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-synthesis: none;
  color: #242537;
  background: #f7f7fb;
  --purple: #6656c9;
  --purple-dark: #4f40ad;
  --border: #e5e5ef;
  --muted: #626579;
  --shadow: 0 20px 55px rgba(42, 38, 94, .07);
}

* { box-sizing: border-box; }

html { min-width: 320px; }

body {
  margin: 0;
  min-width: 320px;
  background: radial-gradient(circle at 8% 0%, #ece8ff 0, transparent 360px), #f7f7fb;
}

button, input, select { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .55; }
:focus-visible { outline: 3px solid #8174dd; outline-offset: 3px; }

.page-shell { width: min(1240px, 100%); margin: 0 auto; padding: 28px 24px 32px; }

.site-header { margin: 0 0 20px; }
.brand-line { display: flex; align-items: center; gap: 12px; }
.brand-icon { width: 44px; height: 44px; flex: none; }
.eyebrow { margin: 0 0 5px; color: var(--purple-dark); font-size: .72rem; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: clamp(1.55rem, 3vw, 2.15rem); line-height: 1.18; letter-spacing: -.035em; }
.site-header > p { margin: 12px 0 0 56px; color: var(--muted); font-size: .95rem; }

.reference-card, .panel { background: #fff; border: 1px solid var(--border); box-shadow: var(--shadow); border-radius: 22px; }
.reference-card { margin-bottom: 18px; padding: 0 22px; }
.reference-card summary { padding: 16px 0; font-weight: 750; cursor: pointer; }
.reference-content { border-top: 1px solid var(--border); padding: 17px 0 20px; }
.reference-content p { color: var(--muted); line-height: 1.65; margin-bottom: 14px; }
.example-controls { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; }
.example-controls label { font-weight: 650; }
.example-controls select { flex: 1 1 190px; max-width: 360px; }

.workspace { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, .85fr); align-items: start; gap: 20px; }
.panel { min-width: 0; padding: 26px; }
.panel-heading { display: flex; justify-content: space-between; align-items: end; gap: 12px; margin-bottom: 23px; }
h2 { margin: 0; font-size: 1.35rem; line-height: 1.25; }
h3 { margin: 0; font-size: 1rem; }
.step-hint, .section-heading span { color: var(--muted); font-size: .78rem; }
.step-hint { text-align: right; max-width: 180px; }
.section-block { margin-bottom: 23px; }
.section-heading { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; margin-bottom: 10px; }

.layer-buttons { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.layer-button { min-height: 46px; border: 1px solid var(--border); border-radius: 12px; background: #f7f7fb; color: #494a60; font-weight: 750; }
.layer-button[aria-pressed="true"] { background: #edeaff; color: var(--purple-dark); border-color: #b5aaf3; box-shadow: inset 0 0 0 1px #b5aaf3; }

.shape-slots { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.shape-slot { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; min-width: 0; min-height: 83px; padding: 7px 3px; border: 1.5px dashed #d3d4e3; border-radius: 13px; background: #fafaff; color: #5b5d70; }
.shape-slot.selected { border-style: solid; border-color: var(--purple); background: #f0edff; box-shadow: inset 0 0 0 1px var(--purple); }
.shape-slot.filled { border-style: solid; }
.shape-slot .shape-symbol { font-size: 1.65rem; line-height: 1; font-weight: 800; }
.shape-slot .slot-caption { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .73rem; }
.shape-slot .empty-symbol { color: #a1a3b7; font-size: 1.5rem; line-height: 1; }
.shape-slot.red .shape-symbol, .palette-button.red .shape-symbol { color: #d34d48; }
.shape-slot.yellow .shape-symbol, .palette-button.yellow .shape-symbol { color: #c19412; }
.shape-slot.blue .shape-symbol, .palette-button.blue .shape-symbol { color: #3174c9; }
.shape-slot.green .shape-symbol, .palette-button.green .shape-symbol { color: #26915b; }

.code-layers { display: grid; gap: 9px; }
.code-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(105px, 145px); align-items: center; gap: 12px; padding: 9px 12px; border: 1px solid var(--border); border-radius: 12px; background: #fcfcff; }
.code-row label { font-weight: 650; font-size: .9rem; }
.code-row input { width: 100%; min-width: 0; text-align: center; letter-spacing: .19em; font-weight: 750; }
.code-row.solved { border-color: #c9c0ff; background: #f5f2ff; }
.code-row.solved input { color: var(--purple-dark); }

input, select { min-height: 44px; padding: 9px 12px; border: 1px solid #cfd0df; border-radius: 10px; background: #fff; color: #242537; font-size: 1rem; }
input::placeholder { color: #888a9e; opacity: 1; }

.palette-block { margin: 5px 0 18px; padding: 17px; border-radius: 16px; background: #f6f5fc; }
.shape-palette { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; }
.palette-button { display: flex; align-items: center; justify-content: center; gap: 8px; min-height: 51px; min-width: 0; border: 1px solid #dcdbea; border-radius: 11px; background: #fff; color: #2a2b3b; font-size: .9rem; font-weight: 670; }
.palette-button:hover, .shape-slot:hover, .answer-choice:hover { border-color: var(--purple); }
.palette-button .shape-symbol { font-size: 1.3rem; font-weight: 800; }
.shape-notice { margin: 12px 0 0; color: var(--muted); font-size: .83rem; line-height: 1.4; }
.shape-warnings { margin-top: 8px; }
.shape-warnings p { margin: 4px 0; color: #9a6010; font-size: .83rem; }

.action-bar { display: grid; grid-template-columns: minmax(0, 1.5fr) repeat(2, minmax(0, 1fr)); gap: 8px; }
.action-bar button, .example-controls button { min-height: 47px; padding: 8px 13px; border-radius: 11px; font-weight: 750; }
.button-primary { border: 1px solid var(--purple); background: var(--purple); color: #fff; }
.button-primary:hover { background: var(--purple-dark); }
.button-secondary { border: 1px solid #c8c4e0; background: #f6f4ff; color: var(--purple-dark); }
.button-quiet { border: 1px solid var(--border); background: #fff; color: #55566a; }

.result-panel { min-height: 470px; }
.result-panel .panel-heading { margin-bottom: 18px; }
.empty-result { padding: 28px 18px; border: 1px dashed #d7d5e8; border-radius: 14px; background: #faf9ff; color: var(--muted); line-height: 1.7; }
.empty-result p { margin-bottom: 0; }
.status-banner { margin-bottom: 16px; padding: 13px 15px; border-radius: 12px; line-height: 1.5; font-weight: 700; }
.status-banner.success { background: #e9f8ef; color: #1d6840; }
.status-banner.warning { background: #fff5df; color: #8c5913; }
.status-banner.error { background: #fff0ee; color: #a0443d; }
.error-list { padding-left: 21px; color: #874642; line-height: 1.6; }
.error-list li + li { margin-top: 5px; }
.result-section { margin-top: 20px; }
.result-section h3 { margin-bottom: 10px; }
.filter-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.filter-field { display: grid; gap: 5px; color: #4d4e64; font-size: .82rem; font-weight: 650; }
.filter-field input { min-width: 0; width: 100%; }
.filter-hint, .result-count { color: var(--muted); font-size: .82rem; line-height: 1.5; }
.filter-hint { margin-bottom: 10px; }
.filter-errors p { margin: 7px 0; color: #9a6010; font-size: .83rem; }
.answer-list { display: grid; gap: 7px; max-height: 240px; overflow-y: auto; padding: 2px; }
.answer-choice { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; width: 100%; min-height: 46px; padding: 7px 11px; text-align: left; border: 1px solid var(--border); border-radius: 10px; background: #fff; color: #34354c; }
.answer-choice.selected { background: #f0edff; border-color: var(--purple); }
.answer-choice .answer-number { min-width: 58px; font-size: .8rem; color: var(--muted); font-weight: 750; }
.code-chip { padding: 3px 7px; border-radius: 6px; background: #f2f2f8; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .8rem; }
.answer-choice.selected .code-chip { background: #fff; }
.resolved-list { display: grid; gap: 7px; }
.resolved-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 9px 12px; border: 1px solid var(--border); border-radius: 10px; }
.resolved-row strong { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 1.08rem; letter-spacing: .14em; }
.resolved-row.solved strong { color: var(--purple-dark); }
.resolved-note { margin: 9px 0 0; color: var(--muted); font-size: .8rem; }
.trace-details { margin-top: 18px; border-top: 1px solid var(--border); padding-top: 15px; }
.trace-details summary { cursor: pointer; color: var(--purple-dark); font-weight: 750; }
.trace-block { margin-top: 15px; }
.trace-block h4 { margin: 0 0 8px; }
.trace-card { margin: 7px 0; padding: 10px 12px; border-radius: 10px; background: #f7f7fb; color: #4f5065; font-size: .84rem; line-height: 1.5; }
.trace-card strong { display: block; margin-bottom: 3px; color: #303146; }
.mapping-list { padding-left: 20px; margin: 8px 0 0; color: #4f5065; font-size: .83rem; line-height: 1.7; }
.mapping-list li + li { margin-top: 5px; }
.site-footer { padding: 21px 4px 0; color: var(--muted); font-size: .78rem; line-height: 1.5; }
.site-footer p { margin: 0; }
.noscript { max-width: 600px; margin: 20px auto; padding: 20px; background: #fff0ee; }

@media (max-width: 900px) {
  .workspace { grid-template-columns: minmax(0, 1fr); }
  .result-panel { min-height: 0; }
}

@media (max-width: 640px) {
  .page-shell { padding: 18px 12px 25px; }
  .site-header { margin-bottom: 16px; }
  .site-header > p { margin-left: 0; }
  .reference-card { padding: 0 16px; }
  .panel { padding: 19px 16px; border-radius: 18px; }
  .panel-heading { display: block; margin-bottom: 20px; }
  .step-hint { display: block; max-width: none; margin-top: 5px; text-align: left; }
  .section-block { margin-bottom: 20px; }
  .shape-slot { min-height: 74px; }
  .palette-block { padding: 14px; }
  .action-bar { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .action-bar .button-primary { grid-column: 1 / -1; }
}

@media (max-width: 380px) {
  .shape-slots { gap: 5px; }
  .shape-slot { min-height: 68px; }
  .shape-slot .slot-caption { font-size: .68rem; }
  .palette-button { gap: 4px; padding: 4px; font-size: .8rem; }
  .code-row { grid-template-columns: minmax(0, 1fr) 108px; }
}

@media (prefers-reduced-motion: no-preference) {
  .palette-button, .shape-slot, .layer-button, .answer-choice { transition: border-color .15s, background-color .15s, transform .15s; }
  .palette-button:active { transform: scale(.98); }
}
