:root {
  color-scheme: dark;
  --ink: #130d09;
  --paper: #ead9b1;
  --paper-muted: #bda982;
  --cinnabar: #bd352b;
  --cinnabar-bright: #f05a3f;
  --gold: #f4c96b;
  --panel: rgba(20, 13, 9, 0.88);
  --panel-edge: rgba(234, 217, 177, 0.2);
  --focus: #ffd87d;
  font-family: "Microsoft YaHei", "PingFang SC", "Noto Sans CJK SC", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #090604;
  user-select: none;
  -webkit-user-select: none;
  overscroll-behavior: none;
}

body {
  display: grid;
  place-items: center;
  min-height: 100dvh;
  padding: max(8px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
  background:
    radial-gradient(circle at 50% 30%, rgba(108, 63, 31, 0.22), transparent 48%),
    #080503;
}

button {
  font: inherit;
}

button:focus-visible,
canvas:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

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

#game-shell {
  position: relative;
  width: min(calc(100vw - 16px), calc((100vh - 16px) * 16 / 9));
  width: min(calc(100vw - 16px), calc((100dvh - 16px) * 16 / 9));
  aspect-ratio: 16 / 9;
  overflow: hidden;
  border: 1px solid rgba(244, 201, 107, 0.3);
  border-radius: clamp(10px, 2vw, 22px);
  background: #22150d;
  box-shadow:
    0 28px 80px rgba(0, 0, 0, 0.72),
    inset 0 0 0 2px rgba(0, 0, 0, 0.35);
  isolation: isolate;
}

#game-shell::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 20;
  pointer-events: none;
  border-radius: inherit;
  box-shadow: inset 0 0 80px rgba(0, 0, 0, 0.72);
}

#game-canvas {
  position: absolute;
  inset: 0;
  z-index: 0;
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: crosshair;
}

.screen {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: none;
  place-items: center;
  padding: clamp(18px, 4vw, 48px);
  background: radial-gradient(circle at 50% 45%, rgba(15, 10, 7, 0.18), rgba(9, 6, 4, 0.58));
}

.screen.is-active {
  display: grid;
  animation: reveal 240ms ease-out both;
}

#home-screen {
  grid-template-rows: 1fr auto auto;
  gap: clamp(12px, 2.4vh, 26px);
  text-align: center;
}

.title-wrap {
  align-self: end;
  filter: drop-shadow(0 8px 18px rgba(0, 0, 0, 0.65));
}

.eyebrow {
  margin: 0 0 7px;
  color: var(--gold);
  font-size: clamp(10px, 1.45vw, 15px);
  font-weight: 700;
  letter-spacing: 0.22em;
  text-transform: uppercase;
}

#game-title {
  position: relative;
  margin: 0;
  color: var(--paper);
  font-family: "STKaiti", "KaiTi", serif;
  font-size: clamp(56px, 10.5vw, 112px);
  font-weight: 900;
  letter-spacing: -0.08em;
  line-height: 0.95;
  transform: rotate(-2deg);
}

#game-title span,
#game-title em {
  display: inline-block;
  font-style: normal;
}

#game-title em {
  margin-left: 0.06em;
  color: var(--cinnabar-bright);
  transform: translateY(0.04em) rotate(3deg);
  text-shadow: 3px 4px 0 rgba(66, 8, 5, 0.78);
}

.tagline {
  margin: 12px 0 0;
  color: var(--paper-muted);
  font-family: "STKaiti", "KaiTi", serif;
  font-size: clamp(14px, 2vw, 22px);
  letter-spacing: 0.22em;
}

.menu-actions,
.stack-actions {
  display: flex;
  gap: 12px;
}

.stack-actions {
  flex-direction: column;
  width: min(100%, 280px);
  margin: 20px auto 0;
}

.brush-button,
.text-button,
.icon-button {
  border: 0;
  color: var(--paper);
  cursor: pointer;
  transition: transform 150ms ease, filter 150ms ease, background 150ms ease;
}

