* { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  height: 100%;
  background: #1b2838;
  color: #2b1a0e;
  font-family: 'Fredoka', 'Trebuchet MS', system-ui, sans-serif;
  overflow: hidden;
  -webkit-user-select: none; user-select: none;
  -webkit-tap-highlight-color: transparent;
}
button { font-family: inherit; cursor: pointer; }

#app { height: 100vh; height: 100svh; display: flex; flex-direction: column; }

/* ---------- HUD ---------- */
#hud {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 8px 12px;
  background: linear-gradient(#7a4d27, #4e2f16);
  border-bottom: 4px solid #2e1a0a;
  box-shadow: 0 4px 12px rgba(0,0,0,.35);
  z-index: 2;
}
.version {
  font-size: 12px; font-weight: 700; letter-spacing: .05em;
  background: #000; color: #fff; padding: 2px 8px; border-radius: 5px;
}
#sunbox {
  display: flex; align-items: center; gap: 8px;
  background: #fff3c4; border: 3px solid #5a3b1a; border-radius: 14px;
  padding: 6px 14px 6px 8px; box-shadow: 0 4px 0 #2e1a0a;
  font-size: 26px; font-weight: 700; color: #7a4300; min-width: 110px;
  transition: transform .12s;
}
#sunbox.bump { transform: scale(1.12); }
.sunicon {
  width: 30px; height: 30px; border-radius: 50%;
  background: radial-gradient(circle at 40% 40%, #fff7b0, #ffd23f 45%, #ff9f1c);
  box-shadow: 0 0 10px #ffd23f;
}

#cards { display: flex; gap: 8px; }
.card, .tool {
  position: relative; overflow: hidden;
  width: 76px; height: 88px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
  background: linear-gradient(#fffbe8, #ffe39a);
  border: 3px solid #5a3b1a; border-radius: 12px;
  box-shadow: 0 4px 0 #2e1a0a;
  transition: transform .1s, box-shadow .1s, filter .15s;
}
.card:hover, .tool:hover { transform: translateY(-2px); }
.card .ico, .tool .ico { font-size: 32px; line-height: 1; }
.card .nm { font-size: 12px; font-weight: 700; }
.card .cost { font-size: 13px; font-weight: 700; color: #b45f00; }
.card .key { position: absolute; top: 3px; left: 6px; font-size: 11px; font-weight: 700; opacity: .55; }
.card .cd { position: absolute; left: 0; right: 0; top: 0; height: 0; background: rgba(20,10,0,.5); pointer-events: none; }
.card.poor { filter: grayscale(.75) brightness(.85); }
.card.sel, .tool.sel {
  transform: translateY(-5px);
  border-color: #ff3d00;
  box-shadow: 0 0 0 3px #ffd23f, 0 7px 0 #2e1a0a;
}
.tool { width: 62px; background: linear-gradient(#e8eef3, #b9c6d1); }
.tool small { font-size: 12px; font-weight: 700; }

.right { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.prog { display: flex; flex-direction: column; gap: 3px; color: #ffe9a8; font-weight: 700; }
.prog small { font-size: 11px; letter-spacing: .08em; text-transform: uppercase; }
#progress {
  width: 160px; height: 16px; border-radius: 10px;
  background: #2e1a0a; border: 2px solid #ffd23f; overflow: hidden;
}
#bar { height: 100%; width: 0; background: linear-gradient(90deg, #66d95c, #ffd23f, #ff5a36); transition: width .3s; }
.btns { display: flex; gap: 6px; }
.btns button {
  width: 40px; height: 40px; border-radius: 10px;
  background: #ffd23f; border: 3px solid #5a3b1a; box-shadow: 0 3px 0 #2e1a0a;
  font-size: 16px; font-weight: 700;
}
.btns button:active { transform: translateY(2px); box-shadow: 0 1px 0 #2e1a0a; }

/* ---------- Scène ---------- */
#stage {
  flex: 1; min-height: 0; position: relative;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(ellipse at center, #2c4660, #16212d 75%);
  padding: 10px;
}
canvas {
  display: block; border-radius: 16px;
  box-shadow: 0 12px 34px rgba(0,0,0,.45);
  touch-action: none;
}

/* ---------- Overlay ---------- */
#overlay {
  position: absolute; inset: 0; display: none;
  align-items: center; justify-content: center; padding: 16px;
  background: rgba(10,20,30,.55);
  -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px);
}
#overlay.show { display: flex; }
.panel {
  background: #fff8e1; border: 5px solid #5a3b1a; border-radius: 22px;
  padding: 24px 28px; width: min(100%, 480px); text-align: center;
  box-shadow: 0 10px 0 #3a2410, 0 20px 40px rgba(0,0,0,.4);
  max-height: 100%; overflow: auto;
  animation: pop .35s cubic-bezier(.2,1.4,.4,1);
}
@keyframes pop { from { transform: scale(.8); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.panel h1 {
  font-size: 46px; line-height: 1; color: #3fae4a; letter-spacing: 2px;
  text-shadow: 3px 3px 0 #1f5a26;
}
.panel h1 span { color: #ff8a1f; text-shadow: 3px 3px 0 #8a3d00; }
.panel .sub { font-weight: 700; color: #7a4d27; margin: 4px 0 14px; }
.legend { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-bottom: 12px; text-align: left; }
.legend div {
  background: #eaf7d8; border: 2px solid #9ccc7a; border-radius: 10px; padding: 6px 8px;
  display: flex; flex-direction: column;
}
.legend div.z { background: #eee4f5; border-color: #b69ccc; }
.legend b { font-size: 14px; }
.legend span { font-size: 12px; opacity: .8; }
.help { font-size: 13px; line-height: 1.5; margin-bottom: 16px; color: #5a3b1a; }
kbd {
  display: inline-block; min-width: 20px; padding: 0 5px; border-radius: 5px;
  background: #fff; border: 1px solid #b28a5a; border-bottom-width: 3px; font-family: inherit; font-size: 12px;
}
.big {
  font-size: 24px; font-weight: 700; color: #fff; letter-spacing: 1px;
  padding: 12px 42px; border-radius: 16px;
  background: linear-gradient(#7be86c, #3fae4a); border: 4px solid #1f5a26;
  box-shadow: 0 6px 0 #1f5a26; text-shadow: 2px 2px 0 #1f5a26;
}
.big:hover { filter: brightness(1.08); }
.big:active { transform: translateY(4px); box-shadow: 0 2px 0 #1f5a26; }
.stats { font-size: 16px; margin: 10px 0 18px; font-weight: 700; color: #5a3b1a; }
.panel .emoji { font-size: 56px; line-height: 1.1; }

/* ---------- Mobile ---------- */
.rotate-hint { display: none; position: absolute; bottom: 14px; left: 50%; transform: translateX(-50%);
  background: rgba(0,0,0,.6); color: #fff; font-weight: 700; font-size: 13px; padding: 6px 12px; border-radius: 20px; white-space: nowrap; }
@media (orientation: portrait) and (max-width: 720px) { .rotate-hint { display: block; } }

@media (max-width: 720px) {
  #hud { gap: 6px; padding: 6px 8px; }
  #sunbox { font-size: 20px; min-width: 84px; padding: 4px 10px 4px 6px; }
  .sunicon { width: 22px; height: 22px; }
  .card, .tool { width: 56px; height: 66px; }
  .card .ico, .tool .ico { font-size: 24px; }
  .card .nm, .tool small { display: none; }
  .right { width: 100%; margin-left: 0; justify-content: space-between; }
  #progress { width: 120px; }
  .btns button { width: 36px; height: 36px; }
  .panel h1 { font-size: 36px; }
  .legend { grid-template-columns: 1fr; }
}
