html, body {
  margin: 0;
  min-height: 100%;
  font-family: Georgia, serif;
}

body {
  background-image: url("../general/textures/backgrounds/orphanage.png");
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  min-height: 100vh;
}

* {
  box-sizing: border-box;
}

.search-btn {
  position: fixed;
  right: 18px;
  top: 12px;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 8px;
  background: #5a4632;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  cursor: pointer;
  z-index: 40;
}

.search-popup {
  position: fixed;
  right: 18px;
  top: 64px;
  width: min(380px, calc(100vw - 36px));
  max-height: 420px;
  background: #efe1b6;
  border: 3px solid #5a4632;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.3);
  padding: 12px;
  z-index: 41;
  display: none;
}

.search-popup[aria-hidden="false"] {
  display: block;
}

.search-header {
  display: flex;
  gap: 8px;
}

.search-input {
  flex: 1;
  min-width: 0;
  padding: 10px 12px;
  border: 2px solid #5a4632;
  border-radius: 6px;
  font: 15px Georgia, serif;
}

.search-close {
  width: 36px;
  padding: 6px;
  border: 0;
  background: #5a4632;
  color: #fff;
  cursor: pointer;
}

.search-results {
  max-height: 320px;
  overflow: auto;
  list-style: none;
  margin: 10px 0 0;
  padding: 0;
}

.search-results li {
  padding: 10px 12px;
  border-bottom: 1px solid rgba(90, 70, 50, 0.15);
  cursor: pointer;
  font-size: 15px;
}

.search-results li:hover,
.search-results li:focus {
  background: rgba(90, 70, 50, 0.1);
  outline: none;
}

.go-back {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 40;
  transition: transform 0.2s ease;
}

.go-back:hover,
.go-back:focus-visible {
  transform: scale(1.12);
}

.go-back img {
  width: 72px;
  display: block;
}

#mark {
  position: fixed;
  bottom: -115px;
  right: -70px;
  scale: 0.42;
}

#go_back {
  position: fixed;
  bottom: 30px;
  right: 35px;
  z-index: 1000;
  scale: 0.5;
  transition: scale 0.2s ease;
}

#go_back:hover,
#go_back:focus-visible {
  scale: 0.53;
}

#go_back img {
  width: 145px;
  vertical-align: middle;
}

.recipe-page {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 2fr);
  gap: 0;
  width: 100%;
  height: 100vh;
  min-height: 0;
  overflow: hidden;
}

.tree-panel {
  align-self: stretch;
  width: 100%;
  height: 100%;
  min-height: 0;
  padding: 24px;
  background: #f6edd2;
  border: 0;
  border-right: 2px solid #000;
  overflow-y: auto;
}

.tree-root {
  display: flex;
  flex-direction: column;
  gap: 0;
  margin-top: 8px;
}

.tree-node {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 0 0 0;
  transform: translateX(calc(var(--depth, 0) * 20px));
}

.tree-toggle,
.tree-link {
  font: inherit;
  color: #1d1d1d;
  background: transparent;
  border: none;
  cursor: pointer;
}

.tree-toggle {
  width: 22px;
  height: 22px;
  font-size: 24px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transform: translateY(-1px);
  padding: 0;
}

.tree-toggle.closed {
  transform: rotate(-90deg);
}

.tree-link {
  font-size: clamp(18px, 1.2vw, 28px);
  text-transform: none;
  text-align: left;
  padding: 4px 0;
}

.tree-children {
  margin-top: 4px;
  margin-bottom: 10px;
  display: flex;
  flex-direction: column;
}

.tree-children.hidden {
  display: none;
}

.tree-node.has-children > .tree-link {
  flex: 1;
  font-size: clamp(25px, 1.5vw, 34px);
  line-height: 1.1;
  padding: 5px 0;
}

.tree-node.leaf > .tree-link {
  font-size: clamp(18px, 1.1vw, 25px);
}

.tree-node.has-children {
  padding: 3px 14px 3px 7px;
  border: 2px solid #000;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.08);
  min-height: 44px;
  width: fit-content;
}

.tree-node.leaf {
  padding: 4px 0 4px 0;
  width: 100%;
}

.tree-spacer {
  display: inline-block;
  height: 1px;
}

.recipe-detail {
  position: relative;
  width: 100%;
  min-width: 0;
  min-height: 0;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  background: transparent;
  border: 0;
}

.title-panel {
  width: min(100%, 560px);
  padding: 18px 24px;
  background: #40313a;
  border: 3px solid #171217;
  border-radius: 8px;
  box-shadow: inset 0 0 0 2px rgba(246, 237, 210, 0.2);
}

.item-title {
  margin: 0;
  font-size: clamp(46px, 3.5vw, 78px);
  line-height: 1;
  font-weight: 700;
  color: #f6edd2;
  letter-spacing: -0.04em;
  text-align: center;
}

.crafting-panel {
  width: min(100%, 560px);
  max-height: calc(100vh - 150px);
  margin-top: 18px;
  padding: 14px;
  overflow: auto;
  background: #f6edd2;
  border: 3px solid #000;
  border-radius: 8px;
}

.recipe-content-row {
  display: flex;
  align-items: stretch;
  justify-content: center;
  gap: 14px;
  width: min(100%, 720px);
  margin-top: 18px;
}

