@import url('https://fonts.googleapis.com/css2?family=Cinzel:wght@400;600;700&family=Crimson+Text:ital,wght@0,400;0,600;1,400&display=swap');

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --gold: #f0c040;
  --gold-dark: #c8a020;
  --stone: #5a5a5a;
  --stone-mid: #686868;
  --stone-light: #7a7a7a;
  --border-gold: #8b6914;
  --text-warm: #e8d4a0;
  --text-muted: #a07030;
}

html, body {
  height: 100%;
}

body {
  background: #070807;
  font-family: 'Crimson Text', Georgia, serif;
  color: var(--text-warm);
  min-height: 100vh;
  overflow: hidden;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
  position: relative;
}

#header {
  background: #4a4a4a;
  border-bottom: 2px solid var(--border-gold);
  padding: 8px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-shrink: 0;
  box-shadow: 0 2px 16px rgba(240,192,64,0.12);
}

#app-title {
  font-family: 'Cinzel', serif;
  font-size: 20px;
  color: var(--gold);
  text-shadow: 0 0 24px rgba(240,192,64,0.6);
  letter-spacing: 3px;
  font-weight: 700;
}

#level-info {
  text-align: center;
  flex: 1;
  cursor: pointer;
  border: 0;
  border-radius: 6px;
  padding: 4px 8px;
}

#level-info:hover {
  background: rgba(255, 220, 140, 0.06);
}

.level-name {
  font-family: 'Cinzel', serif;
  font-size: 14px;
  color: #f0d060;
  font-weight: 600;
}

.level-sub {
  font-size: 11px;
  color: var(--text-muted);
  font-family: 'Cinzel', serif;
  margin-top: 2px;
}

.header-side {
  display: flex;
  align-items: center;
  gap: 10px;
}

.header-badge {
  font-family: 'Cinzel', serif;
  font-size: 11px;
  color: var(--text-muted);
  border: 1px solid var(--border-gold);
  padding: 4px 10px;
  border-radius: 4px;
  white-space: nowrap;
}

.language-picker,
.level-jump {
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: 'Cinzel', serif;
  font-size: 11px;
  color: var(--text-muted);
}

.language-picker select,
.level-jump select {
  background: #3f3f3f;
  color: var(--text-warm);
  border: 1px solid var(--border-gold);
  border-radius: 6px;
  padding: 5px 8px;
  font-family: 'Cinzel', serif;
  font-size: 11px;
}

.level-jump select {
  max-width: min(240px, 24vw);
}

#tutorial-box {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.72);
  padding: 20px;
  color: var(--text-warm);
  display: grid;
  align-items: center;
  justify-items: center;
  z-index: 215;
}

#tutorial-box.collapsed {
  display: none;
}

.mission-window {
  width: min(92vw, 620px);
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 16px;
  align-items: start;
  padding: 28px 32px;
  border: 3px solid var(--gold);
  border-radius: 14px;
  background: var(--stone);
  box-shadow: 0 0 70px rgba(240,192,64,0.28);
}

.mission-copy {
  min-width: 0;
}

#mission-title {
  font-family: 'Cinzel', serif;
  color: var(--gold);
  font-size: 22px;
  letter-spacing: 1px;
  margin-bottom: 10px;
}

#btn-mission-close {
  grid-column: 1 / -1;
  justify-self: end;
}

.dwarf-portrait {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 2px solid var(--border-gold);
  background: var(--stone-mid);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
}

.dwarf-portrait img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  border-radius: 50%;
}

#tutorial-text {
  font-style: italic;
  font-size: 17px;
  line-height: 1.6;
}

#game-area {
  display: flex;
  flex: 1;
  overflow: hidden;
  min-width: 0;
  min-height: 0;
}

#grid-container {
  flex: 1;
  overflow: hidden;
  position: relative;
  background:
    radial-gradient(ellipse at 50% 38%, rgba(42, 45, 43, 0.78) 0%, rgba(15, 16, 16, 0.96) 55%, #050606 100%),
    linear-gradient(90deg, rgba(0, 0, 0, 0.54), transparent 18%, transparent 78%, rgba(0, 0, 0, 0.62));
  min-width: 0;
  min-height: 0;
}