.brush-button {
  min-width: 142px;
  padding: 12px 22px;
  border: 1px solid rgba(234, 217, 177, 0.32);
  border-radius: 8px 3px 10px 4px;
  background: linear-gradient(150deg, rgba(33, 23, 16, 0.94), rgba(12, 8, 5, 0.94));
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.32);
  font-size: clamp(14px, 1.6vw, 18px);
  font-weight: 800;
  letter-spacing: 0.08em;
}

.brush-button.primary {
  border-color: rgba(255, 190, 114, 0.55);
  background: linear-gradient(150deg, #d94a35, #8e201c);
}

.brush-button.subtle {
  min-width: 110px;
  color: var(--paper-muted);
}

.brush-button:hover,
.text-button:hover,
.icon-button:hover {
  filter: brightness(1.18);
  transform: translateY(-2px);
}

.brush-button:active,
.text-button:active,
.icon-button:active {
  transform: translateY(1px) scale(0.98);
}

.text-button {
  padding: 8px 12px;
  background: transparent;
  color: var(--paper-muted);
  text-decoration: underline;
  text-underline-offset: 4px;
}

.control-tip {
  margin: 0;
  color: rgba(234, 217, 177, 0.64);
  font-size: clamp(11px, 1.35vw, 14px);
}

.panel {
  width: min(100%, 560px);
  padding: clamp(22px, 4vw, 42px);
  border: 1px solid var(--panel-edge);
  border-radius: 18px 6px 20px 8px;
  background:
    linear-gradient(140deg, rgba(255, 255, 255, 0.035), transparent 42%),
    var(--panel);
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.55);
  text-align: center;
  backdrop-filter: blur(8px);
}

.panel h1,
.panel h2 {
  margin: 0;
  color: var(--paper);
  font-family: "STKaiti", "KaiTi", serif;
  font-size: clamp(30px, 5vw, 50px);
}

.panel p:not(.eyebrow) {
  color: var(--paper-muted);
  line-height: 1.7;
}

.compact-panel {
  width: min(100%, 400px);
}

.wide-panel {
  width: min(100%, 760px);
  max-height: 92%;
  overflow: auto;
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  text-align: left;
}

.seal,
.result-seal,
.bomb-mark {
  display: grid;
  width: 64px;
  height: 64px;
  margin: 0 auto 16px;
  place-items: center;
  border: 3px solid currentColor;
  color: var(--cinnabar-bright);
  font-family: "STKaiti", "KaiTi", serif;
  font-size: 38px;
  font-weight: 900;
  transform: rotate(-7deg);
}

.loading-track {
  width: 100%;
  height: 7px;
  margin: 24px 0 10px;
  overflow: hidden;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.08);
}

.loading-track span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #9e221e, #f4c96b);
  transition: width 200ms ease;
}

.level-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(72px, 1fr));
  gap: 12px;
  margin-top: 26px;
}

.level-card {
  position: relative;
  min-height: 86px;
  padding: 12px 8px;
  border: 1px solid rgba(234, 217, 177, 0.24);
  border-radius: 12px 4px;
  background: rgba(255, 255, 255, 0.035);
  color: var(--paper);
  cursor: pointer;
}

.level-card:hover:not(:disabled) {
  border-color: rgba(244, 201, 107, 0.7);
  background: rgba(244, 201, 107, 0.08);
}

.level-card:disabled {
  cursor: not-allowed;
  filter: grayscale(1);
  opacity: 0.36;
}

.level-card strong {
  display: block;
  font-size: 26px;
}

.level-card small {
  display: block;
  margin-top: 6px;
  color: var(--paper-muted);
}

.level-card .lock {
  position: absolute;
  top: 6px;
  right: 8px;
  font-size: 12px;
}

.tutorial-panel {
  position: relative;
}

