:root {
  color-scheme: light;
  --canvas: #eef4f5;
  --paper: #f9fcfc;
  --ink: #243e47;
  --muted: #526974;
  --line: #cad8dc;
  --berry: #9b3c48;
  --accent: #197783;
  --sans: "Avenir Next", Avenir, "Segoe UI", system-ui, sans-serif;
  --serif: var(--sans);
}
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--canvas); color: var(--ink); font: 16px/1.55 var(--sans); }
a { color: inherit; text-decoration: none; }
button, input, textarea { font: inherit; }
h1, h2, h3, p { margin: 0; }
h1, h2 { font-family: var(--serif); font-weight: 600; line-height: 1.1; }
button, .button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 4px; }
.shell { width: 100%; }
.button { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; border: 1px solid transparent; border-radius: 3px; padding: 8px 15px; font-size: .94rem; font-weight: 650; line-height: 1.25; }
.button:hover { filter: brightness(.96); }
.button:active:not(:disabled) { translate: 0 1px; }
.button:disabled { cursor: wait; opacity: .65; }
.primary { background: var(--berry); color: white; }
.secondary { background: var(--paper); border-color: var(--line); color: var(--ink); }
.danger { background: #a22632; color: #fff; }
.form-actions { display: flex; align-items: center; gap: 12px; }
.avatar-art { display: block; width: 100%; height: auto; aspect-ratio: 1; }
#person-content { padding: clamp(20px, 5vw, 44px); }
#person { width: min(100%, 1040px); margin-inline: auto; }
#person:has(.profile-form) { width: min(100%, 1060px); }
#person-content:has(.profile-form) { padding: clamp(16px, 4vw, 32px); }
.profile-form h1 { font-size: clamp(1.95rem, 6vw, 3rem); overflow-wrap: anywhere; }
#person-content h1[tabindex="-1"]:focus { outline: none; }
.form-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px 22px; margin: 0; }
.form-grid.preferences { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-heading { isolation: isolate; position: relative; overflow: hidden; margin-bottom: 16px; padding: 17px 24px 21px; border-radius: 15px; background: #213e32; color: #fff9e9; }
.form-heading::after { position: absolute; inset: auto 0 0; height: 5px; content: ""; background: repeating-linear-gradient(125deg, #a54a56 0 13px, #f4dfb9 13px 25px, #457056 25px 39px, #f4dfb9 39px 51px); }
.character-name { position: relative; max-width: 28rem; margin-bottom: 16px; }
.field-requirement { position: absolute; top: 2px; right: 0; color: var(--muted); font-size: .78rem; font-weight: 500; }
.character-studio { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.16fr); grid-template-areas: "stage workbench"; gap: 16px; align-items: start; }
.character-stage { grid-area: stage; position: sticky; top: 12px; z-index: 2; display: grid; gap: 8px; align-items: center; min-width: 0; padding: 12px; border: 1px solid #395645; border-radius: 16px; background: #264537; color: #fff9eb; }
.character-stage .avatar-art { border: 2px solid #e7d4ab; border-radius: 10px; }
.character-stage .avatar-art[data-renderer="3d"] { touch-action: pan-y; cursor: grab; }
.character-stage .avatar-art.is-rotating { cursor: grabbing; }
.character-viewport { min-width: 0; }
.character-turn { display: flex; flex-basis: 100%; justify-content: space-between; align-items: center; gap: 5px; }
.turn-button { width: 35px; min-height: 35px; padding: 0; border-color: #d7c6a0; background: #fff9ed; font-size: 1.1rem; }
.turn-hint { color: #edf0df; font-size: .79rem; text-align: center; }
.character-stage-controls { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 7px 10px; }
.character-motion { display: flex; align-items: center; gap: 5px; }
.motion-button { padding-inline: 10px; border-color: #d7c6a0; background: #fff9ed; }
.motion-button[aria-pressed="true"] { border-color: #eed399; background: #f0e1b7; }
.character-actions { display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: 6px 12px; }
.character-actions .secondary { border-color: #d7c6a0; background: #fff9ed; }
.character-actions .text-button { color: #f7e4b6; }
.character-stage :focus-visible { outline-color: #f7d68b; }
.character-workbench { grid-area: workbench; min-width: 0; border: 1px solid #e6dcc7; border-radius: 15px; background: #fffdf7; }
.character-categories { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; padding: 13px; }
.character-category { justify-content: flex-start; gap: 9px; min-height: 53px; border-color: #e7ddc8; border-radius: 9px; padding: 7px 9px; color: var(--ink); background: #fff8e9; font-size: .94rem; text-align: left; }
.character-category:hover { border-color: #b38f68; background: #f9efd7; filter: none; }
.category-icon { flex: none; width: 31px; height: 31px; padding: 4px; border-radius: 8px; background: #ebeedf; }
.character-panel { padding: 13px 16px 16px; }
.character-panel-heading { display: flex; align-items: center; flex-wrap: wrap; gap: 3px 10px; margin: 0 0 14px; padding-bottom: 9px; border-bottom: 1px solid #e6dcc7; }
.character-panel-heading h2 { font-size: 1.36rem; }
.character-panel-heading h2:focus { outline: none; }
.category-back { margin-right: auto; min-height: 44px; padding-inline: 0; }
.character-field { min-width: 0; margin: 0 0 16px; padding: 0; border: 0; }
.character-field:last-child { margin-bottom: 0; }
.character-field legend, .character-slider { padding: 0; font-size: .91rem; font-weight: 700; }
.character-color-name { margin-left: 8px; color: var(--muted); font-weight: 500; font-size: .82rem; }
.character-options { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 7px; }
.character-option { position: relative; cursor: pointer; }
.character-option input { position: absolute; width: 1px; height: 1px; margin: 0; opacity: 0; }
.character-chip { display: grid; place-items: center; min-height: 38px; border: 1px solid #e1d4bc; border-radius: 8px; padding: 5px 10px; background: #fffefa; font-size: .85rem; }
.character-option:hover .character-chip { border-color: #ad8568; }
.character-option input:checked + .character-chip { border-color: #4a765b; box-shadow: inset 0 0 0 1px #4a765b; background: #e8f1e9; }
.character-option input:focus-visible + .character-chip { outline: 2px solid var(--berry); outline-offset: 2px; }
.option-previews { display: grid; grid-template-columns: repeat(auto-fill, minmax(66px, 1fr)); }
.option-previews .character-chip { align-content: start; height: 100%; gap: 4px; padding: 4px 4px 6px; font-size: .76rem; line-height: 1.2; text-align: center; }
.option-previews .avatar-art { border-radius: 5px; }
.hairstyle-filters { display: flex; flex-wrap: wrap; margin-top: 7px; gap: 5px; }
.hairstyle-filter { min-height: 38px; padding: 5px 8px; border-color: #e1d4bc; font-size: .81rem; }
.hairstyle-filter[aria-pressed="true"] { border-color: #4a765b; background: #e8f1e9; color: var(--ink); }
.wardrobe-groups { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 14px; }
.wardrobe-group { flex: 1 0 auto; padding: 6px; border-color: #e1d4bc; font-size: .82rem; }
.wardrobe-group[aria-pressed="true"] { border-color: #4a765b; background: #e8f1e9; }
.color-options { gap: 6px; }
.color-options .character-chip { width: 36px; min-height: 36px; padding: 0; }
.color-options .character-chip::before { content: ""; width: 24px; height: 24px; border-radius: 50%; background: var(--character-color); box-shadow: inset 0 0 0 1px #392a3921; }
.tuning-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 16px; }
.character-slider input { display: block; width: 100%; margin: 3px 0; height: 24px; cursor: pointer; accent-color: var(--berry); }
.slider-ends { display: flex; justify-content: space-between; gap: 5px; color: var(--muted); font-size: .75rem; font-weight: 500; }
.form-fold { margin-top: 11px; border: 1px solid var(--line); border-radius: 12px; }
.form-fold:first-of-type { margin-top: 18px; }
.form-fold summary { display: flex; align-items: center; gap: 12px; min-height: 66px; padding: 10px 15px; border-radius: 11px; cursor: pointer; list-style: none; }
.form-fold summary::-webkit-details-marker { display: none; }
.form-fold summary:hover { background: var(--canvas); }
.form-fold summary::after { content: ""; flex: none; width: 9px; height: 9px; margin: -4px 3px 0 auto; border: solid var(--berry); border-width: 0 2px 2px 0; transform: rotate(45deg); }
.form-fold[open] summary::after { margin-top: 4px; transform: rotate(225deg); }
.fold-icon { position: relative; display: grid; place-items: center; flex: none; width: 38px; height: 38px; border-radius: 11px; }
.fold-icon-shirt { background: #e4eee2; color: #315a43; }
.fold-icon-shirt::before { content: ""; width: 21px; height: 20px; background: currentColor; clip-path: polygon(25% 3%, 39% 0, 42% 14%, 50% 18%, 58% 14%, 61% 0, 75% 3%, 100% 30%, 85% 52%, 74% 42%, 74% 98%, 26% 98%, 26% 42%, 15% 52%, 0 30%); }
.fold-icon-gift { background: #f6e4e9; color: var(--berry); }
.fold-icon-gift::before { content: ""; width: 19px; height: 15px; margin-top: 6px; border-radius: 2px 2px 3px 3px; background: linear-gradient(90deg, transparent 42%, #f6e4e9 42% 58%, transparent 58%), linear-gradient(currentColor 0 32%, #f6e4e9 32% 42%, currentColor 42%); }
.fold-icon-gift::after { content: ""; position: absolute; top: 8px; left: 12px; width: 8px; height: 6px; border: 1.5px solid currentColor; border-radius: 60% 60% 10% 60%; transform: rotate(22deg); box-shadow: 5px -2px 0 -1px #f6e4e9, 5px -2px 0 0 currentColor; }
.fold-label { display: grid; min-width: 0; }
.fold-title { font: 600 1.2rem/1.2 var(--serif); }
.fold-caption { overflow: hidden; color: var(--muted); font-size: .83rem; text-overflow: ellipsis; white-space: nowrap; }
.fold-caption:empty, .form-fold[open] .fold-caption { display: none; }
.fold-fields { min-width: 0; margin: 0; padding: 2px 15px 15px; border: 0; }
.profile-form .form-grid { row-gap: 14px; }
.profile-form label { display: block; min-width: 0; font-size: .92rem; font-weight: 700; }
.profile-form input:not([type]), .profile-form textarea { display: block; width: 100%; margin-top: 6px; border: 1px solid #bcb4c3; border-radius: 8px; padding: 9px 11px; color: var(--ink); background: var(--paper); font-size: 1rem; font-weight: 400; }
.profile-form ::placeholder { color: #626b66; opacity: 1; }
.profile-form textarea { min-height: 45px; resize: vertical; }
.color-field, .form-grid.preferences > label:last-child { grid-column: 1 / -1; }
.color-choices { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.color-choice { min-height: 36px; padding: 4px 10px; border: 1px solid var(--line); border-radius: 100px; background: var(--paper); color: var(--ink); font-size: .83rem; }
.color-choice::before { content: ""; width: 12px; height: 12px; border-radius: 50%; background: var(--swatch); }
.color-choice[aria-pressed="true"] { border-color: var(--ink); background: #edf3ee; }
.text-button { border: 0; background: none; color: var(--berry); padding: 4px; font-weight: 700; }
.text-button:hover { text-decoration: underline; }
.form-actions { justify-content: flex-end; flex-wrap: wrap; margin-top: 25px; }
.profile-form .remove { min-height: 44px; margin-top: 8px; }
.profile-form-footer { position: sticky; z-index: 3; bottom: 0; margin-top: 14px; padding: 10px 0 max(10px, env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: var(--paper); }
.profile-form-footer .form-actions { margin: 0; }
.form-status { margin-bottom: 8px; color: #9a2537; }
.form-status:empty { display: none; }
html:has(.profile-form) { scroll-padding-bottom: calc(76px + env(safe-area-inset-bottom)); }
dialog { max-width: min(430px, 100% - 32px); width: 100%; border: 1px solid var(--line); border-radius: 16px; background: var(--paper); color: var(--ink); padding: 24px; }
dialog::backdrop { background: #17362dae; }
dialog p { margin-top: 10px; color: var(--muted); overflow-wrap: anywhere; }

@media (max-width: 730px) {
  .character-studio { grid-template-columns: minmax(0, 1fr); grid-template-areas: "stage" "workbench"; gap: 12px; }
  .character-stage { grid-template-columns: minmax(0, 224px) 104px; justify-content: center; gap: 10px; }
  .character-stage-controls { display: grid; gap: 5px; }
  .character-turn, .character-motion, .character-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; }
  .turn-hint { display: none; }
  .turn-button { width: 100%; min-height: 44px; }
  .motion-button, .character-actions .button { padding-inline: 3px; font-size: .81rem; }
  .character-panel :is(h2, button, input, .character-option) { scroll-margin-top: 272px; }
}
@media (max-width: 510px) {
  .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 13px; }
  .form-grid.preferences { grid-template-columns: 1fr; }
  .form-fold summary { padding-inline: 10px; gap: 10px; }
  .fold-fields { padding-inline: 10px; }
  .color-choice { min-height: 40px; }
  .character-stage { top: 5px; padding: 8px; }
  .form-heading { padding: 15px 14px 18px; }
  .profile-form h1 { font-size: clamp(1.58rem, 7.7vw, 1.95rem); }
  .character-stage .avatar-art { border-radius: 9px; }
  .character-categories { grid-template-columns: repeat(3, minmax(0, 1fr)); padding: 8px; gap: 6px; }
  .character-category { flex-direction: column; justify-content: center; gap: 4px; min-height: 58px; padding: 5px 3px; font-size: .77rem; text-align: center; }
  .category-icon { width: 27px; height: 27px; padding: 4px; }
  .character-panel { padding: 12px; }
  .character-panel :is(h2, button, input, .character-option) { scroll-margin-top: clamp(168px, 100vw - 162px, 255px); }
  .character-chip { min-height: 41px; }
  .color-options .character-chip { width: 42px; min-height: 42px; }
  .wardrobe-group { min-width: 44px; padding-inline: 2px; font-size: .78rem; }
  .wardrobe-panel .option-previews { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .profile-form-footer .form-actions { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.3fr); gap: 8px; }
}
@media (360px <= width <= 510px) {
  .form-grid:not(.preferences) { grid-template-columns: repeat(3, minmax(0, 1fr)); column-gap: 8px; }
}
@media (max-width: 359px) {
  .wardrobe-groups { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-height: 520px) {
  .character-stage, .profile-form-footer { position: static; }
  .character-panel :is(h2, button, input, .character-option) { scroll-margin-top: 0; }
}