#zoom-controls {
  position: absolute;
  right: 10px;
  top: 10px;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px;
  border: 1px solid rgba(200, 185, 142, 0.45);
  border-radius: 8px;
  background: rgba(42, 42, 42, 0.84);
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.22);
  z-index: 5;
}

.zoom-btn {
  width: 32px;
  height: 32px;
  border: 1.5px solid var(--border-gold);
  border-radius: 6px;
  background: var(--stone-mid);
  color: var(--text-warm);
  cursor: pointer;
  font-family: 'Cinzel', serif;
  font-size: 16px;
  line-height: 1;
}

#zoom-slider {
  width: 112px;
  accent-color: var(--gold);
}

#grid-canvas {
  width: 100%;
  height: 100%;
  display: block;
  cursor: default;
  touch-action: none;
}

.pixi-render-layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  pointer-events: none;
  z-index: 2;
}

.mentor-card {
  position: absolute;
  left: 12px;
  top: 12px;
  display: grid;
  grid-template-columns: 150px minmax(0, 250px);
  align-items: center;
  gap: 12px;
  z-index: 6;
  color: var(--text-warm);
  cursor: pointer;
  max-width: min(420px, calc(100vw - 24px));
}

.mentor-card.bubble-hidden {
  grid-template-columns: 150px;
  max-width: 174px;
}

.mentor-card img {
  width: 150px;
  height: 150px;
  object-fit: contain;
  border-radius: 0;
  filter: drop-shadow(0 0 18px rgba(255, 226, 150, 0.38)) drop-shadow(0 8px 18px rgba(0, 0, 0, 0.55));
}

.mentor-card.bubble-hidden .mentor-bubble {
  display: none;
}

.mentor-bubble {
  padding: 11px 13px 12px;
  border: 1px solid rgba(218, 191, 118, 0.54);
  border-radius: 8px;
  background: rgba(12, 13, 12, 0.78);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.34), inset 0 0 18px rgba(240, 192, 64, 0.05);
  backdrop-filter: blur(3px);
  font-size: 15px;
  line-height: 1.28;
}

.mentor-bubble::before {
  content: '';
  position: absolute;
  left: 150px;
  top: 64px;
  width: 10px;
  height: 10px;
  transform: rotate(45deg);
  border-left: 1px solid rgba(218, 191, 118, 0.54);
  border-bottom: 1px solid rgba(218, 191, 118, 0.54);
  background: rgba(12, 13, 12, 0.78);
}

.mentor-name {
  margin-bottom: 3px;
  font-family: 'Cinzel', serif;
  font-size: 11px;
  color: var(--gold);
  letter-spacing: 0.6px;
}

#mentor-comment {
  display: -webkit-box;
  overflow: hidden;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
}

#inventory-bar {
  background: #484848;
  border-top: 2px solid var(--stone-light);
  padding: 10px 14px 12px;
  display: grid;
  gap: 10px;
  flex-shrink: 0;
  position: relative;
  min-width: 0;
  overflow: hidden;
}

#inventory-bar::before {
  content: '';
  position: absolute;
  inset: 0 0 auto 0;
  height: 100%;
  pointer-events: none;
  background:
    linear-gradient(128deg, transparent 24%, rgba(255, 245, 200, 0.12) 33%, rgba(255, 255, 255, 0.18) 36%, transparent 44%),
    linear-gradient(128deg, transparent 46%, rgba(255, 220, 120, 0.08) 54%, transparent 61%);
  opacity: 0.35;
}

#toolbox {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 8px;
  position: relative;
  z-index: 1;
  min-width: 0;
  width: 100%;
  max-width: 100%;
  overflow: hidden;
}

.tool-crate-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 7px;
  align-items: end;
  min-width: 0;
  width: 100%;
  max-width: 100%;
}

.tool-crate {
  background: transparent;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  overflow: visible;
  min-width: 0;
}

.tool-crate-toggle {
  width: 100%;
  aspect-ratio: 180 / 92;
  min-height: 0;
  display: block;
  padding: 0;
  background: transparent;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  position: relative;
  filter: drop-shadow(0 7px 10px rgba(0, 0, 0, 0.2));
}

.tool-crate-toggle:hover {
  filter: brightness(1.08);
}

.tool-crate-image {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
}

.tool-crate-chevron {
  position: absolute;
  right: 6px;
  bottom: 5px;
  font-size: 10px;
  color: #f1d47f;
  transition: transform 0.15s ease;
  z-index: 1;
}

