:root {
  --abyss: #0d0b09;
  --night: #16130f;
  --stone-deep: #231f1a;
  --stone: #3a342c;
  --stone-light: #5c5346;
  --stone-edge: #8a7d68;
  --bone: #cbbd9e;
  --moss: #33452a;
  --moss-glow: #8fae5a;
  --amber-deep: #7a3208;
  --amber-mid: #c25e12;
  --amber: #f08a24;
  --amber-light: #ffb547;
  --amber-core: #ffe2a0;
  --ember: #ff6a2b;
  --blood: #b8322a;
  --parchment: #e8dcc0;
  --parchment-dim: #cfc2a6;
  --font-serif: "Noto Serif SC", "Source Han Serif SC", "Songti SC", "STSong", "SimSun", serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
  -webkit-touch-callout: none;
  background: var(--abyss);
  color: var(--parchment);
  font-family: var(--font-serif);
  letter-spacing: 0.04em;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.92), 0 0 10px rgba(255, 165, 80, 0.16);
}

#world {
  position: fixed;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  z-index: 1;
}

#ui-root {
  position: fixed;
  inset: 0;
  z-index: 10;
  pointer-events: none;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
}

.hidden {
  display: none !important;
}

.interactive,
button {
  touch-action: manipulation;
  -webkit-touch-callout: none;
}

.interactive {
  pointer-events: auto;
}

.plate9 {
  border-style: solid;
  border-width: 18px;
  border-image: var(--tex-plate9) 28 fill / 22px stretch;
  background-color: rgba(35, 31, 26, 0.94);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.65);
}

.plate-small9 {
  border-style: solid;
  border-width: 10px;
  border-image: var(--tex-plate-small9) 16 fill / 12px stretch;
  background-color: rgba(28, 24, 20, 0.92);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.55);
}

.medallion-btn {
  appearance: none;
  border: none;
  padding: 0;
  margin: 0;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: transparent center / 100% 100% no-repeat;
  background-image: var(--tex-medallion);
  color: var(--parchment);
  font-family: var(--font-serif);
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  position: relative;
  transition: transform 0.12s ease, filter 0.15s ease;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.65);
}

.medallion-btn:hover {
  filter: brightness(1.14) drop-shadow(0 0 8px rgba(255, 181, 71, 0.45));
}

.medallion-btn:active {
  transform: scale(0.93);
}

.stone-btn {
  appearance: none;
  border-style: solid;
  border-width: 12px;
  border-image: var(--tex-plate9) 28 fill / 14px stretch;
  background: rgba(38, 33, 27, 0.96);
  color: var(--parchment);
  font-family: var(--font-serif);
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.08em;
  cursor: pointer;
  padding: 4px 16px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: transform 0.12s ease, filter 0.15s ease;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.6);
}

.stone-btn:hover:not(:disabled) {
  filter: brightness(1.16) drop-shadow(0 0 10px rgba(255, 165, 65, 0.4));
}

.stone-btn:active:not(:disabled) {
  transform: scale(0.96);
}

.stone-btn:disabled {
  filter: saturate(0.3) brightness(0.7);
  cursor: not-allowed;
}

.gem-btn {
  appearance: none;
  border: none;
  background: transparent center / 100% 100% no-repeat;
  background-image: var(--tex-gem-btn);
  color: #1f1308;
  text-shadow: 0 1px 0 rgba(255, 226, 160, 0.55);
  font-family: var(--font-serif);
  font-weight: 800;
  font-size: 17px;
  letter-spacing: 0.08em;
  cursor: pointer;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  transition: transform 0.12s ease, filter 0.15s ease;
  filter: drop-shadow(0 6px 14px rgba(0, 0, 0, 0.72));
}

.medallion-btn > *,
.stone-btn > *,
.gem-btn > * {
  pointer-events: none;
}

.gem-btn:hover:not(:disabled) {
  filter: brightness(1.1) drop-shadow(0 0 14px rgba(255, 168, 56, 0.58));
}

.gem-btn:active:not(:disabled) {
  transform: scale(0.95);
}

