:root {
  --tr3-bg: #0a0616;
  --tr3-gold: #ffb300;
  --tr3-panel: rgba(18, 14, 32, 0.92);
  --tr3-border: rgba(255, 255, 255, 0.12);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--tr3-bg);
  overflow: hidden;
  font-family: 'DM Sans', sans-serif;
  color: #fff;
  -webkit-user-select: none;
  user-select: none;
}

#tr3-root {
  position: fixed;
  inset: 0;
}

#tr3-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  cursor: crosshair;
}

/* Screens */
.tr3-screen {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(5, 3, 12, 0.72);
  backdrop-filter: blur(6px);
  z-index: 20;
}
.tr3-screen.is-visible { display: flex; }

.tr3-menu-panel, .tr3-dialog-panel {
  background: var(--tr3-panel);
  border: 1px solid var(--tr3-border);
  border-radius: 18px;
  padding: 32px 28px;
  max-width: 420px;
  width: min(90vw, 420px);
  text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}

.tr3-logo { display: flex; flex-direction: column; margin-bottom: 8px; }
.tr3-logo-troll { font-weight: 900; font-size: 28px; letter-spacing: 1px; }
.tr3-logo-3d { font-weight: 900; font-size: 40px; color: var(--tr3-gold); letter-spacing: 2px; }
.tr3-menu-tag { opacity: 0.75; font-size: 14px; margin: 6px 0 22px; }

.tr3-btn-primary, .tr3-btn-ghost {
  font-family: 'DM Sans', sans-serif;
  font-weight: 700;
  font-size: 16px;
  border-radius: 12px;
  padding: 14px 22px;
  border: none;
  cursor: pointer;
  width: 100%;
}
.tr3-btn-primary {
  background: var(--tr3-gold);
  color: #1a1200;
  margin-bottom: 18px;
}
.tr3-btn-ghost {
  background: transparent;
  border: 1px solid var(--tr3-border);
  color: #fff;
  margin-top: 10px;
}

.tr3-difficulty-picker { display: flex; gap: 6px; margin-bottom: 14px; }
.tr3-diff-btn {
  flex: 1;
  background: transparent;
  border: 1px solid var(--tr3-border);
  color: rgba(255,255,255,0.7);
  border-radius: 8px;
  padding: 8px 4px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}
.tr3-diff-btn.is-active { border-color: var(--tr3-gold); color: var(--tr3-gold); background: rgba(255,179,0,0.08); }

.tr3-menu-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  font-size: 12px;
  opacity: 0.8;
  margin-bottom: 10px;
}
.tr3-menu-controls kbd {
  background: rgba(255,255,255,0.1);
  border-radius: 4px;
  padding: 2px 6px;
  font-family: 'DM Mono', monospace;
}
.tr3-mobile-only { display: none; }
@media (hover: none) and (pointer: coarse) {
  .tr3-menu-controls span:not(.tr3-mobile-only) { display: none; }
  .tr3-mobile-only { display: inline; }
}

.tr3-menu-back {
  display: block;
  margin-top: 16px;
  color: rgba(255,255,255,0.5);
  font-size: 13px;
  text-decoration: none;
}

/* Minecraft-style title screen (scoped to the main menu only) */
#tr3-screen-menu {
  background:
    linear-gradient(rgba(4,2,10,0.2), rgba(4,2,10,0.4)),
    repeating-linear-gradient(135deg, rgba(0,0,0,0.1) 0 32px, transparent 32px 64px),
    linear-gradient(180deg, #8fd0ec 0%, #cdeaf5 58%, #3a8a4f 58%, #235c30 100%);
  background-size: cover, 128px 128px, cover;
  background-position: center, 0 0, center;
  background-repeat: no-repeat, repeat, no-repeat;
  animation: tr3-mc-pan 50s linear infinite;
  backdrop-filter: none;
}
@keyframes tr3-mc-pan {
  from { background-position: center, 0 0, center; }
  to { background-position: center, 1024px 0, center; }
}

