* { box-sizing: border-box; margin: 0; padding: 0; }
body, html { width: 100%; height: 100%; overflow: hidden; font-family: 'Fredoka One', cursive; background: #87CEEB; color: #fff; user-select: none; }
canvas { display: block; width: 100%; height: 100%; touch-action: none; background: linear-gradient(to bottom, #87CEEB 30%, #1E90FF 30%, #00008B 100%); cursor: crosshair; }
#ui-layer { position: absolute; inset: 0; pointer-events: none; display: flex; flex-direction: column; justify-content: space-between; padding: clamp(16px, 3vw, 30px); z-index: 5; }
.hidden {
  display: none !important;
}

/* Item Modal */
#item-modal {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.8);
  backdrop-filter: blur(5px);
  z-index: 100;
  display: flex;
  justify-content: center;
  align-items: center;
  opacity: 1;
  transition: opacity 0.2s;
}

#item-modal.hidden {
  opacity: 0;
  pointer-events: none;
}

.modal-content {
  background: var(--panel-bg);
  border: 1px solid rgba(255,255,255,0.2);
  padding: 30px;
  border-radius: 20px;
  text-align: center;
  position: relative;
  width: 80%;
  max-width: 300px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.5);
  transform: scale(1);
  transition: transform 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

#item-modal.hidden .modal-content {
  transform: scale(0.8);
}

#close-modal {
  position: absolute;
  top: 10px;
  right: 15px;
  background: none;
  border: none;
  color: white;
  font-size: 24px;
  cursor: pointer;
  padding: 0;
}

#modal-img-container {
  width: 150px;
  height: 150px;
  margin: 0 auto 20px;
  background-color: #fff;
  border-radius: 50%;
  position: relative;
  overflow: hidden;
  box-shadow: 0 0 20px rgba(255,255,255,0.1);
}

#modal-img-container .item-img {
  width: 100%;
  height: 100%;
  animation: none;
}

#modal-title {
  color: var(--accent);
  font-size: 1.5rem;
  margin-bottom: 10px;
}

