:root {
  --bg-deep: #050914;
  --bg-night: #0b1428;
  --bg-panel: rgba(8, 14, 28, 0.88);
  --bg-panel-solid: #091021;
  --gold-primary: #e6be6a;
  --gold-bright: #f9dfa1;
  --gold-muted: rgba(230, 190, 106, 0.42);
  --gold-border: rgba(230, 190, 106, 0.72);
  --text-main: #f5efe2;
  --text-soft: #c9c0ae;
  --text-thought: #a8c5f0;
  --accent-blue: #2f5fa8;
  --font-serif: 'Cormorant Garamond', Georgia, serif;
  --font-sans: 'Manrope', -apple-system, BlinkMacSystemFont, sans-serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  width: 100%;
  height: 100%;
  background: var(--bg-deep);
  color: var(--text-main);
  font-family: var(--font-sans);
  overflow: hidden;
}

#starfield-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  pointer-events: none;
}

#app-shell {
  position: relative;
  z-index: 1;
  width: 100vw;
  height: 100vh;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top, 0px) env(safe-area-inset-right, 0px) env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px);
  transition: max-width 0.35s ease, height 0.35s ease;
  margin: 0 auto;
}

/* Portrait simulation mode for testing mobile portrait switching per Section 12 GDD */
#app-shell.mode-portrait {
  max-width: 460px;
  height: 94vh;
  margin-top: 3vh;
  border: 1.5px solid var(--gold-muted);
  border-radius: 28px;
  overflow: hidden;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.85), 0 0 40px rgba(230, 190, 106, 0.14);
}

/* Top HUD */
#top-hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 22px;
  background: linear-gradient(180deg, rgba(5, 9, 20, 0.88) 0%, rgba(5, 9, 20, 0) 100%);
  z-index: 20;
  flex-shrink: 0;
}

.hud-left, .hud-right {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.hud-right {
  flex-shrink: 0;
}

.star-progress {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 34px;
  color: var(--gold-primary);
  filter: drop-shadow(0 0 6px rgba(230, 190, 106, 0.45));
  padding: 0 11px;
  border-radius: 999px;
  background: rgba(9, 16, 33, 0.65);
  border: 1px solid rgba(230, 190, 106, 0.3);
  flex-shrink: 0;
}

.star-slot {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.svg-icon {
  display: block;
  flex-shrink: 0;
}

.icon-wrap {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--gold-bright);
  line-height: 1;
  flex-shrink: 0;
}

.scene-badge {
  display: inline-flex;
  align-items: center;
  height: 34px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--gold-bright);
  background: rgba(12, 22, 45, 0.78);
  border: 1px solid var(--gold-muted);
  padding: 0 14px;
  border-radius: 999px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1;
}

.hud-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  height: 34px;
  background: rgba(9, 16, 33, 0.78);
  color: var(--text-main);
  border: 1px solid var(--gold-muted);
  border-radius: 999px;
  padding: 0 13px;
  font-family: var(--font-sans);
  font-size: 12.5px;
  font-weight: 500;
  line-height: 1;
  white-space: nowrap;
  flex-shrink: 0;
  cursor: pointer;
  transition: all 0.2s ease;
}

.hud-btn .svg-icon {
  width: 15px;
  height: 15px;
}

.hud-btn:hover {
  border-color: var(--gold-bright);
  background: rgba(24, 40, 76, 0.88);
  box-shadow: 0 0 14px rgba(230, 190, 106, 0.28);
  transform: translateY(-1px);
}

.hud-btn-menu {
  width: 34px;
  height: 34px;
  padding: 0;
  justify-content: center;
  font-size: 16px;
  color: var(--gold-bright);
}

#app-shell.mode-portrait #top-hud {
  padding: 10px 12px;
  gap: 6px;
}

#app-shell.mode-portrait .hud-left,
#app-shell.mode-portrait .hud-right {
  gap: 5px;
}

