* { margin:0; padding:0; box-sizing:border-box; -webkit-tap-highlight-color:transparent; }
:root {
  --stone:#4a4a5a; --stone-dark:#2a2a3a; --stone-light:#6a6a7a;
  --gold:#c8a832; --gold-light:#e8c850;
  --dungeon-bg:#1a1520; --text-light:#e8d8b0; --text-dim:#8a7a5a;
  --green:#4caf50; --red:#e53935; --orange:#ff9800;
}
html,body { width:100%; height:100%; overflow:hidden; background:var(--dungeon-bg);
  font-family:'Georgia','Times New Roman',serif; color:var(--text-light); }

/* ── SCREENS ── */
.screen { display:none; position:fixed; inset:0; }
.screen.active { display:flex; }

/* ── SHARED ── */
.btn-back {
  background:none; border:1px solid var(--stone-light); color:var(--text-light);
  padding:8px 14px; border-radius:4px; font-family:inherit; cursor:pointer;
  font-size:14px; transition:all .2s; white-space:nowrap;
}
.btn-back:hover { border-color:var(--gold); color:var(--gold-light); }

.btn-menu {
  width:100%; padding:15px 20px; font-size:clamp(14px,3.5vw,17px);
  font-family:inherit; border:2px solid var(--gold);
  background:linear-gradient(180deg,rgba(200,168,50,.15) 0%,rgba(100,80,20,.2) 100%);
  color:var(--gold-light); cursor:pointer; border-radius:4px; letter-spacing:2px;
  transition:all .2s; display:flex; align-items:center; justify-content:center; gap:10px;
}
.btn-menu:hover { border-color:var(--gold-light); box-shadow:0 0 20px rgba(200,168,50,.3); transform:translateY(-2px); }
.btn-menu:active { transform:translateY(0); }
.btn-menu.btn-secondary { border-color:var(--stone-light); color:var(--text-light);
  background:linear-gradient(180deg,rgba(100,100,130,.15) 0%,rgba(50,50,70,.2) 100%); }
.btn-menu.btn-retry { border-color:var(--red); color:#ff8a80;
  background:linear-gradient(180deg,rgba(229,57,53,.15) 0%,rgba(120,20,20,.2) 100%); }
.btn-icon { font-size:16px; }

