:root {
  color-scheme: light;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #25223e;
  background: #f7f6fb;
  --ink: #25223e;
  --muted: #625d74;
  --accent: #6945b0;
  --line: #e6e0ef;
  --panel: #fff;
}

* { box-sizing: border-box; }
body { margin: 0; }
[hidden] { display: none !important; }
button, input { font: inherit; }
a { color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; }
button:focus-visible, a:focus-visible, input:focus-visible {
  outline: 2px solid #7049bc;
  outline-offset: 3px;
}
svg { width: 1.15rem; height: 1.15rem; flex: 0 0 auto; vertical-align: middle; }

.site-header { background: var(--panel); border-bottom: 1px solid var(--line); }
.header-content {
  width: min(100% - 3rem, 82rem);
  min-height: 4.35rem;
  margin-inline: auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}
.brand { display: flex; align-items: center; gap: .7rem; font-size: 1rem; letter-spacing: -.018em; }
.brand-icon {
  width: 2.35rem;
  height: 2.35rem;
  display: grid;
  place-items: center;
  background: #744cc0;
  color: white;
  border-radius: .73rem;
}
.brand-icon svg { width: 1.25rem; height: 1.25rem; }
.repository {
  display: inline-flex;
  align-items: center;
  gap: .45rem;
  text-decoration: none;
  padding: .5rem .8rem;
  border: 1px solid var(--line);
  border-radius: .65rem;
  font-weight: 650;
  font-size: .875rem;
}
.repository:hover { background: #f3edfc; }

.page { width: min(100% - 3rem, 82rem); margin: 2.4rem auto 3rem; }
.intro { margin-bottom: 1.65rem; }
.intro h1 {
  font-size: clamp(2.45rem, 4.8vw, 3.8rem);
  line-height: 1.02;
  letter-spacing: -.065em;
  font-weight: 760;
  margin: 0 0 .65rem;
}
.intro h1 span { color: #8057c9; }
.intro p { margin: 0; color: var(--muted); font-size: 1.02rem; }
.workspace { display: grid; grid-template-columns: 17.6rem minmax(0, 1fr); gap: 1.25rem; align-items: start; }
.tools { display: grid; grid-template-columns: minmax(0, 1fr); gap: .9rem; }
.tool-card, .artwork {
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: .95rem;
}
.tool-card { padding: 1rem; }
.tool-card h2 {
  display: flex;
  align-items: center;
  gap: .55rem;
  font-size: .95rem;
  margin: 0 0 .85rem;
}
.tool-card h2 svg { color: var(--accent); }
.swatches { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: .45rem; }
.swatch {
  border: 1px solid #261d3d28;
  background: var(--swatch);
  color: var(--check-color, #302847);
  border-radius: .62rem;
  aspect-ratio: 1;
  min-width: 0;
  padding: 0;
  display: grid;
  place-items: center;
}
.swatch svg { visibility: hidden; width: .95rem; height: .95rem; stroke-width: 2.4; }
.swatch[aria-pressed="true"] { outline: 2px solid #6e49b8; outline-offset: 1px; }
.swatch[aria-pressed="true"] svg { visibility: visible; }
.swatch:hover { box-shadow: inset 0 0 0 2px #fff8; }
.custom-color {
  display: flex;
  align-items: center;
  gap: .65rem;
  min-height: 2.65rem;
  margin-top: .8rem;
  padding: .4rem .6rem;
  border: 1px solid var(--line);
  border-radius: .64rem;
  cursor: pointer;
  font-size: .845rem;
  font-weight: 630;
}
.custom-color:hover { background: #fbf9ff; }
.custom-color input {
  width: 1.5rem;
  height: 1.5rem;
  padding: 0;
  background: transparent;
  border: 0;
  border-radius: .35rem;
  cursor: pointer;
}
.custom-color input::-webkit-color-swatch-wrapper { padding: 0; }
.custom-color input::-webkit-color-swatch { border: 1px solid #261d3d28; border-radius: .35rem; }
.custom-color input::-moz-color-swatch { border: 1px solid #261d3d28; border-radius: .35rem; }
.color-value { margin-left: auto; color: var(--muted); font: 580 .74rem ui-monospace, monospace; }
.gap-control {
  margin-top: .8rem;
  padding-top: .8rem;
  border-top: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: .5rem;
  cursor: pointer;
}
.gap-text { font-weight: 650; font-size: .84rem; }
.gap-text small { display: block; margin-top: .17rem; font-size: .75rem; font-weight: 450; color: var(--muted); }
.gap-control input {
  appearance: none;
  width: 2.3rem;
  height: 1.33rem;
  flex: 0 0 auto;
  margin: 0;
  position: relative;
  border: 1px solid #9b93ad;
  border-radius: 2rem;
  background: #ede9f2;
  cursor: pointer;
}
.gap-control input::before {
  content: "";
  position: absolute;
  top: .145rem;
  left: .15rem;
  width: .9rem;
  height: .9rem;
  border-radius: 50%;
  background: #786e8b;
}
.gap-control input:checked { background: #744cc0; border-color: #744cc0; }
.gap-control input:checked::before { left: 1.15rem; background: #fff; }

.page-list {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  align-content: start;
  gap: .35rem;
  block-size: 7rem;
  padding: .35rem;
  overflow-y: auto;
  overscroll-behavior-y: contain;
  scrollbar-width: thin;
  scrollbar-color: #b8a4d5 #f4effa;
}
.page-choice {
  display: flex;
  align-items: center;
  gap: .62rem;
  text-align: left;
  width: 100%;
  min-height: 3.1rem;
  padding: .3rem .5rem;
  border: 1px solid transparent;
  border-radius: .65rem;
  background: #fff;
  color: var(--ink);
  font-size: .86rem;
  font-weight: 650;
}
.page-choice:hover { background: #f8f4fe; }
.page-choice[aria-pressed="true"] { background: #f1e9fc; border-color: #dac9f4; color: #4d2a91; }
.page-choice img {
  width: 2.45rem;
  height: 2.05rem;
  flex: 0 0 auto;
  object-fit: contain;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: .33rem;
}
.page-choice span { max-width: 100%; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.page-choice svg { display: none; margin-left: auto; width: .95rem; height: .95rem; }
.page-choice[aria-pressed="true"] svg { display: block; }
.upload-photo {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .5rem;
  width: 100%;
  min-height: 2.65rem;
  margin-top: .75rem;
  border: 1px solid #dac9f4;
  border-radius: .65rem;
  background: #faf7fe;
  color: #50317f;
  font-size: .86rem;
  font-weight: 650;
}
.upload-photo:hover:not(:disabled) { background: #eee5fb; }
.upload-status { margin: .5rem 0 0; color: var(--muted); font-size: .8rem; }
.upload-status:empty { display: none; }
.template-link {
  display: flex;
  align-items: center;
  gap: .65rem;
  background: #eee8f9;
  border: 1px solid #e4d9f5;
  border-radius: .88rem;
  padding: .72rem .68rem;
  text-decoration: none;
  color: #50317f;
}
.template-link:hover { background: #e8ddf7; }
.template-mark { width: 2rem; height: 2rem; display: grid; place-items: center; border-radius: .55rem; background: #fff9; flex: 0 0 auto; }
.template-mark svg, .template-external { width: .95rem; height: .95rem; }
.template-link strong { display: block; font-size: .815rem; }
.template-link small { display: block; margin-top: .13rem; font-size: .75rem; }
.template-external { margin-left: auto; }

.artwork { overflow: hidden; }
.artwork-bar {
  min-height: 3.55rem;
  padding: .5rem .9rem .5rem 1.15rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .65rem;
  border-bottom: 1px solid var(--line);
}
.artwork-bar h2 { font-size: .99rem; margin: 0; overflow-wrap: anywhere; }
.artwork-actions { display: flex; flex: 0 0 auto; gap: .4rem; }
.action {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .35rem;
  min-height: 2.2rem;
  padding: .25rem .55rem;
  border: 1px solid var(--line);
  border-radius: .5rem;
  background: #fff;
  color: var(--ink);
  font-size: .8rem;
  font-weight: 650;
}
.action svg { width: .95rem; height: .95rem; }
.action:not(:disabled):hover { background: #f3edfc; }
.action-download:not(:disabled) { color: #50317f; background: #f1e9fc; border-color: #dac9f4; }
.action-download:not(:disabled):hover { background: #e8daf8; }
.action:disabled { color: #746b88; background: #f7f6fa; }
.download-error { margin: 0; padding: .65rem 1.15rem; color: #8c2744; font-size: .85rem; }

.artwork-stage {
  display: grid;
  place-items: center;
  min-height: 33rem;
  padding: clamp(.9rem, 3vw, 2rem);
  background-color: #eee9f6;
  background-image: radial-gradient(#a99abb86 .65px, transparent .75px);
  background-size: .8rem .8rem;
}
.sheet {
  position: relative;
  width: min(100%, var(--sheet-width, 38rem));
  aspect-ratio: var(--page-ratio, 1.25);
  background: white;
  box-shadow: 0 .7rem 1.8rem #3d2b6426, 0 0 0 1px #ded5e9;
  border-radius: .24rem;
  overflow: hidden;
}
.sheet .canvas-container {
  width: 100% !important;
  height: 100% !important;
}
.sheet canvas {
  position: absolute !important;
  inset: 0;
  width: 100% !important;
  height: 100% !important;
}
.stage-message { max-width: 22rem; text-align: center; color: var(--muted); }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 840px) {
  .header-content, .page { width: calc(100% - 2rem); }
  .workspace { grid-template-columns: 14.5rem minmax(0, 1fr); gap: .8rem; }
  .artwork-stage { min-height: 24rem; }
  .swatches { gap: .35rem; }
  .tool-card { padding: .8rem; }
}

@media (min-width: 651px) and (max-height: 820px) {
  .header-content { min-height: 3.5rem; }
  .page { margin-top: 1.35rem; }
  .intro { margin-bottom: 1.05rem; }
  .intro h1 { font-size: clamp(2.45rem, 4.8vw, 3.25rem); }
  .tools { gap: .7rem; }
  .tool-card { padding: .8rem; }
  .page-list { block-size: clamp(4.25rem, calc(100svh - 40.75rem), 7rem); }
}

@media (max-width: 650px) {
  .header-content { min-height: 3.6rem; }
  .page { margin-top: 1.55rem; }
  .intro { margin-bottom: 1.15rem; }
  .intro p { font-size: .95rem; }
  .workspace { display: flex; flex-direction: column; gap: .8rem; }
  .tools { display: contents; }
  .palette-card, .artwork, .pages-card, .template-link { width: 100%; }
  .palette-card { order: 0; display: grid; grid-template-columns: 1fr 1fr; gap: .65rem; }
  .palette-card h2 { grid-column: 1 / -1; margin-bottom: 0; }
  .swatches { grid-column: 1 / -1; grid-template-columns: repeat(12, minmax(0, 1fr)); }
  .swatch { min-height: 1.65rem; }
  .custom-color { margin: 0; min-width: 0; }
  .gap-control { margin: 0; padding: 0 0 0 .45rem; border: 0; }
  .gap-text small { display: none; }
  .artwork { order: 2; }
  .artwork-bar { padding-left: .8rem; min-height: 3.25rem; }
  .artwork-stage { min-height: 14rem; }
  .pages-card { order: 3; }
  .page-list { grid-template-columns: repeat(3, minmax(0, 1fr)); block-size: 4.8rem; }
  .page-choice { flex-direction: column; justify-content: center; gap: .3rem; line-height: 1.2; text-align: center; padding: .4rem .25rem; }
  .page-choice img { width: 3.25rem; height: 2.6rem; }
  .page-choice[aria-pressed="true"] svg { display: none; }
  .template-link { order: 1; }
}

@media (max-width: 520px) {
  .action:not(.action-download) span { display: none; }
  .action { min-width: 2.15rem; }
}

@media (max-width: 380px) {
  .swatches { grid-template-columns: repeat(6, minmax(0, 1fr)); }
  .swatch { aspect-ratio: auto; min-height: 1.7rem; }
  .color-value { display: none; }
  .action span { display: none; }
}