#app-shell.mode-portrait .star-progress {
  height: 30px;
  padding: 0 8px;
  gap: 3px;
}

#app-shell.mode-portrait .star-progress .svg-icon {
  width: 14px;
  height: 14px;
}

#app-shell.mode-portrait .scene-badge {
  height: 30px;
  padding: 0 10px;
  font-size: 11px;
}

#app-shell.mode-portrait .scene-badge-title {
  display: none;
}

#app-shell.mode-portrait .hud-btn {
  width: 30px;
  height: 30px;
  padding: 0;
}

#app-shell.mode-portrait .hud-btn-label {
  display: none;
}

/* Main Stage */
#game-stage {
  flex: 1;
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  overflow: hidden;
  padding: 0 22px 18px 22px;
}

/* Gold Frame Styling matching сказка.png & сказка 5.png */
.gold-frame {
  background: var(--bg-panel);
  border: 1.5px solid var(--gold-border);
  border-radius: 16px;
  box-shadow: 0 14px 44px rgba(0, 0, 0, 0.75), inset 0 0 24px rgba(230, 190, 106, 0.07);
  backdrop-filter: blur(10px);
  position: relative;
}

/* Visual Novel Stage Layout */
.vn-layout {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.vn-artwork-stage {
  flex: 1;
  width: 100%;
  max-width: 1220px;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  position: relative;
}

.art-panel {
  height: 100%;
  max-height: 58vh;
  border-radius: 14px;
  overflow: hidden;
  border: 1.5px solid rgba(230, 190, 106, 0.55);
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.8), 0 0 28px rgba(230, 190, 106, 0.12);
  position: relative;
  transition: all 0.45s cubic-bezier(0.22, 1, 0.36, 1);
  background: #060b16;
}

.art-panel img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.art-panel.dimmed {
  opacity: 0.42;
  filter: saturate(0.65) brightness(0.7);
  transform: scale(0.96);
}

.art-panel.active-focus {
  border-color: var(--gold-bright);
  box-shadow: 0 18px 54px rgba(0, 0, 0, 0.85), 0 0 32px rgba(249, 223, 161, 0.25);
  transform: scale(1.01);
}

.art-panel.landscape-single {
  width: 100%;
  max-width: 920px;
  aspect-ratio: 16 / 9;
}

.art-panel.portrait-card {
  aspect-ratio: 1 / 1.48;
}

#app-shell.mode-portrait .vn-artwork-stage {
  gap: 6px;
}

#app-shell.mode-portrait .art-panel.dimmed {
  display: none;
}

/* Double Avatar Trait Badge overlay when double has chosen traits */
.double-trait-preview {
  position: absolute;
  bottom: 12px;
  right: 12px;
  background: rgba(7, 13, 27, 0.9);
  border: 1px solid var(--gold-border);
  border-radius: 12px;
  padding: 6px 12px;
  font-size: 12px;
  color: var(--gold-bright);
  display: flex;
  align-items: center;
  gap: 8px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.65);
}

/* Dialogue Box (Exact match to сказка.png & сказка 4.png) */
.vn-dialogue-wrap {
  width: 100%;
  max-width: 880px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 10;
}

.vn-dialogue-box {
  padding: 18px 26px 20px 26px;
  cursor: pointer;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
  min-height: 118px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.vn-dialogue-box:hover {
  border-color: var(--gold-bright);
  box-shadow: 0 14px 48px rgba(0, 0, 0, 0.82), 0 0 22px rgba(230, 190, 106, 0.18);
}

.dialogue-meta-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid rgba(230, 190, 106, 0.22);
}

.speaker-tag {
  display: inline-flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  row-gap: 4px;
  min-width: 0;
  font-family: var(--font-serif);
  font-size: 19px;
  font-weight: 700;
  color: var(--gold-bright);
  letter-spacing: 0.02em;
  line-height: 1.1;
}