#tr3-screen-menu .tr3-menu-panel {
  background: transparent;
  border: none;
  box-shadow: none;
  padding: 36px 20px;
  max-width: 480px;
}

#tr3-screen-menu .tr3-logo {
  position: relative;
  margin-bottom: 6px;
}
#tr3-screen-menu .tr3-logo-troll {
  font-family: 'Press Start 2P', 'DM Sans', sans-serif;
  font-size: 14px;
  letter-spacing: 2px;
  color: #d8d8d8;
  text-shadow: 3px 3px 0 #3a3a3a, 5px 5px 0 rgba(0,0,0,0.5);
}
#tr3-screen-menu .tr3-logo-3d {
  font-family: 'Press Start 2P', 'DM Sans', sans-serif;
  font-size: 30px;
  letter-spacing: 3px;
  color: #7bc94b;
  -webkit-text-stroke: 2px #2e5c1a;
  text-shadow: 4px 4px 0 #2e5c1a, 6px 6px 0 rgba(0,0,0,0.55), 8px 8px 14px rgba(0,0,0,0.4);
  margin-top: 8px;
  display: inline-block;
}
#tr3-screen-menu .tr3-menu-splash {
  position: absolute;
  top: -4px;
  right: 4px;
  transform: rotate(-16deg);
  color: #ffff33;
  font-family: 'Press Start 2P', monospace;
  font-size: 10px;
  text-shadow: 2px 2px 0 #6b6b00;
  animation: tr3-splash-bounce 0.7s ease-in-out infinite alternate;
}
@keyframes tr3-splash-bounce {
  from { transform: rotate(-16deg) scale(1); }
  to { transform: rotate(-16deg) scale(1.15); }
}

#tr3-screen-menu .tr3-menu-tag {
  font-family: 'DM Mono', monospace;
  font-size: 12px;
  color: #f0f0f0;
  text-shadow: 1px 1px 0 rgba(0,0,0,0.6);
  opacity: 0.95;
}

#tr3-screen-menu .tr3-btn-primary {
  font-family: 'DM Mono', monospace;
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 0.5px;
  color: #e8e8e8;
  background: #6b6b6b;
  border-radius: 2px;
  border-style: solid;
  border-width: 2px 2px 4px 2px;
  border-color: #a8a8a8 #2b2b2b #2b2b2b #a8a8a8;
  text-shadow: 2px 2px 0 rgba(0,0,0,0.6);
  transition: none;
}
#tr3-screen-menu .tr3-btn-primary:hover,
#tr3-screen-menu .tr3-btn-primary:focus-visible {
  background: #7d7d7d;
  color: #ffff8a;
}
#tr3-screen-menu .tr3-btn-primary:active {
  border-width: 4px 2px 2px 2px;
  border-color: #2b2b2b #a8a8a8 #a8a8a8 #2b2b2b;
}

#tr3-screen-menu .tr3-menu-controls kbd {
  font-family: 'DM Mono', monospace;
  background: rgba(0,0,0,0.45);
  border: 1px solid rgba(255,255,255,0.25);
}
#tr3-screen-menu .tr3-menu-controls span {
  color: #f0f0f0;
  text-shadow: 1px 1px 0 rgba(0,0,0,0.5);
}

#tr3-screen-menu .tr3-menu-back {
  color: rgba(255,255,255,0.8);
  text-shadow: 1px 1px 0 rgba(0,0,0,0.6);
}

.tr3-dialog-title { font-weight: 900; font-size: 22px; margin: 0 0 14px; }
.tr3-dialog-title.is-danger { color: #ff4d4d; }
.tr3-respawn-note { opacity: 0.8; font-size: 14px; margin-bottom: 18px; }
.tr3-dialog-actions { display: flex; flex-direction: column; gap: 10px; }

/* HUD */
#tr3-hud {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 10;
}
.tr3-hp-wrap {
  position: absolute;
  top: 16px;
  left: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--tr3-panel);
  border: 1px solid var(--tr3-border);
  border-radius: 10px;
  padding: 8px 12px;
}
.tr3-hp-label { font-size: 11px; font-weight: 700; opacity: 0.7; }

