html, body {
  margin: 0;
  padding: 0;
  overflow: hidden;
  background: #111;
  font-family: "Marcellus", serif;
  color: white;
  touch-action: none;
}

#game {
  position: fixed;
  inset: 0;
  z-index: 1;
}

body {
  position: relative;
}

.menu-root {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  pointer-events: auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background:
    linear-gradient(180deg, rgba(28, 16, 10, 0.16) 0%, rgba(14, 12, 10, 0.42) 100%),
    url("../assets/menu-winter.jpg") center center / cover no-repeat;
}

.menu-root.is-hidden {
  display: none;
}

.menu-shell {
  width: min(100%, 1040px);
  display: flex;
  justify-content: center;
  min-height: 100%;
  align-items: center;
}

.menu-card {
  width: min(100%, 720px);
  background: rgba(18, 14, 11, 0.82);
  border: 1px solid rgba(255, 255, 255, 0.18);
  box-shadow: 0 28px 80px rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(8px);
  color: #fff8ec;
  max-height: calc(100vh - 48px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  overflow: auto;
}

.menu-hero {
  text-align: center;
  padding: 52px 48px;
  background:
    radial-gradient(circle at top, rgba(242, 195, 123, 0.16), transparent 46%),
    radial-gradient(circle at bottom, rgba(103, 53, 24, 0.32), transparent 52%),
    rgba(18, 14, 11, 0.82);
}

.menu-logo {
  margin: 0;
  display: inline-flex;
  flex-direction: column;
  gap: 0.08em;
  font-family: "Cinzel Decorative", serif;
  font-size: clamp(44px, 9vw, 96px);
  line-height: 0.88;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #f5e0b8;
  text-shadow:
    0 2px 0 #fff2cf,
    0 5px 0 #8d5428,
    0 12px 24px rgba(0, 0, 0, 0.45);
}

.menu-logo span {
  display: block;
  padding: 0 0.14em;
  background: linear-gradient(180deg, #fff4d6 0%, #f0c982 45%, #bf7138 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.menu-logo span:last-child {
  letter-spacing: 0.16em;
  transform: translateX(0.08em);
}

.menu-subtitle {
  margin-top: 18px;
  font-size: 18px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(255, 248, 236, 0.82);
}

.menu-actions {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-top: 28px;
}

.menu-actions-inline {
  flex-direction: row;
  justify-content: flex-start;
}

.menu-btn,
.menu-mode-btn {
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.06);
  color: #fff8ec;
  min-height: 46px;
  padding: 10px 16px;
  font-size: 16px;
  font-weight: 700;
}

.menu-link-btn {
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}

.menu-btn-primary {
  background: linear-gradient(180deg, #e39b56 0%, #b85d24 100%);
  border-color: rgba(255, 215, 176, 0.4);
  color: #22140b;
}

.menu-btn-danger {
  background: rgba(160, 44, 34, 0.5);
}

.menu-form-card,
.menu-load-card {
  padding: 28px;
}

.menu-panel-title {
  font-size: 28px;
  font-weight: 800;
  margin-bottom: 18px;
}

.menu-field {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
}

.menu-field span {
  font-size: 14px;
  color: rgba(255, 248, 236, 0.76);
}

.menu-field input {
  min-height: 44px;
  padding: 10px 12px;
  background: rgba(0, 0, 0, 0.24);
  border: 1px solid rgba(255, 255, 255, 0.18);
  color: #fff;
  font-size: 16px;
}

.menu-textarea {
  min-height: 120px;
  padding: 12px;
  background: rgba(0, 0, 0, 0.24);
  border: 1px solid rgba(255, 255, 255, 0.18);
  color: #fff;
  font-size: 16px;
  resize: vertical;
  font-family: "Marcellus", serif;
}

.menu-mode-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.menu-mode-btn.is-active {
  background: rgba(227, 155, 86, 0.26);
  border-color: rgba(227, 155, 86, 0.7);
}

.menu-hint {
  font-size: 13px;
  line-height: 1.45;
  color: rgba(255, 248, 236, 0.76);
  margin-bottom: 18px;
}


.item-tooltip {
  position: fixed;
  z-index: 60;
  max-width: 260px;
  padding: 10px 12px;
  background: rgba(14, 12, 10, 0.98);
  border: 2px solid rgba(255, 220, 140, 0.96);
  color: #fff;
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.65);
  pointer-events: none;
  transform: translate3d(0, 0, 0);
}

.item-tooltip.is-hidden {
  display: none;
}

.assistant-root {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  pointer-events: auto;
}

.assistant-root.is-hidden {
  display: none;
}

.assistant-panel {
  width: min(100%, 720px);
  max-height: min(78vh, 760px);
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 18px;
  background: rgba(18, 14, 11, 0.96);
  border: 1px solid rgba(255, 210, 150, 0.24);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.45);
  color: #fff8ec;
}

