:root {
  color-scheme: dark;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  background: #080a0d;
  color: #f7eecf;
}

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

body {
  margin: 0;
  min-height: 100vh;
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at 50% 22%, rgba(214, 157, 83, 0.16), transparent 26%),
    radial-gradient(circle at 50% 56%, rgba(41, 129, 148, 0.16), transparent 34%),
    linear-gradient(180deg, rgba(7, 17, 27, 0.94), rgba(7, 9, 14, 0.99)),
    repeating-linear-gradient(0deg, #07111b 0 2px, #0d1823 2px 4px);
  overflow-x: hidden;
  overscroll-behavior-x: none;
  overscroll-behavior-y: contain;
  touch-action: pan-y;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

body.game-active {
  overflow: hidden;
  touch-action: none;
}

.shell {
  width: min(100vw, 1040px);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 10px;
  padding: 16px;
}

.screen-hidden {
  display: none !important;
}

.top-screen {
  width: min(100vw, 520px);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 9px;
  padding: 12px 16px;
  touch-action: pan-y;
}

.ad-banner {
  position: relative;
  width: 100%;
  height: 52px !important;
  min-height: 52px !important;
  max-height: 52px !important;
  display: block;
  overflow: hidden !important;
  padding: 0;
  border: 0;
  background: transparent;
  color: transparent;
  font-size: 0;
  letter-spacing: 0;
  text-align: center;
  box-shadow: none;
}

.ad-label {
  display: none;
}

.ad-slot {
  width: 100%;
  height: 50px !important;
  min-height: 50px !important;
  max-height: 50px !important;
  overflow: hidden !important;
}

.adsbygoogle {
  width: 100% !important;
  height: 50px !important;
  min-height: 50px !important;
  max-height: 50px !important;
  overflow: hidden !important;
}

.title-card,
.account-card {
  border: 3px solid #8b643a;
  background:
    linear-gradient(180deg, rgba(54, 64, 71, 0.97), rgba(24, 30, 38, 0.99)),
    repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.045) 0 1px, transparent 1px 6px);
  box-shadow:
    inset 0 0 0 2px #0a0d11,
    inset 0 -9px 0 rgba(0, 0, 0, 0.24),
    0 14px 36px rgba(0, 0, 0, 0.36);
}

.title-card {
  min-height: 206px;
  display: grid;
  grid-template-rows: 92px auto auto;
  place-items: center;
  padding: 12px 14px 14px;
  overflow: hidden;
}

.title-scene {
  position: relative;
  width: min(100%, 330px);
  height: 92px;
  display: grid;
  place-items: end center;
  image-rendering: pixelated;
}

.title-scene::before {
  content: "";
  position: absolute;
  inset: 22px 24px 0;
  border: 3px solid #15191f;
  border-bottom: 0;
  background:
    linear-gradient(180deg, rgba(11, 14, 19, 0.08), rgba(5, 7, 10, 0.7)),
    repeating-linear-gradient(90deg, #5d6770 0 26px, #4a535c 26px 52px);
  box-shadow:
    inset 0 0 0 2px rgba(242, 209, 139, 0.14),
    0 9px 0 #111318;
}

.title-scene::after {
  content: "";
  position: absolute;
  left: 40px;
  right: 40px;
  bottom: 0;
  height: 16px;
  background: repeating-linear-gradient(90deg, #66533d 0 28px, #4c3b2b 28px 56px);
  border: 2px solid #17120d;
}

.title-hero {
  position: relative;
  z-index: 2;
  width: 78px;
  height: 78px;
  object-fit: contain;
  object-position: center bottom;
  filter: drop-shadow(0 8px 0 rgba(0, 0, 0, 0.45));
}

.scene-torch {
  position: absolute;
  z-index: 2;
  bottom: 19px;
  width: 12px;
  height: 34px;
  background: #3a2315;
  border: 2px solid #120c08;
}

.scene-torch::before {
  content: "";
  position: absolute;
  left: -5px;
  top: -18px;
  width: 18px;
  height: 20px;
  background:
    radial-gradient(circle at 50% 55%, #fff2a4 0 3px, #ffb23e 4px 8px, #c43b20 9px 11px, transparent 12px);
}

.scene-torch-left {
  left: 62px;
}

.scene-torch-right {
  right: 62px;
}

.title-mark {
  margin: 0;
  color: #f7eecf;
  font-size: clamp(42px, 10.6vw, 60px);
  line-height: 1;
  transform: rotate(-6deg);
  text-shadow: 4px 4px 0 #111318, 7px 7px 0 #6a402d;
}

.title-sub {
  margin: 7px 0 0;
  color: #f2c46d;
  font-size: 12px;
  letter-spacing: 2px;
  text-shadow: 2px 2px 0 #111318;
}

.explore-button {
  width: min(100%, 316px);
  height: 72px;
  align-self: center;
  border-color: #f0bd6d;
  background:
    linear-gradient(180deg, #b87a30 0 48%, #83511e 49% 100%);
  color: #fff2cd;
  font-size: 30px;
  font-weight: 700;
  text-shadow: 2px 2px 0 #3a1e0d;
  box-shadow:
    inset 0 0 0 2px #1a1209,
    inset 0 -8px 0 rgba(0, 0, 0, 0.2),
    0 8px 0 #24170c;
}

.account-card {
  min-height: 218px;
  display: grid;
  justify-items: center;
  align-content: start;
  gap: 8px;
  padding: 14px 16px 12px;
  text-align: center;
}

.account-heading {
  display: grid;
  gap: 3px;
  justify-items: center;
}

.continue-overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(0, 0, 0, 0.76);
}

.continue-panel {
  width: min(100%, 360px);
  display: grid;
  gap: 12px;
  justify-items: center;
  padding: 18px;
  border: 3px solid #725436;
  background:
    linear-gradient(180deg, rgba(41, 46, 56, 0.98), rgba(18, 22, 30, 0.99)),
    repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.03) 0 1px, transparent 1px 5px);
  box-shadow:
    inset 0 0 0 2px #0a0d11,
    0 18px 48px rgba(0, 0, 0, 0.54);
}

.continue-panel h2,
.continue-panel p {
  margin: 0;
}

.continue-panel h2 {
  font-size: 30px;
}

.continue-ad {
  width: 100%;
  min-height: 130px;
  display: grid;
  place-items: center;
  gap: 8px;
  border: 2px dashed rgba(183, 196, 206, 0.45);
  background: rgba(8, 12, 18, 0.76);
  color: #d7d0bd;
}

.continue-ad span {
  color: #9ba9b8;
  font-size: 11px;
  letter-spacing: 2px;
}

#continueCountdown {
  font-size: 42px;
}