.emotion-pill {
  display: inline-flex;
  align-items: center;
  height: 22px;
  font-family: var(--font-sans);
  font-size: 11px;
  font-weight: 500;
  line-height: 1;
  color: var(--text-soft);
  background: rgba(255, 255, 255, 0.06);
  padding: 0 10px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 240px;
}

.dlg-id-badge {
  font-size: 11px;
  color: rgba(230, 190, 106, 0.65);
  font-family: monospace;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.replay-voice-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 28px;
  padding: 0 12px;
  background: rgba(230, 190, 106, 0.14);
  border: 1px solid rgba(230, 190, 106, 0.5);
  color: var(--gold-bright);
  border-radius: 999px;
  font-family: var(--font-sans);
  font-size: 12px;
  font-weight: 500;
  line-height: 1;
  white-space: nowrap;
  flex-shrink: 0;
  cursor: pointer;
  transition: all 0.15s ease;
}

.replay-voice-btn .svg-icon {
  width: 14px;
  height: 14px;
  display: block;
}

.replay-voice-btn:hover {
  background: rgba(230, 190, 106, 0.28);
  border-color: var(--gold-bright);
  box-shadow: 0 0 12px rgba(230, 190, 106, 0.25);
}

.dialogue-text {
  font-family: var(--font-serif);
  font-size: 23px;
  line-height: 1.42;
  color: var(--text-main);
  letter-spacing: 0.01em;
}

.dialogue-text.thought-style {
  font-style: italic;
  color: var(--text-thought);
}

.dialogue-footer-hint {
  align-self: flex-end;
  margin-top: 8px;
  font-size: 12.5px;
  color: var(--gold-primary);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  line-height: 1;
  opacity: 0.88;
  animation: pulseStar 1.8s infinite ease-in-out;
}

#app-shell.mode-portrait #game-stage {
  padding: 0 14px 14px 14px;
}

#app-shell.mode-portrait .vn-dialogue-box {
  padding: 14px 16px;
  min-height: 104px;
}

#app-shell.mode-portrait .dlg-id-code {
  display: none;
}

#app-shell.mode-portrait .emotion-pill {
  max-width: 155px;
  font-size: 10.5px;
  padding: 0 8px;
}

#app-shell.mode-portrait .dialogue-text {
  font-size: 19.5px;
  line-height: 1.38;
}

@keyframes pulseStar {
  0%, 100% { opacity: 0.45; transform: scale(0.96); }
  50% { opacity: 1; transform: scale(1.08); }
}

/* Choices List (Exact match to сказка 3.png & сказка2.png) */
.choices-container {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 2px;
}

.choice-prompt-label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--gold-bright);
  text-align: center;
  margin-bottom: 2px;
}

.choice-btn {
  width: 100%;
  text-align: left;
  padding: 13px 20px;
  font-family: var(--font-serif);
  font-size: 20px;
  color: var(--text-main);
  background: rgba(8, 14, 29, 0.92);
  border: 1.5px solid var(--gold-border);
  border-radius: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  transition: all 0.2s ease;
}

.choice-btn:hover {
  background: rgba(25, 43, 82, 0.94);
  border-color: var(--gold-bright);
  box-shadow: 0 0 20px rgba(230, 190, 106, 0.3);
  transform: translateX(4px);
}

.choice-btn-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.choice-star {
  color: var(--gold-primary);
  font-size: 17px;
  flex-shrink: 0;
}

.choice-sparkle {
  color: var(--gold-muted);
  font-size: 16px;
}

/* Star Map Stage (СЦ-004) */
.starmap-stage {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  position: relative;
}

.starmap-board {
  position: relative;
  width: 100%;
  max-width: 1020px;
  flex: 1;
  min-height: 0;
  border-radius: 20px;
  overflow: hidden;
  border: 1.5px solid var(--gold-border);
  background: radial-gradient(circle at 50% 48%, rgba(36, 62, 118, 0.45), rgba(6, 11, 24, 0.95));
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.85);
}

.starmap-bg-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0.42;
  filter: contrast(1.1);
}

