:root {
  --sky-top: #7ec8ff;
  --sky-bot: #e8f6ff;
  --grass: #7bc96f;
  --panel: rgba(255, 255, 255, 0.92);
  --ink: #1a2a3a;
  --accent: #e83030;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
  --palette-h: 118px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; padding: 0; height: 100%; width: 100%;
  overflow: hidden; background: var(--sky-top);
  font-family: "Nunito", "Segoe UI", system-ui, sans-serif;
  color: var(--ink); touch-action: none; user-select: none;
}
#app { position: relative; width: 100%; height: 100%; overflow: hidden; }
#world {
  position: absolute; inset: 0 0 var(--palette-h) 0;
  width: 100%; height: calc(100% - var(--palette-h));
  display: block; touch-action: none; background:
    linear-gradient(180deg, var(--sky-top) 0%, var(--sky-bot) 70%, #c8e99b 70%, var(--grass) 100%);
}
#hud {
  position: absolute; top: calc(8px + var(--safe-top)); left: 8px; right: 8px;
  display: flex; gap: 8px; align-items: center; justify-content: space-between;
  pointer-events: none; z-index: 5;
}
#hud .cluster { display: flex; gap: 8px; pointer-events: auto; flex-wrap: wrap; }
.btn {
  min-width: 52px; min-height: 52px; border: none; border-radius: 16px;
  background: var(--panel); color: var(--ink); font-size: 22px; font-weight: 800;
  box-shadow: 0 4px 0 rgba(0,0,0,.15); cursor: pointer; padding: 8px 14px;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.btn:active { transform: translateY(2px); box-shadow: 0 2px 0 rgba(0,0,0,.15); }
.btn.danger { background: #ffe0e0; color: #b01020; }
.btn.primary { background: #ffe66d; }
.btn:disabled { opacity: .4; }
#badge {
  pointer-events: auto; background: var(--panel); border-radius: 14px;
  padding: 6px 12px; font-size: 12px; font-weight: 700; max-width: 46vw;
  line-height: 1.25; box-shadow: 0 2px 8px rgba(0,0,0,.08);
}
#palette {
  position: absolute; left: 0; right: 0; bottom: 0;
  height: calc(var(--palette-h) + var(--safe-bottom));
  padding: 8px 10px calc(10px + var(--safe-bottom));
  background: linear-gradient(180deg, rgba(255,255,255,.75), rgba(255,255,255,.95));
  border-top: 3px solid rgba(255,255,255,.9);
  display: flex; gap: 10px; align-items: stretch; overflow-x: auto;
  overflow-y: hidden; -webkit-overflow-scrolling: touch; z-index: 6;
  touch-action: pan-x;
}
.pal-item {
  flex: 0 0 auto; width: 78px; border-radius: 18px; border: 3px solid rgba(0,0,0,.08);
  background: #fff; display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 2px; cursor: grab; position: relative;
  box-shadow: 0 3px 0 rgba(0,0,0,.1);
}
.pal-item canvas { width: 56px; height: 56px; pointer-events: none; }
.pal-item .n {
  font-size: 16px; font-weight: 900; line-height: 1;
}
.pal-item:active { transform: scale(.96); }
#toast {
  position: absolute; left: 50%; bottom: calc(var(--palette-h) + 16px);
  transform: translateX(-50%); background: rgba(20,30,40,.88); color: #fff;
  padding: 10px 16px; border-radius: 999px; font-weight: 700; font-size: 15px;
  opacity: 0; transition: opacity .2s; pointer-events: none; z-index: 20;
  max-width: 90vw; text-align: center;
}
#toast.show { opacity: 1; }
#modal {
  position: absolute; inset: 0; background: rgba(0,0,0,.45); display: none;
  align-items: center; justify-content: center; z-index: 30; padding: 20px;
}
#modal.open { display: flex; }
#modal .card {
  background: #fff; border-radius: 24px; padding: 22px; max-width: 340px; width: 100%;
  text-align: center; box-shadow: 0 12px 40px rgba(0,0,0,.25);
}
#modal h2 { margin: 0 0 8px; font-size: 22px; }
#modal p { margin: 0 0 18px; font-size: 15px; opacity: .8; }
#modal .row { display: flex; gap: 10px; justify-content: center; }
#help {
  position: absolute; left: 12px; bottom: calc(var(--palette-h) + 12px);
  background: var(--panel); border-radius: 14px; padding: 8px 12px;
  font-size: 13px; font-weight: 700; box-shadow: 0 2px 8px rgba(0,0,0,.08);
  z-index: 5; max-width: 70vw; pointer-events: none;
}