.tool-crate.open .tool-crate-chevron {
  transform: rotate(180deg);
}

.tool-crate-content {
  display: none;
}

.tool-crate-drawer .tool-crate-content {
  display: block;
  padding: 8px;
  border: 1px solid rgba(240, 192, 64, 0.12);
  border-radius: 7px;
  background: rgba(26, 18, 8, 0.32);
  min-width: 0;
  width: 100%;
  max-width: 100%;
  overflow: hidden;
}

.tool-crate-drawer {
  min-width: 0;
  width: 100%;
  max-width: 100%;
  overflow: hidden;
}

.tool-crate-grid {
  display: flex;
  grid-template-columns: none;
  gap: 8px;
  padding: 2px 2px 5px;
  min-width: 0;
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  overscroll-behavior-x: contain;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  touch-action: pan-x;
}

.tool-item {
  flex: 0 0 96px;
  min-height: 86px;
  background: var(--stone-mid);
  border: 1.5px solid var(--stone-light);
  border-radius: 4px;
  padding: 8px 6px;
  cursor: grab;
  text-align: center;
  transition: border-color 0.15s, background 0.15s, transform 0.1s;
  user-select: none;
  position: relative;
  overflow: hidden;
}

.tool-item::before {
  content: '';
  position: absolute;
  inset: -12% auto auto -24%;
  width: 88%;
  height: 46%;
  background: linear-gradient(120deg, transparent 18%, rgba(255, 247, 214, 0.22) 42%, rgba(255, 255, 255, 0.38) 48%, transparent 56%);
  opacity: 0.32;
  pointer-events: none;
}

.tool-item:hover:not(.depleted) {
  border-color: var(--gold-dark);
  background: #2e1e0e;
  transform: scale(1.03);
}

.tool-item.selected {
  border-color: #f6de83;
  background: #3b2812;
  box-shadow: 0 0 0 2px rgba(246, 222, 131, 0.18), 0 0 18px rgba(240,192,64,0.24);
  transform: scale(1.03);
}

.tool-item.depleted {
  opacity: 0.35;
  cursor: not-allowed;
}

.tool-item .tool-icon { font-size: 22px; display: block; margin-bottom: 3px; }
.tool-mirror-preview {
  --mirror-angle: calc((var(--mirror-rotation) * 60deg) + 30deg);
  position: relative;
  display: block;
  width: 54px;
  height: 54px;
  margin: 2px auto 6px;
}

.tool-mirror-preview-back,
.tool-mirror-preview-front,
.tool-mirror-preview-glint {
  position: absolute;
  left: 50%;
  top: 50%;
  transform-origin: center;
  border-radius: 999px;
}

.tool-mirror-preview-back {
  width: 8px;
  height: 38px;
  background: #1d1d1d;
  transform: translate(-50%, -50%) rotate(var(--mirror-angle)) translateX(-4px);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
}

