:root {
  --design-w: 1280;
  --design-h: 720;
  --stage-scale: 1;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --gold: #f3c66f;
  --gold-dark: #7e5622;
  --emerald: #79e9b5;
  --text: #fff2d9;
  --muted: #bea98a;
  --panel: rgba(11, 13, 18, .74);
  --panel-strong: rgba(8, 10, 14, .90);
  --line: rgba(243, 198, 111, .28);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { width: 100%; height: 100%; margin: 0; padding: 0; overflow: hidden; }
body {
  background: #07090e;
  color: var(--text);
  font-family: Arial, Helvetica, sans-serif;
  touch-action: manipulation;
  user-select: none;
}
button, input { font: inherit; }
button { border: 0; }

.app {
  position: fixed;
  inset: 0;
  overflow: hidden;
  background: #07090e;
}

.scene-background {
  position: absolute;
  left: 50%;
  top: 50%;
  width: max(100vw, 1280px);
  height: max(100vh, 720px);
  transform: translate(-50%, -50%);
  background-color: #12141c;
  background-image:
    radial-gradient(circle at 50% 30%, rgba(243,198,111,.14), transparent 34%),
    linear-gradient(145deg, #101824, #24170d 55%, #07090e);
  background-position: center center;
  background-size: cover, cover, cover;
  background-repeat: no-repeat;
  transition: opacity .18s ease, filter .18s ease;
}

.scene-vignette {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(ellipse at center, rgba(255,255,255,.02) 0%, rgba(0,0,0,.04) 44%, rgba(0,0,0,.58) 100%),
    linear-gradient(to bottom, rgba(0,0,0,.26), transparent 22%, rgba(0,0,0,.40));
}

.stage {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 1280px;
  height: 720px;
  transform: translate(-50%, -50%) scale(var(--stage-scale));
  transform-origin: center center;
  overflow: visible;
}

.screen {
  position: absolute;
  inset: 0;
  display: none;
}
.screen.is-active { display: block; }

.ui-button,
.text-input,
.field-label,
.character-preview,
.location-title,
.resource-widget {
  position: absolute;
}

.ui-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1px;
  min-height: 1px;
  padding: 0 18px;
  border-radius: 18px;
  color: var(--text);
  font-weight: 800;
  letter-spacing: .02em;
  text-align: center;
  cursor: pointer;
  border: 1px solid rgba(255,255,255,.12);
  background:
    linear-gradient(180deg, rgba(68, 49, 31, .92), rgba(26, 22, 21, .94));
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,.15),
    inset 0 -2px 0 rgba(0,0,0,.26),
    0 12px 28px rgba(0,0,0,.34);
  text-shadow: 0 2px 2px rgba(0,0,0,.55);
}
.ui-button:active { transform: translateY(2px); }
.ui-button:disabled {
  cursor: not-allowed;
  opacity: .58;
  filter: grayscale(.45);
}
.primary-button {
  color: #2a1705;
  font-size: 26px;
  background: linear-gradient(180deg, #ffe4a1, #d49237 58%, #9a5b1d);
  border-color: rgba(255,232,175,.65);
  text-shadow: 0 1px 0 rgba(255,255,255,.28);
}
.icon-button {
  z-index: 30;
  padding: 0;
  border-radius: 50%;
  font-size: 28px;
  background: rgba(9, 11, 16, .66);
  backdrop-filter: blur(4px);
}
.sex-button,
.nav-button,
.action-button { font-size: 18px; }
.sex-button.is-active {
  color: #2a1705;
  background: linear-gradient(180deg, #ffe4a1, #d49237 58%, #9a5b1d);
  border-color: rgba(255,232,175,.65);
  text-shadow: 0 1px 0 rgba(255,255,255,.28);
}
.nav-button {
  border-radius: 20px;
  background: linear-gradient(180deg, rgba(27, 39, 51, .93), rgba(11, 14, 20, .95));
}
.action-button {
  white-space: normal;
  line-height: 1.1;
}
.action-button small {
  display: block;
  width: 100%;
  margin-top: 4px;
  color: rgba(255,242,217,.70);
  font-size: 12px;
  font-weight: 700;
}

.game-logo {
  position: absolute;
  left: 50%;
  top: 92px;
  width: 700px;
  min-height: 220px;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  border-radius: 34px;
  background: radial-gradient(circle at 50% 10%, rgba(243,198,111,.17), rgba(6,8,12,.28) 70%);
}
.game-logo__mark {
  font-size: 78px;
  line-height: 1;
  color: var(--gold);
  filter: drop-shadow(0 8px 18px rgba(0,0,0,.50));
}
.game-logo h1 {
  margin: 10px 0 0;
  font-size: 68px;
  line-height: .98;
  color: var(--gold);
  text-shadow: 0 5px 0 rgba(0,0,0,.36), 0 18px 38px rgba(0,0,0,.60);
}

.screen-title {
  position: absolute;
  left: 40px;
  top: 28px;
  margin: 0;
  color: var(--gold);
  font-size: 42px;
  line-height: 1;
  text-shadow: 0 4px 12px rgba(0,0,0,.55);
}

.character-preview {
  border-radius: 28px;
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 28%, rgba(243,198,111,.18), transparent 32%),
    linear-gradient(180deg, rgba(17,23,31,.68), rgba(5,6,8,.54));
  border: 1px solid rgba(243,198,111,.20);
  box-shadow: 0 18px 60px rgba(0,0,0,.38);
}
.character-preview__shadow {
  position: absolute;
  left: 50%;
  bottom: 36px;
  width: 210px;
  height: 34px;
  transform: translateX(-50%);
  border-radius: 50%;
  background: rgba(0,0,0,.42);
  filter: blur(2px);
}
.character-preview__body {
  position: absolute;
  left: 50%;
  bottom: 70px;
  width: 138px;
  height: 170px;
  transform: translateX(-50%);
  border-radius: 54px 54px 26px 26px;
  background: linear-gradient(180deg, #76583a, #2e2730);
  box-shadow: inset 0 0 0 3px rgba(0,0,0,.16), 0 15px 28px rgba(0,0,0,.28);
  animation: previewIdle 1.6s ease-in-out infinite;
}
.character-preview__head {
  position: absolute;
  left: 50%;
  top: 82px;
  width: 92px;
  height: 92px;
  transform: translateX(-50%);
  border-radius: 50%;
  background: radial-gradient(circle at 38% 28%, #f3c89b, #bb7c55 65%, #573129);
  box-shadow: inset 0 -10px 0 rgba(0,0,0,.10), 0 14px 28px rgba(0,0,0,.28);
  animation: previewIdle 1.6s ease-in-out infinite;
}
.character-preview[data-gender="female"] .character-preview__body {
  width: 128px;
  border-radius: 68px 68px 30px 30px;
  background: linear-gradient(180deg, #6f3e4a, #2b202c);
}
.character-preview[data-gender="female"] .character-preview__head {
  background: radial-gradient(circle at 38% 28%, #f4ca9e, #c1845d 65%, #2d2028);
}
.character-preview__label {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 14px;
  color: rgba(255,242,217,.78);
  text-align: center;
  font-weight: 700;
  font-size: 16px;
}
@keyframes previewIdle {
  0%, 100% { margin-top: 0; }
  50% { margin-top: -6px; }
}

.field-label {
  display: flex;
  align-items: center;
  color: var(--gold);
  font-weight: 800;
  text-shadow: 0 2px 4px rgba(0,0,0,.60);
}
.text-input {
  padding: 0 16px;
  border-radius: 16px;
  border: 1px solid rgba(243,198,111,.34);
  color: var(--text);
  background: rgba(5,7,10,.72);
  outline: none;
  box-shadow: inset 0 2px 8px rgba(0,0,0,.32), 0 10px 28px rgba(0,0,0,.24);
}
.text-input:focus { border-color: rgba(255,226,160,.82); }

.top-hud,
.bottom-nav,
.location-actions { position: absolute; inset: 0; pointer-events: none; }
.top-hud > *, .bottom-nav > *, .location-actions > * { pointer-events: auto; }
.location-title {
  display: flex;
  align-items: center;
  padding: 0 22px;
  border-radius: 18px;
  color: var(--gold);
  font-size: 28px;
  font-weight: 900;
  background: rgba(8, 10, 14, .72);
  border: 1px solid var(--line);
  box-shadow: 0 12px 34px rgba(0,0,0,.34);
  backdrop-filter: blur(4px);
  text-shadow: 0 3px 6px rgba(0,0,0,.52);
}
.resource-widget {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  border-radius: 18px;
  background: rgba(8, 10, 14, .72);
  border: 1px solid var(--line);
  box-shadow: 0 12px 34px rgba(0,0,0,.34);
  backdrop-filter: blur(4px);
}
.resource-widget__icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: rgba(255,255,255,.08);
  font-size: 20px;
}
.resource-widget--emerald .resource-widget__icon { color: var(--emerald); }
.resource-widget--gold .resource-widget__icon { color: var(--gold); }
.resource-widget--premium .resource-widget__icon { color: #ffe38f; }
.resource-widget__value {
  color: #fff8e8;
  font-size: 22px;
  font-weight: 900;
}

.panel-overlay {
  position: absolute;
  inset: 0;
  z-index: 50;
  display: none;
  align-items: center;
  justify-content: center;
  padding: max(16px, var(--safe-top)) max(16px, var(--safe-right)) max(16px, var(--safe-bottom)) max(16px, var(--safe-left));
  background: rgba(0,0,0,.58);
  backdrop-filter: blur(4px);
}
.panel-overlay.is-open { display: flex; }
.panel-window {
  width: min(100%, 980px);
  max-height: min(92vh, 680px);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  border-radius: 28px;
  background: var(--panel-strong);
  border: 1px solid rgba(243, 198, 111, .24);
  box-shadow: 0 28px 100px rgba(0,0,0,.62);
}
.panel-window__header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 20px 22px;
  border-bottom: 1px solid rgba(243, 198, 111, .14);
}
.small-label {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .12em;
}
.panel-title {
  margin: 4px 0 0;
  color: var(--gold);
  font-size: 36px;
  line-height: 1;
}
.close-button {
  position: static;
  min-width: 120px;
  min-height: 48px;
  border-radius: 15px;
}
.panel-content {
  overflow: auto;
  padding: 24px;
}
.panel-content--stub { display: none; }
.panel-overlay[data-panel="inventory"] .panel-content--map,
.panel-overlay[data-panel="parameters"] .panel-content--map,
.panel-overlay[data-panel="talents"] .panel-content--map { display: none; }
.panel-overlay[data-panel="inventory"] .panel-content--stub,
.panel-overlay[data-panel="parameters"] .panel-content--stub,
.panel-overlay[data-panel="talents"] .panel-content--stub { display: block; }
.map-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}
.map-location-button {
  position: relative;
  min-height: 118px;
  padding: 16px;
  border-radius: 20px;
  text-align: left;
  color: var(--text);
  background: linear-gradient(180deg, rgba(45, 39, 34, .94), rgba(12, 13, 17, .96));
  border: 1px solid rgba(243,198,111,.18);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.10), 0 10px 24px rgba(0,0,0,.28);
}
.map-location-button strong {
  display: block;
  color: var(--gold);
  font-size: 21px;
  line-height: 1.1;
}
.map-location-button span {
  display: block;
  margin-top: 8px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.3;
}
.map-location-button.is-current,
.map-location-button:disabled {
  cursor: not-allowed;
  opacity: .62;
  filter: grayscale(.35);
}
.map-location-button.is-current::after {
  content: 'Вы здесь';
  position: absolute;
  right: 12px;
  bottom: 10px;
  color: var(--emerald);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: .08em;
  text-transform: uppercase;
}
.panel-content--stub h3 {
  margin: 0 0 10px;
  color: var(--gold);
  font-size: 32px;
}
.panel-content--stub p {
  margin: 0;
  color: var(--muted);
  font-size: 18px;
  line-height: 1.5;
}

@media (max-width: 720px) {
  .panel-window { border-radius: 22px; }
  .panel-title { font-size: 28px; }
  .map-grid { grid-template-columns: 1fr; }
}

/* 0.1.6: картинки кнопок и персонаж в idle */
.ui-button.has-layout-image {
  overflow: hidden;
}
.ui-button.has-layout-image.is-text-hidden {
  color: transparent;
  text-shadow: none;
}
.ui-button.has-layout-image.is-text-hidden > * {
  opacity: 0;
}

.character-sprite {
  position: absolute;
  display: block;
  object-fit: contain;
  pointer-events: none;
  user-select: none;
}
.character-sprite[hidden] { display: none; }
.character-sprite--create {
  left: 50%;
  top: 50%;
  z-index: 3;
  width: 88%;
  height: 88%;
  transform: translate(-50%, -50%);
  object-fit: contain;
  filter: drop-shadow(0 18px 22px rgba(0,0,0,.42));
}
.character-preview.has-sprite .character-preview__body,
.character-preview.has-sprite .character-preview__head,
.character-preview.has-sprite .character-preview__shadow {
  display: none;
}
.character-preview.has-sprite {
  background: transparent;
  border-color: transparent;
  box-shadow: none;
}

.location-character {
  position: absolute;
  z-index: 4;
  pointer-events: none;
}
.location-character[hidden] { display: none; }
.location-character__placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 28px;
  color: rgba(255,242,217,.70);
  font-weight: 900;
  font-size: 22px;
  text-shadow: 0 3px 8px rgba(0,0,0,.65);
  background: radial-gradient(circle at 50% 35%, rgba(243,198,111,.16), rgba(4,5,8,.10) 70%);
  border: 1px dashed rgba(243,198,111,.22);
}
.location-character.has-sprite .location-character__placeholder { display: none; }
.character-sprite--location {
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter: drop-shadow(0 22px 24px rgba(0,0,0,.46));
}

/* 0.1.8: idle-персонаж собирается из split-rig структуры редактора */
.character-preview.has-rig .character-preview__body,
.character-preview.has-rig .character-preview__head,
.character-preview.has-rig .character-preview__shadow {
  display: none;
}
.character-preview.has-rig {
  background: transparent;
  border-color: transparent;
  box-shadow: none;
}
.location-character.has-rig .location-character__placeholder { display: none; }

.character-rig {
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: 4;
  transform: translate(-50%, -50%) scale(var(--character-rig-scale, 1));
  transform-origin: center center;
  pointer-events: none;
  user-select: none;
  filter: drop-shadow(0 22px 24px rgba(0,0,0,.46));
}
.character-rig[hidden] { display: none; }
.character-rig__part {
  position: absolute;
  overflow: hidden;
  pointer-events: none;
  user-select: none;
}
.character-rig__part:not(.is-loaded) { opacity: 0; }
.character-rig__strip {
  position: absolute;
  left: 0;
  top: 0;
  display: block;
  max-width: none;
  transform: translate3d(0, 0, 0);
  will-change: transform;
  pointer-events: none;
  user-select: none;
}
.character-preview .character-rig {
  filter: drop-shadow(0 18px 22px rgba(0,0,0,.42));
}
.character-preview__label { z-index: 8; }

/* 0.1.9: фон привязан к той же дизайн-системе, что и кнопки */
.scene-background {
  width: var(--scene-bg-w, 1280px);
  height: var(--scene-bg-h, 720px);
  transform: translate(-50%, -50%) scale(var(--stage-scale));
  transform-origin: center center;
}

/* 0.1.9: если кнопка сделана картинкой — не рисуем игровую рамку поверх */
.ui-button.has-layout-image {
  padding: 0;
  border: 0;
  border-radius: 0;
  background-color: transparent;
  box-shadow: none;
  text-shadow: none;
  overflow: hidden;
}
.ui-button.has-layout-image.is-text-hidden {
  color: transparent;
  text-shadow: none;
}
.ui-button.has-layout-image.is-text-hidden > * {
  opacity: 0;
}