.tr3-hunger-wrap {
  position: absolute;
  top: 64px;
  left: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--tr3-panel);
  border: 1px solid var(--tr3-border);
  border-radius: 10px;
  padding: 8px 12px;
}
.tr3-hunger-fill {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, #a8672e, #ffd166);
  transition: width 0.2s ease;
}

.tr3-clock {
  position: absolute;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--tr3-panel);
  border: 1px solid var(--tr3-border);
  border-radius: 10px;
  padding: 8px 14px;
  font-family: 'DM Mono', monospace;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.3px;
}
.tr3-hardmode-badge {
  position: absolute;
  top: 58px;
  left: 50%;
  transform: translateX(-50%);
  background: linear-gradient(90deg, #7f1d1d, #b91c1c);
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 8px;
  padding: 4px 12px;
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 1px;
}
.tr3-safestart-badge {
  position: absolute;
  top: 58px;
  left: 50%;
  transform: translateX(-50%);
  background: linear-gradient(90deg, #14532d, #15803d);
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 8px;
  padding: 4px 12px;
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 1px;
  transition: opacity 0.6s ease;
}
.tr3-hp-bar {
  width: 120px;
  height: 10px;
  background: rgba(255,255,255,0.1);
  border-radius: 6px;
  overflow: hidden;
}
.tr3-hp-fill {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, #ff4d4d, #ffb300);
  transition: width 0.2s ease;
}

.tr3-hotbar {
  position: absolute;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 6px;
  pointer-events: auto;
}
.tr3-hotbar-slot {
  width: 48px;
  height: 48px;
  border-radius: 10px;
  background: var(--tr3-panel);
  border: 2px solid var(--tr3-border);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-family: 'DM Mono', monospace;
  cursor: pointer;
}
.tr3-hotbar-slot.is-active { border-color: var(--tr3-gold); }
.tr3-hotbar-swatch { width: 20px; height: 20px; border-radius: 4px; margin-bottom: 2px; }
.tr3-hotbar-swatch-empty { background: rgba(255,255,255,0.06); }
.tr3-hotbar-count { opacity: 0.8; }

.tr3-pause-btn, .tr3-inv-btn, .tr3-music-btn, .tr3-coop-btn, .tr3-waypoints-btn {
  position: absolute;
  top: 16px;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  border: 1px solid var(--tr3-border);
  background: var(--tr3-panel);
  color: #fff;
  font-size: 14px;
  cursor: pointer;
  pointer-events: auto;
}
.tr3-pause-btn { right: 16px; }
.tr3-waypoints-btn { right: 64px; font-size: 16px; }
.tr3-coop-btn { right: 112px; font-size: 16px; }
.tr3-music-btn { right: 160px; font-size: 16px; }
.tr3-inv-btn { right: 208px; font-size: 18px; }

.tr3-minimap {
  position: absolute;
  top: 100px;
  right: 16px;
  width: 120px;
  height: 120px;
  border-radius: 50%;
  border: 1px solid var(--tr3-border);
  background: rgba(10,6,22,0.4);
  box-shadow: 0 4px 14px rgba(0,0,0,0.35);
}

.tr3-cursor-hint {
  position: absolute;
  top: 60px;
  right: 16px;
  max-width: 200px;
  text-align: right;
  font-family: 'DM Mono', monospace;
  font-size: 11px;
  color: rgba(255,255,255,0.75);
  background: rgba(0,0,0,0.35);
  border: 1px solid var(--tr3-border);
  border-radius: 8px;
  padding: 5px 10px;
  transition: opacity 0.6s ease;
}

.tr3-peer-count {
  position: absolute;
  top: 60px;
  right: 16px;
  font-family: 'DM Mono', monospace;
  font-size: 12px;
  font-weight: 700;
  opacity: 0.85;
}

.tr3-dialogue {
  position: absolute;
  bottom: 100px;
  left: 50%;
  transform: translateX(-50%);
  max-width: min(80vw, 480px);
  background: var(--tr3-panel);
  border: 1px solid var(--tr3-border);
  border-radius: 12px;
  padding: 10px 16px;
  font-size: 13px;
  text-align: center;
}

.tr3-boss-bar {
  position: absolute;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  margin-top: 46px;
  width: min(70vw, 420px);
  text-align: center;
}
.tr3-boss-name {
  display: block;
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: #ff4d4d;
  margin-bottom: 4px;
  text-shadow: 0 1px 3px rgba(0,0,0,0.6);
}
.tr3-boss-track {
  height: 10px;
  background: rgba(0,0,0,0.5);
  border: 1px solid rgba(255,77,77,0.4);
  border-radius: 6px;
  overflow: hidden;
}
.tr3-boss-fill {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, #7c2d12, #ff4d4d);
  transition: width 0.2s ease;
}

.tr3-waypoint-list { display: flex; flex-direction: column; gap: 10px; }
.tr3-waypoint-row {
  font-family: 'DM Sans', sans-serif;
  font-size: 15px;
  font-weight: 700;
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--tr3-border);
  border-radius: 10px;
  padding: 14px;
  color: #fff;
  cursor: pointer;
  text-align: left;
}
.tr3-waypoint-row:hover { border-color: var(--tr3-gold); }

.tr3-coop-input {
  width: 100%;
  box-sizing: border-box;
  background: rgba(255,255,255,0.06);
  border: 1px solid var(--tr3-border);
  border-radius: 10px;
  padding: 12px;
  color: #fff;
  font-family: 'DM Mono', monospace;
  font-size: 16px;
  letter-spacing: 3px;
  text-align: center;
  text-transform: uppercase;
  margin: 12px 0 16px;
}

/* Inventory / crafting / chest panels */
.tr3-panel-wide {
  max-width: 640px;
  width: min(92vw, 640px);
  max-height: 86vh;
  overflow-y: auto;
  text-align: left;
}
.tr3-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}
.tr3-panel-head .tr3-dialog-title { margin: 0; }
.tr3-panel-close {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: 1px solid var(--tr3-border);
  background: transparent;
  color: #fff;
  cursor: pointer;
  font-size: 14px;
}
.tr3-panel-subtitle {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  opacity: 0.7;
  margin: 18px 0 10px;
}
.tr3-panel-hint { font-size: 13px; opacity: 0.7; margin: 0; }
.tr3-panel-hint-inline { font-size: 11px; font-weight: 400; text-transform: none; opacity: 0.7; letter-spacing: 0; }