.assistant-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.assistant-title {
  font-size: 28px;
  font-weight: 800;
}

.assistant-subtitle {
  margin-top: 4px;
  font-size: 13px;
  color: rgba(255, 248, 236, 0.76);
}

.assistant-close,
.assistant-send,
.assistant-quick-btn {
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.06);
  color: #fff8ec;
  min-height: 40px;
  padding: 8px 12px;
  font-size: 14px;
  font-weight: 700;
}

.assistant-quick {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.assistant-quick-btn {
  min-height: 34px;
  font-size: 13px;
}

.assistant-messages {
  min-height: 240px;
  max-height: 420px;
  overflow: auto;
  padding: 10px;
  background: rgba(0, 0, 0, 0.22);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.assistant-message {
  display: flex;
  margin-bottom: 10px;
}

.assistant-message-user {
  justify-content: flex-end;
}

.assistant-message-assistant {
  justify-content: flex-start;
}

.assistant-bubble {
  max-width: min(92%, 520px);
  padding: 10px 12px;
  font-size: 14px;
  line-height: 1.4;
  background: rgba(255, 255, 255, 0.08);
}

.assistant-message-user .assistant-bubble {
  background: rgba(227, 155, 86, 0.2);
}

.assistant-form {
  display: flex;
  gap: 10px;
}

.assistant-input {
  flex: 1 1 auto;
  min-height: 42px;
  padding: 10px 12px;
  background: rgba(0, 0, 0, 0.24);
  border: 1px solid rgba(255, 255, 255, 0.18);
  color: #fff;
  font-size: 16px;
}

.item-tooltip-title {
  font-size: 15px;
  font-weight: 800;
  line-height: 1.1;
}

.item-tooltip-subtitle {
  margin-top: 4px;
  font-size: 12px;
  line-height: 1.2;
  color: rgba(255, 255, 255, 0.84);
}

.world-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
  max-height: min(52vh, 520px);
  overflow: auto;
  padding-right: 6px;
}

.world-card {
  display: grid;
  grid-template-columns: 180px 1fr auto;
  gap: 14px;
  align-items: center;
  padding: 14px;
  background: rgba(255, 255, 255, 0.05);
}

.world-preview {
  width: 180px;
  height: 102px;
  object-fit: cover;
  background: #1b1b1b;
}

.world-preview-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  color: rgba(255, 248, 236, 0.54);
  font-size: 14px;
}

.world-name {
  font-size: 20px;
  font-weight: 800;
  margin-bottom: 8px;
}

.world-line {
  font-size: 14px;
  color: rgba(255, 248, 236, 0.8);
  margin-top: 4px;
}

.world-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 160px;
}

.menu-empty {
  padding: 18px;
  color: rgba(255, 248, 236, 0.7);
}

canvas {
  display: block;
  width: 100vw;
  height: 100vh;
  background: #7ec8ff;
  cursor: crosshair;
}

body.touch-mode canvas {
  cursor: default;
}

.touch-controls {
  position: fixed;
  inset: 0;
  z-index: 35;
  pointer-events: none;
  display: none;
}

body.touch-mode .touch-controls {
  display: block;
}

body.ui-overlay-hidden .touch-controls,
body.menu-open .touch-controls {
  display: none;
}

.touch-cluster {
  position: absolute;
  bottom: calc(18px + env(safe-area-inset-bottom));
  pointer-events: auto;
}

.touch-left {
  left: 12px;
}

.touch-right {
  right: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: stretch;
}

.touch-stick {
  position: relative;
  width: 132px;
  height: 132px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(10, 10, 10, 0.42);
  backdrop-filter: blur(4px);
  pointer-events: auto;
}

.touch-stick-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 52px;
  height: 52px;
  margin-left: -26px;
  margin-top: -26px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.26);
  background: rgba(255, 255, 255, 0.14);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.2);
}

