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

html, body {
  width: 100%;
  height: 100%;
  background: #111;
  overflow: hidden;
  font-family: 'Press Start 2P', monospace;
}

/* Prevent double-tap zoom on all buttons */
button { touch-action: manipulation; }

/* ── App shell ── */
#app {
  position: relative;   /* anchor for main-menu absolute overlay */
  display: flex;
  flex-direction: column;
  height: 100vh;        /* fallback for older desktop browsers */
  height: 100dvh;       /* dynamic viewport height (mobile, overrides above) */
  max-width: 480px;
  margin: 0 auto;
  background: #000;
  border-left: 1px solid #222;
  border-right: 1px solid #222;
}

/* ── HUD ── */
#hud {
  flex-shrink: 0;
  height: 48px;
  background: #0d0d0d;
  border-bottom: 2px solid #2a2a2a;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 8px;
  gap: 6px;
}

.hud-block {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: 1;
}

.hud-right {
  justify-content: flex-end;
}

.hud-label {
  font-size: 7px;
  color: #888;
  width: 14px;
  flex-shrink: 0;
}

.bar-track {
  flex: 1;
  height: 10px;
  background: #1a1a1a;
  border: 1px solid #333;
  overflow: hidden;
  max-width: 80px;
}

.bar {
  height: 100%;
  transition: width 0.2s ease;
}

.hp-bar { background: #cc2222; }
.mp-bar { background: #2244cc; }

.hud-val {
  font-size: 6px;
  color: #aaa;
  min-width: 30px;
}

.hud-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
}

#level-text {
  font-size: 7px;
  color: #ffcc44;
}

#gold-text {
  font-size: 6px;
  color: #cc9900;
}

/* ── Game area ── */
#game-wrap {
  flex: 1;
  min-height: 0;
  position: relative;
  overflow: hidden;
  background: #000;
}

#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  cursor: none;
}

/* ── Floating message ── */
#message {
  position: absolute;
  bottom: 8px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,0.85);
  border: 2px solid #555;
  color: #ffcc44;
  font-size: 8px;
  padding: 6px 10px;
  white-space: nowrap;
  pointer-events: none;
  z-index: 10;
}

/* ── Dialog box ── */
#dialog {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: #0d0d0d;
  border-top: 2px solid #555;
  padding: 10px 12px 8px;
  z-index: 20;
}

#dialog-name {
  font-size: 8px;
  color: #ffcc44;
  margin-bottom: 6px;
}

#dialog-text {
  font-size: 7px;
  color: #ddd;
  line-height: 1.8;
  min-height: 40px;
}

#dialog-next {
  text-align: right;
  font-size: 8px;
  color: #888;
  margin-top: 4px;
  animation: blink 1s infinite;
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0; }
}

/* ── Controls — 3×3 Gurk-style grid ── */
#controls {
  flex-shrink: 0;
  background: #1a1a1a;
  border-top: 2px solid #333;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  gap: 5px;
  padding: 5px;
  /* Height: fill remaining space, but cap so it doesn't overwhelm small screens */
  height: clamp(150px, 36vw, 200px);
}

/* All control buttons share base style */
.ctrl-btn {
  background: #2e2e2e;
  color: #cccccc;
  border: 2px solid #4a4a4a;
  border-radius: 5px;
  font-family: 'Press Start 2P', monospace;
  font-size: clamp(6px, 2vw, 9px);
  cursor: pointer;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  outline: none;
  display: flex;
  align-items: center;
  justify-content: center;
  letter-spacing: 0;
  padding: 0 2px;
}

/* Directional buttons — slightly brighter arrow */
.ctrl-dir {
  font-size: clamp(14px, 4vw, 20px);
  color: #ffffff;
}

/* Side/action buttons — slightly dimmer text */
.ctrl-side {
  color: #aaaaaa;
}

/* Press feedback */
.ctrl-btn:active,
.ctrl-btn.pressed {
  background: #484848;
  border-color: #888;
  color: #fff;
}

/* Dark center spacer */
.ctrl-center {
  background: #111;
  border-radius: 5px;
  border: 2px solid #222;
}

/* ── HUD: XP mini bar ── */
.xp-mini-track {
  width: 48px;
  height: 3px;
  background: #1a1a1a;
  border: 1px solid #333;
  overflow: hidden;
  margin: 1px 0;
}

.xp-bar-mini {
  height: 100%;
  background: #aa8800;
  transition: width 0.3s ease;
  width: 0%;
}