.tr3-slot-grid {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  gap: 6px;
}
.tr3-grid-slot {
  aspect-ratio: 1;
  border-radius: 8px;
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--tr3-border);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  min-width: 0;
}
.tr3-grid-slot.is-hotbar { border-color: rgba(255,179,0,0.4); }
.tr3-grid-slot.is-equippable { border-color: rgba(192,38,211,0.6); }
.tr3-armor-slot {
  width: 64px;
  height: 64px;
  margin-bottom: 14px;
}
.tr3-armor-slot.is-empty { border-style: dashed; opacity: 0.5; }
.tr3-slot-swatch { width: 55%; aspect-ratio: 1; border-radius: 4px; }
.tr3-slot-count { font-size: 10px; font-family: 'DM Mono', monospace; opacity: 0.85; margin-top: 2px; }
.tr3-slot-icon {
  background: none;
  object-fit: contain;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.tr3-recipe-list { display: flex; flex-direction: column; gap: 8px; }
.tr3-recipe-row {
  display: flex;
  align-items: center;
  gap: 12px;
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--tr3-border);
  border-radius: 10px;
  padding: 8px 12px;
}
.tr3-recipe-row.is-disabled { opacity: 0.45; }
.tr3-recipe-out { display: flex; align-items: center; gap: 8px; min-width: 110px; }
.tr3-recipe-out .tr3-slot-swatch { width: 22px; }
.tr3-recipe-cost { flex: 1; font-size: 12px; opacity: 0.75; }
.tr3-recipe-btn {
  background: var(--tr3-gold);
  color: #1a1200;
  border: none;
  border-radius: 8px;
  padding: 8px 14px;
  font-weight: 700;
  cursor: pointer;
}
.tr3-recipe-btn:disabled { background: rgba(255,255,255,0.1); color: rgba(255,255,255,0.4); cursor: not-allowed; }