.ar-icon {
  width: 20px;
  height: 20px;
  display: inline-block;
  vertical-align: middle;
  filter: drop-shadow(0 1px 0 rgba(0, 0, 0, 0.85)) drop-shadow(0 0 4px rgba(255, 160, 60, 0.25));
}

.num {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  color: var(--amber-light);
}

@keyframes pulse-num {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.16); }
}

.num-bump {
  animation: pulse-num 0.25s ease;
}

.num-blood {
  color: var(--blood) !important;
  animation: pulse-num 0.9s infinite ease-in-out;
}

/* ---------------- Main Menu ---------------- */
.ar-menu {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  padding-bottom: max(36px, calc(env(safe-area-inset-bottom) + 24px));
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}

.ar-menu-fs-btn {
  position: absolute;
  top: max(12px, calc(env(safe-area-inset-top, 0px) + 8px));
  right: max(12px, calc(env(safe-area-inset-right, 0px) + 8px));
  width: 44px;
  height: 44px;
}

.ar-menu-copy {
  text-align: center;
  margin-bottom: 18px;
  max-width: 640px;
}

.ar-menu-sub {
  font-size: 20px;
  color: var(--amber-core);
  letter-spacing: 0.24em;
  margin-bottom: 8px;
}

.ar-menu-intro {
  font-size: 14px;
  color: var(--parchment-dim);
  line-height: 1.5;
}

.ar-menu-actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 11px;
}

.ar-menu-actions .gem-btn {
  width: 260px;
  height: 62px;
  font-size: 20px;
}

.ar-menu-actions .stone-btn {
  width: 260px;
  height: 52px;
}

.ar-menu-best {
  margin-top: 12px;
  font-size: 14px;
  color: var(--amber-light);
  display: flex;
  align-items: center;
  gap: 6px;
}

.ar-audio-hint {
  position: absolute;
  right: max(14px, env(safe-area-inset-right));
  bottom: max(10px, env(safe-area-inset-bottom));
  font-size: 12px;
  color: var(--parchment-dim);
  opacity: 0.72;
}

/* ---------------- Battle HUD ---------------- */
.ar-hud {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.ar-hud-top-left {
  position: absolute;
  top: max(10px, env(safe-area-inset-top));
  left: max(12px, env(safe-area-inset-left));
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 2px 10px;
  border-width: 12px;
  border-image-width: 14px;
}

.ar-res-item {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 21px;
  font-weight: 700;
}

.ar-res-wave {
  font-size: 18px;
  font-weight: 700;
  color: #f4ebd2;
}

.ar-hud-top-right {
  position: absolute;
  top: max(10px, env(safe-area-inset-top));
  right: max(12px, env(safe-area-inset-right));
  display: flex;
  align-items: center;
  gap: 10px;
}

.ar-hud-bot-left {
  position: absolute;
  bottom: max(10px, env(safe-area-inset-bottom));
  left: max(12px, env(safe-area-inset-left));
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 10px;
  max-width: calc(100vw - 268px);
  overflow-x: auto;
}

.ar-incoming-label {
  font-size: 15px;
  font-weight: 700;
  color: var(--parchment);
  margin-right: 4px;
  white-space: nowrap;
}

.ar-incoming-list {
  display: flex;
  align-items: center;
  gap: 10px;
}

.ar-incoming-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  position: relative;
}

.ar-incoming-chip canvas {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1.5px solid var(--amber-mid);
  background: var(--night);
}

.ar-incoming-cnt {
  font-size: 16px;
  font-weight: 700;
  color: var(--amber-core);
}

.ar-new-badge {
  position: absolute;
  top: -5px;
  left: -4px;
  background: var(--amber);
  color: #16130f;
  font-size: 11px;
  font-weight: 800;
  padding: 0 4px;
  border-radius: 3px;
  text-shadow: none;
}

.ar-hud-bot-right {
  position: absolute;
  bottom: max(10px, env(safe-area-inset-bottom));
  right: max(12px, env(safe-area-inset-right));
}

.ar-summon-btn {
  width: 228px;
  height: 66px;
  font-size: 19px;
}

.ar-summon-sub {
  font-size: 14px;
  color: #190d03;
  font-weight: 800;
  margin-top: 2px;
  text-shadow: 0 1px 0 rgba(255, 236, 185, 0.78);
}

