:root {
  color-scheme: light;
  --sky: #cfe6f5;
  --amber: #ffb44d;
  --amber-deep: #e58a2e;
  --wood: #9c5e2c;
  --wood-dark: #6b3d1c;
  --cream: #fff3dc;
  --ink: #3a2414;
  --glass: rgba(30, 44, 70, 0.55);
  --display: "Grandstander", "Nunito", "Trebuchet MS", system-ui, sans-serif;
  --body: "Nunito", "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; overflow: hidden; background: var(--sky); }
body { font-family: var(--body); color: var(--cream); user-select: none; -webkit-user-select: none; }
#app { position: fixed; inset: 0; }
#scene { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }

button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
button:focus-visible { outline: 3px solid var(--amber); outline-offset: 3px; }
svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- HUD ---------- */
#hud {
  position: absolute; left: 0; right: 0; top: 0;
  padding: calc(env(safe-area-inset-top, 0px) + 10px) 16px 0;
  display: flex; justify-content: space-between; align-items: flex-start; gap: 12px;
  pointer-events: none;
}
#hud > * { pointer-events: auto; }
#plaque {
  display: flex; flex-direction: column; align-items: flex-start;
  padding: 6px 18px 8px; border-radius: 12px;
  background:
    repeating-linear-gradient(0deg, rgba(0,0,0,0) 0 9px, rgba(0,0,0,.09) 9px 11px),
    linear-gradient(180deg, #b87238, var(--wood));
  box-shadow: inset 0 0 0 2px rgba(255, 220, 170, .25), 0 5px 0 var(--wood-dark), 0 10px 20px rgba(0,0,0,.25);
  min-width: 120px;
}
#town { font: 800 11px/1.2 var(--body); letter-spacing: .14em; text-transform: uppercase; opacity: .8; }
#toolName { font: 800 22px/1.1 var(--display); text-shadow: 0 2px 0 rgba(60, 30, 10, .45); }

#tools { display: flex; gap: 8px; align-items: center; }
.round {
  width: 44px; height: 44px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--glass); backdrop-filter: blur(6px);
  box-shadow: inset 0 0 0 1.5px rgba(255, 243, 220, .2);
}
.round:active { transform: scale(.92); }
#btnSound .mute { display: none; }
#btnSound[aria-pressed="false"] .wave { display: none; }
#btnSound[aria-pressed="false"] .mute { display: inline; }
#btnGfx[aria-pressed="true"] { background: var(--amber); color: var(--ink); }

.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 10px 16px; border-radius: 999px;
  background: var(--amber); color: var(--ink);
  font: 800 16px/1 var(--display);
  box-shadow: 0 4px 0 var(--amber-deep);
}
.pill.ghost { background: var(--glass); color: var(--cream); box-shadow: inset 0 0 0 1.5px rgba(255,243,220,.2); backdrop-filter: blur(6px); }
.pill.small svg { width: 20px; height: 20px; }
#btnNew.armed { background: #e2483d; color: #fff; box-shadow: 0 4px 0 #a52d24; }

/* ---------- hint ---------- */
#hint {
  position: absolute; left: 50%; top: calc(env(safe-area-inset-top, 0px) + 74px);
  transform: translateX(-50%);
  width: max-content; max-width: calc(100% - 32px);
  padding: 8px 16px; border-radius: 999px;
  background: var(--glass); backdrop-filter: blur(6px);
  font-weight: 800; font-size: 15px; text-align: center;
  opacity: 0; transition: opacity .5s; pointer-events: none;
}
#hint.show { opacity: 1; }

/* ---------- tálca ---------- */
#tray {
  position: absolute; left: 0; right: 0; bottom: 0;
  padding: 12px 16px calc(env(safe-area-inset-bottom, 0px) + 12px);
  display: flex; gap: 10px;
  overflow-x: auto; scrollbar-width: none;
  background: linear-gradient(180deg, rgba(30,44,70,0) 0%, rgba(30,44,70,.45) 40%, rgba(30,44,70,.7) 100%);
}
#tray::-webkit-scrollbar { display: none; }
#tray::before, #tray::after { content: ""; flex: 1 0 0; }
.card {
  position: relative; flex: 0 0 auto;
  width: 86px; height: 92px; border-radius: 20px;
  display: flex; flex-direction: column; align-items: center; justify-content: flex-end;
  padding: 4px 4px 7px;
  background: radial-gradient(circle at 50% 38%, #fffaf0 0%, #f3dfbd 72%);
  box-shadow: inset 0 -5px 0 rgba(160, 100, 50, .22), 0 5px 12px rgba(0,0,0,.25);
  transition: transform .25s cubic-bezier(.3,1.6,.5,1), box-shadow .2s;
  animation: cardIn .45s cubic-bezier(.3,1.6,.5,1) both;
}
.card img, .card .eraser { width: 64px; height: 64px; object-fit: contain; pointer-events: none; -webkit-user-drag: none; }
.card .eraser { padding: 8px; }
.card .lbl { font: 800 12px/1 var(--body); color: var(--ink); white-space: nowrap; }
.card.on {
  transform: translateY(-8px);
  box-shadow: inset 0 0 0 3px var(--amber), inset 0 -5px 0 rgba(160, 100, 50, .22), 0 10px 18px rgba(0,0,0,.3);
}
.card:active { transform: translateY(-4px) scale(.95); }
@keyframes cardIn { from { transform: translateY(40px) scale(.6); opacity: 0; } }

/* ---------- betöltő ---------- */
#loader {
  position: absolute; inset: 0; z-index: 10;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 24px;
  background: radial-gradient(ellipse at 50% 40%, #e9f4fb, #9fcbe8);
  transition: opacity .6s;
}
#loader img { width: min(180px, 40vw); height: auto; }
#loader .bar { width: min(220px, 60vw); height: 10px; border-radius: 5px; background: rgba(30,44,70,.15); overflow: hidden; }
#loader .bar i { display: block; height: 100%; width: 0; background: var(--amber); border-radius: 5px; transition: width .3s; }
#loader.out { opacity: 0; pointer-events: none; }

@media (max-width: 560px) {
  #toolName { font-size: 19px; }
  #btnNew span { display: none; }
  #btnNew.armed span { display: inline; }
  #btnNew { padding: 10px 12px; }
  .card { width: 74px; height: 80px; border-radius: 18px; }
  .card img, .card .eraser { width: 54px; height: 54px; }
  #hint { top: calc(env(safe-area-inset-top, 0px) + 70px); font-size: 14px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