.tr3-quest-card {
  background: rgba(255,179,0,0.06);
  border: 1px solid rgba(255,179,0,0.3);
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 16px;
}
.tr3-quest-title { font-weight: 900; font-size: 15px; margin-bottom: 4px; }
.tr3-quest-intro { font-size: 12px; opacity: 0.75; margin: 0 0 10px; }
.tr3-quest-obj { font-size: 13px; font-family: 'DM Mono', monospace; opacity: 0.7; margin-bottom: 4px; }
.tr3-quest-obj.is-met { opacity: 1; color: var(--tr3-gold); }
.tr3-quest-claim { width: 100%; margin-top: 10px; }
.tr3-prestige-btn { width: 100%; margin-top: 8px; }
.tr3-prestige-hint { margin-top: 8px; font-size: 11px; }

/* Crosshair */
#tr3-canvas::after { content: ''; }
.tr3-crosshair {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 6px;
  height: 6px;
  margin: -3px 0 0 -3px;
  border-radius: 50%;
  background: rgba(255,255,255,0.8);
  pointer-events: none;
  z-index: 11;
}

/* Mining progress ring — fills clockwise around the crosshair while
   holding down the dig button, Minecraft-style hold-to-break feedback. */
.tr3-mine-progress {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 26px;
  height: 26px;
  margin: -13px 0 0 -13px;
  border-radius: 50%;
  pointer-events: none;
  z-index: 11;
  --mine-progress: 0;
  background: conic-gradient(rgba(255,255,255,0.95) calc(var(--mine-progress) * 360deg), rgba(255,255,255,0.15) 0deg);
  -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 3px), #000 calc(100% - 3px));
  mask: radial-gradient(farthest-side, transparent calc(100% - 3px), #000 calc(100% - 3px));
}

.tr3-rain {
  position: absolute;
  inset: -20px;
  pointer-events: none;
  z-index: 9;
  background-image: repeating-linear-gradient(
    115deg,
    rgba(200, 220, 255, 0.35) 0px,
    rgba(200, 220, 255, 0.35) 1px,
    transparent 1px,
    transparent 14px
  );
  background-size: 100% 140px;
  animation: tr3-rain-fall 0.35s linear infinite;
  opacity: 0.5;
}
@keyframes tr3-rain-fall {
  from { background-position: 0 -140px; }
  to { background-position: 40px 0; }
}

/* Touch controls */
#tr3-touch { position: absolute; inset: 0; z-index: 15; }
.tr3-joystick {
  position: absolute;
  bottom: 90px;
  left: 24px;
  width: 100px;
  height: 100px;
  border-radius: 50%;
  background: rgba(255,255,255,0.08);
  border: 1px solid var(--tr3-border);
  pointer-events: auto;
}
.tr3-joystick-knob {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 40px;
  height: 40px;
  margin: -20px 0 0 -20px;
  border-radius: 50%;
  background: rgba(255,179,0,0.5);
}
.tr3-look-pad {
  position: absolute;
  top: 0;
  right: 0;
  width: 55%;
  height: 100%;
  pointer-events: auto;
}
.tr3-touch-btn {
  position: absolute;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  border: 1px solid var(--tr3-border);
  background: var(--tr3-panel);
  color: #fff;
  font-size: 20px;
  pointer-events: auto;
}
.tr3-btn-jump { bottom: 170px; left: 44px; }
.tr3-btn-dig { bottom: 100px; right: 24px; }
.tr3-btn-place { bottom: 24px; right: 92px; }
