* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #183b2d;
  color: #24332a;
  font-family: "Segoe UI", Arial, sans-serif;
}

#gameShell {
  position: relative;
  width: 100vw;
  height: 100vh;
}

#game {
  display: block;
  width: 100%;
  height: 100%;
  background: #7bcf5d;
  image-rendering: auto;
  touch-action: none;
}

#hud {
  position: absolute;
  top: 14px;
  left: 14px;
  width: min(380px, calc(100vw - 28px));
  display: grid;
  gap: 8px;
  pointer-events: none;
}

.brand,
#message,
#inventory,
#quests {
  border: 2px solid rgba(35, 79, 47, 0.28);
  border-radius: 8px;
  background: rgba(255, 252, 229, 0.93);
  box-shadow: 0 10px 24px rgba(18, 45, 30, 0.16);
}

.brand {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
}

.brand strong {
  font-size: 18px;
}

.brand span {
  flex: 0 0 auto;
  border-radius: 999px;
  padding: 5px 9px;
  background: #d9f2c1;
  font-weight: 700;
  font-size: 13px;
}

#bagBtn {
  pointer-events: auto;
  flex: 0 0 auto;
  width: 42px;
  height: 38px;
  font-size: 20px;
  line-height: 1;
}

#message {
  display: flex;
  align-items: center;
  gap: 10px;
}

.mportrait {
  flex: 0 0 auto;
  width: 52px;
  height: 52px;
  border-radius: 10px;
  background: #e7f3d2;
  border: 1px solid rgba(35, 79, 47, 0.25);
  image-rendering: auto;
}

.chip img {
  width: 26px;
  height: 26px;
  margin-right: 5px;
}

.chip.resource {
  border-radius: 8px;
  background: #eef3d3;
}

.chip.resource img {
  width: 32px;
  height: 32px;
  object-fit: contain;
}

.quest img {
  width: 26px;
  height: 26px;
  border-radius: 6px;
  background: #eef6df;
}

#bagPanel {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(24, 59, 45, 0.55);
}

#bagPanel[hidden] {
  display: none;
}

#buildPanel {
  position: absolute;
  left: 12px;
  right: 244px;
  bottom: 12px;
  z-index: 16;
  pointer-events: auto;
}

#buildPanel[hidden] {
  display: none;
}

.buildCard {
  border-radius: 14px;
  background: rgba(32, 50, 41, 0.94);
  border: 2px solid rgba(250, 239, 190, 0.45);
  box-shadow: 0 18px 42px rgba(8, 20, 14, 0.34);
  color: #fff7cf;
  padding: 10px 12px;
}

.buildCard header,
.buildCard footer {
  display: flex;
  align-items: center;
  gap: 8px;
}

.buildCard header {
  justify-content: space-between;
  margin-bottom: 8px;
}

.buildCard header strong {
  font-size: 17px;
  white-space: nowrap;
}

#buildClose {
  width: 44px;
  height: 40px;
  font-size: 16px;
  flex: 0 0 auto;
}

#buildResources {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
  flex: 1;
  min-width: 0;
}

#buildResources .chip.resource {
  background: #fff7cf;
  color: #203326;
  border: 1px solid rgba(75, 48, 20, 0.25);
  font-size: 13px;
  min-height: 34px;
}

#buildGrid {
  display: flex;
  overflow-x: auto;
  gap: 8px;
  padding: 2px 2px 6px;
  scrollbar-width: thin;
}

.buildOption {
  flex: 0 0 auto;
  width: 104px;
  display: grid;
  justify-items: center;
  gap: 4px;
  padding: 8px 6px 7px;
  border-radius: 12px;
  border: 3px solid rgba(250, 239, 190, 0.2);
  background: #f6efd0;
  box-shadow: none;
  text-align: center;
}

.buildOption img {
  width: 54px;
  height: 54px;
  object-fit: contain;
}

.buildOption strong,
.buildOption span {
  display: block;
}

.buildOption strong {
  font-size: 12px;
  color: #203326;
}

.buildOption span {
  margin-top: 1px;
  color: #53624e;
  font-size: 10px;
  line-height: 1.2;
}

.buildOption.selected {
  border-color: #ffd23e;
  background: #dff0bd;
  box-shadow: 0 0 0 3px rgba(255, 210, 62, 0.4);
}

.buildOption.disabled {
  cursor: not-allowed;
  filter: grayscale(1);
  opacity: 0.42;
}

.miniCosts {
  min-height: 20px;
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 3px;
}

.miniCosts span,
.miniCosts em {
  display: inline-flex;
  align-items: center;
  gap: 1px;
  border-radius: 999px;
  padding: 1px 5px;
  background: rgba(255, 252, 229, 0.85);
  font-size: 11px;
  font-style: normal;
  font-weight: 800;
  color: #35442f;
}

.miniCosts img {
  width: 17px;
  height: 17px;
}

.buildCard footer {
  margin-top: 8px;
}

.buildCard footer button {
  flex: 1;
  min-height: 48px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  font-size: 15px;
  box-shadow: 0 4px 0 #b78f39, 0 8px 16px rgba(0, 0, 0, 0.16);
}

.buildCard footer button .ico {
  font-size: 20px;
}

.buildCard footer button:disabled {
  opacity: 0.45;
  filter: grayscale(0.7);
  cursor: not-allowed;
}

#confirmBuildBtn {
  background: #7ccf68;
  flex: 1.4;
}

#cancelBuildBtn {
  background: #ffd9c4;
}

