:root {
  color-scheme: light;
  --ink: #161616;
  --muted: #66645f;
  --line: #d8d4ca;
  --panel: #f7f3ea;
  --paper: #fffdf8;
  --accent: #0d6b4f;
  --accent-dark: #084936;
  --amber: #bf7b24;
  --blue: #24658f;
  --shadow: 0 18px 50px rgba(33, 29, 20, 0.16);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: "Yu Gothic", "Hiragino Kaku Gothic ProN", Meiryo, system-ui, sans-serif;
  background:
    linear-gradient(90deg, rgba(13, 107, 79, 0.08) 1px, transparent 1px),
    linear-gradient(0deg, rgba(191, 123, 36, 0.08) 1px, transparent 1px),
    var(--paper);
  background-size: 28px 28px;
}

button,
select,
input {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 380px;
  gap: 28px;
  width: min(1180px, calc(100% - 40px));
  min-height: 100vh;
  margin: 0 auto;
  padding: 30px 0;
  align-items: center;
}

.preview-panel {
  display: grid;
  gap: 18px;
}

.stage-wrap {
  display: grid;
  place-items: center;
  min-height: min(70vh, 620px);
  padding: clamp(18px, 4vw, 48px);
  background: linear-gradient(135deg, #f5efe2, #e9f0eb 48%, #f8f7f2);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

canvas {
  display: block;
  width: min(100%, 610px);
  height: auto;
  image-rendering: auto;
  filter: drop-shadow(0 16px 20px rgba(0, 0, 0, 0.16));
}

.output-row {
  display: block;
}

.silks-name {
  min-height: 48px;
  margin: 0;
  padding: 12px 14px;
  border-left: 5px solid var(--accent);
  background: rgba(255, 253, 248, 0.78);
  font-weight: 700;
  line-height: 1.45;
}

.control-panel {
  display: grid;
  gap: 18px;
  padding: 24px;
  background: rgba(255, 253, 248, 0.94);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.app-header {
  display: grid;
  gap: 5px;
}

.app-description {
  margin: 0;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.6;
}

.eyebrow {
  margin: 0;
  color: var(--blue);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(1.55rem, 3vw, 2.2rem);
  line-height: 1.15;
}

h2 {
  font-size: 1rem;
}

.control-group {
  display: grid;
  gap: 12px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.control-group label {
  display: grid;
  grid-template-columns: 58px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 700;
}

select {
  width: 100%;
  min-height: 40px;
  border: 1px solid #bdb8ab;
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
}

select.color-select {
  font-size: 1.28rem;
  font-weight: 900;
  line-height: 1;
}

.native-color-select {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.color-picker {
  position: relative;
  width: 100%;
}

.color-picker__button,
.color-picker__option {
  display: block;
  width: 100%;
  min-height: 40px;
  border: 0;
  border-radius: 0;
  font: inherit;
  font-size: 1.28rem;
  font-weight: 900;
  line-height: 1;
  text-align: left;
}

.color-picker__button {
  position: relative;
  min-height: 44px;
  padding: 9px 42px 9px 14px;
  border: 1px solid #bdb8ab;
  border-radius: 6px;
  cursor: pointer;
}

.color-picker__button::after {
  content: "";
  position: absolute;
  right: 15px;
  top: 50%;
  width: 8px;
  height: 8px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: translateY(-65%) rotate(45deg);
}

.color-picker.is-open .color-picker__button::after {
  transform: translateY(-35%) rotate(225deg);
}

.color-picker__list {
  position: absolute;
  z-index: 20;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  max-height: min(440px, 70vh);
  overflow-y: auto;
  border: 1px solid #8f8a80;
  border-radius: 6px;
  background: #fff;
  box-shadow: 0 16px 34px rgba(0, 0, 0, 0.22);
}

.color-picker__option {
  min-height: 38px;
  padding: 7px 14px;
  cursor: pointer;
}

.color-picker__option.is-selected {
  outline: 3px solid rgba(255, 255, 255, 0.7);
  outline-offset: -5px;
}

.color-picker__option:hover,
.color-picker__option:focus-visible {
  filter: brightness(0.94);
}

.color-picker.is-disabled {
  opacity: 0.55;
}

.color-picker.is-disabled .color-picker__button {
  cursor: not-allowed;
}

@media (max-width: 900px) {
  .app-shell {
    grid-template-columns: 1fr;
    width: min(100% - 24px, 680px);
    padding: 16px 0 24px;
  }

  .control-panel {
    order: -1;
    padding: 18px;
  }

  .stage-wrap {
    min-height: auto;
    padding: 16px;
  }

}

.reference-shell {
  display: grid;
  gap: 24px;
  width: min(900px, calc(100% - 40px));
  margin: 0 auto;
  padding: 30px 0 56px;
}

.back-link {
  width: fit-content;
  color: var(--accent-dark);
  font-weight: 700;
}

.reference-header,
.reference-section {
  padding: clamp(20px, 4vw, 32px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.94);
  box-shadow: var(--shadow);
}

.reference-header {
  display: grid;
  gap: 10px;
}

.reference-header p,
.reference-section p {
  margin: 0;
  line-height: 1.7;
}

.reference-section {
  display: grid;
  gap: 16px;
}

.reference-section h2 {
  font-size: 1.25rem;
}

.reference-section ul {
  margin: 0;
  padding-left: 1.4rem;
  line-height: 1.8;
}

.table-wrap {
  overflow-x: auto;
}

.reference-section table {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
}

.reference-section th,
.reference-section td {
  padding: 10px 12px;
  border: 1px solid var(--line);
  text-align: left;
  white-space: nowrap;
}

.reference-section thead th {
  background: var(--panel);
}

.reference-section tbody th {
  width: 5rem;
  text-align: center;
}

.code-diagram {
  padding: 18px;
  overflow-x: auto;
  border-left: 5px solid var(--accent);
  background: var(--panel);
  --diagram-cell: 1.4rem;
  --diagram-line: #5c5147;
}

.code-diagram__value,
.code-diagram__row {
  display: grid;
  grid-template-columns: repeat(6, var(--diagram-cell)) minmax(8rem, 1fr);
}

.code-diagram__value {
  margin-bottom: 2px;
  font-family: Consolas, "Courier New", monospace;
  font-size: 1.15rem;
  line-height: 1.4;
}

.code-diagram__value span {
  text-align: center;
}

.code-diagram__row {
  min-height: 1.65rem;
}

.code-diagram__branch {
  position: relative;
}

.code-diagram__branch.is-stem::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  border-left: 1px solid var(--diagram-line);
}

.code-diagram__branch.is-corner::before {
  content: "";
  position: absolute;
  top: 0;
  right: 0;
  bottom: 50%;
  left: 50%;
  border-bottom: 1px solid var(--diagram-line);
  border-left: 1px solid var(--diagram-line);
}

.code-diagram__branch.is-line::before {
  content: "";
  position: absolute;
  right: 0;
  bottom: 50%;
  left: 0;
  border-bottom: 1px solid var(--diagram-line);
}

.code-diagram__label {
  align-self: center;
  padding-left: 0.45rem;
  white-space: nowrap;
}

.reference-note {
  color: var(--muted);
}

.color-swatch {
  display: inline-block;
  width: 1.15em;
  height: 1.15em;
  margin-right: 0.55em;
  vertical-align: -0.18em;
  border: 1px solid #777;
  border-radius: 3px;
  background: var(--swatch);
}

@media (max-width: 600px) {
  .reference-shell {
    width: min(100% - 24px, 900px);
    padding: 16px 0 32px;
  }

  .reference-header,
  .reference-section {
    padding: 18px;
  }
}
