* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { width: 100%; height: 100%; overflow: hidden; background: #1a3a5c; }
body { font-family: 'Baloo 2', 'Comic Sans MS', sans-serif; user-select: none; -webkit-user-select: none; }
canvas#game { display: block; width: 100vw; height: 100vh; touch-action: none; }
.hidden { display: none !important; }

/* ---------- HUD ---------- */
#hud { position: fixed; top: 0; left: 0; right: 0; padding: 10px 12px; display: flex; justify-content: space-between; pointer-events: none; z-index: 20; }
.hud-left, .hud-right { display: flex; gap: 8px; align-items: flex-start; }
.hud-pill {
  background: rgba(255, 250, 230, 0.94); color: #5a4a32; font-weight: 800; font-size: 17px;
  padding: 5px 14px; border-radius: 999px; border: 3px solid #b89b6b;
  box-shadow: 0 3px 0 rgba(0,0,0,0.15); display: flex; align-items: center; gap: 6px;
}
.hud-pill .star { color: #e8ad00; }
.hud-tool { font-size: 15px; }
.hud-btn {
  pointer-events: auto; width: 46px; height: 46px; border-radius: 50%; border: 3px solid #b89b6b;
  background: rgba(255, 250, 230, 0.94); font-size: 21px; cursor: pointer;
  box-shadow: 0 3px 0 rgba(0,0,0,0.15); transition: transform 0.1s;
}
.hud-btn:active { transform: scale(0.9); }

/* ---------- Toast ---------- */
#toast {
  position: fixed; top: 70px; left: 50%; transform: translateX(-50%) translateY(-20px);
  background: rgba(90, 74, 50, 0.92); color: #fff8e1; font-weight: 700; font-size: 16px;
  padding: 8px 22px; border-radius: 999px; opacity: 0; transition: all 0.25s; z-index: 40; pointer-events: none;
  max-width: 90vw; text-align: center;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- Dialog ---------- */
#dialog {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  width: min(620px, 92vw); min-height: 110px; z-index: 30;
  background: #fffbe8; border: 4px solid #c9a86a; border-radius: 24px;
  padding: 26px 24px 18px; box-shadow: 0 6px 0 rgba(0,0,0,0.2);
  cursor: pointer;
}
#dialogName {
  position: absolute; top: -18px; left: 22px; background: #ff9d3c; color: #fff;
  font-weight: 800; font-size: 16px; padding: 3px 18px; border-radius: 999px;
  border: 3px solid #fff; box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}
#dialogText { font-size: 19px; font-weight: 700; color: #5a4a32; line-height: 1.45; min-height: 56px; }
#dialogNext { position: absolute; bottom: 8px; right: 18px; color: #c9a86a; font-size: 16px; animation: bob 0.8s infinite alternate; }
@keyframes bob { from { transform: translateY(0); } to { transform: translateY(4px); } }

/* ---------- Catch popup ---------- */
#catchPopup {
  position: fixed; top: 50%; left: 50%; transform: translate(-50%, -55%);
  background: #fffbe8; border: 4px solid #c9a86a; border-radius: 28px; z-index: 35;
  padding: 26px 40px; text-align: center; box-shadow: 0 8px 30px rgba(0,0,0,0.35);
  animation: popIn 0.3s cubic-bezier(0.2, 1.6, 0.4, 1);
}
@keyframes popIn { from { transform: translate(-50%, -55%) scale(0.5); opacity: 0; } to { transform: translate(-50%, -55%) scale(1); opacity: 1; } }
#catchEmoji { font-size: 64px; margin-bottom: 6px; }
#catchTitle { font-size: 24px; font-weight: 800; color: #5a4a32; }
#catchDesc { font-size: 17px; font-weight: 700; color: #9c8a68; margin-top: 4px; }