.ar-inwave-tag {
  padding: 6px 18px;
  font-size: 16px;
  font-weight: 700;
  color: var(--parchment);
  letter-spacing: 0.16em;
}

/* ---------------- Boss Bar ---------------- */
.ar-boss-bar {
  position: absolute;
  top: max(10px, env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  width: min(520px, 52vw);
  text-align: center;
  pointer-events: none;
}

.ar-boss-name {
  font-size: 17px;
  font-weight: 700;
  color: var(--amber-core);
  letter-spacing: 0.3em;
  margin-bottom: 4px;
}

.ar-boss-track {
  position: relative;
  height: 14px;
  background: var(--abyss);
  border: 2px solid var(--stone-edge);
  box-shadow: 0 3px 12px rgba(0, 0, 0, 0.8), inset 0 0 6px #000;
}

.ar-boss-fill {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, var(--ember) 0%, var(--amber-light) 100%);
  transition: width 0.08s linear;
}

.ar-boss-bar.petrified .ar-boss-fill {
  background: linear-gradient(90deg, #5c5346 0%, #8a8478 100%);
}

.ar-boss-tick {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  background: rgba(13, 11, 9, 0.85);
}

/* ---------------- Radial Menu ---------------- */
.ar-radial-root {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.ar-radial-ring {
  position: absolute;
  border: 1.5px dashed rgba(255, 181, 71, 0.55);
  border-radius: 50%;
  transform: translate(-50%, -50%);
  transition: transform 0.18s ease-out;
}

.ar-radial-item {
  position: absolute;
  transform: translate(-50%, -50%) scale(0.3);
  display: flex;
  flex-direction: column;
  align-items: center;
  opacity: 0;
  transition: transform 0.22s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.16s ease;
}

.ar-radial-item.open {
  transform: translate(-50%, -50%) scale(1);
  opacity: 1;
}

.ar-radial-item.unaffordable .medallion-btn {
  filter: saturate(0.25) brightness(0.7);
}

.ar-radial-item.unaffordable .ar-radial-tag {
  color: var(--blood);
}

@keyframes shake-item {
  0%, 100% { transform: translate(-50%, -50%) translateX(0); }
  25% { transform: translate(-50%, -50%) translateX(-5px); }
  75% { transform: translate(-50%, -50%) translateX(5px); }
}

.ar-radial-item.shake {
  animation: shake-item 0.22s ease;
}

.ar-radial-tag {
  margin-top: 3px;
  padding: 2px 7px;
  font-size: 12px;
  font-weight: 700;
  background: rgba(13, 11, 9, 0.9);
  border: 1px solid var(--stone-edge);
  color: var(--amber-light);
  white-space: nowrap;
  pointer-events: auto;
  cursor: pointer;
}

.ar-radial-item.confirming .medallion-btn {
  filter: drop-shadow(0 0 12px rgba(255, 181, 71, 0.85)) brightness(1.2);
}

/* ---------------- Info Panel ---------------- */
.ar-info-panel {
  position: absolute;
  top: 74px;
  width: 244px;
  padding: 6px 10px;
  transition: transform 0.25s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.2s ease;
}

.ar-info-panel.side-left {
  left: max(12px, env(safe-area-inset-left));
}

.ar-info-panel.side-right {
  right: max(12px, env(safe-area-inset-right));
}

.ar-info-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}

.ar-info-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--amber-core);
}

.ar-info-stars {
  display: flex;
  gap: 3px;
}

.ar-info-role {
  font-size: 13.5px;
  color: var(--parchment-dim);
  line-height: 1.45;
  margin-bottom: 8px;
}

.ar-info-stats {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 14.5px;
  margin-bottom: 8px;
}

.ar-stat-row {
  display: flex;
  justify-content: space-between;
  gap: 6px;
}

.ar-stat-next {
  color: var(--amber-light);
  font-weight: 700;
}

.ar-info-trait {
  font-size: 13.5px;
  padding: 5px 7px;
  background: rgba(13, 11, 9, 0.62);
  border-left: 2px solid var(--amber-mid);
  margin-bottom: 10px;
  line-height: 1.45;
}