.tool-mirror-preview-front {
  width: 6px;
  height: 38px;
  background: linear-gradient(180deg, #eef6ff, #b8d6ff);
  transform: translate(-50%, -50%) rotate(var(--mirror-angle)) translateX(3px);
  box-shadow: 0 0 10px rgba(96, 128, 255, 0.28);
}

.tool-mirror-preview-glint {
  width: 2px;
  height: 26px;
  background: rgba(255, 255, 255, 0.92);
  transform: translate(-50%, -50%) rotate(var(--mirror-angle)) translateX(5px);
}

.tool-mirror-preview-arrow {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 0;
  height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-bottom: 11px solid #ffe08a;
  transform: translate(-50%, -50%) rotate(calc(var(--mirror-angle) + 90deg)) translateY(-24px);
  filter: drop-shadow(0 0 4px rgba(255, 224, 138, 0.35));
}

.tool-prism-preview,
.tool-splitter-preview {
  position: relative;
  display: block;
  width: 54px;
  height: 54px;
  margin: 2px auto 6px;
}

.tool-prism-preview svg,
.tool-splitter-preview svg {
  display: block;
  width: 100%;
  height: 100%;
}

.tool-splitter-preview svg {
  overflow: visible;
}

.splitter-preview-input {
  stroke: rgba(255, 255, 255, 0.78);
  stroke-width: 3.4;
  stroke-linecap: round;
}

.splitter-preview-ray line {
  filter: drop-shadow(0 0 2px rgba(58, 39, 16, 0.95));
  stroke: currentColor;
  stroke-width: 4;
  stroke-linecap: round;
}

.splitter-preview-ray {
  color: var(--splitter-color, #ffd060);
}

.splitter-preview-ray polygon {
  filter: drop-shadow(0 0 2px rgba(58, 39, 16, 0.95));
  fill: currentColor;
}

.splitter-preview-core {
  fill: #f4c456;
  stroke: #101216;
  stroke-width: 1.4;
}

.splitter-preview-spark {
  fill: #fff1b8;
}

.tool-prism-preview-triangle {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 0;
  height: 0;
  border-left: 17px solid transparent;
  border-right: 17px solid transparent;
  border-bottom: 30px solid var(--prism-color, #ffffff);
  transform: translate(-50%, -54%);
  filter: drop-shadow(0 0 7px var(--prism-glow, rgba(255,255,255,0.4)));
}

.tool-prism-preview-beam {
  position: absolute;
  top: 50%;
  height: 4px;
  border-radius: 999px;
  transform: translateY(-50%);
}

.tool-prism-preview-beam-in {
  left: 4px;
  width: 16px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 0 10px rgba(255, 255, 255, 0.38);
}

.tool-prism-preview-beam-out {
  right: 4px;
  width: 16px;
  background: var(--prism-color, #ffffff);
  box-shadow: 0 0 10px var(--prism-glow, rgba(255,255,255,0.4));
}

.tool-prism-preview-shine {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 5px;
  height: 18px;
  background: rgba(255, 255, 255, 0.9);
  transform: translate(-2px, -18px) rotate(22deg);
  border-radius: 999px;
  opacity: 0.82;
}

.tool-splitter-preview-stem,
.tool-splitter-preview-branch {
  position: absolute;
  left: 50%;
  top: 50%;
  height: 4px;
  border-radius: 999px;
  background: var(--splitter-color, #ffd060);
  transform-origin: left center;
  box-shadow: 0 0 8px color-mix(in srgb, var(--splitter-color, #ffd060) 45%, transparent);
}

.tool-splitter-preview-stem {
  width: 18px;
  transform: translate(-2px, -2px);
}

.tool-splitter-preview-core {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: color-mix(in srgb, var(--splitter-color, #ffd060) 82%, white 18%);
  transform: translate(-50%, -50%);
  box-shadow: 0 0 10px color-mix(in srgb, var(--splitter-color, #ffd060) 55%, transparent);
}

.tool-splitter-preview-branch {
  width: 16px;
  transform: translate(-1px, -2px) rotate(var(--branch-angle, 0rad));
}

.tool-splitter-preview-tip {
  position: absolute;
  right: -1px;
  top: 50%;
  width: 0;
  height: 0;
  border-left: 6px solid var(--splitter-color, #ffd060);
  border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
  transform: translateY(-50%);
  filter: drop-shadow(0 0 4px color-mix(in srgb, var(--splitter-color, #ffd060) 40%, transparent));
}

.tool-item .tool-name { font-size: 10px; color: var(--gold-dark); font-family: 'Cinzel', serif; line-height: 1.3; }
.tool-item .tool-meta {
  display: block;
  margin-top: 4px;
  font-size: 9px;
  color: #e7d08d;
  font-family: 'Cinzel', serif;
  letter-spacing: 0.4px;
}
.tool-item .tool-count {
  position: absolute;
  top: 4px;
  right: 6px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  font-family: 'Cinzel', serif;
}

.tool-submenu {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid rgba(240, 192, 64, 0.15);
  display: grid;
  gap: 6px;
}

.tool-submenu-toggle {
  display: none;
  width: 100%;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: rgba(18, 12, 4, 0.45);
  color: var(--text-warm);
  border: 1px solid rgba(240, 192, 64, 0.18);
  border-radius: 8px;
  padding: 7px 9px;
  font-family: 'Cinzel', serif;
  font-size: 10px;
  letter-spacing: 0.3px;
  text-align: left;
}

.tool-submenu-toggle-label {
  min-width: 0;
}

.tool-submenu-toggle-chevron {
  font-size: 12px;
  color: var(--gold);
  transition: transform 0.15s ease;
}

.tool-submenu-toggle.open .tool-submenu-toggle-chevron {
  transform: rotate(180deg);
}

.tool-submenu-label {
  font-family: 'Cinzel', serif;
  font-size: 9px;
  letter-spacing: 0.8px;
  color: var(--text-muted);
  text-transform: uppercase;
}

.tool-submenu-options {
  display: grid;
  gap: 4px;
}

.tool-submenu-option {
  --variant-color: rgba(240, 192, 64, 0.6);
  width: 100%;
  background: rgba(26, 18, 8, 0.45);
  color: var(--text-warm);
  border: 1px solid rgba(240, 192, 64, 0.18);
  border-radius: 6px;
  padding: 7px 8px;
  cursor: pointer;
  text-align: left;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
}

.tool-submenu-option:hover {
  background: rgba(46, 30, 14, 0.9);
  border-color: var(--variant-color);
}

.tool-submenu-option.selected {
  border-color: var(--variant-color);
  background: rgba(59, 40, 18, 0.95);
  box-shadow: 0 0 0 1px rgba(240, 192, 64, 0.16), 0 0 12px rgba(240, 192, 64, 0.18);
}

.tool-submenu-option-preview {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px 6px;
  width: 42px;
  margin-bottom: 6px;
}

.tool-submenu-option-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: rgba(216, 193, 140, 0.22);
  border: 1px solid rgba(216, 193, 140, 0.16);
}

.tool-submenu-option-dot.active {
  background: var(--variant-color);
  border-color: var(--variant-color);
  box-shadow: 0 0 8px rgba(240, 192, 64, 0.32);
}

.tool-submenu-option-name {
  display: block;
  font-family: 'Cinzel', serif;
  font-size: 10px;
  color: var(--gold);
}

.tool-submenu-option-pattern {
  display: block;
  margin-top: 2px;
  font-size: 9px;
  line-height: 1.3;
  color: #d8c18c;
}

#bottom-bar {
  background: #4a4a4a;
  padding: 8px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  gap: 12px;
}

.crystals-status {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 1;
  flex-wrap: wrap;
}

.status-label {
  font-family: 'Cinzel', serif;
  font-size: 11px;
  color: var(--text-muted);
  margin-right: 4px;
}

.crystal-pip {
  width: 20px;
  height: 20px;
  clip-path: polygon(50% 0%, 86% 22%, 78% 82%, 22% 82%, 14% 22%);
  border: 2px solid #5a4010;
  background: linear-gradient(180deg, rgba(255,255,255,0.16), rgba(255,255,255,0.03));
  transition: all 0.3s;
  flex-shrink: 0;
}

.crystal-pip.lit {
  box-shadow: 0 0 10px 2px var(--pip-color, #fff), 0 0 18px rgba(255,255,255,0.16);
  border-color: var(--pip-color, #fff);
  background:
    linear-gradient(140deg, rgba(255,255,255,0.68), transparent 42%),
    linear-gradient(180deg, color-mix(in srgb, var(--pip-color, #fff) 90%, white 10%), var(--pip-color, #fff));
  opacity: 0.94;
}

#version-badge {
  font-family: 'Cinzel', serif;
  font-size: 10px;
  color: rgba(232, 212, 160, 0.68);
  letter-spacing: 0.4px;
  white-space: nowrap;
  flex-shrink: 0;
  padding: 0 2px;
}

.btn {
  font-family: 'Cinzel', serif;
  font-size: 12px;
  padding: 7px 16px;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s;
  letter-spacing: 0.5px;
  flex-shrink: 0;
  position: relative;
  overflow: hidden;
}

.btn::before {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(118deg, transparent 24%, rgba(255, 243, 186, 0.18) 40%, rgba(255, 255, 255, 0.28) 46%, transparent 54%),
    linear-gradient(180deg, rgba(255,255,255,0.08), transparent 48%);
  opacity: 0.78;
}

#btn-reset {
  background: var(--stone-mid);
  border: 1.5px solid #8b3010;
  color: #e8a060;
}

#btn-reset:hover { border-color: #e8a060; background: #2e1a0a; }

#btn-intro {
  background: var(--stone-mid);
  border: 1.5px solid #4a6f88;
  color: #9ed0ea;
}

#btn-intro:hover { border-color: #9ed0ea; background: #102230; }

#btn-hint {
  background: var(--stone-mid);
  border: 1.5px solid #305080;
  color: #60a0e8;
  display: none;
}

#btn-hint:hover { border-color: #60a0e8; background: #0a1a2e; }

#btn-next {
  background: #1e3010;
  border: 1.5px solid #40a010;
  color: #80e040;
  display: none;
}

#btn-next.visible { display: block; }
#btn-next:hover { border-color: #80e040; background: #2a4010; }

#win-overlay {
  position: fixed;
  inset: 78px 0 auto 0;
  display: none;
  align-items: flex-start;
  justify-content: center;
  z-index: 200;
  padding: 0 16px;
  pointer-events: none;
}

#win-overlay.visible { display: flex; }

#win-box,
#intro-box {
  background: var(--stone);
  border: 3px solid var(--gold);
  border-radius: 16px;
  box-shadow: 0 0 80px rgba(240,192,64,0.35);
}

#win-box {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 14px;
  padding: 12px 16px;
  text-align: left;
  animation: winPop 0.36s cubic-bezier(0.34, 1.56, 0.64, 1);
  width: min(92vw, 760px);
  background: rgba(18, 16, 12, 0.88);
  border-width: 2px;
  border-radius: 8px;
  backdrop-filter: blur(4px);
  pointer-events: auto;
}

@keyframes winPop {
  from { transform: translateY(-14px) scale(0.96); opacity: 0; }
  to   { transform: translateY(0) scale(1); opacity: 1; }
}

#win-box .win-emoji {
  font-size: 28px;
  display: block;
}

#win-box h2,
#intro-box h2 {
  font-family: 'Cinzel', serif;
  color: var(--gold);
}

#win-box h2 {
  font-size: 17px;
  margin-bottom: 2px;
  text-shadow: 0 0 24px rgba(240,192,64,0.7);
  letter-spacing: 1.2px;
}

#win-box p {
  font-size: 14px;
  color: var(--text-warm);
  margin-bottom: 0;
  line-height: 1.45;
  font-style: italic;
}

#win-box .win-btns {
  display: flex;
  gap: 8px;
  justify-content: center;
}

#win-box button,
#intro-box button {
  background: var(--stone-mid);
  border: 2px solid var(--gold);
  color: var(--gold);
  font-family: 'Cinzel', serif;
  font-size: 12px;
  padding: 8px 14px;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s;
  letter-spacing: 1px;
}

#win-box button:hover,
#intro-box button:hover {
  background: var(--stone-light);
  box-shadow: 0 0 14px rgba(240,192,64,0.35);
}

#intro-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.78);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 220;
}

#intro-box {
  padding: 34px 40px;
  max-width: 560px;
}

#intro-box h2 {
  font-size: 28px;
  letter-spacing: 1px;
  margin-bottom: 14px;
}