.recipe-content-row .crafting-panel {
  margin-top: 0;
}

.tips-section {
  position: absolute;
  left: 24px;
  bottom: 18px;
  width: 260px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  z-index: 3;
}

.tips-section[hidden] {
  display: none;
}

.tips-box {
  position: relative;
  width: min(100%, 260px);
  min-height: 115px;
  padding: 16px;
  background: #fff;
  border: 2px solid #171217;
  border-radius: 9px;
  color: #1d1d1d;
  font: 16px/1.35 Georgia, serif;
  white-space: pre-line;
  overflow-wrap: anywhere;
  align-self: flex-start;
}

.tips-box::before {
  content: "";
  position: absolute;
  left: 22px;
  bottom: -17px;
  width: 25px;
  height: 25px;
  background: #fff;
  border-right: 2px solid #171217;
  border-bottom: 2px solid #171217;
  transform: rotate(45deg);
  z-index: 0;
}

.tips-box::after {
  content: "";
  position: absolute;
  left: 24px;
  bottom: -13px;
  width: 24px;
  height: 18px;
  background: #fff;
  transform: rotate(45deg);
  z-index: 1;
}

.tips-character {
  align-self: flex-start;
  width: 130px;
  height: 130px;
  margin: 18px 0 0 12px;
  object-fit: contain;
  image-rendering: pixelated;
}

.recipe-panels {
  display: grid;
  grid-auto-rows: 245px;
  gap: 24px;
  width: max-content;
  min-width: 500px;
  margin: 0 auto;
}

.craft-card {
  position: relative;
  width: 500px;
  height: 245px;
  max-width: 100%;
  background: url("./assets/crafting_ui.png") no-repeat center;
  background-size: 100% 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  overflow: visible;
}

.craft-grid {
  position: absolute;
  left: 83px;
  top: 50px;
  width: 150px;
  height: 150px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  z-index: 1;
}

.brew-card {
  position: relative;
  width: 500px;
  height: 245px;
  max-width: 100%;
  background: url("./assets/brewing_ui.png") no-repeat center;
  background-size: 100% 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  overflow: visible;
}

.brew-grid {
  position: absolute;
  left: 83px;
  top: 50px;
  width: 150px;
  height: 150px;
  z-index: 1;
}

.furnace-card {
  position: relative;
  width: 500px;
  height: 245px;
  max-width: 100%;
  background: url("./assets/furnace_ui.png") no-repeat center;
  background-size: 100% 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  overflow: visible;
}

.furnace-grid {
  position: absolute;
  left: 83px;
  top: 50px;
  width: 150px;
  height: 150px;
  z-index: 1;
}

.blast-card {
  position: relative;
  width: 500px;
  height: 245px;
  max-width: 100%;
  background: url("./assets/blast_furnace_ui.png") no-repeat center;
  background-size: 100% 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  overflow: visible;
}

.blast-grid {
  position: absolute;
  left: 83px;
  top: 50px;
  width: 150px;
  height: 150px;
  z-index: 1;
}

.craft-slot,
.output-mini {
  position: absolute;
  width: 50px;
  height: 50px;
  background-position: center;
  background-repeat: no-repeat;
  background-size: 44px 44px;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  transition: transform 0.15s ease;
}

.craft-slot {
  position: relative;
  cursor: default;
}

.brew-slot {
  position: absolute;
  width: 50px;
  height: 50px;
  background-position: center;
  background-repeat: no-repeat;
  background-size: 44px 44px;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  cursor: default;
  transition: transform 0.15s ease;
}

.output-mini {
  left: 345px;
  top: 95px;
  width: 60px;
  height: 60px;
  background-size: 46px 46px;
  z-index: 1;
}

.filled-slot[data-link],
.output-mini[data-link] {
  cursor: pointer;
}

.craft-slot:hover,
.brew-slot:hover,
.output-mini:hover {
  transform: scale(1.3);
  z-index: 5;
}

.craft-slot[data-name]:hover::after,
.brew-slot[data-name]:hover::after,
.output-mini[data-name]:hover::after {
  content: attr(data-name);
  position: absolute;
  left: 50%;
  bottom: 110%;
  transform: translateX(-50%);
  background: #111;
  color: #fff;
  border: 2px solid #5a4632;
  padding: 6px 10px;
  font: 12px Georgia, serif;
  white-space: nowrap;
  z-index: 10;
}

.empty-slot {
  background: transparent;
}

.mini-block {
  display: none;
}

@media (max-width: 980px) {
  .recipe-page {
    grid-template-columns: 1fr;
  }

  .tree-panel {
    height: min(45vh, 520px);
    min-height: 220px;
    padding-right: 12px;
    border-right: 0;
    border-bottom: 2px solid #000;
  }

  .recipe-detail {
    min-height: 0;
  }

  .item-title {
    font-size: 42px;
  }

  .recipe-content-row {
    width: 100%;
  }
}

@media (max-width: 700px) {
  .tips-section {
    position: relative;
    left: auto;
    bottom: auto;
    align-self: flex-start;
    width: min(100%, 260px);
    margin: 36px 0 0 0;
  }

  .recipe-content-row {
    align-items: stretch;
    flex-direction: column;
  }

  .tips-box::before {
    left: 22px;
    top: auto;
    transform: rotate(45deg);
  }
}