.ar-info-actions {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.ar-info-actions .stone-btn {
  width: 100%;
  min-height: 44px;
  font-size: 14px;
  padding: 2px 8px;
}

/* ---------------- Toasts, First-Seen Card, Center Alerts ---------------- */
.ar-toast-stack {
  position: absolute;
  top: 66px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  pointer-events: none;
}

.ar-toast {
  padding: 3px 12px;
  font-size: 14px;
  color: var(--amber-core);
  white-space: nowrap;
}

.ar-first-card {
  position: absolute;
  right: max(12px, env(safe-area-inset-right));
  top: 76px;
  width: 284px;
  padding: 7px 11px;
  display: flex;
  gap: 10px;
  align-items: flex-start;
  pointer-events: auto;
  animation: slide-in-right 0.25s ease-out;
}

@keyframes slide-in-right {
  from { transform: translateX(30px); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

.ar-first-card canvas {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 1.5px solid var(--amber);
  background: var(--night);
  flex-shrink: 0;
}

.ar-first-card-body {
  flex: 1;
  font-size: 13.5px;
  line-height: 1.48;
}

.ar-first-card-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--amber-light);
  margin-bottom: 2px;
}

.ar-first-card-tip {
  color: var(--amber-core);
  margin-top: 3px;
}

.ar-icon-close {
  background: transparent;
  border: none;
  color: var(--parchment-dim);
  cursor: pointer;
  padding: 2px;
  min-width: 44px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.ar-tutorial-close,
.ar-rotate-close {
  margin: -6px;
}

.ar-center-banner {
  position: absolute;
  top: 32%;
  left: 50%;
  transform: translate(-50%, -50%);
  padding: 10px 28px;
  font-size: 24px;
  font-weight: 700;
  letter-spacing: 0.2em;
  color: var(--amber-core);
  pointer-events: none;
  text-align: center;
}

/* ---------------- Modals: Pause, Result, Tutorial ---------------- */
.ar-modal-backdrop {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(8, 6, 4, 0.62);
  pointer-events: auto;
  padding: 16px;
}

.ar-pause-panel {
  width: min(320px, 90vw);
  padding: 14px 18px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.ar-modal-title {
  font-size: 24px;
  font-weight: 700;
  color: var(--amber-core);
  letter-spacing: 0.2em;
  margin-bottom: 4px;
}

.ar-pause-panel .stone-btn {
  width: 100%;
  height: 48px;
}

.ar-confirm-box {
  text-align: center;
  padding: 8px 4px;
}

.ar-confirm-msg {
  font-size: 15px;
  margin-bottom: 14px;
  line-height: 1.5;
}

.ar-confirm-btns {
  display: flex;
  gap: 10px;
  justify-content: center;
}

.ar-result-panel {
  width: min(440px, 94vw);
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  animation: drop-slab 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes drop-slab {
  from { transform: translateY(-70px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.ar-result-title {
  font-size: 28px;
  font-weight: 800;
  letter-spacing: 0.22em;
}

.ar-result-title.win {
  color: var(--amber-core);
}

.ar-result-title.lose {
  color: var(--bone);
}

.ar-result-sub {
  font-size: 14px;
  color: var(--parchment-dim);
  margin: 4px 0 12px;
}

.ar-result-stars {
  display: flex;
  gap: 14px;
  margin-bottom: 10px;
}

.ar-result-stars .ar-icon {
  width: 34px;
  height: 34px;
  transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.ar-result-newbest {
  font-size: 13px;
  color: var(--amber-light);
  margin-bottom: 10px;
}

.ar-result-stats {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 6px 0 16px;
}

.ar-inscribed-row {
  display: flex;
  align-items: baseline;
  font-size: 15px;
}

.ar-inscribed-dots {
  flex: 1;
  border-bottom: 1px dotted rgba(168, 156, 132, 0.45);
  margin: 0 8px;
}

.ar-result-actions {
  display: flex;
  gap: 12px;
  width: 100%;
}

.ar-result-actions .gem-btn,
.ar-result-actions .stone-btn {
  flex: 1;
  height: 50px;
}

/* ---------------- Tutorial Modal & Contextual Hint ---------------- */
.ar-tutorial-panel {
  width: min(760px, 94vw);
  padding: 12px 16px;
  position: relative;
}

.ar-tutorial-close {
  position: absolute;
  top: 8px;
  right: 8px;
}

.ar-tutorial-body {
  display: flex;
  gap: 18px;
  align-items: center;
  min-height: 240px;
}

.ar-tutorial-canvas {
  width: 45%;
  max-width: 320px;
  aspect-ratio: 4 / 3;
  background: var(--night);
  border: 2px solid var(--stone-edge);
  flex-shrink: 0;
}

.ar-tutorial-text {
  flex: 1;
}

.ar-tutorial-title {
  font-size: 22px;
  color: var(--amber-light);
  margin-bottom: 10px;
}

.ar-tutorial-desc {
  font-size: 15px;
  line-height: 1.65;
  color: var(--parchment);
}

.ar-tutorial-foot {
  margin-top: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.ar-tutorial-dots {
  display: flex;
  gap: 8px;
}

.ar-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--stone-light);
  border: 1px solid var(--stone-edge);
}

.ar-dot.active {
  background: var(--amber-light);
  box-shadow: 0 0 8px var(--amber);
}

.ar-context-hint {
  position: absolute;
  max-width: 262px;
  padding: 7px 11px;
  font-size: 14px;
  line-height: 1.48;
  color: var(--amber-core);
  display: flex;
  align-items: flex-start;
  gap: 6px;
  pointer-events: none;
}

/* ---------------- Asset Error & Debug ---------------- */
.ar-asset-error {
  width: min(460px, 90vw);
  padding: 18px;
  text-align: center;
  font-size: 16px;
  color: var(--blood);
}

.ar-debug-box {
  position: absolute;
  top: 64px;
  left: 12px;
  padding: 6px 10px;
  background: rgba(13, 11, 9, 0.85);
  border: 1px solid var(--amber-mid);
  font-family: monospace;
  font-size: 12px;
  color: var(--amber-core);
  pointer-events: none;
  white-space: pre;
}

/* ---------------- Rotate Prompt (Portrait Soft Card) ---------------- */
.ar-rotate-backdrop {
  position: absolute;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(8, 6, 4, 0.72);
  padding: max(16px, env(safe-area-inset-top, 0px)) max(16px, env(safe-area-inset-right, 0px)) max(16px, env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px));
  pointer-events: auto;
}

.ar-rotate-card {
  position: relative;
  width: min(360px, 90vw);
  max-height: calc(100dvh - 32px);
  overflow-y: auto;
  overscroll-behavior: contain;
  touch-action: pan-y;
  padding: 20px 22px 18px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.ar-rotate-close {
  position: absolute;
  top: 8px;
  right: 8px;
}

.ar-rotate-icon {
  color: var(--amber-light);
  margin: 4px 0 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  filter: drop-shadow(0 0 10px rgba(240, 138, 36, 0.45));
  animation: ar-rotate-tilt 2.4s ease-in-out infinite;
}

.ar-rotate-icon .ar-icon {
  width: 52px;
  height: 52px;
}

@keyframes ar-rotate-tilt {
  0%, 100% { transform: rotate(0deg); }
  45% { transform: rotate(-14deg); }
}

.ar-rotate-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--amber-core);
  letter-spacing: 0.16em;
  margin-bottom: 8px;
}

.ar-rotate-desc {
  font-size: 14px;
  line-height: 1.55;
  color: var(--parchment-dim);
  margin-bottom: 16px;
}

.ar-rotate-actions {
  display: flex;
  justify-content: center;
  width: 100%;
}

.ar-rotate-actions .stone-btn {
  min-width: 170px;
  min-height: 44px;
}

/* ---------------- Modal Scroll Safety & Touch Hover Guard ---------------- */
.ar-pause-panel,
.ar-result-panel,
.ar-tutorial-panel {
  max-height: calc(100dvh - 16px);
  overflow-y: auto;
  overscroll-behavior: contain;
  touch-action: pan-y;
}

@media (hover: none) {
  .medallion-btn:hover,
  .stone-btn:hover:not(:disabled) {
    filter: none;
  }
  .gem-btn:hover:not(:disabled) {
    filter: drop-shadow(0 6px 14px rgba(0, 0, 0, 0.72));
  }
}

/* ---------------- Narrow Viewport Boss Bar Safety ---------------- */
@media (max-width: 960px) {
  .ar-boss-bar {
    top: max(54px, calc(env(safe-area-inset-top, 0px) + 46px));
    width: min(400px, 56vw);
  }
}

/* ---------------- Mobile Landscape Adaptation (844x390 / 915x412 / 740x360) ---------------- */
@media (max-height: 500px) and (orientation: landscape) {
  .ar-menu {
    padding-top: max(10px, env(safe-area-inset-top, 0px));
    padding-bottom: max(12px, calc(env(safe-area-inset-bottom, 0px) + 6px));
  }
  .ar-menu-copy {
    margin-bottom: 10px;
    max-width: min(580px, 88vw);
  }
  .ar-menu-sub {
    font-size: 16px;
    letter-spacing: 0.18em;
    margin-bottom: 4px;
  }
  .ar-menu-intro {
    font-size: 12px;
    line-height: 1.35;
  }
  .ar-menu-actions {
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
  }
  .ar-menu-actions .gem-btn {
    width: 176px;
    height: 50px;
    font-size: 16px;
  }
  .ar-menu-actions .stone-btn {
    width: 148px;
    height: 46px;
    font-size: 14px;
    padding: 2px 10px;
  }
  .ar-menu-best {
    margin-top: 8px;
    font-size: 13px;
  }
  .ar-audio-hint {
    bottom: max(6px, env(safe-area-inset-bottom, 0px));
    font-size: 11px;
  }

  .ar-hud-top-left {
    top: max(6px, env(safe-area-inset-top, 0px));
    left: max(8px, env(safe-area-inset-left, 0px));
    gap: 10px;
    padding: 0 8px;
    border-width: 10px;
    border-image-width: 12px;
  }
  .ar-res-item {
    font-size: 16px;
    gap: 5px;
  }
  .ar-res-wave {
    font-size: 14px;
  }
  .ar-hud-top-right {
    top: max(6px, env(safe-area-inset-top, 0px));
    right: max(8px, env(safe-area-inset-right, 0px));
    gap: 8px;
  }
  .ar-hud-top-right .medallion-btn {
    width: 44px;
    height: 44px;
  }

  .ar-hud-bot-left {
    bottom: max(6px, env(safe-area-inset-bottom, 0px));
    left: max(8px, env(safe-area-inset-left, 0px));
    padding: 3px 8px;
    border-width: 10px;
    border-image-width: 12px;
    max-width: calc(100vw - env(safe-area-inset-left, 0px) - env(safe-area-inset-right, 0px) - 196px);
  }
  .ar-incoming-label {
    font-size: 13px;
  }
  .ar-incoming-chip canvas {
    width: 22px;
    height: 22px;
  }
  .ar-hud-bot-right {
    bottom: max(6px, env(safe-area-inset-bottom, 0px));
    right: max(8px, env(safe-area-inset-right, 0px));
  }
  .ar-summon-btn {
    width: 174px;
    height: 50px;
    font-size: 15px;
  }
  .ar-summon-sub {
    font-size: 12px;
    margin-top: 1px;
  }
  .ar-inwave-tag {
    padding: 6px 12px;
    font-size: 13px;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
  }

  .ar-boss-bar {
    top: max(54px, calc(env(safe-area-inset-top, 0px) + 46px));
    width: min(400px, 56vw);
  }
  .ar-boss-name {
    font-size: 14px;
    letter-spacing: 0.2em;
    margin-bottom: 2px;
  }
  .ar-boss-track {
    height: 11px;
  }

  .ar-toast-stack {
    top: max(56px, calc(env(safe-area-inset-top, 0px) + 50px));
  }
  .ar-first-card {
    top: max(56px, calc(env(safe-area-inset-top, 0px) + 50px));
    right: max(8px, env(safe-area-inset-right, 0px));
    width: min(260px, 60vw);
  }

  .ar-info-panel {
    top: max(52px, calc(env(safe-area-inset-top, 0px) + 46px));
    bottom: max(58px, calc(env(safe-area-inset-bottom, 0px) + 52px));
    width: 228px;
    overflow-y: auto;
    overscroll-behavior: contain;
    touch-action: pan-y;
    padding: 6px 8px;
  }
  .ar-info-panel.side-left {
    left: max(8px, env(safe-area-inset-left, 0px));
  }
  .ar-info-panel.side-right {
    right: max(8px, env(safe-area-inset-right, 0px));
  }
  .ar-info-head {
    margin-bottom: 3px;
  }
  .ar-info-title {
    font-size: 16px;
  }
  .ar-info-role {
    font-size: 12px;
    margin-bottom: 4px;
  }
  .ar-stat-row {
    font-size: 12px;
  }
  .ar-info-trait {
    font-size: 11px;
    margin-bottom: 6px;
    padding: 4px 6px;
    line-height: 1.3;
  }
  .ar-info-actions .stone-btn {
    min-height: 44px;
    font-size: 13px;
    padding: 2px 6px;
  }

  .ar-modal-backdrop {
    padding: max(8px, env(safe-area-inset-top, 0px)) max(12px, env(safe-area-inset-right, 0px)) max(8px, env(safe-area-inset-bottom, 0px)) max(12px, env(safe-area-inset-left, 0px));
  }
  .ar-pause-panel {
    width: min(460px, 92vw);
    padding: 10px 14px;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }
  .ar-pause-panel .ar-modal-title,
  .ar-pause-panel .ar-confirm-box,
  .ar-pause-panel #p-resume {
    grid-column: 1 / -1;
  }
  .ar-pause-panel .ar-modal-title {
    text-align: center;
    font-size: 20px;
    margin-bottom: 2px;
  }
  .ar-pause-panel .stone-btn {
    height: 44px;
    font-size: 14px;
  }

  .ar-result-panel {
    width: min(540px, 94vw);
    padding: 10px 16px;
  }
  .ar-result-title {
    font-size: 22px;
  }
  .ar-result-sub {
    font-size: 13px;
  }
  .ar-result-stats {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    column-gap: 18px;
    row-gap: 4px;
    margin: 4px 0 10px;
  }
  .ar-inscribed-row {
    font-size: 13px;
  }
  .ar-result-actions .gem-btn,
  .ar-result-actions .stone-btn {
    height: 44px;
    font-size: 15px;
  }

  .ar-tutorial-panel {
    width: min(680px, 94vw);
    padding: 10px 14px;
  }
  .ar-tutorial-body {
    min-height: 0;
    gap: 14px;
  }
  .ar-tutorial-canvas {
    width: 38%;
    max-width: 220px;
    max-height: 165px;
  }
  .ar-tutorial-title {
    font-size: 18px;
    margin-bottom: 6px;
  }
  .ar-tutorial-desc {
    font-size: 13px;
    line-height: 1.45;
  }
  .ar-tutorial-foot {
    margin-top: 8px;
  }
}

/* ---------------- Portrait Adaptation ---------------- */
@media (orientation: portrait) {
  .ar-hud-top-left {
    gap: 10px;
    padding: 0 6px;
  }
  .ar-res-item {
    font-size: 15px;
  }
  .ar-res-wave {
    font-size: 13px;
  }
  .ar-hud-top-right .medallion-btn {
    width: 44px;
    height: 44px;
  }
  .ar-boss-bar {
    top: max(62px, calc(env(safe-area-inset-top, 0px) + 54px));
    width: 84vw;
  }
  .ar-summon-btn {
    width: 164px;
    height: 54px;
    font-size: 15px;
  }
  .ar-summon-sub {
    font-size: 12px;
  }
  .ar-hud-bot-left {
    max-width: calc(100vw - env(safe-area-inset-left, 0px) - env(safe-area-inset-right, 0px) - 188px);
    overflow-x: auto;
  }
  .ar-info-panel {
    top: auto;
    bottom: max(0px, env(safe-area-inset-bottom, 0px));
    left: 0 !important;
    right: 0 !important;
    width: 100%;
    max-height: 40dvh;
    overflow-y: auto;
    overscroll-behavior: contain;
    touch-action: pan-y;
  }
  .ar-tutorial-body {
    flex-direction: column;
  }
  .ar-tutorial-canvas {
    width: 100%;
  }
}