#intro-box p {
  font-size: 17px;
  line-height: 1.65;
  color: var(--text-warm);
  margin-bottom: 14px;
}

#intro-box .intro-note {
  font-size: 14px;
  color: #d8b870;
  border-top: 1px solid rgba(240,192,64,0.25);
  padding-top: 12px;
  margin-top: 6px;
}

#tooltip {
  position: fixed;
  background: rgba(10,6,0,0.95);
  border: 1px solid var(--border-gold);
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 12px;
  color: var(--text-warm);
  font-family: 'Cinzel', serif;
  pointer-events: none;
  z-index: 100;
  display: none;
  max-width: 220px;
  line-height: 1.4;
}

@media (min-width: 901px) {
  #app {
    display: grid;
    grid-template-columns: minmax(0, 1fr) clamp(260px, 22vw, 330px);
    grid-template-rows: minmax(0, 1fr);
    grid-template-areas:
      "game inventory";
  }

  #header {
    position: absolute;
    left: calc((100% - clamp(260px, 22vw, 330px)) / 2);
    top: 18px;
    width: min(540px, 48vw);
    transform: translateX(-50%);
    z-index: 8;
    padding: 10px 24px;
    justify-content: center;
    background:
      linear-gradient(90deg, rgba(16, 12, 8, 0), rgba(16, 12, 8, 0.9) 14%, rgba(20, 15, 10, 0.94) 86%, rgba(16, 12, 8, 0));
    border: 1px solid rgba(165, 119, 48, 0.45);
    border-left: 0;
    border-right: 0;
    box-shadow: 0 10px 36px rgba(0, 0, 0, 0.45), inset 0 0 18px rgba(240, 192, 64, 0.06);
  }

  #app-title,
  .header-badge {
    display: none;
  }

  .header-side {
    flex-shrink: 0;
  }

  .language-picker {
    padding-left: 8px;
    border-left: 1px solid rgba(165, 119, 48, 0.34);
  }

  #level-info {
    padding: 0;
  }

  .level-name {
    font-size: 17px;
    letter-spacing: 1.1px;
    text-transform: uppercase;
  }

  .level-sub {
    display: none;
  }

  #game-area {
    grid-area: game;
    padding: 0;
  }

  #grid-container {
    border: 0;
    border-radius: 0;
    box-shadow:
      inset -28px 0 34px rgba(0, 0, 0, 0.44),
      inset 0 0 0 1px rgba(255, 235, 180, 0.035);
  }

  .mentor-card {
    left: 0;
    top: 18px;
    grid-template-columns: 210px minmax(0, 250px);
    gap: 14px;
    max-width: min(520px, 42vw);
  }

  .mentor-card img {
    width: 210px;
    height: 210px;
    transform: translateX(-18px);
  }

  .mentor-card.bubble-hidden {
    grid-template-columns: 210px;
    max-width: 230px;
  }

  .mentor-bubble {
    margin-top: 8px;
    padding: 14px 16px 16px;
    background: rgba(12, 10, 8, 0.88);
    border-color: rgba(160, 113, 47, 0.62);
    font-size: 16px;
  }

  .mentor-bubble::before {
    left: 208px;
    top: 64px;
  }

  #mentor-comment {
    -webkit-line-clamp: 4;
  }

  #inventory-bar {
    grid-area: inventory;
    align-content: start;
    align-self: stretch;
    border-top: 0;
    border-left: 1px solid rgba(155, 112, 48, 0.5);
    padding: 184px 16px 24px;
    background:
      linear-gradient(180deg, rgba(33, 25, 14, 0.95), rgba(10, 10, 9, 0.98)),
      radial-gradient(ellipse at 50% 8%, rgba(156, 96, 34, 0.18), transparent 42%);
    box-shadow: inset 10px 0 28px rgba(0, 0, 0, 0.48), -12px 0 32px rgba(0, 0, 0, 0.32);
    min-height: 0;
    height: 100vh;
    overflow-y: auto;
    overflow-x: hidden;
    overscroll-behavior: contain;
  }

  #inventory-bar::after {
    content: 'WERKZEUGE';
    position: absolute;
    top: 136px;
    left: 16px;
    right: 16px;
    padding: 10px 0;
    border: 1px solid rgba(139, 105, 20, 0.62);
    background: rgba(5, 5, 4, 0.72);
    font-family: 'Cinzel', serif;
    font-size: 15px;
    font-weight: 700;
    text-align: center;
    letter-spacing: 0.8px;
    color: var(--gold);
    box-shadow: 0 10px 22px rgba(0, 0, 0, 0.34);
  }

  #toolbox {
    gap: 12px;
    overflow: visible;
  }

  .tool-crate-row {
    grid-template-columns: minmax(0, 1fr);
    gap: 10px;
    align-items: start;
  }

  .tool-crate-toggle {
    aspect-ratio: 210 / 90;
  }

  .tool-crate-drawer .tool-crate-content {
    padding: 10px;
  }

  .tool-crate-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(108px, 1fr));
    gap: 10px;
    padding: 2px;
    overflow: visible;
  }

  .tool-item {
    min-height: 130px;
    padding: 14px 10px;
    background: linear-gradient(180deg, rgba(47, 42, 34, 0.96), rgba(20, 19, 17, 0.98));
    border-color: rgba(142, 105, 45, 0.58);
    box-shadow: inset 0 0 22px rgba(255, 210, 120, 0.04), 0 10px 18px rgba(0, 0, 0, 0.24);
  }

  #bottom-bar {
    position: absolute;
    left: 20px;
    right: calc(clamp(260px, 22vw, 330px) + 20px);
    bottom: 18px;
    z-index: 7;
    background: transparent;
    padding: 0;
    pointer-events: none;
  }

  .crystals-status {
    max-width: 350px;
    flex: 0 0 auto;
    padding: 13px 16px;
    border: 1px solid rgba(139, 105, 20, 0.62);
    border-radius: 4px;
    background: rgba(9, 9, 7, 0.82);
    box-shadow: 0 12px 28px rgba(0, 0, 0, 0.38), inset 0 0 18px rgba(240, 192, 64, 0.05);
    pointer-events: auto;
  }

  #bottom-bar .btn,
  #version-badge {
    pointer-events: auto;
  }

  #bottom-bar .btn {
    width: 64px;
    height: 64px;
    padding: 0;
    border-radius: 50%;
    font-size: 10px;
    display: inline-grid;
    place-items: center;
    text-align: center;
    border-width: 2px;
    background: radial-gradient(circle at 45% 35%, #3b3325, #10100f 72%);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45), inset 0 0 0 3px rgba(218, 191, 118, 0.08);
  }

  #version-badge {
    align-self: center;
  }
}