/* ── MENU ── */
.menu-bg {
  width:100%; height:100%; display:flex; align-items:center; justify-content:center;
  position:relative; overflow:hidden;
  background: radial-gradient(ellipse at 20% 80%,rgba(255,104,32,.12) 0%,transparent 50%),
              radial-gradient(ellipse at 80% 80%,rgba(255,104,32,.12) 0%,transparent 50%),
              linear-gradient(180deg,#0d0b14 0%,#1a1520 40%,#120f1a 100%);
}
.menu-bg::before {
  content:''; position:absolute; inset:0;
  background-image: repeating-linear-gradient(0deg,transparent,transparent 39px,rgba(255,255,255,.015) 39px,rgba(255,255,255,.015) 40px),
                    repeating-linear-gradient(90deg,transparent,transparent 39px,rgba(255,255,255,.015) 39px,rgba(255,255,255,.015) 40px);
}
.menu-torch { position:absolute; bottom:100px; width:20px; height:60px;
  background:linear-gradient(180deg,#8a6030 0%,#4a3010 100%); border-radius:4px 4px 2px 2px; }
.menu-torch::before { content:'🔥'; position:absolute; top:-30px; left:-8px; font-size:28px; animation:flicker .5s infinite alternate; }
.menu-torch.left { left:40px; } .menu-torch.right { right:40px; }
@keyframes flicker { 0%{transform:scale(1) rotate(-2deg)} 100%{transform:scale(1.1) rotate(2deg)} }
@keyframes float   { 0%,100%{transform:translateY(0)} 50%{transform:translateY(-8px)} }

.menu-container { text-align:center; z-index:10; padding:20px; max-width:460px; width:100%; }
.game-title { margin-bottom:34px; }
.title-emblem { font-size:56px; display:block; margin-bottom:8px;
  filter:drop-shadow(0 0 20px rgba(200,168,50,.6)); animation:float 3s ease-in-out infinite; }
h1 { font-size:clamp(26px,7vw,46px); color:var(--gold-light);
  text-shadow:0 0 20px rgba(200,168,50,.5),2px 2px 4px rgba(0,0,0,.8); letter-spacing:4px; margin-bottom:8px; }
.subtitle { font-size:clamp(11px,3vw,15px); color:var(--text-dim); letter-spacing:6px; text-transform:uppercase; }
.menu-buttons { display:flex; flex-direction:column; gap:12px; margin-bottom:26px; }
.menu-footer { color:var(--text-dim); font-size:11px; letter-spacing:1px; }

/* ── DIFFICULTY SELECT ── */
.diff-bg { width:100%; height:100%; display:flex; flex-direction:column;
  background:linear-gradient(180deg,#0d0b14 0%,#1a1520 100%); overflow:hidden; }
.diff-header { display:flex; align-items:center; justify-content:space-between;
  padding:14px 20px; border-bottom:1px solid rgba(200,168,50,.2); background:rgba(0,0,0,.3); }
.diff-header h2 { color:var(--gold-light); font-size:clamp(15px,4vw,21px); }
.diff-grid { display:grid; grid-template-columns:1fr 1fr; gap:14px;
  padding:20px; flex:1; overflow-y:auto; align-content:start; }
.diff-card { background:rgba(30,28,40,.85); border:2px solid var(--stone-light);
  border-radius:10px; padding:20px 14px; cursor:pointer; text-align:center;
  transition:all .2s; font-family:inherit; display:flex; flex-direction:column; gap:8px; }
.diff-card:hover { transform:translateY(-4px); }
.diff-easy    { border-color:#4caf50; } .diff-easy:hover    { box-shadow:0 8px 24px rgba(76,175,80,.3); }
.diff-normal  { border-color:var(--gold); } .diff-normal:hover  { box-shadow:0 8px 24px rgba(200,168,50,.3); }
.diff-hard    { border-color:#ff9800; } .diff-hard:hover    { box-shadow:0 8px 24px rgba(255,152,0,.3); }
.diff-veryhard{ border-color:#e53935; } .diff-veryhard:hover{ box-shadow:0 8px 24px rgba(229,57,53,.3); }
.diff-icon { font-size:clamp(28px,6vw,40px); }
.diff-name { font-size:clamp(14px,3.5vw,18px); font-weight:bold; color:var(--gold-light); }
.diff-desc { font-size:clamp(10px,2.5vw,13px); color:var(--text-dim); line-height:1.5; }
.diff-progress { font-size:clamp(11px,2.5vw,13px); color:var(--text-dim);
  background:rgba(0,0,0,.3); border-radius:8px; padding:3px 10px; margin-top:4px; }

/* ── LEVEL SELECT ── */
.levels-bg { width:100%; height:100%; display:flex; flex-direction:column;
  background:linear-gradient(180deg,#0d0b14 0%,#1a1520 100%); overflow:hidden; }
.levels-header { display:flex; align-items:center; justify-content:space-between;
  padding:14px 20px; border-bottom:1px solid rgba(200,168,50,.2); background:rgba(0,0,0,.3); }
.levels-header h2 { color:var(--gold-light); font-size:clamp(14px,4vw,20px); }
.levels-grid { display:grid; grid-template-columns:repeat(auto-fill,minmax(64px,1fr));
  gap:8px; padding:14px; overflow-y:auto; flex:1; }
.level-cell { aspect-ratio:1; display:flex; flex-direction:column; align-items:center;
  justify-content:center; border-radius:6px; border:2px solid; cursor:pointer;
  transition:all .2s; font-family:inherit; gap:2px; }
.level-cell.locked   { border-color:#333; background:rgba(20,20,30,.8); color:#444; cursor:not-allowed; }
.level-cell.cleared  { border-color:var(--gold); background:linear-gradient(135deg,rgba(200,168,50,.2),rgba(100,80,20,.3)); color:var(--gold-light); }
.level-cell.cleared:hover  { transform:scale(1.08); box-shadow:0 0 12px rgba(200,168,50,.4); }
.level-cell.available { border-color:var(--stone-light); background:rgba(60,60,80,.5); color:var(--text-light); }
.level-cell.available:hover { border-color:var(--gold); transform:scale(1.08); }
.level-num  { font-size:clamp(13px,3vw,17px); font-weight:bold; }
.level-icon { font-size:13px; }

/* ── GAME SCREEN ── */
#screen-game { flex-direction:column; background:var(--dungeon-bg); }
.game-header { display:flex; align-items:center; justify-content:space-between;
  padding:8px 13px; background:rgba(0,0,0,.5); border-bottom:1px solid rgba(200,168,50,.2);
  flex-shrink:0; gap:8px; }
.game-info { display:flex; align-items:center; gap:12px; flex:1; justify-content:center; }
.level-badge { background:rgba(200,168,50,.2); border:1px solid var(--gold); color:var(--gold-light);
  padding:3px 11px; border-radius:12px; font-size:clamp(11px,2.8vw,14px); white-space:nowrap; }
.move-display { font-size:clamp(11px,2.8vw,14px); color:var(--text-light); white-space:nowrap; transition:color .3s; }
.move-display.warn   { color:var(--orange); }
.move-display.danger { color:var(--red); animation:pulse-red .8s infinite; }
@keyframes pulse-red { 0%,100%{opacity:1} 50%{opacity:.5} }

.game-controls { display:flex; gap:5px; }
.btn-icon-sm { background:rgba(60,60,80,.6); border:1px solid var(--stone-light); color:var(--text-light);
  width:32px; height:32px; border-radius:6px; font-size:14px; cursor:pointer;
  display:flex; align-items:center; justify-content:center; transition:all .15s; }
.btn-icon-sm:hover { border-color:var(--gold); background:rgba(200,168,50,.2); }

.move-bar-wrap { height:4px; background:rgba(255,255,255,.05); flex-shrink:0; }
.move-bar { height:100%; background:linear-gradient(90deg,#4caf50,#8bc34a);
  transition:width .2s, background .3s; width:100%; }
.move-bar.warn   { background:linear-gradient(90deg,#ff9800,#ffc107); }
.move-bar.danger { background:linear-gradient(90deg,#e53935,#ff5722); }

.game-area { flex:1; display:flex; align-items:center; justify-content:center;
  overflow:hidden; position:relative;
  background: radial-gradient(ellipse at 50% 50%,rgba(60,50,80,.3) 0%,transparent 70%),
              repeating-linear-gradient(0deg,transparent,transparent 39px,rgba(255,255,255,.01) 39px,rgba(255,255,255,.01) 40px),
              repeating-linear-gradient(90deg,transparent,transparent 39px,rgba(255,255,255,.01) 39px,rgba(255,255,255,.01) 40px); }
#game-canvas { display:block; image-rendering:pixelated; max-width:100%; max-height:100%; }

/* Mobile */
.mobile-controls { display:none; padding:10px 14px; background:rgba(0,0,0,.4);
  border-top:1px solid rgba(200,168,50,.2); justify-content:space-between;
  align-items:center; gap:14px; flex-shrink:0; }
@media (pointer:coarse),(max-width:768px) { .mobile-controls { display:flex; } }
.d-pad { display:flex; flex-direction:column; align-items:center; gap:3px; }
.d-row  { display:flex; gap:3px; }
.d-btn  { width:48px; height:48px; background:linear-gradient(180deg,rgba(80,80,100,.8),rgba(40,40,60,.9));
  border:2px solid var(--stone-light); color:var(--text-light); font-size:17px;
  border-radius:8px; cursor:pointer; display:flex; align-items:center; justify-content:center;
  user-select:none; -webkit-user-select:none; transition:all .1s; }
.d-btn:active { background:rgba(200,168,50,.3); border-color:var(--gold); transform:scale(.93); }
.d-center { background:rgba(30,30,50,.9); color:var(--gold); font-size:18px; }
.action-btns { display:flex; flex-direction:column; gap:7px; }
.btn-action { background:rgba(60,60,80,.7); border:1px solid var(--stone-light); color:var(--text-light);
  padding:7px 14px; border-radius:6px; font-family:inherit; font-size:11px;
  cursor:pointer; text-align:center; line-height:1.4; transition:all .15s; }
.btn-action:active { background:rgba(200,168,50,.3); border-color:var(--gold); }

/* ── VICTORY ── */
#screen-victory { background:rgba(0,0,0,.92); align-items:center; justify-content:center; }
.victory-container { text-align:center; padding:26px 18px; max-width:400px; width:100%; }
.victory-banner h2 { font-size:clamp(22px,6vw,34px); color:var(--gold-light);
  text-shadow:0 0 20px rgba(200,168,50,.6); margin:10px 0; }
.victory-stars { font-size:32px; letter-spacing:8px; margin-bottom:10px; }
.victory-details { color:var(--text-dim); font-size:14px; margin:12px 0 26px; line-height:2; }
.victory-details span { color:var(--gold-light); }
.victory-buttons { display:flex; flex-direction:column; gap:10px; }

/* ── FAIL ── */
#screen-fail { background:rgba(0,0,0,.94); align-items:center; justify-content:center; }
.fail-container { text-align:center; padding:26px 18px; max-width:400px; width:100%; }
.fail-icon { font-size:68px; margin-bottom:12px; animation:shake .5s ease-in-out; }
@keyframes shake {
  0%,100%{transform:translateX(0)} 20%{transform:translateX(-8px)}
  40%{transform:translateX(8px)} 60%{transform:translateX(-6px)} 80%{transform:translateX(6px)} }
.fail-container h2 { font-size:clamp(20px,5vw,30px); color:#ff5722;
  text-shadow:0 0 20px rgba(229,57,53,.5); margin-bottom:10px; }
#fail-msg { color:var(--text-dim); margin-bottom:24px; font-size:13px; line-height:1.6; }
.fail-buttons { display:flex; flex-direction:column; gap:10px; }

/* ── COMPLETE ── */
#screen-complete { background:rgba(0,0,0,.95); align-items:center; justify-content:center;
  text-align:center; flex-direction:column; gap:14px; padding:20px; }
.complete-emblem { font-size:72px; animation:float 2s ease-in-out infinite; }
#screen-complete h2 { font-size:clamp(22px,6vw,36px); color:var(--gold-light); }
#screen-complete p  { color:var(--text-dim); font-size:clamp(13px,3vw,16px); }

/* ── SCROLLBAR ── */
::-webkit-scrollbar { width:5px; }
::-webkit-scrollbar-track { background:rgba(0,0,0,.3); }
::-webkit-scrollbar-thumb { background:var(--stone-light); border-radius:3px; }

/* ── RESPONSIVE ── */
@media (max-width:480px) {
  .menu-torch { display:none; }
  .levels-grid { grid-template-columns:repeat(5,1fr); gap:6px; padding:10px; }
  .diff-grid { gap:10px; padding:12px; }
  .d-btn { width:43px; height:43px; font-size:15px; }
}
@media (min-width:769px) { .mobile-controls { display:none !important; } }

/* ── HINT SYSTEM ── */
.btn-hint { border-color: #ffd700 !important; color: #ffd700 !important; }
.btn-hint:hover { background: rgba(255,215,0,.25) !important; box-shadow:0 0 12px rgba(255,215,0,.4); }
.btn-hint-mobile { border-color:#ffd700; color:#ffd700; }

#hint-playing-overlay {
  position:absolute; top:0; left:0; right:0; z-index:10;
  background:rgba(0,0,0,.78); padding:8px 14px;
  display:flex; align-items:center; justify-content:space-between; gap:12px;
  border-bottom:2px solid #ffd700; font-size:13px; color:#ffd700; letter-spacing:1px;
}
#hint-playing-overlay button {
  background:rgba(229,57,53,.3); border:1px solid #e53935; color:#ff8a80;
  padding:5px 14px; border-radius:4px; font-family:inherit; font-size:12px; cursor:pointer;
  transition:all .15s; white-space:nowrap;
}
#hint-playing-overlay button:hover { background:rgba(229,57,53,.5); }

/* Modal */
.modal-overlay {
  position:fixed; inset:0; z-index:100;
  background:rgba(0,0,0,.82); display:flex; align-items:center; justify-content:center;
  padding:20px;
}
.modal-box {
  background:linear-gradient(180deg,#1e1c2e 0%,#16141e 100%);
  border:2px solid var(--gold); border-radius:8px;
  padding:28px 22px; max-width:360px; width:100%;
  box-shadow:0 0 40px rgba(200,168,50,.25);
}
.modal-title {
  font-size:clamp(18px,5vw,24px); color:var(--gold-light);
  text-align:center; margin-bottom:12px; letter-spacing:2px;
}
.modal-desc {
  color:var(--text-dim); font-size:13px; text-align:center;
  line-height:1.7; margin-bottom:20px;
}
.modal-buttons { display:flex; flex-direction:column; gap:10px; }
.btn-autoplay { border-color:#4caf50; color:#a5d6a7;
  background:linear-gradient(180deg,rgba(76,175,80,.15) 0%,rgba(27,94,32,.2) 100%) !important; }
.btn-autoplay:hover { border-color:#81c784; box-shadow:0 0 20px rgba(76,175,80,.3); }