.starmap-svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.dream-node {
  position: absolute;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  z-index: 5;
  transition: transform 0.25s ease;
}

.dream-node:hover {
  transform: translate(-50%, -50%) scale(1.08);
}

.dream-bubble {
  width: 96px;
  height: 96px;
  border-radius: 50%;
  border: 2px solid var(--gold-bright);
  overflow: hidden;
  position: relative;
  box-shadow: 0 0 26px rgba(249, 223, 161, 0.45);
  background: #0a1326;
}

.dream-node.locked .dream-bubble {
  border-color: rgba(230, 190, 106, 0.32);
  filter: grayscale(0.75) brightness(0.55);
  box-shadow: none;
}

.dream-bubble img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.dream-node-label {
  background: rgba(7, 12, 26, 0.92);
  border: 1px solid var(--gold-border);
  border-radius: 999px;
  padding: 4px 12px;
  font-family: var(--font-serif);
  font-size: 15px;
  font-weight: 600;
  color: var(--gold-bright);
  white-space: nowrap;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.75);
}

.chibi-travelers {
  position: absolute;
  transform: translate(-50%, -100%);
  pointer-events: none;
  z-index: 8;
  transition: left 0.85s cubic-bezier(0.22, 1, 0.36, 1), top 0.85s cubic-bezier(0.22, 1, 0.36, 1);
  display: flex;
  align-items: flex-end;
  gap: 4px;
  filter: drop-shadow(0 0 12px rgba(249, 223, 161, 0.85));
}

/* Mini-Game Stage: Coloring (СЦ-006) & Star Jump (АСТ-04) */
.minigame-wrap {
  width: 100%;
  max-width: 1040px;
  height: 100%;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 10px;
}

.coloring-workspace {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 20px;
}

.canvas-frame {
  position: relative;
  border: 3px solid var(--gold-primary);
  border-radius: 12px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.85), 0 0 30px rgba(230, 190, 106, 0.22);
  background: #0b1325;
  overflow: hidden;
  touch-action: none;
}

#coloring-canvas, #starjump-canvas {
  display: block;
  max-width: 100%;
  max-height: 54vh;
  cursor: crosshair;
}

.palette-column {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px;
}

.swatch-btn {
  width: 52px;
  height: 52px;
  border-radius: 10px;
  border: 2px solid var(--gold-border);
  cursor: pointer;
  position: relative;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.swatch-btn.active {
  transform: scale(1.14);
  border-color: #ffffff;
  box-shadow: 0 0 18px var(--gold-bright);
}

.swatch-btn.completed::after {
  content: "✓";
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  font-weight: 700;
  color: #fff;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.9);
}

#app-shell.mode-portrait .coloring-workspace {
  flex-direction: column;
}

#app-shell.mode-portrait .palette-column {
  flex-direction: row;
  padding: 8px;
}

/* Trait Builder (СЦ-009 / ВБР-05) */
.trait-builder-grid {
  display: grid;
  grid-template-columns: 1fr 1.2fr;
  gap: 18px;
  width: 100%;
  max-width: 960px;
  margin: 0 auto;
  flex: 1;
  min-height: 0;
  align-items: center;
}

#app-shell.mode-portrait .trait-builder-grid {
  grid-template-columns: 1fr;
  overflow-y: auto;
}

.double-portrait-card {
  padding: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  text-align: center;
}

.trait-group {
  margin-bottom: 14px;
}

.trait-group h3 {
  font-family: var(--font-serif);
  font-size: 20px;
  color: var(--gold-bright);
  margin-bottom: 8px;
}

.trait-options-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.trait-option-btn {
  padding: 12px 10px;
  border-radius: 12px;
  border: 1.5px solid var(--gold-muted);
  background: rgba(10, 18, 38, 0.85);
  color: var(--text-main);
  cursor: pointer;
  text-align: center;
  transition: all 0.2s ease;
}