.touch-btn {
  min-width: 62px;
  min-height: 52px;
  font-size: 16px;
  font-weight: bold;
  border: 1px solid rgba(255, 255, 255, 0.24);
  background: rgba(10, 10, 10, 0.7);
  color: #fff;
  border-radius: 12px;
  padding: 10px 12px;
  line-height: 1;
  backdrop-filter: blur(4px);
}

.touch-btn.is-active {
  background: rgba(255, 255, 255, 0.18);
  border-color: rgba(255, 255, 255, 0.4);
}

@media (max-width: 520px) {
  .menu-root {
    padding: calc(8px + env(safe-area-inset-top)) 10px calc(8px + env(safe-area-inset-bottom));
  }

  .menu-hero {
    padding: 26px 16px;
  }

  .menu-form-card,
  .menu-load-card {
    padding: 16px;
  }

  .menu-logo {
    font-size: clamp(34px, 10vw, 56px);
  }

  .menu-subtitle {
    margin-top: 12px;
    font-size: 14px;
  }

  .menu-panel-title {
    font-size: 22px;
    margin-bottom: 14px;
  }

  .menu-actions {
    gap: 10px;
    margin-top: 18px;
  }

  .menu-btn,
  .menu-mode-btn {
    min-height: 42px;
    padding: 8px 12px;
    font-size: 15px;
  }

  .menu-actions-inline,
  .menu-mode-row {
    flex-direction: column;
  }

  .assistant-panel {
    padding: 14px;
    max-height: min(82vh, 760px);
  }

  .assistant-title {
    font-size: 22px;
  }

  .assistant-header,
  .assistant-form {
    flex-direction: column;
  }

  .assistant-close,
  .assistant-send {
    width: 100%;
  }

  .assistant-messages {
    min-height: 210px;
  }

  .world-card {
    grid-template-columns: 1fr;
  }

  .world-preview,
  .world-preview-placeholder {
    width: 100%;
    height: 150px;
  }

  .world-actions {
    min-width: 100%;
  }

  .touch-btn {
    min-width: 56px;
    min-height: 48px;
    font-size: 14px;
  }

  .touch-stick {
    width: 112px;
    height: 112px;
  }

  .touch-stick-knob {
    width: 46px;
    height: 46px;
    margin-left: -23px;
    margin-top: -23px;
  }
}

@media (max-height: 760px) {
  .menu-root {
    align-items: flex-start;
    padding-top: calc(10px + env(safe-area-inset-top));
    padding-bottom: calc(10px + env(safe-area-inset-bottom));
  }

  .menu-shell {
    align-items: flex-start;
  }

  .menu-card {
    max-height: calc(100vh - 20px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  }

  .menu-hero {
    padding: 28px 22px;
  }

  .menu-logo {
    font-size: clamp(34px, 7vw, 60px);
  }

  .menu-subtitle {
    margin-top: 10px;
    font-size: 15px;
  }

  .menu-actions {
    margin-top: 16px;
    gap: 10px;
  }

  .world-list {
    max-height: min(44vh, 360px);
  }
}

@media (max-height: 620px) {
  .menu-hero {
    padding: 20px 18px;
  }

  .menu-logo {
    font-size: clamp(30px, 6vw, 46px);
  }

  .menu-subtitle {
    font-size: 13px;
  }

  .menu-form-card,
  .menu-load-card {
    padding: 14px;
  }

  .menu-panel-title {
    font-size: 20px;
    margin-bottom: 12px;
  }

  .menu-field {
    gap: 6px;
    margin-bottom: 12px;
  }

  .menu-field input {
    min-height: 38px;
    padding: 8px 10px;
    font-size: 15px;
  }

  .menu-btn,
  .menu-mode-btn {
    min-height: 38px;
    font-size: 14px;
  }

  .world-list {
    max-height: min(40vh, 280px);
  }

  .world-preview,
  .world-preview-placeholder {
    height: 120px;
  }
}
.menu-btn-horror {
  color: #ffd599;
  border-color: #bc7138;
  background: linear-gradient(135deg, #392132, #382c19);
  box-shadow: inset 0 0 20px #110e1680;
}
.menu-btn-horror:hover {
  background: linear-gradient(135deg, #56304a, #69451f);
  border-color: #eead62;
}

.menu-btn-christmas { border-color: #afceaf; background: linear-gradient(120deg, #245d4d, #377969); color: #fff0c5; }
.menu-btn-christmas:hover { background: linear-gradient(120deg, #30755f, #46917e); }
