:root {
  --bg: #05070a;
  --panel: #10161e;
  --line: #2ce6ff;
  --accent: #ff2d55;
  --yellow: #ffd84d;
  --green: #4df58b;
  --text: #eef7ff;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: "Trebuchet MS", Verdana, sans-serif;
  background: radial-gradient(circle at top, #122030, var(--bg) 60%);
  color: var(--text);
  padding-top: env(safe-area-inset-top, 0);
}

.wrap {
  max-width: 1480px;
  margin: 0 auto;
  padding: 20px;
}

.hero-image {
  margin-bottom: 18px;
  background: rgba(16, 22, 30, 0.9);
  border: 2px solid #35506b;
  padding: 12px;
}
.hero-image img {
  display: block;
  width: 100%;
  height: auto;
  border: 3px solid #86f1ff;
  box-shadow: inset 0 0 0 2px rgba(255,255,255,0.12);
}
.hero-caption {
  margin: 10px 0 0;
  color: #d0e5f9;
  font-size: 0.95rem;
  opacity: 0.9;
}

.hud {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 20px;
  margin-bottom: 16px;
}

h1 {
  margin: 0;
  font-size: clamp(2rem, 5vw, 4.2rem);
  line-height: 0.95;
  letter-spacing: 0.08em;
  color: var(--line);
  text-shadow: 4px 4px 0 #013e61, -3px 0 0 var(--yellow);
}

h1 span {
  color: var(--accent);
  text-shadow: 4px 4px 0 #6b1029, -3px 0 0 white;
}
.subtitle { margin: 8px 0 0; opacity: 0.85; max-width: 780px; }

.stats {
  display: grid;
  gap: 6px;
  padding: 12px 16px;
  background: rgba(16, 22, 30, 0.9);
  border: 2px solid #35506b;
  min-width: 240px;
}

.game-shell {
  display: grid;
  grid-template-columns: minmax(0, 960px) 340px;
  gap: 18px;
  align-items: start;
}
.game-column {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.stage-wrap {
  position: relative;
}
canvas {
  width: 100%;
  height: auto;
  border: 4px solid #86f1ff;
  background:
    linear-gradient(180deg, rgba(255,255,255,0.04), rgba(255,255,255,0) 18%),
    repeating-linear-gradient(45deg, rgba(255,255,255,0.025) 0 2px, rgba(0,0,0,0.025) 2px 4px),
    #000;
  image-rendering: pixelated;
  box-shadow: 0 0 0 6px #113148;
}
.panel {
  background: var(--panel);
  border: 2px solid #35506b;
  padding: 16px;
}
.panel h2, .inventory-box h3 { margin-top: 0; color: var(--yellow); }
.panel ul, .inventory-box ul {
  padding-left: 18px;
  line-height: 1.5;
}
button {
  width: 100%;
  padding: 12px;
  border: 0;
  background: var(--accent);
  color: white;
  font-weight: 700;
  cursor: pointer;
  margin: 12px 0;
}
.inventory-box {
  border: 1px dashed #496781;
  padding: 10px;
  margin-top: 14px;
}
.message {
  min-height: 96px;
  border: 1px dashed #496781;
  padding: 10px;
  color: #d0e5f9;
}

.dialogue-overlay {
  position: absolute;
  left: 24px;
  right: 24px;
  bottom: 24px;
  background: rgba(10, 14, 20, 0.94);
  border: 3px solid #86f1ff;
  box-shadow: 0 0 0 4px rgba(17, 49, 72, 0.9);
  padding: 14px 16px;
  z-index: 3;
}

.dialogue-overlay.hidden {
  display: none;
}

.dialogue-overlay {
  display: none;
}

.dialogue-title {
  color: var(--yellow);
  font-weight: 700;
  margin-bottom: 8px;
  font-size: 1rem;
}

.dialogue-body {
  color: #eef7ff;
  font-size: 1rem;
  line-height: 1.4;
  margin-bottom: 12px;
}

.dialogue-options {
  display: grid;
  gap: 8px;
}

.dialogue-option {
  width: 100%;
  margin: 0;
  padding: 10px 12px;
  text-align: left;
  border-radius: 10px;
  border: 2px solid #5ec7ff;
  background: #18344b;
  color: #fff;
  font-weight: 600;
}

.touch-controls {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-top: 8px;
  align-items: stretch;
}
.controls-top-row {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 18px;
}

.joystick-cluster, .jump-cluster, .action-cluster {
  background: rgba(16, 22, 30, 0.96);
  border: 2px solid #35506b;
  padding: 12px;
  border-radius: 18px;
}
.joystick-title {
  text-align: center;
  margin-bottom: 10px;
  color: var(--line);
  font-weight: 700;
}
.joystick-base {
  width: 160px;
  height: 160px;
  margin: 0;
  border-radius: 50%;
  border: 3px solid #86f1ff;
  background: radial-gradient(circle at 35% 35%, #2e5778, #17324a 65%);
  position: relative;
  touch-action: none;
}

.joystick-cluster {
  margin-right: auto;
}

.joystick-knob {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #c4f5ff, #6bd8ff 65%);
  border: 3px solid #ffffff;
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  box-shadow: 0 6px 16px rgba(0,0,0,0.35);
}
.jump-cluster {
  margin-left: auto;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  min-width: 220px;
}

.jump-cluster .touch-btn {
  width: 180px;
}

.action-cluster {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
}

.action-row {
  display: flex;
  gap: 10px;
}

.action-row-dialogue,
.action-row-secondary {
  justify-content: space-between;
  flex-wrap: nowrap;
}

.action-row-dialogue .touch-btn,
.action-row-secondary .touch-btn {
  flex: 1 1 0;
}

.touch-btn-nav {
  background: linear-gradient(180deg, #60749b 0%, #374b6b 65%, #243148 100%);
}
.touch-btn {
  margin: 0;
  min-height: 76px;
  border-radius: 16px;
  font-size: 1.08rem;
  background: linear-gradient(180deg, #2a5376 0%, #17324a 62%, #112435 100%);
  border: 2px solid #86f1ff;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  touch-action: manipulation;
  box-shadow: inset 0 2px 0 rgba(255,255,255,0.15), inset 0 -3px 0 rgba(0,0,0,0.22);
}
.touch-btn-jump { background: linear-gradient(180deg, #e44b73 0%, #b82447 65%, #7d1530 100%); }
.touch-btn-take { background: linear-gradient(180deg, #4b95c4 0%, #2d6f9e 65%, #1f4f73 100%); }
.touch-btn-give { background: linear-gradient(180deg, #8166de 0%, #5d4ab4 65%, #3c2d7f 100%); }
.touch-btn-talk { background: linear-gradient(180deg, #47af6b 0%, #2f8b4f 65%, #1f5d35 100%); }

.touch-btn-select {
  background: linear-gradient(180deg, #ffd96f 0%, #ffb62f 65%, #c88312 100%) !important;
  color: #201400;
  animation: select-spin-glow 1.2s linear infinite;
}

@keyframes select-spin-glow {
  0% { box-shadow: inset 0 2px 0 rgba(255,255,255,0.18), inset 0 -3px 0 rgba(0,0,0,0.22), 0 0 0 rgba(255,214,87,0); transform: rotate(0deg); }
  50% { box-shadow: inset 0 2px 0 rgba(255,255,255,0.18), inset 0 -3px 0 rgba(0,0,0,0.22), 0 0 18px rgba(255,214,87,0.55); }
  100% { box-shadow: inset 0 2px 0 rgba(255,255,255,0.18), inset 0 -3px 0 rgba(0,0,0,0.22), 0 0 0 rgba(255,214,87,0); transform: rotate(360deg); }
}

@media (max-width: 1180px) {
  .game-shell { grid-template-columns: 1fr; }
  .hud { align-items: start; flex-direction: column; }
  .stats { min-width: unset; width: 100%; }
}

@media (max-width: 860px) {
  .controls-top-row { align-items: stretch; }
  .joystick-base { margin: 0 auto; }
  .joystick-cluster,
  .jump-cluster { margin: 0; min-width: 0; }
}
