:root {
  --gold: #d7b45c;
  --gold2: #f3d889;
  --ink: #161719;
  --paper: #eee9dc;
}
* { box-sizing: border-box; }
html, body { margin: 0; width: 100%; height: 100%; overflow: hidden; }
body {
  background: radial-gradient(circle at 50% 30%, #5c7b87 0, #203442 55%, #10171d 100%);
  font-family: "Microsoft YaHei", "PingFang SC", sans-serif;
  color: #efe9d9;
  user-select: none;
}
button, input { font: inherit; }
#viewport {
  position: fixed;
  inset: 0;
  width: auto;
  height: auto;
  display: block;
  overflow: hidden;
}
.sim-shell {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 1096px;
  height: 666px;
  transform: translate(-50%, -50%) scale(var(--sim-scale, 1));
  transform-origin: center center;
  will-change: transform;
}
.stage {
  position: absolute;
  left: 0;
  top: 65px;
  width: 1096px;
  height: 601px;
  overflow: visible;
  filter: drop-shadow(0 18px 30px rgba(0,0,0,.45));
}
.stage-bg {
  position: absolute; inset: 0;
  background: url('assets/background.png') center/100% 100% no-repeat;
  border-radius: 4px;
  overflow: hidden;
}
.game-panel {
  background: linear-gradient(180deg, rgba(20,22,23,.88), rgba(11,13,14,.84));
  border: 1px solid rgba(214,181,96,.58);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.06), 0 3px 12px rgba(0,0,0,.45);
}
.control-panel {
  position: absolute;
  left: 56px;
  top: 4px;
  width: 984px;
  height: 55px;
  padding: 7px 10px;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 10px;
  border-radius: 2px;
}
.control-title {
  flex: 0 0 122px;
  color: #f0d587;
  font-weight: 700;
  font-size: 15px;
  text-shadow: 0 1px 2px #000;
  letter-spacing: 1px;
  white-space: nowrap;
}
.grant-bar {
  flex: 0 0 360px;
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  gap: 4px;
}
.grant-btn {
  position: relative;
  height: 37px;
  border: 1px solid #8f7340;
  background: linear-gradient(#6a5428,#2b2111);
  color: #ffe49a;
  cursor: pointer;
  font-size: 17px;
  box-shadow: inset 0 0 7px rgba(255,210,93,.2), 0 1px 2px rgba(0,0,0,.45);
}
.grant-btn:hover { filter: brightness(1.35); transform: translateY(-1px); }
.grant-btn:active { transform: translateY(0); }
.control-actions {
  min-width: 0;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  color: #dcd5c3;
  font-size: 12px;
}
.control-actions input {
  width: 44px;
  height: 28px;
  padding: 2px 4px;
  text-align: center;
  background: #181b1d;
  border: 1px solid #71684e;
  color: #fff4c5;
}
.batch-label { margin-left: 3px; }
.batch-unit { margin-left: -3px; }
.ui-btn {
  border: 1px solid #8a8168;
  background: linear-gradient(#60615e,#313331);
  color: #f0eee6;
  cursor: pointer;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.15);
}
.ui-btn:hover { filter: brightness(1.2); }
.ui-btn.small { height: 26px; padding: 0 10px; font-size: 12px; }
.ui-btn.gold { border-color:#a97d25; background:linear-gradient(#c49a43,#72500d); color:#fff3c6; }
.ui-btn.danger { border-color:#80534b; }
.ui-btn.strong-danger {
  border-color:#9b4d43;
  background:linear-gradient(#74443d,#3f2421);
  color:#ffe1d4;
}
.ui-btn.strong-danger:hover { filter:brightness(1.28); }
.ui-btn:disabled { opacity:.45; cursor:not-allowed; filter:none; }
.ui-btn.active { outline:2px solid #d5b257; }

.bag-shell {
  position: absolute;
  left: 647px;
  top: 154px;
  width: 304px;
  height: 344px;
  padding: 5px;
  background: rgba(9,17,24,.82);
  border: 1px solid rgba(76,100,123,.85);
  z-index: 3;
}
.bag-head {
  height: 24px; display:flex; justify-content:space-between; align-items:center;
  padding: 0 4px; color:#c7c9c8; font-size:12px;
}
.bag-grid {
  height: 309px;
  overflow-y: auto;
  overflow-x: hidden;
  display: grid;
  grid-template-columns: repeat(6, 42px);
  grid-auto-rows: 42px;
  gap: 6px;
  align-content: start;
  padding: 2px 1px 8px;
  scrollbar-width: thin;
  scrollbar-color: #8b7750 #151d25;
}
.bag-cell {
  position: relative;
  width: 42px; height:42px;
  border: 1px solid #49586b;
  background: rgba(17,28,40,.78);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.04);
  cursor: pointer;
}
.bag-cell.empty { cursor:default; opacity:.7; }
.bag-cell img { width:100%; height:100%; object-fit:contain; image-rendering:auto; }
.bag-cell:hover:not(.empty) { border-color:#c8a85f; box-shadow:0 0 7px rgba(221,183,85,.65); }
.bag-cell.selected { border:2px solid #e4c56d; box-shadow:0 0 10px rgba(236,197,98,.9); }
.bag-cell.identified::after {
  content:""; position:absolute; inset:0; pointer-events:none;
  box-shadow: inset 0 0 10px rgba(255,181,48,.18);
}
.bag-cell .check {
  position:absolute; left:2px; top:2px; width:13px; height:13px;
  border:1px solid #d6c48c; background:rgba(0,0,0,.65); z-index:2;
}
.bag-cell.checked .check::after {
  content:"✓"; display:grid; place-items:center; color:#fff2ae; font-size:12px; line-height:11px;
}
.bag-cell .reward-mark {
  position:absolute; right:1px; bottom:1px; background:#9c5a08; color:#fff1b5; font-size:8px; padding:1px 2px;
}

.selected-view {
  position:absolute;
  left: 225px;
  top: 184px;
  width: 355px;
  height: 252px;
  z-index:3;
  color:#26221b;
  text-shadow:0 1px rgba(255,255,255,.45);
  display:flex;
  align-items:center;
  justify-content:center;
}
.selected-empty { color:#5b5a54; font-size:16px; opacity:.75; }
.selected-book {
  width:100%; height:100%; padding:12px 16px;
  display:grid; grid-template-columns:100px 1fr; gap:12px;
  align-content:center;
}
.selected-book .large-icon {
  width:92px; height:92px; object-fit:contain;
  filter:drop-shadow(0 4px 6px rgba(0,0,0,.35));
}
.selected-book h3 { margin:0 0 6px; font-size:18px; color:#6f4f11; }
.selected-book p { margin:3px 0; font-size:13px; }
.selected-book .power { color:#985e00; font-weight:700; }
.selected-book .mini-attrs { margin-top:6px; line-height:1.55; font-size:12px; max-height:120px; overflow:hidden; }

.selected-result-only {
  width:100%; height:100%; display:flex; align-items:center; justify-content:center;
}
.selected-result-icon {
  position:relative; width:96px; height:96px; cursor:help;
  border:1px solid rgba(126,103,61,.55);
  background:rgba(30,30,26,.08);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.18), 0 4px 10px rgba(0,0,0,.18);
}
.selected-result-icon img {
  width:100%; height:100%; object-fit:contain; display:block;
  filter:drop-shadow(0 3px 5px rgba(0,0,0,.35));
}
.selected-result-icon:hover {
  border-color:#caa95c; box-shadow:0 0 10px rgba(211,170,74,.5), inset 0 0 0 1px rgba(255,255,255,.18);
}
.selected-result-icon::after {
  content:""; position:absolute; inset:0; pointer-events:none;
  box-shadow: inset 0 0 12px rgba(255,181,48,.16);
}

.identify-btn {
  position:absolute;
  left:288px; top:465px;
  width:131px; height:36px;
  z-index:5;
  border:1px solid #8f7741;
  color:#2a210e;
  font-weight:700;
  letter-spacing:5px;
  cursor:pointer;
  background:linear-gradient(#f3d579,#b98322 55%, #8f5e0b);
  box-shadow:0 0 12px rgba(255,205,73,.7), inset 0 1px 0 #fff4c3;
}
.identify-btn.disabled {
  cursor:not-allowed; color:#202020;
  border-color:#aaa; background:linear-gradient(#ddd,#999); box-shadow:none; opacity:.8;
}
.reward-reminder {
  position:absolute;
  left:44px;
  top:374px;
  z-index:6;
  width:116px;
  height:140px;
}
.reward-hint {
  position:absolute;
  left:-10px;
  bottom:88px;
  min-width:142px;
  max-width:184px;
  padding:8px 11px;
  border:1px solid rgba(174,128,48,.72);
  border-radius:4px;
  background:linear-gradient(180deg,rgba(255,249,216,.97),rgba(238,220,166,.96));
  color:#a64818;
  font-size:12px;
  font-weight:700;
  line-height:1.35;
  text-align:center;
  white-space:nowrap;
  box-shadow:0 3px 8px rgba(0,0,0,.22), inset 0 0 0 1px rgba(255,255,255,.62);
  text-shadow:0 1px rgba(255,255,255,.6);
}
.reward-hint::after {
  content:"";
  position:absolute;
  left:50%;
  bottom:-9px;
  width:16px;
  height:16px;
  transform:translateX(-50%) rotate(45deg);
  background:#eedda8;
  border-right:1px solid rgba(174,128,48,.72);
  border-bottom:1px solid rgba(174,128,48,.72);
}
.reward-hint.ready {
  color:#b21f1c;
  background:linear-gradient(180deg,rgba(255,243,207,.98),rgba(244,210,137,.97));
  animation:rewardHintPulse 1.6s ease-in-out infinite;
}
.reward-entry {
  position:absolute;
  left:12px;
  bottom:0;
  z-index:5;
  width:92px;
  height:82px;
  padding:0;
  border:0;
  background:transparent;
  cursor:pointer;
}
.reward-entry:hover { filter: brightness(1.14) drop-shadow(0 0 5px rgba(225,170,65,.55)); }
.reward-chest { width:92px; height:82px; object-fit:contain; display:block; filter:drop-shadow(0 2px 3px rgba(0,0,0,.28)); }
.badge {
  position:absolute;
  top:-4px;
  right:-4px;
  min-width:19px;
  height:19px;
  padding:0 4px;
  border-radius:10px;
  background:#d21f1b;
  color:white;
  font-size:10px;
  display:grid;
  place-items:center;
  border:1px solid #ffe0a8;
  box-shadow:0 0 7px rgba(210,31,27,.78);
  animation:rewardDotPulse 1.2s ease-in-out infinite;
}
.counter-chip {
  position:absolute;
  left:288px;
  top:507px;
  width:131px;
  z-index:4;
  color:#5d4820;
  font-size:14px;
  font-weight:700;
  text-align:center;
  white-space:nowrap;
}
.counter-chip b { color:#9c5800; font-size:17px; }
@keyframes rewardDotPulse {
  0%,100% { transform:scale(1); box-shadow:0 0 6px rgba(210,31,27,.62); }
  50% { transform:scale(1.15); box-shadow:0 0 12px rgba(240,48,35,.9); }
}
@keyframes rewardHintPulse {
  0%,100% { filter:brightness(1); }
  50% { filter:brightness(1.08); }
}
.admin-link {
  position:absolute; right:43px; bottom:14px; z-index:5; color:#615e57; text-decoration:none; font-size:9px; opacity:.45;
}
.admin-link:hover { opacity:1; }

.item-tooltip {
  position:absolute; z-index:20; width:410px; min-height:245px; padding:12px 16px 14px;
  background:linear-gradient(180deg, rgba(18,18,18,.94), rgba(25,25,25,.91));
  border:1px solid rgba(112,112,112,.45); color:#f0f0ee;
  box-shadow:0 6px 20px rgba(0,0,0,.55); pointer-events:none;
  text-shadow:0 1px 2px #000;
}
.tip-head { display:grid; grid-template-columns:58px 1fr; gap:10px; align-items:center; }
.tip-head img { width:54px; height:54px; object-fit:contain; }
.tip-head h4 { margin:0; color:#f3a914; font-size:18px; }
.tip-powers { border-top:1px solid rgba(255,255,255,.18); border-bottom:1px solid rgba(255,255,255,.18); margin:8px 0; padding:7px 0; }
.tip-powers b { color:#f0d91d; margin-right:6px; }
.tip-attrs-title { color:#f5e01a; font-weight:700; margin:7px 0 4px; }
.tip-attr { line-height:1.55; font-size:14px; }
.tip-attr .val, .tip-feature strong { color:#ff9d00; }
.tip-attr .extra { color:#ffdb1e; }
.tip-feature { margin-top:8px; line-height:1.5; }
.tip-feature .range { color:#fff; }

.toast {
  position:absolute; left:50%; top:50%; transform:translate(-50%,-50%); z-index:50;
  padding:11px 18px; background:rgba(15,15,15,.88); border:1px solid #907a4c; color:#f3e7c4; box-shadow:0 6px 18px rgba(0,0,0,.45);
}
.hidden { display:none !important; }

.modal {
  position:fixed; inset:0; z-index:100; background:rgba(0,0,0,.62); display:grid; place-items:center;
}
.modal-card {
  position:relative; background:#ede9de; color:#352f26; border:3px solid #8e7b57; box-shadow:0 20px 50px rgba(0,0,0,.55), inset 0 0 0 2px #d9cda9;
}
.modal-close { position:absolute; right:8px; top:7px; width:31px; height:31px; border-radius:50%; border:1px solid #d8cdb1; background:#6d665b; color:white; font-size:22px; cursor:pointer; }
.reward-modal-card { width:930px; min-height:405px; padding:26px 26px 22px; background:linear-gradient(rgba(245,242,232,.97),rgba(238,234,221,.97)), url('assets/reward-reference.png') center/cover; }
.reward-modal-card h2 { text-align:center; margin:6px 0 28px; font-size:20px; }
.reward-modal-card h2 span { margin-left:20px; font-size:16px; }
.reward-modal-card h2 b { color:#d27016; font-size:23px; }
.reward-cards { display:grid; grid-template-columns:repeat(3,1fr); gap:18px; }
.reward-card { border-right:1px solid rgba(110,94,68,.25); padding:0 10px 8px; text-align:center; }
.reward-card:last-child { border-right:0; }
.reward-card h4 { background:linear-gradient(90deg,transparent,#ae9a71,transparent); color:white; padding:5px; margin:0 0 16px; font-size:17px; }
.reward-book-icon { width:58px; height:58px; object-fit:contain; display:block; margin:0 auto 8px; }
.reward-band { font-size:15px; line-height:1.45; min-height:44px; }
.reward-progress { margin:15px 0 10px; padding:5px 7px; border-radius:14px; background:rgba(190,178,151,.42); font-size:13px; }
.reward-progress b { color:#d36616; }
.reward-claim { min-width:86px; height:30px; border:0; border-radius:16px; color:white; background:#90764a; cursor:pointer; }
.reward-claim:disabled { background:#bdb5a4; color:#ece7dc; cursor:not-allowed; }
.reward-claim.ready { background:linear-gradient(#c58c32,#8d5b12); box-shadow:0 0 9px rgba(195,132,32,.45); }
.slot-modal-card { width:620px; padding:24px 28px 28px; text-align:center; }
.slot-choices { display:grid; grid-template-columns:repeat(9,1fr); gap:8px; margin-top:20px; }
.slot-choice { border:1px solid #9c8656; background:#3c3426; color:#ffe2a0; padding:10px 2px; cursor:pointer; }
.slot-choice:hover { background:#7f5d24; }
.history-modal-card { width:760px; max-height:80vh; padding:22px; }
.history-list { max-height:62vh; overflow:auto; border:1px solid #b5aa91; background:rgba(255,255,255,.5); }
.history-row { display:grid; grid-template-columns:85px 1fr 90px 130px; gap:8px; padding:8px 10px; border-bottom:1px solid #d0c7b1; font-size:13px; }
.history-row b { color:#a55c08; }

.high-power-fx {
  position:absolute; inset:0; z-index:60; pointer-events:none; display:grid; place-items:center;
  background:radial-gradient(circle, rgba(255,236,144,.72) 0, rgba(255,180,25,.18) 35%, rgba(255,120,0,0) 67%);
  animation:fxFade 2.2s ease both;
}
.fx-card { text-align:center; color:#fff2b3; font-size:24px; font-weight:700; text-shadow:0 0 8px #ff8b00,0 2px 3px #000; animation:fxPop 1s ease both; }
.fx-card img { width:110px; height:110px; object-fit:contain; display:block; margin:0 auto 10px; filter:drop-shadow(0 0 18px #ffce55); }
.fx-card strong { font-size:18px; color:#fff0a1; display:block; margin-top:4px; }
.particle { position:absolute; left:50%; top:50%; width:6px; height:6px; border-radius:50%; background:#ffe18a; box-shadow:0 0 8px #ff9b00; animation:particleFly 1.5s ease-out both; }
@keyframes fxFade { 0%{opacity:0} 15%{opacity:1} 75%{opacity:1} 100%{opacity:0} }
@keyframes fxPop { 0%{transform:scale(.55);opacity:0} 55%{transform:scale(1.08);opacity:1} 100%{transform:scale(1);opacity:1} }
@keyframes particleFly { from{transform:translate(-50%,-50%) scale(1);opacity:1} to{transform:translate(var(--x),var(--y)) scale(.1);opacity:0} }

/* V1.4 mobile landscape support */
html, body { min-height: 100%; overscroll-behavior: none; }
#viewport {
  /* fixed inset tracks the browser's actual content viewport more reliably than 100dvh in embedded mobile browsers */
  width: auto;
  height: auto;
  padding:
    max(2px, env(safe-area-inset-top))
    max(2px, env(safe-area-inset-right))
    max(2px, env(safe-area-inset-bottom))
    max(2px, env(safe-area-inset-left));
}
button, .bag-cell, .selected-result-icon, .reward-entry, .slot-choice { touch-action: manipulation; }
.bag-grid { -webkit-overflow-scrolling: touch; touch-action: pan-y; }

.orientation-gate {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 1000;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 10px;
  padding: max(24px, env(safe-area-inset-top)) max(24px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom)) max(24px, env(safe-area-inset-left));
  background: radial-gradient(circle at 50% 35%, #405866 0, #1a2b36 56%, #0c1318 100%);
  color: #f3e6ba;
  text-align: center;
  text-shadow: 0 2px 4px #000;
}
.orientation-gate strong { font-size: 24px; letter-spacing: 1px; }
.orientation-gate p { margin: 0; color: #d0c7ad; font-size: 14px; }
.rotate-phone {
  width: 66px;
  height: 104px;
  padding: 7px;
  border: 3px solid #e4c46c;
  border-radius: 11px;
  transform: rotate(-18deg);
  box-shadow: 0 0 20px rgba(226,188,86,.22);
  animation: phoneRotate 1.8s ease-in-out infinite;
}
.rotate-phone span { display:block; width:100%; height:100%; border:1px solid rgba(245,225,164,.45); background:rgba(0,0,0,.18); border-radius:5px; }
@keyframes phoneRotate {
  0%, 20% { transform: rotate(-18deg); }
  65%, 100% { transform: rotate(72deg); }
}

@media (orientation: portrait) and (hover: none), (orientation: portrait) and (pointer: coarse) {
  .orientation-gate { display: flex; }
  #viewport { visibility: hidden; }
}

@media (orientation: landscape) and (hover: none), (orientation: landscape) and (pointer: coarse) {
  body { background: #101820; }
  .sim-shell { margin: 0; }
  .control-panel { left: 5px; width: 1086px; gap: 7px; }
  .control-title { display: none; }
  .grant-bar { flex-basis: 430px; gap: 5px; }
  .grant-btn { height: 39px; font-size: 18px; }
  .control-actions { gap: 5px; font-size: 13px; }
  .ui-btn.small { height: 31px; padding: 0 11px; font-size: 13px; }
  .control-actions input { height: 31px; width: 48px; font-size: 14px; }
  .bag-cell { cursor: pointer; }
  .selected-result-icon { cursor: pointer; }
  .item-tooltip.touch-open { box-shadow: 0 8px 24px rgba(0,0,0,.7), 0 0 0 1px rgba(220,183,88,.15); }
  .admin-link { opacity: .62; }
}

@media (max-width: 980px) {
  .modal { padding: 8px max(8px, env(safe-area-inset-right)) 8px max(8px, env(safe-area-inset-left)); }
  .modal-card { max-width: calc(100vw - 20px); max-height: calc(100dvh - 16px); overflow: auto; }
  .reward-modal-card { width: min(930px, calc(100vw - 20px)); min-height: 0; padding: 18px 18px 16px; }
  .reward-modal-card h2 { margin-bottom: 14px; }
  .reward-cards { gap: 8px; }
  .reward-card { padding: 0 5px 7px; }
  .slot-modal-card { width: min(620px, calc(100vw - 20px)); }
  .history-modal-card { width: min(760px, calc(100vw - 20px)); max-height: calc(100dvh - 16px); }
  .history-list { max-height: calc(100dvh - 110px); }
}