.bagCard {
  width: min(560px, 100%);
  max-height: min(80vh, 640px);
  overflow: auto;
  border-radius: 12px;
  background: rgba(255, 252, 229, 0.98);
  border: 2px solid rgba(35, 79, 47, 0.32);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.3);
  padding: 14px 16px 16px;
}

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

.bagCard header strong {
  font-size: 19px;
}

#bagClose {
  width: 38px;
  height: 34px;
  font-size: 15px;
}

#bagContent h3 {
  margin: 12px 0 8px;
  font-size: 14px;
  color: #3c5540;
}

.bagGrid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: 8px;
}

.bagItem {
  display: grid;
  justify-items: center;
  gap: 2px;
  padding: 8px 4px;
  border-radius: 10px;
  background: #f2ecc9;
  border: 1px solid rgba(75, 48, 20, 0.18);
  text-align: center;
}

.bagGrid.done .bagItem {
  background: #e0efd2;
}

.bagItem img {
  width: 56px;
  height: 56px;
}

.bagItem span {
  font-size: 13px;
  font-weight: 700;
}

.bagItem small {
  font-size: 11px;
  color: #5c6b52;
}

.bagFoot {
  margin: 12px 0 0;
  font-size: 13px;
  font-weight: 650;
  color: #3c5540;
}

#message {
  min-height: 44px;
  padding: 10px 12px;
  line-height: 1.25;
  font-weight: 650;
}

#inventory {
  min-height: 56px;
  padding: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.chip {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 5px 8px;
  border-radius: 999px;
  background: #f5dd8b;
  border: 1px solid rgba(75, 48, 20, 0.2);
  font-size: 13px;
  font-weight: 700;
}

.empty {
  color: #6f715f;
  font-size: 13px;
  padding: 5px;
}

#quests {
  max-height: min(34vh, 230px);
  overflow: auto;
  padding: 8px;
}

.quest {
  display: grid;
  grid-template-columns: 18px 28px 1fr;
  gap: 6px;
  align-items: center;
  padding: 4px 2px;
  font-size: 13px;
  line-height: 1.2;
}

.quest.done {
  color: #54705a;
  text-decoration: line-through;
}

.farmPanel {
  display: grid;
  gap: 7px;
  padding: 5px 3px;
  font-size: 13px;
  line-height: 1.25;
  font-weight: 650;
}

#controls {
  position: absolute;
  inset: auto 12px 12px auto;
  width: 216px;
  height: 148px;
  display: grid;
  grid-template-columns: repeat(4, 48px);
  grid-template-rows: repeat(3, 44px);
  gap: 6px;
}

button {
  min-width: 0;
  min-height: 0;
  border: 0;
  border-radius: 8px;
  background: #fff7cf;
  color: #203326;
  box-shadow: 0 5px 0 #b78f39, 0 10px 22px rgba(0, 0, 0, 0.2);
  font-weight: 800;
  cursor: pointer;
}

button:active {
  transform: translateY(3px);
  box-shadow: 0 2px 0 #b78f39, 0 6px 16px rgba(0, 0, 0, 0.2);
}

.pad {
  font-size: 18px;
}

.up {
  grid-column: 2;
  grid-row: 1;
}

.left {
  grid-column: 1;
  grid-row: 2;
}

.down {
  grid-column: 2;
  grid-row: 3;
}

.right {
  grid-column: 3;
  grid-row: 2;
}

.action {
  grid-column: 4;
  width: 58px;
  display: grid;
  place-items: center;
  gap: 0;
  padding: 3px 0;
}

.action .ico {
  font-size: 20px;
  line-height: 1;
}

.action .lbl {
  font-size: 11px;
  line-height: 1;
}

#catchBtn {
  grid-row: 1 / span 1;
}

#talkBtn {
  grid-row: 2 / span 2;
}

.corner {
  font-size: 19px;
}

.corner.tl {
  grid-column: 1;
  grid-row: 1;
}

.corner.tr {
  grid-column: 3;
  grid-row: 1;
}

#startScreen {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(24, 59, 45, 0.52);
}

.startPanel {
  width: min(520px, 100%);
  padding: 24px;
  border-radius: 8px;
  background: rgba(255, 252, 229, 0.96);
  border: 2px solid rgba(35, 79, 47, 0.32);
  text-align: center;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.28);
}

.startPanel h1 {
  margin: 0 0 8px;
  font-size: clamp(32px, 7vw, 58px);
  line-height: 0.95;
}

.startPanel p {
  margin: 0 auto 18px;
  max-width: 410px;
  line-height: 1.35;
  font-weight: 650;
}

#startBtn {
  padding: 12px 18px;
  margin-bottom: 14px;
  background: #f6c94f;
  font-size: 16px;
}

.startPanel small {
  display: block;
  color: #5c665d;
  line-height: 1.35;
}

@media (max-width: 900px) {
  #buildPanel {
    right: 12px;
    bottom: 176px;
  }
}

@media (max-width: 720px) {
  #hud {
    top: 8px;
    left: 8px;
    width: calc(100vw - 16px);
  }

  #quests {
    display: none;
  }

  #controls {
    left: 10px;
    right: 10px;
    width: auto;
    justify-content: end;
  }
}

@media (pointer: coarse) {
  #controls {
    grid-template-columns: repeat(4, 56px);
    grid-template-rows: repeat(3, 52px);
    width: 252px;
    height: 172px;
    gap: 7px;
  }

  .action {
    width: 66px;
  }

  #bagBtn {
    width: 48px;
    height: 44px;
  }
}