#continueButton,
#giveUpButton {
  width: min(100%, 220px);
}

#continueButton {
  border-color: #8ccf91;
  background: linear-gradient(180deg, #3f6844, #243a28);
}

#giveUpButton {
  border-color: #596a76;
  background: linear-gradient(180deg, #3a4652, #242d35);
}

.account-card h2,
.account-card p {
  margin: 0;
}

.account-card h2 {
  color: #f2c46d;
  font-size: 20px;
  line-height: 1;
  letter-spacing: 1px;
  text-shadow: 2px 2px 0 #111318;
}

.account-card p {
  font-size: 13px;
  font-weight: 700;
}

.account-note,
.login-status {
  color: #f7eecf;
}

.top-scores {
  width: min(100%, 300px);
  min-height: 62px;
  margin: 0;
  padding: 7px 10px 7px 28px;
  display: grid;
  align-content: center;
  gap: 3px;
  border: 2px solid rgba(10, 13, 17, 0.9);
  background:
    linear-gradient(180deg, rgba(16, 22, 30, 0.88), rgba(9, 13, 18, 0.92)),
    repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.03) 0 1px, transparent 1px 5px);
  color: #f7eecf;
  text-align: left;
  box-shadow: inset 0 0 0 1px rgba(242, 196, 109, 0.12);
}

.top-scores li {
  margin: 0;
  font-size: 12px;
  line-height: 1.15;
}

.login-button {
  width: min(100%, 240px);
  height: 40px;
  border-color: #7bb1c9;
  background: linear-gradient(180deg, #2d6d82, #1b3d4d);
  color: #e8fbff;
  font-size: 15px;
  font-weight: 700;
}

.login-status {
  max-width: 100%;
  margin: 0;
  color: #b7c4ce;
  font-size: 10px;
  font-weight: 400;
  line-height: 1.25;
}

.masthead {
  width: min(100%, 956px);
  display: flex;
  align-items: end;
  justify-content: space-between;
  border-bottom: 2px solid #4f3f2e;
  padding: 0 4px 8px;
  color: #f7eecf;
}

h1 {
  margin: 0;
  font-size: clamp(24px, 5vw, 42px);
  line-height: 0.9;
  text-transform: uppercase;
  text-shadow: 3px 3px 0 #111318, 5px 5px 0 #53382c;
}

#rank {
  color: #d29f5a;
  font-size: 12px;
  letter-spacing: 2px;
}

.hud {
  width: min(100%, 956px);
  display: grid;
  grid-template-columns: 1fr 1.35fr 1fr 1fr 1.2fr;
  gap: 8px;
}

.stat,
.controls,
.choice {
  border: 2px solid #4b5361;
  background:
    linear-gradient(180deg, rgba(41, 46, 56, 0.96), rgba(24, 28, 36, 0.98)),
    repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.03) 0 1px, transparent 1px 5px);
  box-shadow:
    inset 0 0 0 2px #0a0d11,
    inset 0 -8px 0 rgba(0, 0, 0, 0.16);
}

