:root {
  --bg: #e9e9e6;
  --ink: #171717;
  --muted: #6d6d6a;
  --line: #e3e3e0;
  --panel: #ffffff;
  --shadow: 0 16px 40px rgba(23, 23, 23, 0.06);
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
}

body {
  min-height: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--ink);
  font-family: "Segoe UI", "Microsoft YaHei", sans-serif;
}

header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 24px;
  padding: 22px 28px 0;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: 28px;
  font-weight: 650;
  letter-spacing: -0.04em;
  line-height: 1;
}

.warning {
  margin: 12px 28px 0;
  padding: 10px 12px;
  border-radius: 10px;
  background: #fff4d8;
  color: #5c4308;
  font-size: 13px;
}

main {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 22px;
  padding: 18px 28px 24px;
}

.stage {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
  min-height: 0;
}

.frame {
  flex: 1;
  min-height: 0;
  display: grid;
  place-items: center;
  container-type: size;
}

canvas {
  width: min(100cqw, 100cqh);
  height: auto;
  max-width: 100%;
  background: white;
  border: 1px solid rgba(23, 23, 23, 0.08);
  box-shadow: var(--shadow);
  image-rendering: pixelated;
}

.ratio {
  margin: 0;
  color: var(--ink);
  font-family: "Cambria Math", "Times New Roman", serif;
  font-size: 14px;
  line-height: 1.5;
  font-variant-numeric: tabular-nums;
}

.ratio p { margin: 0; }

.ratio p + p { margin-top: 2px; }

.readout {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.01em;
}

.strip {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 2px 2px 8px;
  scroll-padding-inline: 24px;
}

.tag {
  flex: 0 0 auto;
  width: 68px;
  padding: 5px 5px 4px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: var(--panel);
  cursor: pointer;
  color: var(--muted);
}

.tag img {
  display: block;
  width: 100%;
  height: auto;
  image-rendering: pixelated;
}

.tag span {
  display: block;
  margin-top: 3px;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  text-align: center;
}

.tag.is-on {
  border-color: var(--ink);
  color: var(--ink);
}

aside {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-height: 0;
  overflow: auto;
  padding: 18px 18px 16px;
  border-radius: 18px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.field { display: flex; flex-direction: column; gap: 8px; }

.field-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 28px;
}

label, .field-top span {
  font-size: 13px;
  font-weight: 600;
}

input[type="number"],
input[type="text"] {
  width: 84px;
  height: 28px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fafafa;
  color: var(--ink);
  font: inherit;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 18px;
  margin: 0;
  background: transparent;
  cursor: pointer;
}

input[type="range"]::-webkit-slider-runnable-track {
  height: 2px;
  background: #d9d9d6;
  border-radius: 999px;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  margin-top: -7px;
  border: 0;
  border-radius: 50%;
  background: var(--ink);
}

.hint {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

input[type="color"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 36px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fafafa;
  cursor: pointer;
}

input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }

input[type="color"]::-webkit-color-swatch {
  border: 0;
  border-radius: 6px;
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  padding: 3px;
  border-radius: 10px;
  background: #f3f3f1;
}

.segmented button {
  height: 32px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}

.segmented button.is-on {
  background: white;
  color: var(--ink);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}

.segmented.density button {
  height: 34px;
  font-size: 12px;
}

.field.is-idle .segmented {
  opacity: 0.4;
}

.actions {
  display: grid;
  gap: 8px;
  margin-top: auto;
}

button.primary,
button.ghost,
button.text {
  height: 42px;
  border-radius: 10px;
  font: inherit;
  font-size: 14px;
  cursor: pointer;
}

button.primary {
  border: 0;
  background: var(--ink);
  color: white;
  font-weight: 650;
}

button.primary:disabled {
  opacity: 0.4;
  cursor: default;
}

button.ghost {
  border: 1px solid var(--line);
  background: white;
  color: var(--ink);
}

button.text {
  height: 32px;
  border: 0;
  background: transparent;
  color: var(--muted);
}

button:focus-visible,
.tag:focus-visible,
input:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
}

@media (max-width: 960px) {
  body { display: block; height: auto; }
  header { align-items: flex-start; }
  main { display: block; }
  .frame { min-height: 68vw; }
  canvas { width: min(100%, 68vw); }
}