#modal-desc {
  color: var(--text-secondary);
  font-size: 0.9rem;
  line-height: 1.4;
}
header { display: flex; justify-content: space-between; align-items: center; gap: 14px; text-shadow: 0 4px 6px rgba(0,0,0,0.5); }
h1 { font-size: clamp(2rem, 5vw, 3.5rem); color: #FFA500; -webkit-text-stroke: 2px #8B4513; text-shadow: 0 4px 10px rgba(0,0,0,0.3); }
#score-indicator { font-size: clamp(1.2rem, 3.4vw, 2rem); background: rgba(0,0,0,0.4); padding: 10px 24px; border-radius: 30px; backdrop-filter: blur(5px); border: 2px solid rgba(255,255,255,0.2); white-space: nowrap; }
#combo-indicator { font-size: 2rem; background: rgba(255,165,0,0.8); padding: 10px 30px; border-radius: 30px; backdrop-filter: blur(5px); border: 2px solid rgba(255,255,255,0.8); color: white; transition: transform 0.2s, opacity 0.3s; }
#combo-indicator.hidden { opacity: 0; transform: scale(0.8); pointer-events: none; }
.combo-pop { animation: pop 0.3s ease-out; }
@keyframes pop { 0% { transform: scale(1); } 50% { transform: scale(1.3); } 100% { transform: scale(1); } }
#controls-hint { position: fixed !important; left: 50%; bottom: 118px !important; transform: translateX(-50%); width: fit-content; max-width: min(640px, calc(100vw - 42px)); align-self: center; text-align: center; margin: 0; font-size: clamp(.95rem, 2.2vw, 1.28rem); line-height: 1.25; animation: floatHint 2.2s infinite ease-in-out; text-shadow: 0 2px 5px rgba(0,0,0,0.68); background: rgba(34,38,46,.48); border: 1px solid rgba(255,255,255,.3); padding: 10px 18px; border-radius: 999px; backdrop-filter: blur(6px); box-shadow: 0 14px 34px rgba(35, 45, 58, .18); }
#cast-button { pointer-events: auto; position: fixed; left: 50%; bottom: 18px !important; transform: translateX(-50%); z-index: 14; min-width: 148px; border: 0; border-radius: 999px; padding: 15px 32px; font: 900 clamp(1.05rem, 2.7vw, 1.45rem) 'Fredoka One', cursive; color: #4f331f; background: linear-gradient(135deg,#fff4a9,#ffb45e,#ff8fc7); box-shadow: 0 12px 0 rgba(116,67,38,.32), 0 22px 38px rgba(62,41,30,.22); cursor: pointer; }
#cast-button:active { transform: translateX(-50%) translateY(7px); box-shadow: 0 7px 0 rgba(116,67,38,.35), 0 14px 25px rgba(62,41,30,.22); }
@keyframes floatHint { 0%, 100% { transform: translateX(-50%) translateY(0); } 50% { transform: translateX(-50%) translateY(-7px); } }

/* Inventory UI */
#inventory-toggle { position: fixed; right: 18px; top: 92px; z-index: 12; display: none; border: 0; border-radius: 999px; background: linear-gradient(135deg,#ffd66f,#ff9dc5); color: #432c35; font-weight: 900; padding: 12px 16px; box-shadow: 0 12px 30px rgba(59,40,44,.28); cursor: pointer; }
#inventory-toggle.show { display: block; }
#inventory-panel { position: fixed; right: clamp(12px, 2vw, 20px); top: clamp(96px, 14vh, 120px); width: min(300px, 28vw); max-height: calc(100vh - 150px); overflow-y: auto; overscroll-behavior: contain; background: linear-gradient(155deg, rgba(50,42,36,.72), rgba(35,46,42,.72)); padding: 16px; border-radius: 22px; backdrop-filter: blur(10px); border: 1px solid rgba(255,255,255,0.22); z-index: 11; transition: transform .22s ease, opacity .22s ease; box-shadow: 0 18px 55px rgba(25,22,20,.32); }
#inventory-panel.collapsed { transform: translateX(calc(100% + 24px)); opacity: 0; pointer-events: none; }
#inventory-panel::-webkit-scrollbar { width: 8px; }
#inventory-panel::-webkit-scrollbar-thumb { background: rgba(255,255,255,.28); border-radius: 999px; }
.inventory-header { display: grid; grid-template-columns: 1fr auto auto; gap: 8px; align-items: center; margin-bottom: 10px; border-bottom: 1px solid rgba(255,255,255,0.2); padding-bottom: 8px; }
.inventory-header h2 { font-size: 1.2rem; color: #fff; }
.inventory-header button { width: 32px; height: 32px; border: 1px solid rgba(255,255,255,.22); border-radius: 999px; background: rgba(255,255,255,.12); color: #fff; font-weight: 900; cursor: pointer; }
.inventory-header.master-completed { color: #facc15; text-shadow: 0 0 10px #facc15; }

.progress-bar-container { width: 100%; height: 8px; background: rgba(255,255,255,0.1); border-radius: 4px; margin-bottom: 15px; overflow: hidden; box-shadow: inset 0 1px 3px rgba(0,0,0,0.5); }
#progress-bar-fill { height: 100%; background: linear-gradient(90deg, #38bdf8, #facc15); transition: width 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275); }

#inventory-grid { display: grid; grid-template-columns: repeat(3, minmax(54px, 1fr)); gap: 10px; }
.inv-slot { width: 100%; aspect-ratio: 1; background: rgba(255,255,255,0.1); border-radius: 8px; border: 1px solid rgba(255,255,255,0.1); display: flex; justify-content: center; align-items: center; cursor: pointer; transition: transform 0.2s, background 0.2s; position: relative; overflow: hidden; }
.inv-slot:hover { transform: scale(1.1); background: rgba(255,255,255,0.2); }
.inv-slot.rare { border-color: #facc15; box-shadow: 0 0 10px rgba(250,204,21,0.5); }
.inv-slot.junk { filter: grayscale(1); }
.item-img { width: 80%; height: 80%; background-size: contain; background-repeat: no-repeat; background-position: center; }

@media (max-width: 900px) {
  header { align-items: flex-start; }
  .header-right { flex-direction: column; align-items: flex-end !important; gap: 8px !important; }
  #inventory-panel { width: min(280px, 82vw); top: 92px; max-height: calc(100vh - 132px); }
  #controls-hint { max-width: calc(100vw - 36px); bottom: 108px !important; padding: 9px 14px; }
  #cast-button { min-width: 132px; padding: 13px 28px; }
}

@media (max-height: 740px) {
  #inventory-panel { top: 86px; max-height: calc(100vh - 112px); width: min(260px, 30vw); padding: 12px; }
  #inventory-grid { gap: 8px; grid-template-columns: repeat(3, minmax(44px, 1fr)); }
  .inventory-header h2 { font-size: 1rem; }
}