.stat {
  position: relative;
  overflow: hidden;
  min-width: 0;
  min-height: 62px;
  padding: 9px 11px;
}

.stat::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 3px;
  background: var(--accent, #d29f5a);
}

.stat-depth { --accent: #d29f5a; }
.stat-hp { --accent: #d76262; }
.stat-gold { --accent: #f0ca76; }
.stat-atk { --accent: #8ccf91; }
.stat-score { --accent: #6fc3c7; }

.meter {
  display: block;
  width: 100%;
  height: 6px;
  margin-top: 7px;
  border: 1px solid #111318;
  background: #351b1d;
}

#hpbar {
  display: block;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, #d76262, #f0b66d);
}

.label {
  display: block;
  margin-bottom: 3px;
  color: #9ba9b8;
  font-size: 11px;
}

strong {
  font-size: clamp(16px, 3vw, 24px);
  line-height: 1;
  text-shadow: 2px 2px 0 #0a0d11;
}

.stage {
  position: relative;
  width: min(100%, calc((100vh - 300px) * 0.769));
  aspect-ratio: 10 / 13;
  max-width: 480px;
  margin: 0 auto;
  padding: 8px;
  border: 3px solid #725436;
  background:
    linear-gradient(135deg, #24455a, #102235 35%, #233143);
  box-shadow:
    0 18px 60px rgba(0, 0, 0, 0.48),
    0 0 0 2px #111318,
    inset 0 0 0 2px #0c0e12;
  touch-action: none;
}

.stage::before,
.stage::after {
  content: "";
  position: absolute;
  pointer-events: none;
}

.stage::before {
  inset: 8px;
  z-index: 2;
  opacity: 0.46;
  background:
    linear-gradient(rgba(255, 255, 255, 0.028) 50%, rgba(0, 0, 0, 0.025) 50%);
  background-size: 100% 4px;
  mix-blend-mode: screen;
}

.stage::after {
  inset: -3px;
  border: 3px solid rgba(247, 238, 207, 0.08);
  box-shadow: inset 0 0 36px rgba(0, 0, 0, 0.68);
}

#game {
  width: 100%;
  height: 100%;
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  border: 2px solid #0a0d11;
  background: #090b0f;
  touch-action: none;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

.controls {
  width: min(100%, 956px);
  min-height: 86px;
  display: grid;
  grid-template-columns: auto auto auto auto minmax(0, 1fr);
  align-items: center;
  gap: 12px;
  padding: 10px;
  touch-action: none;
}

button {
  height: 42px;
  min-width: 42px;
  border: 2px solid #8a7651;
  background:
    linear-gradient(180deg, #3c4634, #243127);
  color: #f7eecf;
  font: inherit;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  box-shadow: inset 0 -4px 0 #141d17, 2px 2px 0 #0a0d11;
}

button:focus-visible {
  outline: 3px solid #d7b85d;
  outline-offset: 2px;
}

button:active {
  transform: translateY(1px);
  box-shadow: inset 0 -1px 0 #172318;
}

#restart {
  width: 116px;
}

#skillButton {
  width: 94px;
  border-color: #9b5b66;
  background: linear-gradient(180deg, #653746, #3a202d);
}

#waitButton {
  width: 84px;
  border-color: #4f8993;
  background: linear-gradient(180deg, #2f5661, #1d3540);
}

#checkButton {
  width: 92px;
  border-color: #d2a55f;
  background: linear-gradient(180deg, #625331, #3a2d1d);
}

.choice {
  position: fixed;
  inset: 0;
  z-index: 19;
  width: 100%;
  display: grid;
  grid-template-columns: 128px 128px;
  justify-content: center;
  align-content: center;
  gap: 12px;
  padding: 18px;
  background: rgba(0, 0, 0, 0.58);
  touch-action: none;
}

.choice.hidden {
  display: none;
}

.choice p {
  grid-column: 1 / -1;
  margin: 0;
  color: #f7eecf;
  font-size: 22px;
  font-weight: 700;
  text-align: center;
  text-shadow: 3px 3px 0 #0a0d11;
}

#openChest {
  width: 128px;
  height: 54px;
  border-color: #d2a55f;
  background: linear-gradient(180deg, #65512a, #3a2d1d);
}

#leaveChest {
  width: 128px;
  height: 54px;
  border-color: #596a76;
  background: linear-gradient(180deg, #3a4652, #242d35);
}

#message {
  margin: 0;
  min-width: 0;
  color: #d7d0bd;
  font-size: 13px;
  line-height: 1.4;
  text-shadow: 1px 1px 0 #0a0d11;
}

.pad {
  display: none;
  grid-template-columns: repeat(3, 42px);
  gap: 4px;
  touch-action: none;
}

.ghost {
  visibility: hidden;
}

.key-help {
  width: min(100%, 956px);
  display: grid;
  grid-template-columns: repeat(5, auto);
  justify-content: center;
  gap: 8px;
  color: #b7c4ce;
  font-size: 12px;
}

.key-help span {
  border: 1px solid #394553;
  background: rgba(13, 20, 29, 0.82);
  padding: 5px 8px;
  box-shadow: inset 0 0 0 1px #0a0d11;
}

@media (max-width: 720px) {
  body {
    place-items: start center;
    min-height: 100dvh;
    overflow-x: hidden;
    overflow-y: auto;
  }

  body.game-active {
    overflow: hidden;
  }

  .top-screen {
    width: 100vw;
    height: 100dvh;
    min-height: 0;
    justify-content: center;
    gap: 8px;
    padding: 8px 18px;
    overflow: hidden;
  }

  .ad-banner {
    min-height: 42px;
    font-size: 9px;
  }

  .title-card {
    min-height: 192px;
    grid-template-rows: 86px auto auto;
    padding: 10px 12px 12px;
  }

  .title-scene {
    height: 86px;
  }

  .title-hero {
    width: 72px;
    height: 72px;
  }

  .title-mark {
    font-size: 38px;
  }

  .title-sub {
    font-size: 10px;
  }

  .explore-button {
    width: min(100%, 286px);
    height: 60px;
    font-size: 26px;
  }

  .account-card {
    min-height: 194px;
    padding: 12px 14px 10px;
    gap: 7px;
  }

  .account-card h2 {
    font-size: 18px;
  }

  .account-card p {
    font-size: 12px;
  }

  .top-scores {
    min-height: 54px;
    padding-top: 6px;
    padding-bottom: 6px;
  }

  .login-button {
    height: 38px;
  }

  .shell {
    width: 100vw;
    height: 100dvh;
    min-height: 0;
    justify-content: start;
    padding: 6px;
    gap: 4px;
    overflow: hidden;
  }

  .masthead {
    width: 100%;
    align-items: start;
    gap: 6px;
    padding: 0 2px 4px;
    border-bottom-width: 1px;
  }

  h1 {
    font-size: 22px;
    text-shadow: 2px 2px 0 #111318, 3px 3px 0 #53382c;
  }

  #rank {
    max-width: 96px;
    font-size: 10px;
    text-align: right;
    line-height: 1.2;
  }

  .hud {
    width: 100%;
    grid-template-columns: repeat(5, 1fr);
    gap: 3px;
  }

  .stat {
    min-height: 38px;
    padding: 5px 4px;
    border-width: 1px;
    box-shadow: inset 0 0 0 1px #0a0d11;
  }

  .stat::before {
    height: 2px;
  }

  .label {
    margin-bottom: 1px;
    font-size: 8px;
  }

  strong {
    font-size: 13px;
  }

  .meter {
    height: 3px;
    margin-top: 3px;
  }

  .stage {
    width: min(calc(100vw - 12px), calc((100dvh - 220px) * 0.769));
    padding: 3px;
    border-width: 2px;
    box-shadow:
      0 8px 24px rgba(0, 0, 0, 0.42),
      0 0 0 1px #111318,
      inset 0 0 0 1px #0c0e12;
  }

  .stage::before {
    inset: 3px;
    opacity: 0.16;
  }

  #game {
    border-width: 1px;
    background: #18364d;
  }

  .controls {
    width: 100%;
    min-height: 0;
    grid-template-columns: repeat(4, 1fr) 118px;
    gap: 5px;
    padding: 6px;
    border-width: 1px;
    box-shadow: inset 0 0 0 1px #0a0d11;
  }

  #restart,
  #skillButton,
  #waitButton,
  #checkButton {
    width: 100%;
  }

  .choice {
    width: 100%;
    grid-template-columns: 124px 124px;
    gap: 10px;
    padding: 18px;
    border-width: 0;
    box-shadow: none;
  }

  .choice p {
    font-size: 20px;
  }

  #openChest,
  #leaveChest {
    width: 124px;
    height: 52px;
  }

  #message {
    grid-column: 1 / -1;
    order: 3;
    min-height: 30px;
    font-size: 11px;
    line-height: 1.25;
  }

  .pad {
    display: grid;
    grid-template-columns: repeat(3, 36px);
    gap: 3px;
  }

  .key-help {
    display: none;
  }

  button {
    height: 36px;
    min-width: 36px;
    font-size: 13px;
    border-width: 1px;
    box-shadow: inset 0 -3px 0 #141d17, 1px 1px 0 #0a0d11;
  }
}