.trait-option-btn.selected {
  border-color: var(--gold-bright);
  background: rgba(42, 68, 125, 0.55);
  box-shadow: 0 0 18px rgba(230, 190, 106, 0.32);
}

/* Modals (Pause Menu matching сказка 5.png, History, Save Slots, Dev Flags) */
#modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(3, 6, 14, 0.78);
  backdrop-filter: blur(6px);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

#modal-overlay.hidden, .hidden {
  display: none !important;
}

#modal-card {
  width: 100%;
  max-width: 560px;
  max-height: 86vh;
  display: flex;
  flex-direction: column;
  padding: 24px 28px;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding-bottom: 14px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--gold-muted);
  position: relative;
}

.modal-header h2 {
  font-family: var(--font-serif);
  font-size: 26px;
  color: var(--gold-bright);
  letter-spacing: 0.04em;
}

.ornament {
  color: var(--gold-primary);
  font-size: 18px;
}

.close-btn {
  position: absolute;
  right: 0;
  top: -2px;
  background: none;
  border: none;
  color: var(--gold-primary);
  font-size: 20px;
  cursor: pointer;
}

#modal-body {
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-right: 4px;
}

.pause-menu-btn {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  padding: 13px 18px;
  background: rgba(13, 23, 46, 0.75);
  border: 1px solid var(--gold-muted);
  border-radius: 12px;
  color: var(--text-main);
  font-family: var(--font-serif);
  font-size: 21px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.pause-menu-btn:hover {
  border-color: var(--gold-bright);
  background: rgba(28, 48, 92, 0.85);
  transform: translateX(4px);
}

.history-item {
  padding: 10px 14px;
  border-radius: 10px;
  background: rgba(12, 21, 42, 0.72);
  border-left: 3px solid var(--gold-primary);
}

.history-item-head {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--gold-bright);
  margin-bottom: 4px;
}

.save-slot-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-radius: 12px;
  border: 1px solid var(--gold-muted);
  background: rgba(11, 20, 40, 0.8);
}

.primary-gold-btn {
  background: linear-gradient(135deg, #e8c170 0%, #c4933b 100%);
  color: #081021;
  font-family: var(--font-sans);
  font-weight: 700;
  font-size: 14px;
  border: none;
  border-radius: 999px;
  padding: 10px 22px;
  cursor: pointer;
  box-shadow: 0 4px 18px rgba(230, 190, 106, 0.4);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.primary-gold-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 24px rgba(230, 190, 106, 0.65);
}

#toast-notification {
  position: fixed;
  bottom: 20px;
  left: 24px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: rgba(9, 16, 33, 0.92);
  border: 1px solid var(--gold-border);
  color: var(--gold-bright);
  padding: 7px 14px;
  border-radius: 999px;
  font-size: 12px;
  line-height: 1;
  z-index: 90;
  pointer-events: none;
}

@media (max-width: 760px) {
  #top-hud {
    padding: 10px 12px;
    gap: 6px;
  }
  .hud-left, .hud-right {
    gap: 5px;
  }
  .star-progress {
    height: 30px;
    padding: 0 8px;
    gap: 3px;
  }
  .star-progress .svg-icon {
    width: 14px;
    height: 14px;
  }
  .scene-badge {
    height: 30px;
    padding: 0 10px;
    font-size: 11px;
  }
  .scene-badge-title {
    display: none;
  }
  .hud-btn {
    width: 30px;
    height: 30px;
    padding: 0;
  }
  .hud-btn-label {
    display: none;
  }
  #game-stage {
    padding: 0 14px 14px 14px;
  }
  .vn-dialogue-box {
    padding: 14px 16px;
  }
  .dlg-id-code {
    display: none;
  }
  .emotion-pill {
    max-width: 155px;
    font-size: 10.5px;
    padding: 0 8px;
  }
  .dialogue-text {
    font-size: 19.5px;
    line-height: 1.38;
  }
  .art-panel.dimmed {
    display: none;
  }
}
