:root {
  color-scheme: dark;
  font: 16px/1.45 "Trebuchet MS", system-ui, sans-serif;
  background: #070a12;
  color: #eff1ff;
  --muted: #aab3d0;
  --accent: #ff89a7;
  --line: #303653;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body, h1, h2, p, figure { margin: 0; }
button, input { font: inherit; }
button, a { touch-action: manipulation; }
button { cursor: pointer; color: inherit; }
button:disabled { cursor: default; }
a { color: inherit; }
:focus-visible { outline: 3px solid #b4aaff; outline-offset: 3px; }
.world {
  display: grid;
  grid-template-rows: auto minmax(0,1fr) auto;
  width: min(100%, 1600px);
  height: 100vh;
  height: 100dvh;
  min-height: 310px;
  margin: auto;
  padding: max(18px, env(safe-area-inset-top)) max(24px, env(safe-area-inset-right))
           max(15px, env(safe-area-inset-bottom)) max(24px, env(safe-area-inset-left));
  gap: 13px;
}
.world-header { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; }
.brand { font: 700 .66rem/1.3 ui-monospace, Consolas, monospace; letter-spacing: .23em; color: #c2b5ff; }
h1 { font-size: clamp(28px, 5.8vw, 62px); line-height: 1.02; letter-spacing: -.052em; margin: 6px 0 5px; }
.byline { color: var(--muted); font-size: .85rem; }
.view-controls { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 7px; }
.quiet, .plain, .close {
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #13182b;
  min-height: 39px;
  padding: 7px 11px;
  font-size: .82rem;
}
.quiet:hover, .plain:hover, .close:hover { background: #242a47; }
.quiet[aria-pressed="true"], .plain[aria-pressed="true"] { border-color: #bfafff; color: #e0d6ff; }
.scene { position: relative; overflow: hidden; border: 1px solid #252b43; border-radius: 14px; background: #04050b; }
.scene canvas { display: block; width: 100%; height: 100%; }
.scene-status {
  pointer-events: none;
  position: absolute; top: 14px; left: 14px; right: 14px;
  display: grid; justify-items: start; gap: 5px;
}
.scene-status p {
  width: fit-content;
  font: 600 .76rem/1.2 ui-monospace, Consolas, monospace;
  background: #0e1324ed; border: 1px solid #383e60; border-radius: 5px;
  padding: 6px 9px; color: #dce1ff;
}
#battle-status:empty { display: none; }
#battle-status { color: #ffd1de; }
#battle-progress { width: 130px; height: 6px; accent-color: #ff7199; }
.dock { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.world-upload { display: flex; gap: 13px; align-items: center; }
#qr-link, .qr-popup a { display: block; flex: none; border-radius: 7px; background: white; overflow: hidden; }
#qr { display: block; width: 78px; height: 78px; }
.add-link { font-weight: 700; text-decoration-thickness: 1px; text-underline-offset: 4px; }
#qr-instruction, #battle-hint { font-size: .76rem; color: var(--muted); margin: 4px 0; }
.text-button { border: 0; background: transparent; color: #d1c4ff; font-size: .8rem; padding: 5px 0; text-decoration: underline; text-underline-offset: 3px; }
.battle-controls { text-align: right; }
.primary {
  background: #fa789c; color: #1d1020; border: 1px solid #ff9bb4;
  border-radius: 8px; padding: 9px 18px; min-height: 45px; font-weight: 800;
}
.primary span { padding-right: 5px; }
.primary:hover:enabled { background: #ff9ab7; }
.primary:disabled { background: #2d273a; color: #d3c1d8; border-color: #51435c; }
.popup {
  width: min(calc(100vw - 22px), 540px);
  max-height: 94dvh;
  max-width: none;
  overflow: auto;
  padding: 19px;
  background: #111528;
  color: #f2f1ff;
  border: 1px solid #535c84; border-radius: 14px;
  box-shadow: 0 18px 80px #0009;
}
.popup::backdrop { background: #03050cba; }
.dialog-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 13px; }
.popup h2 { font-size: clamp(1.32rem, 5vw, 1.85rem); line-height: 1.16; }
.dialog-top .brand { margin: 2px 0 7px; }
.close { font-size: 1.3rem; padding: 0; width: 39px; flex: none; }
.dialog-note { color: #c0c6de; font-size: .88rem; margin: 11px 0; }
.qr-popup a { display: block; width: min(100%, 340px, 60dvh); margin: 12px auto; }
.qr-popup img { display: block; width: 100%; aspect-ratio: 1; }
.popup .primary { width: 100%; }
.host-actions, .edit-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 7px; margin: 9px 0; }
.danger { color: #ffb4c4; }
.parts-list { display: grid; gap: 8px; margin-top: 12px; }
.parts-list:empty::after { content: "Загруженные сердца появятся здесь."; color: var(--muted); }
.part-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 7px; border: 1px solid var(--line); border-radius: 8px; }
.part-row figure { display: grid; place-items: center; width: 44px; height: 44px; background: #252b49; border-radius: 6px; }
.part-row img { max-width: 41px; max-height: 41px; }
.part-title { flex: 1; font-size: .84rem; }
.photo-area {
  display: grid; place-items: center; aspect-ratio: 560/400;
  max-height: 43dvh; overflow: hidden;
  padding: 0; border: 1px solid #434b6c; border-radius: 9px;
  background: repeating-conic-gradient(#202643 0% 25%, #191e34 0% 50%) 50% / 20px 20px;
  color: #c7cdef;
}
.photo-area:has(canvas:not([hidden])) { aspect-ratio: auto; }
.photo-area canvas { display: block; width: auto; height: auto; max-width: 100%; max-height: 43dvh; touch-action: none; }
#photo[data-cropping], #photo[data-outlining] { cursor: crosshair; }
.upload-label { position: relative; display: inline-flex; align-items: center; }
.upload-label input { position: absolute; inset: 0; width: 100%; opacity: 0; cursor: pointer; }
.upload-label:focus-within { outline: 3px solid #b4aaff; }
.brush-size { display: flex; gap: 5px; align-items: center; font-size: .8rem; }
.brush-size input { width: 80px; }
.edit-status { min-height: 19px; margin: 8px 0; font-size: .85rem; color: #ffd1de; }
.report-link { display: block; margin: 7px auto 0; }
.toast {
  position: fixed; z-index: 5; top: 48%; left: 50%; transform: translate(-50%, -50%);
  width: max-content; max-width: calc(100% - 28px); text-align: center;
  background: #171a32; border: 1px solid #837ba8; color: #fff3fa; border-radius: 9px; padding: 12px 18px;
}
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
@media (max-width: 660px) {
  .world { padding-inline: max(10px, env(safe-area-inset-left)) max(10px, env(safe-area-inset-right)); gap: 9px; }
  .world-header { align-items: flex-start; flex-direction: column; gap: 7px; }
  .view-controls { justify-content: flex-start; gap: 5px; }
  .view-controls button { font-size: .72rem; min-height: 35px; padding: 5px 8px; }
  #fullscreen span { display: none; }
  #qr { width: 54px; height: 54px; }
  .world-upload { gap: 6px; }
  .add-link { font-size: .79rem; white-space: nowrap; }
  #qr-instruction { display: none; }
  #open-qr { font-size: .7rem; }
  .battle-controls .primary { padding-inline: 9px; font-size: .82rem; min-height: 38px; }
  #battle-hint { display: none; }
  .scene-status { top: 8px; left: 8px; right: 8px; }
}
@media (max-height: 500px) and (orientation: landscape) {
  .world { padding-block: 7px; gap: 6px; }
  .world-header { flex-direction: row; align-items: flex-end; }
  h1 { font-size: 27px; margin-block: 2px; }
  .world-header .byline { display: none; }
  #qr { width: 47px; height: 47px; }
  #battle-hint, #qr-instruction { display: none; }
}