/* ── Overlay screens ── */
.overlay-screen {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.90);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 10px;
}

.overlay-panel {
  background: #0c0c0c;
  border: 2px solid #555;
  border-radius: 4px;
  padding: 14px 14px 10px;
  width: 100%;
  max-width: 310px;
  max-height: 96%;
  overflow-y: auto;
  font-family: 'Press Start 2P', monospace;
}

.overlay-title {
  font-size: 10px;
  color: #ffcc44;
  text-align: center;
  margin-bottom: 4px;
}

.overlay-subtitle {
  font-size: 7px;
  color: #aaa;
  text-align: center;
  margin-bottom: 10px;
}

.overlay-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.ovl-lv {
  font-size: 8px;
  color: #ffcc44;
}

.ovl-divider {
  border-top: 1px solid #2a2a2a;
  margin: 8px 0;
}

/* LU: Points row */
.lu-points-row {
  font-size: 8px;
  color: #bbb;
  text-align: center;
  margin-bottom: 6px;
}

.lu-highlight { color: #ffcc44; }

/* Attribute rows */
.attr-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.attr-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.attr-name {
  font-size: 6px;
  color: #999;
  flex: 1;
  white-space: nowrap;
}

.attr-val {
  font-size: 9px;
  color: #fff;
  width: 18px;
  text-align: right;
  flex-shrink: 0;
}

.attr-btn {
  width: 38px;
  height: 38px;
  font-size: 20px;
  font-weight: bold;
  background: #222;
  border: 2px solid #444;
  border-radius: 4px;
  cursor: pointer;
  touch-action: none;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  line-height: 1;
  flex-shrink: 0;
  font-family: monospace;
  color: #fff;
  -webkit-user-select: none;
  user-select: none;
}

.attr-btn:disabled { color: #333; border-color: #2a2a2a; }
.attr-btn:active:not(:disabled) { background: #3a3a3a; }

.attr-plus  { color: #55dd55; border-color: #2a4a2a; }
.attr-minus { color: #dd5555; border-color: #4a2a2a; }

/* LU: Stat preview */
.derived-preview { margin-top: 2px; }

.preview-row {
  display: flex;
  justify-content: space-around;
  font-size: 7px;
  color: #888;
  padding: 2px 0;
}

.preview-row span span { color: #ffcc44; }

/* Confirm / Back buttons */
.ovl-confirm-btn {
  display: block;
  width: 100%;
  margin-top: 12px;
  padding: 11px;
  background: #0e280e;
  color: #44cc44;
  border: 2px solid #2a4a2a;
  border-radius: 4px;
  font-family: 'Press Start 2P', monospace;
  font-size: 8px;
  cursor: pointer;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  outline: none;
}

.ovl-confirm-btn:disabled {
  background: #111;
  color: #333;
  border-color: #222;
}

.ovl-confirm-btn:active:not(:disabled) { background: #163016; }

/* CS: Character screen */
.cs-section-title {
  font-size: 6px;
  color: #666;
  letter-spacing: 1px;
  margin-bottom: 5px;
}

.cs-row {
  display: flex;
  justify-content: space-between;
  font-size: 7px;
  color: #bbb;
  padding: 3px 0;
}

.cs-row span:last-child { color: #ffcc44; }

.cs-xp-row {
  font-size: 6px;
  color: #888;
  margin-bottom: 4px;
}

.cs-xp-track {
  height: 6px;
  margin-bottom: 4px;
  max-width: 100%;
}

.xp-bar { background: #aa8800; }

.cs-points {
  font-size: 7px;
  color: #ffcc44;
  text-align: center;
  margin-top: 8px;
  padding: 6px 4px;
  border: 1px solid #554400;
  background: #120f00;
}

/* ── Combat controls ── */
#combat-controls {
  flex-shrink: 0;
  height: clamp(150px, 36vw, 200px);
  background: #0d0d0d;
  border-top: 2px solid #2a2a2a;
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  gap: 5px;
  padding: 5px;
}

.combat-btn {
  background: #101020;
  color: #ccccff;
  border: 2px solid #333366;
  border-radius: 5px;
  font-family: 'Press Start 2P', monospace;
  font-size: clamp(8px, 2.8vw, 11px);
  cursor: pointer;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  outline: none;
  transition: background 0.1s;
}

.combat-btn:active:not(:disabled) {
  background: #202044;
  border-color: #6666cc;
  color: #fff;
}

.combat-btn:disabled {
  color: #333;
  border-color: #1a1a2a;
  background: #080810;
}

/* ── Inventory overlay ── */
.inv-panel { max-height: 92%; }

.inv-count {
  font-size: 7px;
  color: #666;
}

.inv-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 8px;
}

.inv-tab-btn {
  flex: 1;
  padding: 8px 4px;
  background: #1a1a1a;
  color: #888;
  border: 2px solid #333;
  border-radius: 4px;
  font-family: 'Press Start 2P', monospace;
  font-size: 7px;
  cursor: pointer;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

.inv-tab-btn.active {
  background: #0e280e;
  color: #44cc44;
  border-color: #2a4a2a;
}

.inv-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 210px;
  overflow-y: auto;
  margin-bottom: 4px;
}

.inv-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 4px;
  border: 1px solid #1e1e1e;
  border-radius: 3px;
  background: #090909;
}

.inv-type {
  font-size: 6px;
  color: #555;
  flex-shrink: 0;
  width: 22px;
}

.inv-name {
  flex: 1;
  font-size: 6px;
  color: #ccc;
}

.inv-action-btn {
  padding: 5px 7px;
  background: #0e1e0e;
  color: #88cc88;
  border: 1px solid #2a3a2a;
  border-radius: 3px;
  font-family: 'Press Start 2P', monospace;
  font-size: 5px;
  cursor: pointer;
  touch-action: none;
  flex-shrink: 0;
  -webkit-user-select: none;
  user-select: none;
}

.inv-action-btn:active:not(:disabled):not(.disabled) { background: #1a2e1a; }

.inv-action-btn:disabled,
.inv-action-btn.disabled {
  color: #444;
  border-color: #1e1e1e;
  background: #080808;
  cursor: default;
}

.inv-empty {
  font-size: 7px;
  color: #444;
  text-align: center;
  padding: 18px 0;
}

/* Equipment tab */
.equip-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 4px;
  border-bottom: 1px solid #181818;
}

.equip-slot-label {
  font-size: 6px;
  color: #666;
  width: 52px;
  flex-shrink: 0;
}

.equip-item-name {
  flex: 1;
  font-size: 6px;
  color: #ccc;
}

.equip-empty { color: #333; }

.equip-stats {
  margin-top: 8px;
  padding: 6px;
  background: #090909;
  border: 1px solid #1e1e1e;
  border-radius: 3px;
}

.equip-stat-row {
  display: flex;
  justify-content: space-around;
  font-size: 6px;
  color: #666;
  padding: 2px 0;
}

.equip-stat-row span:nth-child(even) { color: #ffcc44; }

/* ── Spell screen ── */
.spell-panel { max-height: 88%; }

.spell-mp-info {
  font-size: 7px;
  color: #6688ff;
}

.spell-list { max-height: 230px; }

.spell-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 4px;
  border: 1px solid #1e1e1e;
  border-radius: 3px;
  background: #090909;
}

.spell-nomp { opacity: 0.45; }

.spell-elem {
  font-size: 6px;
  flex-shrink: 0;
  width: 26px;
}

.spell-name-text {
  flex: 1;
  font-size: 6px;
  color: #ccc;
}

.spell-cost {
  font-size: 6px;
  color: #6688ff;
  flex-shrink: 0;
  width: 34px;
  text-align: right;
}

/* Spell info rows inside inventory Zauber tab */
.spell-info-row { background: #090909; border-color: #1a1a1a; }

.spell-desc-row {
  font-size: 5px;
  color: #555;
  padding: 2px 4px 4px 32px;
  line-height: 1.6;
}

/* ── Dialog Choices ── */
#dialog-choices {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-top: 8px;
}

.dialog-choice-btn {
  padding: 9px 10px;
  background: #141e14;
  color: #88cc88;
  border: 1px solid #2a3a2a;
  border-radius: 3px;
  font-family: 'Press Start 2P', monospace;
  font-size: 7px;
  cursor: pointer;
  touch-action: none;
  text-align: left;
  -webkit-user-select: none;
  user-select: none;
  outline: none;
}
.dialog-choice-btn:active { background: #1e2e1e; }

/* ── Shop Screen ── */
.shop-panel { max-height: 92%; }

.shop-gold-display {
  font-size: 8px;
  color: #cc9900;
}

.shop-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 4px;
  border: 1px solid #1e1e1e;
  border-radius: 3px;
  background: #090909;
  margin-bottom: 3px;
}

.shop-item-name {
  flex: 1;
  font-size: 6px;
  color: #ccc;
}

.shop-item-price {
  font-size: 6px;
  color: #cc9900;
  flex-shrink: 0;
  width: 34px;
  text-align: right;
}

.shop-price-grey { color: #444; }

/* ── Main Menu ── */
.main-menu-screen {
  position: absolute;
  inset: 0;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}

.main-menu-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 24px 16px;
}

.main-menu-logo {
  font-size: 36px;
  color: #88cc88;
  letter-spacing: 10px;
  text-shadow: 0 0 20px #44aa44;
  animation: logo-pulse 2.5s ease-in-out infinite alternate;
}

@keyframes logo-pulse {
  from { text-shadow: 0 0 10px #336633; }
  to   { text-shadow: 0 0 30px #88ff88, 0 0 60px #44aa44; }
}

.main-menu-subtitle {
  font-size: 6px;
  color: #446644;
  letter-spacing: 3px;
  margin-top: -8px;
}

.main-menu-buttons {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 20px;
  width: 200px;
}

.main-menu-btn {
  padding: 13px 8px;
  background: #0a140a;
  color: #88cc88;
  border: 1px solid #2a4a2a;
  border-radius: 3px;
  font-family: 'Press Start 2P', monospace;
  font-size: 9px;
  cursor: pointer;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  outline: none;
  text-align: center;
}
.main-menu-btn:active { background: #142014; border-color: #4a7a4a; }

.main-menu-version {
  font-size: 5px;
  color: #222;
  margin-top: 24px;
}

/* ── Pause Menu ── */
.pause-panel {
  width: 210px;
}

.pause-buttons {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 10px 0;
}

.pause-btn {
  padding: 10px 12px;
  background: #0a140a;
  color: #88cc88;
  border: 1px solid #2a3a2a;
  border-radius: 3px;
  font-family: 'Press Start 2P', monospace;
  font-size: 7px;
  cursor: pointer;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  outline: none;
  text-align: left;
  width: 100%;
}
.pause-btn:active         { background: #142014; }
.pause-btn-danger         { color: #cc5555; border-color: #3a2020; margin-top: 4px; }
.pause-btn-danger:active  { background: #1a0808; }
.pause-btn-sound          { color: #88aacc; border-color: #223344; }
.pause-btn-sound:active   { background: #0a1020; }

/* ── Quest Journal ── */
.quest-panel { max-height: 92%; }

.quest-card {
  background: #090909;
  border: 1px solid #1e2e1e;
  border-radius: 3px;
  padding: 6px;
  margin-bottom: 4px;
}

.quest-done {
  border-color: #1a1a1a;
  opacity: 0.55;
}

.quest-title {
  font-size: 7px;
  color: #88cc88;
  margin-bottom: 4px;
  line-height: 1.5;
}

.quest-desc {
  font-size: 5px;
  color: #888;
  line-height: 1.6;
  margin-bottom: 4px;
}

.quest-obj {
  margin-top: 3px;
}

.quest-obj-text {
  font-size: 5px;
  color: #aaa;
}

.quest-obj-bar-track {
  height: 3px;
  background: #222;
  border-radius: 2px;
  margin-top: 2px;
}

.quest-obj-bar {
  height: 100%;
  background: #448844;
  border-radius: 2px;
  transition: width 0.3s;
}

.quest-reward {
  font-size: 5px;
  color: #cc9900;
  margin-top: 4px;
}

/* ── End Screen ── */
.end-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  padding: 28px 20px;
  text-align: center;
}

.end-title {
  font-size: 28px;
  color: #ffcc44;
  letter-spacing: 6px;
  text-shadow: 0 0 24px #ffaa00, 0 0 48px #ff8800;
  animation: logo-pulse 2s ease-in-out infinite alternate;
}

.end-subtitle {
  font-size: 9px;
  color: #ffee88;
  letter-spacing: 2px;
  margin-top: -6px;
}

.end-story {
  font-size: 7px;
  color: #aaaaaa;
  line-height: 2.2;
  margin-top: 4px;
}

.end-credits {
  font-size: 6px;
  color: #446644;
  letter-spacing: 2px;
  margin-top: 8px;
}

/* ── Utility ── */
.hidden {
  display: none !important;
}

/* ── Landscape warning ── */
@media (orientation: landscape) and (max-height: 500px) {
  #app::after {
    content: 'Bitte Gerät drehen ↺';
    position: fixed;
    inset: 0;
    background: #000;
    color: #fff;
    font-family: 'Press Start 2P', monospace;
    font-size: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 999;
  }
}
