@media (max-width:480px){.game-header{padding:56px 10px 8px}.home-btn{width:40px;height:40px;font-size:1.2rem;top:10px;left:10px}}
*{margin:0;padding:0;box-sizing:border-box;-webkit-tap-highlight-color:transparent}
html,body{width:100%;height:100%;overflow:hidden;font-family:'Zen Maru Gothic',sans-serif;user-select:none;touch-action:manipulation}
body{background:linear-gradient(180deg,#E3F2FD 0%,#BBDEFB 50%,#90CAF9 100%)}
.home-btn{position:fixed;top:12px;left:12px;width:48px;height:48px;background:#fff;border-radius:50%;display:flex;justify-content:center;align-items:center;font-size:1.4rem;text-decoration:none;box-shadow:0 4px 12px rgba(0,0,0,.15);z-index:9999;border:3px solid #42A5F5}
#game-container{width:100%;height:100%;display:flex;flex-direction:column;overflow:hidden}
.game-header{flex-shrink:0;padding:10px 16px;display:flex;align-items:center;justify-content:space-between;gap:10px;flex-wrap:wrap}
.title-badge{background:#fff;padding:8px 14px;border-radius:20px;font-weight:700;display:flex;align-items:center;gap:8px;box-shadow:0 3px 0 #BDBDBD;font-size:.9rem}
.level-pill{background:#fff;padding:8px 12px;border-radius:16px;font-weight:700;box-shadow:0 3px 0 #BDBDBD;font-size:.85rem}
.reset-btn{font-family:inherit;font-weight:700;padding:8px 14px;border-radius:16px;border:none;background:#FF7043;color:#fff;box-shadow:0 3px 0 #E64A19;cursor:pointer;font-size:.85rem}
.play-row{flex:1;display:flex;flex-direction:row;align-items:center;justify-content:center;gap:30px;padding:10px 20px;min-height:0}
.board-wrap{flex:1;display:flex;flex-direction:column;align-items:center;justify-content:center;min-width:0}
.hint{font-size:.9rem;color:#1565C0;margin-bottom:10px;text-align:center;font-weight:700}
.board{display:grid;grid-template-columns:repeat(3,1fr);grid-template-rows:repeat(3,1fr);gap:8px;width:min(60vmin,380px);height:min(60vmin,380px);background:#FFE082;border:8px solid #FFA000;border-radius:24px;padding:12px;box-shadow:0 10px 30px rgba(0,0,0,.15)}
.cell{background:rgba(255,255,255,.45);border-radius:12px;position:relative}
.cell.filled{background:rgba(255,255,255,.15);cursor:grab;touch-action:none}
.cell.preview-valid{box-shadow:inset 0 0 0 4px rgba(76,175,80,.95);background:rgba(200,230,201,.55)!important}
.cell.preview-invalid{box-shadow:inset 0 0 0 4px rgba(244,67,54,.85);background:rgba(255,205,210,.45)!important}
.tray-wrap{width:220px;display:flex;flex-direction:column;align-items:center;gap:10px;flex-shrink:0}
.tray-label{font-weight:700;font-size:1rem;color:#0D47A1;margin-bottom:5px}
.tray{display:grid;grid-template-columns:1fr 1fr;gap:10px;justify-items:center;width:100%;overflow-y:auto;max-height:100%;padding:5px}
.piece-host{position:relative;touch-action:none}
.piece-svg{display:block;filter:drop-shadow(0 3px 4px rgba(0,0,0,.2))}
@media (orientation:portrait){.play-row{flex-direction:column;align-items:center}.tray-wrap{width:100%;max-height:38vh;flex-direction:row;flex-wrap:wrap;justify-content:center}.tray{flex-direction:row;flex-wrap:wrap;justify-content:center}}
@media screen and (max-height: 500px) {
  #game-container {
    margin-left: 80px !important;
    width: calc(100% - 80px) !important;
  }
  .game-header { padding: 4px 16px !important; }
  .title-badge, .level-pill { font-size: 0.8rem; padding: 4px 12px; }
  .reset-btn { font-size: 0.8rem; padding: 6px 12px; }
  .play-row { padding: 5px 15px 10px; gap: 20px; }
  .board-wrap { gap: 4px; flex: 3; }
  .hint { font-size: 0.75rem; margin-bottom: 2px; }
  .board { width:min(70vh,300px); height:min(70vh,300px); border-width: 5px; padding: 8px; border-radius: 16px; }
  .tray-wrap { width: 180px; gap: 2px; flex: 2; margin-right: 10px; }
  .tray-label { font-size: 0.8rem; }
  .tray { gap: 8px; grid-template-columns: 1fr 1fr; transform: scale(0.85); transform-origin: top center; }
}

.overlay{position:fixed;inset:0;background:rgba(0,0,0,.45);display:flex;align-items:center;justify-content:center;z-index:10000;padding:16px}
.overlay.hidden{display:none!important}
.overlay-card{background:#fff;border-radius:22px;padding:22px;max-width:300px;width:100%;text-align:center;box-shadow:0 12px 36px rgba(0,0,0,.2)}
.overlay-title{font-size:1.25rem;font-weight:900;color:#1565C0;margin-bottom:14px}
.overlay-btn{display:block;width:100%;font-family:inherit;font-weight:700;padding:12px;border-radius:16px;border:none;background:#42A5F5;color:#fff;margin-bottom:8px;cursor:pointer;box-shadow:0 4px 0 #1565C0}
.overlay-btn.secondary{background:#B0BEC5;box-shadow:0 4px 0 #78909C;color:#333}
.stage-list{display:flex;flex-direction:column;gap:8px}
.stage-list button{font-family:inherit;font-weight:700;padding:10px;border-radius:12px;border:2px solid #90CAF9;background:#fff;cursor:pointer}