@media (max-width: 900px) {
  .mentor-card {
    grid-template-columns: 76px minmax(0, 210px);
    gap: 8px;
    left: 8px;
    top: 8px;
  }

  .mentor-card img {
    width: 76px;
    height: 76px;
  }

  .mentor-card.bubble-hidden {
    grid-template-columns: 76px;
    max-width: 92px;
  }

  .mentor-bubble {
    padding: 8px 10px 9px;
    font-size: 12.5px;
  }

  .mentor-bubble::before {
    left: 78px;
    top: 32px;
  }

  #mentor-comment {
    -webkit-line-clamp: 2;
  }

  #header {
    padding: 8px 12px;
    gap: 10px;
  }

  #app-title {
    font-size: 16px;
    letter-spacing: 1.5px;
  }

  .header-badge {
    display: none;
  }

  .mission-window {
    width: min(94vw, 560px);
    grid-template-columns: 1fr;
    gap: 12px;
    padding: 24px 20px;
  }

  .mission-window .dwarf-portrait {
    justify-self: center;
  }

  #mission-title {
    font-size: 20px;
    text-align: center;
  }

  #tutorial-text {
    font-size: 15px;
  }

  #btn-mission-close {
    justify-self: stretch;
  }

  #inventory-bar {
    padding: 8px 10px 10px;
  }

  #zoom-controls {
    right: 7px;
    top: 7px;
    gap: 4px;
    padding: 4px;
  }

  .zoom-btn {
    width: 30px;
    height: 30px;
  }

  #zoom-slider {
    width: 78px;
  }

  .tool-crate-row {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 7px;
    align-items: start;
  }

  .tool-crate-toggle {
    width: 100%;
  }

  .tool-crate-drawer .tool-crate-content {
    padding: 7px;
  }

  .tool-crate-grid {
    gap: 7px;
    padding: 2px 2px 4px;
  }

  .tool-item {
    padding: 7px 6px;
  }

  .tool-mirror-preview,
  .tool-prism-preview,
  .tool-splitter-preview {
    width: 44px;
    height: 44px;
    margin-bottom: 4px;
  }

  .tool-submenu-options {
    display: flex;
    grid-template-columns: none;
    overflow-x: auto;
    gap: 6px;
  }

  .tool-submenu-option {
    flex: 0 0 132px;
    min-height: 72px;
    padding: 8px;
  }

  .tool-submenu-option-preview {
    width: 48px;
  }

  #bottom-bar {
    flex-wrap: wrap;
    padding: 8px 10px;
  }

  .btn {
    flex: 1 0 auto;
  }

  #version-badge {
    margin-left: auto;
    align-self: center;
  }

  #intro-box,
  #win-box {
    width: min(92vw, 560px);
    padding: 22px 20px;
  }

  #win-overlay {
    inset: 74px 0 auto 0;
    padding: 0 12px;
  }

  #win-box {
    width: min(94vw, 520px);
    grid-template-columns: auto minmax(0, 1fr);
    gap: 10px;
  }

  #win-box .win-btns {
    grid-column: 1 / -1;
  }

  #win-box h2 {
    font-size: 20px;
  }

  #win-box .win-btns {
    flex-wrap: wrap;
  }

  #intro-box p {
    font-size: 15px;
  }
}