/* ---------- Panels ---------- */
#panel {
  position: fixed; inset: 0; z-index: 50; background: rgba(30, 50, 40, 0.45);
  display: flex; align-items: center; justify-content: center; padding: 14px;
}
#panelBox {
  width: min(640px, 96vw); max-height: 88vh; display: flex; flex-direction: column;
  background: #fffbe8; border: 4px solid #c9a86a; border-radius: 26px; overflow: hidden;
  box-shadow: 0 10px 40px rgba(0,0,0,0.4);
}
#panelHead {
  display: flex; justify-content: space-between; align-items: center;
  background: #8fce5a; padding: 12px 18px; border-bottom: 4px solid #c9a86a;
}
#panelTitle { font-size: 21px; font-weight: 800; color: #fff; text-shadow: 0 2px 0 rgba(0,0,0,0.15); }
#panelClose {
  width: 36px; height: 36px; border-radius: 50%; border: 3px solid #fff; background: #ff7a5c;
  color: #fff; font-size: 17px; font-weight: 800; cursor: pointer;
}
#panelTabs { display: flex; gap: 6px; padding: 10px 14px 0; flex-wrap: wrap; }
#panelTabs:empty { display: none; }
.tab-btn {
  border: 3px solid #c9a86a; background: #f3e8c8; color: #8a744e; font-family: inherit;
  font-weight: 800; font-size: 15px; padding: 5px 16px; border-radius: 999px; cursor: pointer;
}
.tab-btn.active { background: #ffce54; color: #6b5323; }
#panelBody { padding: 14px; overflow-y: auto; flex: 1; }
#panelFoot { padding: 0 14px 14px; }
#panelFoot:empty { display: none; }

.item-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(74px, 1fr)); gap: 8px; }
.item-cell {
  aspect-ratio: 1; background: #f6eed4; border: 3px solid #e0cfa0; border-radius: 16px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  cursor: pointer; position: relative; transition: transform 0.08s;
}
.item-cell:hover { transform: scale(1.05); border-color: #ffce54; }
.item-cell.selected { border-color: #ff9d3c; background: #ffe9c2; }
.item-cell.empty { opacity: 0.45; cursor: default; }
.item-cell .emo { font-size: 30px; line-height: 1; }
.item-cell .cnt {
  position: absolute; bottom: 4px; right: 7px; font-size: 13px; font-weight: 800;
  color: #fff; background: #8fce5a; border-radius: 999px; padding: 0 6px;
}
.item-cell .nm { font-size: 10px; font-weight: 700; color: #8a744e; margin-top: 2px; max-width: 100%; overflow: hidden; white-space: nowrap; text-align:center; }
.item-cell.unknown .emo { filter: grayscale(1) brightness(0.4); opacity: 0.5; }

.shop-row {
  display: flex; align-items: center; gap: 12px; background: #f6eed4; border: 3px solid #e0cfa0;
  border-radius: 16px; padding: 8px 12px; margin-bottom: 8px;
}
.shop-row .emo { font-size: 30px; width: 42px; text-align: center; }
.shop-row .info { flex: 1; }
.shop-row .info b { color: #5a4a32; font-size: 16px; }
.shop-row .info small { display: block; color: #9c8a68; font-weight: 700; font-size: 12px; }
.shop-row .price { font-weight: 800; color: #e8ad00; font-size: 15px; white-space: nowrap; }
.shop-btn {
  border: 3px solid #6ba63e; background: #8fce5a; color: #fff; font-family: inherit;
  font-weight: 800; font-size: 14px; padding: 6px 14px; border-radius: 999px; cursor: pointer;
}
.shop-btn:disabled { opacity: 0.4; cursor: default; }
.shop-btn.sell { background: #ffab54; border-color: #d9832a; }

.act-btn {
  width: 100%; border: 3px solid #6ba63e; background: #8fce5a; color: #fff; font-family: inherit;
  font-weight: 800; font-size: 17px; padding: 10px; border-radius: 16px; cursor: pointer; margin-top: 4px;
}
.act-btn.warn { background: #ff7a5c; border-color: #cc4a2e; }
.panel-note { color: #9c8a68; font-weight: 700; font-size: 14px; text-align: center; padding: 8px; }

/* ---------- Start screen ---------- */
#startScreen {
  position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(180deg, #7ec8e8 0%, #a8dcf0 45%, #f5dfa8 70%, #6db2e0 100%);
  padding: 14px; overflow-y: auto;
}
#startBox {
  width: min(440px, 94vw); background: #fffbe8; border: 4px solid #c9a86a; border-radius: 30px;
  padding: 28px 30px; text-align: center; box-shadow: 0 12px 50px rgba(0,0,0,0.3);
}
#startBox h1 { font-size: 38px; color: #4a8a3c; text-shadow: 0 3px 0 rgba(0,0,0,0.08); }
.tagline { color: #9c8a68; font-weight: 700; margin: 6px 0 18px; }
#startBox label { display: block; text-align: left; font-weight: 800; color: #5a4a32; margin: 14px 0 6px; }
#nameInput {
  width: 100%; font-family: inherit; font-size: 19px; font-weight: 700; color: #5a4a32;
  border: 3px solid #c9a86a; border-radius: 14px; padding: 9px 14px; background: #f6eed4; outline: none;
}
#nameInput:focus { border-color: #ffce54; }
.swatches { display: flex; gap: 10px; flex-wrap: wrap; }
.swatch {
  width: 42px; height: 42px; border-radius: 50%; border: 4px solid rgba(0,0,0,0.12); cursor: pointer;
  transition: transform 0.1s;
}
.swatch.selected { border-color: #5a4a32; transform: scale(1.15); }
.big-btn {
  width: 100%; margin-top: 22px; border: none; border-radius: 18px; background: #ff9d3c;
  color: #fff; font-family: inherit; font-size: 21px; font-weight: 800; padding: 13px;
  cursor: pointer; box-shadow: 0 5px 0 #d9832a; transition: transform 0.1s;
}
.big-btn:active { transform: translateY(3px); box-shadow: 0 2px 0 #d9832a; }
.small-link { background: none; border: none; color: #9c8a68; font-family: inherit; font-weight: 700; margin-top: 14px; cursor: pointer; text-decoration: underline; font-size: 14px; }
.credits { margin-top: 18px; font-size: 13px; color: #b8a888; font-weight: 700; }
#welcomeBack { font-size: 19px; font-weight: 800; color: #5a4a32; margin-top: 10px; }

/* ---------- Touch ---------- */
#touchUI { position: fixed; inset: 0; z-index: 15; pointer-events: none; }
#joyBase {
  position: absolute; bottom: 30px; left: 26px; width: 130px; height: 130px; border-radius: 50%;
  background: rgba(255, 250, 230, 0.25); border: 3px solid rgba(255, 250, 230, 0.5); pointer-events: auto;
}
#joyStick {
  position: absolute; top: 50%; left: 50%; width: 56px; height: 56px; border-radius: 50%;
  background: rgba(255, 250, 230, 0.75); transform: translate(-50%, -50%); box-shadow: 0 3px 6px rgba(0,0,0,0.25);
}
#touchButtons { position: absolute; bottom: 34px; right: 26px; display: flex; flex-direction: column; gap: 14px; align-items: center; pointer-events: auto; }
#tbAction {
  width: 84px; height: 84px; border-radius: 50%; border: 4px solid #d9832a; background: rgba(255, 157, 60, 0.92);
  color: #fff; font-family: inherit; font-size: 32px; font-weight: 800; box-shadow: 0 4px 0 rgba(0,0,0,0.2);
}
#tbTool {
  width: 58px; height: 58px; border-radius: 50%; border: 3px solid #b89b6b; background: rgba(255, 250, 230, 0.92);
  font-size: 24px; box-shadow: 0 3px 0 rgba(0,0,0,0.2);
}
#tbAction:active, #tbTool:active { transform: scale(0.92); }

@media (max-width: 600px) {
  .hud-pill { font-size: 14px; padding: 4px 10px; }
  .hud-btn { width: 40px; height: 40px; font-size: 18px; }
  #dialogText { font-size: 16px; }
  #startBox h1 { font-size: 30px; }
}