.tutorial-slash {
  position: absolute;
  top: 24px;
  left: 13%;
  width: 74%;
  height: 4px;
  border-radius: 50%;
  background: linear-gradient(90deg, transparent, #fff6d4, transparent);
  box-shadow: 0 0 14px #fff2c5;
  transform: rotate(-9deg);
}

.rule-row {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin: 18px 0 24px;
}

.rule-row span {
  padding: 10px 12px;
  border: 1px solid rgba(234, 217, 177, 0.16);
  border-radius: 8px;
  color: var(--paper-muted);
  font-size: 13px;
}

.rule-row b {
  display: block;
  color: var(--gold);
}

.danger-panel {
  border-color: rgba(240, 90, 63, 0.38);
}

.bomb-mark {
  border-radius: 50%;
  color: #ff5c43;
}

.result-seal {
  width: 74px;
  height: 74px;
  font-size: 44px;
}

.result-panel.is-failure .result-seal {
  color: #a99c86;
  transform: rotate(7deg);
}

.result-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin: 20px 0;
}

.result-stats div {
  padding: 12px;
  border: 1px solid rgba(234, 217, 177, 0.15);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.025);
}

.result-stats span,
.result-stats strong {
  display: block;
}

.result-stats span {
  color: var(--paper-muted);
  font-size: 12px;
}

.result-stats strong {
  margin-top: 4px;
  color: var(--gold);
  font-size: 25px;
}

.hud {
  position: absolute;
  inset: 0 0 auto;
  z-index: 15;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: clamp(10px, 2vw, 20px);
  pointer-events: none;
}

.hud-block {
  min-width: 86px;
  padding: 7px 12px;
  border: 1px solid rgba(234, 217, 177, 0.18);
  border-radius: 10px 4px;
  background: rgba(13, 9, 6, 0.66);
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.28);
  backdrop-filter: blur(5px);
}

.hud-label {
  display: block;
  color: var(--paper-muted);
  font-size: clamp(8px, 1vw, 11px);
  letter-spacing: 0.14em;
}

.hud-block strong {
  color: var(--paper);
  font-size: clamp(16px, 2.2vw, 24px);
}

.hud-block small {
  color: var(--paper-muted);
  font-size: 0.62em;
}

.hud-lives {
  margin-left: auto;
}

#hud-lives-value {
  color: #f05a3f;
  letter-spacing: 0.08em;
}

.icon-button {
  width: 44px;
  height: 44px;
  border: 1px solid rgba(234, 217, 177, 0.2);
  border-radius: 50%;
  background: rgba(13, 9, 6, 0.72);
  font-weight: 900;
  pointer-events: auto;
}

#rotate-overlay {
  position: absolute;
  inset: 0;
  z-index: 50;
  display: none;
  place-items: center;
  align-content: center;
  padding: 30px;
  background: #100b07;
  color: var(--paper);
  text-align: center;
}

#rotate-overlay strong,
#rotate-overlay p {
  display: block;
}

#rotate-overlay p {
  margin: 8px 0 0;
  color: var(--paper-muted);
}

.rotate-icon {
  display: block;
  margin-bottom: 10px;
  color: var(--gold);
  font-size: 48px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@keyframes reveal {
  from { opacity: 0; transform: scale(0.99); }
  to { opacity: 1; transform: scale(1); }
}

@media (orientation: portrait) and (max-width: 900px) {
  #game-shell {
    width: calc(100vw - 16px);
    max-height: calc(100dvh - 16px);
  }

  #rotate-overlay {
    display: grid;
  }
}

@media (max-height: 520px) {
  .screen {
    padding: 12px 24px;
  }

  .panel {
    padding: 18px 24px;
  }

  #game-title {
    font-size: clamp(48px, 16vh, 84px);
  }

  .tagline,
  .control-tip {
    display: none;
  }

  .brush-button {
    padding: 9px 18px;
  }

  .level-card {
    min-height: 64px;
    padding: 7px;
  }
}

@media (max-width: 660px) {
  .level-grid {
    grid-template-columns: repeat(5, 1fr);
    gap: 6px;
  }

  .level-card {
    min-height: 60px;
  }

  .level-card strong {
    font-size: 20px;
  }

  .level-card small {
    display: none;
  }

  .rule-row {
    margin: 10px 0 14px;
  }

  .rule-row span {
    padding: 6px 8px;
    font-size: 11px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
