:root {
  color-scheme: dark;
  --page: #101211;
  --panel: #171a18;
  --raised: #202420;
  --line: #313730;
  --text: #f2f0e7;
  --muted: #a4aca0;
  --gold: #e7bb72;
  --gold-dark: #251d12;
  font-family: "Segoe UI", Helvetica, Arial, sans-serif;
  font-size: 14px;
  background: var(--page);
  color: var(--text);
}
* { box-sizing: border-box; }
body { margin: 0; height: 100dvh; min-height: 620px; display: flex; flex-direction: column; }
button, input, select, textarea { font: inherit; color: inherit; }
button, select, input, textarea { border: 1px solid var(--line); border-radius: 7px; background: var(--raised); }
button, select { min-height: 34px; }
button { padding: 6px 11px; cursor: pointer; white-space: nowrap; }
button:hover:not(:disabled) { background: #292f28; border-color: #626a5e; }
button:disabled { opacity: .45; cursor: default; }
button.primary { background: var(--gold); color: var(--gold-dark); border-color: var(--gold); font-weight: 650; }
button.primary:hover:not(:disabled) { background: #f0cb8d; border-color: #f0cb8d; }
select { padding: 5px 27px 5px 8px; }
input, textarea { width: 100%; padding: 8px 10px; }
:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
[hidden] { display: none !important; }
h1, h2, p, ul { margin: 0; }
h1 { font-family: Georgia, serif; font-size: 24px; font-weight: 500; letter-spacing: -.025em; }
h2 { font-size: 17px; font-weight: 650; }
.muted, .source, .studio-foot, .statusbar { color: var(--muted); }
.sr-only { position: absolute; width: 1px; height: 1px; clip-path: inset(50%); overflow: hidden; white-space: nowrap; }
.appbar { flex: none; min-height: 76px; padding: 13px 23px; display: flex; align-items: center; justify-content: space-between; gap: 14px; border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 13px; }
.mark { width: 32px; height: 32px; border: 1px solid #927347; border-radius: 8px; background: #252117; display: grid; place-items: center; }
.mark::after { content: ""; width: 13px; height: 13px; border: 2px solid var(--gold); transform: rotate(45deg); box-shadow: 0 0 9px #bc8b4270; }
.source { font-size: 11px; letter-spacing: .035em; margin-top: 3px; }
.source span { margin: 0 3px; }
.actions { display: flex; gap: 7px; flex-wrap: wrap; }
.workspace { display: grid; grid-template-columns: minmax(278px, 315px) minmax(320px, 1fr) minmax(248px, 284px); grid-template-rows: minmax(0, 1fr); flex: 1 1 0; min-height: 0; padding: 15px; gap: 13px; }
.panel, .studio { min-width: 0; overflow: hidden; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); }
.panel { display: flex; flex-direction: column; }
.panel-top { flex: none; padding: 15px 13px 10px; display: grid; gap: 11px; }
.tabs { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 4px; }
.tabs button { flex: 1; min-height: 30px; padding: 4px 7px; border-color: transparent; background: #1d211d; font-size: 12px; color: var(--muted); }
.tabs button[aria-pressed="true"] { border-color: #695537; background: #30271a; color: #f1c989; }
#search-form { display: flex; gap: 6px; }
#search { min-width: 0; }
.field { display: grid; gap: 5px; color: var(--muted); font-size: 12px; }
.field :is(select,input,textarea) { color: var(--text); font-size: 14px; }
.inline { display: flex; align-items: center; gap: 8px; }
#library-status { min-height: 17px; font-size: 12px; line-height: 1.35; }
.results, .slots { list-style: none; padding: 0 10px; }
.results { min-height: 0; overflow: auto; flex: 1; accent-color: var(--gold); scrollbar-width: thin; }
.result { display: flex; align-items: center; gap: 5px; min-height: 47px; border-top: 1px solid #2b312a; }
.result:last-child { border-bottom: 1px solid #2b312a; }
.result .result-name { display: grid; gap: 3px; text-align: left; white-space: normal; overflow-wrap: anywhere; border: 0; padding: 7px 4px; flex: 1; min-width: 0; background: transparent; }
.result .result-name:disabled { opacity: 1; }
.result small { font-size: 11px; color: var(--muted); }
.result .equip { min-height: 26px; padding: 3px 7px; font-size: 11px; }
.favorite-star { min-height: 26px; padding: 2px 5px; width: 29px; font-size: 17px; background: transparent; }
.favorite-star[aria-pressed="true"], #favorite-model[aria-pressed="true"] { color: var(--gold); }
.variant-tools, #map-form { display: grid; gap: 7px; }
.check { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12px; }
.check input { width: auto; margin: 0; accent-color: var(--gold); }
.map-fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 7px; }
.map-fields select { width: 100%; padding-right: 2px; font-size: 12px; }
#map-grid-details { color: var(--muted); font-size: 12px; }
#map-grid-details summary { cursor: pointer; }
#map-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 3px; margin-top: 5px; }
#map-grid button { min-height: 23px; padding: 1px; }
#map-grid button[aria-current="true"] { border-color: var(--gold); background: #4c3a23; }
.more { margin: 8px 12px 10px; }
.studio { display: grid; grid-template-rows: auto minmax(0, 1fr) auto auto; }
.studio-bar { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.studio-heading { min-width: 0; }
.studio-heading h2 { font-family: Georgia, serif; font-weight: 500; font-size: clamp(21px, 2.3vw, 34px); overflow-wrap: anywhere; }
.studio-nav { justify-content: flex-end; flex-wrap: wrap; }
.view-kind { color: var(--gold); font-size: 11px; margin-bottom: 4px; }
.viewport {
  min-width: 0; min-height: 0; position: relative; isolation: isolate;
  background:
    radial-gradient(ellipse at 50% 50%, #354337 0%, #232c26 38%, transparent 75%),
    linear-gradient(160deg, #252d27, #111714 73%);
}
.viewport::before {
  content: ""; position: absolute; inset: 0; z-index: -1; pointer-events: none; opacity: .35;
  background-image: linear-gradient(#84958221 1px, transparent 1px), linear-gradient(90deg, #84958221 1px, transparent 1px);
  background-size: 38px 38px;
  mask-image: radial-gradient(ellipse at 50% 60%, black, transparent 80%);
}
#preview { width: 100%; height: 100%; display: block; position: absolute; inset: 0; touch-action: none; cursor: grab; }
#preview:active { cursor: grabbing; }
.loading { position: absolute; inset: 0; pointer-events: none; display: flex; align-items: center; justify-content: center; gap: 10px; background: #11171466; color: var(--text); }
.spinner { width: 16px; height: 16px; border-radius: 50%; border: 2px solid #826e4e; border-top-color: var(--gold); animation: spin .9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation: none; } }
.axis { position: absolute; width: 20px; height: 24px; bottom: 16px; left: 18px; pointer-events: none; opacity: .7; }
.axis span { width: 14px; height: 2px; position: absolute; bottom: 4px; left: 5px; transform-origin: left; background: #bd8569; }
.axis span:nth-child(2) { transform: rotate(-90deg); background: #a2ae7a; }
.axis span:nth-child(3) { transform: rotate(140deg); background: #8faeb8; }
.studio-tools { display: flex; justify-content: space-between; gap: 7px; padding: 10px 12px; border-top: 1px solid var(--line); }
#animation-controls { display: flex; gap: 7px; flex-wrap: wrap; }
#animation { max-width: min(180px, 25vw); }
.view-buttons { display: flex; gap: 4px; }
.view-buttons button { padding-inline: 8px; }
.studio-foot { font-size: 11px; padding: 0 12px 11px; display: flex; flex-wrap: wrap; justify-content: space-between; gap: 3px 8px; }
.full { width: 100%; }
.outfit-actions { display: flex; gap: 5px; }
#reset-outfit { flex: 1; min-width: 0; white-space: normal; }
#outfit-info { overflow: auto; scrollbar-width: thin; padding-bottom: 10px; flex: 1; }
.slot { border-top: 1px solid #2b312a; display: flex; align-items: center; gap: 3px; }
.slot-main { flex: 1; min-width: 0; background: transparent; border: 0; text-align: left; padding: 7px 4px; display: grid; gap: 4px; min-height: 44px; }
.slot-main span { color: var(--muted); font-size: 11px; }
.slot-main strong { white-space: normal; font-weight: 550; font-size: 12px; }
.slot-main[aria-pressed="true"] { color: var(--gold); }
.slot .swap { min-height: 25px; padding: 3px 6px; font-size: 11px; }
.slot .clear { min-height: 25px; font-size: 15px; padding: 0 7px; }
#palette { margin: 10px; border-top: 1px solid var(--line); }
#palette summary { padding: 10px 4px; cursor: pointer; }
#colors { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.color-cell { display: flex; align-items: center; gap: 5px; }
.color-chip { width: 20px; height: 20px; border-radius: 4px; border: 1px solid #73786c; flex: none; }
.color-cell select { min-width: 0; width: 100%; padding-right: 5px; }
.statusbar { flex: none; padding: 7px 17px 11px; display: flex; justify-content: space-between; align-items: baseline; gap: 12px; font-size: 12px; min-height: 40px; }
.statusbar a { color: #c7b58e; text-decoration: none; white-space: nowrap; }
.statusbar a:hover { text-decoration: underline; }
.error, .statusbar .error { color: #f2ab8b; }
dialog { width: min(460px, calc(100% - 28px)); background: var(--panel); color: var(--text); border: 1px solid #596153; border-radius: 11px; padding: 17px; }
dialog::backdrop { background: #080c0999; }
#player-form { display: grid; gap: 11px; }
#animation-dialog { position: fixed; inset: auto; margin: 0; z-index: 5; width: min(356px, calc(100% - 16px)); max-height: min(68vh, 610px); box-shadow: 0 10px 36px #0008; }
#animation-dialog[open] { display: grid; grid-template-rows: auto auto auto auto auto minmax(0, 1fr); gap: 10px; }
#animation-titlebar { justify-content: flex-start; cursor: grab; touch-action: none; user-select: none; }
#animation-titlebar:active { cursor: grabbing; }
#animation-titlebar h2 { flex: 1; }
#move-animation { cursor: inherit; padding-inline: 6px; }
#animation-search-form { display: flex; align-items: end; gap: 6px; }
#animation-search-form .field { flex: 1; min-width: 0; }
.sequence-tools { display: flex; align-items: center; gap: 7px; flex-wrap: wrap; }
#favorite-sequences[aria-pressed="true"] { color: var(--gold); background: #30271a; border-color: #695537; }
.sequence-now { display: flex; align-items: center; justify-content: space-between; gap: 7px; }
#sequence-results { max-height: min(39vh, 365px); padding: 0; }
#sequence-results .result-name[aria-pressed="true"] { color: var(--gold); background: #30271a; }
#sequence-preview { color: var(--gold); font-size: 12px; }
#sequence-preview.error { color: #f2ab8b; }
#sequence-status { font-size: 12px; }
.dialog-top, .dialog-actions { display: flex; align-items: center; justify-content: space-between; gap: 7px; }
.dialog-top button { min-height: 28px; }
#player-error:empty { display: none; }
@media (max-width: 1060px) {
  .workspace { grid-template-columns: 255px minmax(280px, 1fr) 218px; gap: 8px; padding: 9px; }
  .panel-top { padding-inline: 9px; }
  .studio-tools { flex-wrap: wrap; }
}
@media (max-width: 800px) {
  body { height: auto; min-height: 100dvh; }
  .workspace { flex: 1 1 auto; grid-template-columns: 1fr 1fr; grid-template-rows: auto; }
  .studio { grid-column: 1 / -1; grid-row: 1; height: max(430px, 58vh); }
  .catalog, .outfit { max-height: 560px; min-height: 380px; }
  .appbar { padding-inline: 11px; }
  #animation { max-width: 150px; }
  #animation-dialog { max-height: 52vh; }
  #sequence-results { max-height: 25vh; }
}
@media (max-width: 510px) {
  .appbar { flex-wrap: wrap; }
  .workspace { grid-template-columns: 1fr; }
  .studio { grid-column: auto; }
  .statusbar { flex-wrap: wrap; }
}

#retry-engine { pointer-events: auto; }
