:root {
  --safe-area-inset-top: env(safe-area-inset-top);
  --safe-area-inset-right: env(safe-area-inset-right);
  --safe-area-inset-bottom: env(safe-area-inset-bottom);
  --safe-area-inset-left: env(safe-area-inset-left);

  --bg-felt-center: #143225;
  --bg-felt-edge: #081711;
  --surface-hud: rgba(9, 24, 17, 0.84);
  --surface-card-btn: rgba(14, 34, 25, 0.88);
  --border-hairline: rgba(255, 255, 255, 0.14);
  --border-active: #c2a366;
  --text-primary: #f0eee9;
  --text-secondary: #a4b7ad;
  --accent-gold: #c2a366;
  --accent-gold-soft: rgba(194, 163, 102, 0.2);
  --font-display: "Hiragino Mincho ProN", "Yu Mincho", Georgia, "Times New Roman", serif;
  --font-ui: "Hiragino Sans", "Yu Gothic UI", system-ui, -apple-system, sans-serif;
}

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

html, body {
  width: 100dvw;
  height: 100dvh;
  margin: 0;
  padding: 0;
  background: radial-gradient(ellipse 80% 70% at 50% 45%, var(--bg-felt-center) 0%, var(--bg-felt-edge) 100%);
  color: var(--text-primary);
  font-family: var(--font-ui);
}

body {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  overflow: hidden;
}

#game-area {
  position: relative;
  flex: 1;
  width: 100%;
  height: 100%;
  padding-top: var(--safe-area-inset-top);
  padding-right: var(--safe-area-inset-right);
  padding-bottom: var(--safe-area-inset-bottom);
  padding-left: var(--safe-area-inset-left);
  overflow: hidden;
}

#assets {
  display: none;
}

/* 言語切り替え */
html[lang="ja"] .lang-en,
html:not([lang="ja"]) .lang-ja {
  display: none;
}

/* ============================================
   Screen Switcher
============================================ */
.loading-screen,
.title-screen,
.game-screen {
  width: 100%;
  height: 100%;
}

body:not(.loading-screen-active) .loading-screen,
body:not(.title-screen-active) .title-screen,
body:not(.game-screen-active) .game-screen {
  display: none;
}

/* ============================================
   Loading Screen (Background only)
============================================ */
.loading-screen {
  background: transparent;
}

/* ============================================
   Title Screen
============================================ */
.title-screen {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 28px 20px;
  overflow-y: auto;
}

.title-panel {
  width: 100%;
  max-width: 640px;
  margin: auto 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 20px;
}

.title-hero-lockup {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.title-cards-emblem {
  position: relative;
  width: 300px;
  height: 146px;
}

.title-cards-fan {
  position: absolute;
  inset: 0 0 18px 0;
}

.emblem-card {
  position: absolute;
  bottom: 0;
  left: 50%;
  width: 76px;
  height: 106px;
  border-radius: 6px;
  transform-origin: bottom center;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.36);
}

.emblem-card-left {
  transform: translateX(-50%) translateX(-68px) rotate(-18deg) translateY(9px);
}

.emblem-card-mid-left {
  transform: translateX(-50%) translateX(-35px) rotate(-9deg) translateY(3px);
}

.emblem-card-center {
  transform: translateX(-50%) rotate(0deg);
  z-index: 3;
}

.emblem-card-mid-right {
  transform: translateX(-50%) translateX(35px) rotate(9deg) translateY(3px);
  z-index: 2;
}

.emblem-card-right {
  transform: translateX(-50%) translateX(68px) rotate(18deg) translateY(9px);
  z-index: 1;
}

.title-logo {
  position: absolute;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  z-index: 6;
  width: 288px;
  margin: 0;
  line-height: 0;
  pointer-events: none;
}

.title-logo-img {
  display: block;
  width: 100%;
  height: auto;
}

.title-tagline {
  font-size: 14px;
  color: var(--text-secondary);
}

.suit-options {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0;
  width: 100%;
  border-radius: 10px;
  border: 1px solid var(--border-hairline);
  background: var(--surface-card-btn);
  overflow: hidden;
}

.suit-option-btn {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-height: 60px;
  padding: 10px 10px;
  border: none;
  border-radius: 0;
  background: transparent;
  color: var(--text-primary);
  cursor: pointer;
  transition: background-color 150ms ease, box-shadow 150ms ease;
}

.suit-option-btn + .suit-option-btn {
  border-left: 1px solid var(--border-hairline);
}

@media (max-width: 560px) {
  .title-screen {
    padding: 20px 18px;
  }

  .title-panel {
    gap: 18px;
  }

  .title-hero-lockup {
    gap: 8px;
  }

  .title-cards-emblem {
    width: 256px;
    height: 126px;
  }

  .title-cards-fan {
    bottom: 15px;
  }

  .emblem-card {
    width: 64px;
    height: 90px;
  }

  .emblem-card-left {
    transform: translateX(-50%) translateX(-58px) rotate(-18deg) translateY(8px);
  }

  .emblem-card-mid-left {
    transform: translateX(-50%) translateX(-30px) rotate(-9deg) translateY(3px);
  }

  .emblem-card-mid-right {
    transform: translateX(-50%) translateX(30px) rotate(9deg) translateY(3px);
  }

  .emblem-card-right {
    transform: translateX(-50%) translateX(58px) rotate(18deg) translateY(8px);
  }

  .title-logo {
    width: 248px;
  }

  .title-tagline {
    font-size: 13px;
  }

  .suit-option-btn {
    min-height: 54px;
    padding: 9px 4px;
  }

  .suit-option-title {
    font-size: 14px;
  }

  .suit-option-desc {
    font-size: 10.5px;
  }
}

@media (max-height: 600px) {
  .title-screen {
    padding: 16px 18px;
  }

  .title-panel {
    gap: 12px;
  }
}

.suit-option-btn:hover:not(.is-selected) {
  background: rgba(255, 255, 255, 0.04);
}

.suit-option-btn:focus-visible {
  outline: 2px solid var(--accent-gold);
  outline-offset: -2px;
}

.suit-option-btn.is-selected {
  background: var(--accent-gold-soft);
  box-shadow: inset 0 0 0 1px var(--border-active);
}

.suit-option-btn.is-selected:first-child {
  border-top-left-radius: 9px;
  border-bottom-left-radius: 9px;
}

.suit-option-btn.is-selected:last-child {
  border-top-right-radius: 9px;
  border-bottom-right-radius: 9px;
}

.suit-option-title {
  font-size: 15px;
  font-weight: 700;
  white-space: nowrap;
}

.suit-option-desc {
  font-size: 12px;
  color: var(--text-secondary);
  white-space: nowrap;
}

.luck-section {
  width: 100%;
  padding: 10px 16px 12px;
  border-radius: 10px;
  border: 1px solid var(--border-hairline);
  background: var(--surface-card-btn);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.luck-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.luck-label {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-primary);
  white-space: nowrap;
}

.luck-value-readout {
  font-size: 13px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--accent-gold);
  white-space: nowrap;
}

.luck-slider-row {
  display: flex;
  align-items: center;
  width: 100%;
  min-height: 28px;
}

.luck-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.14);
  outline: none;
  cursor: pointer;
}

.luck-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--accent-gold);
  border: 2px solid #0b1913;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.45);
  cursor: pointer;
  transition: transform 120ms ease;
}

.luck-slider::-moz-range-thumb {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--accent-gold);
  border: 2px solid #0b1913;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.45);
  cursor: pointer;
  transition: transform 120ms ease;
}

.luck-slider:focus-visible::-webkit-slider-thumb {
  outline: 2px solid var(--text-primary);
  outline-offset: 2px;
}

.luck-slider:focus-visible::-moz-range-thumb {
  outline: 2px solid var(--text-primary);
  outline-offset: 2px;
}

.luck-slider:hover::-webkit-slider-thumb {
  transform: scale(1.08);
}

.luck-slider:hover::-moz-range-thumb {
  transform: scale(1.08);
}

.luck-desc {
  display: none;
}

body.luck-level-1 .luck-desc-1,
body.luck-level-2 .luck-desc-2,
body.luck-level-3 .luck-desc-3,
body.luck-level-4 .luck-desc-4,
body.luck-level-5 .luck-desc-5 {
  display: inline;
}

.settings-stage-seed {
  width: 100%;
  display: flex;
  justify-content: center;
}

.stage-seed-input-box {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  padding: 0 6px 0 12px;
  border-radius: 8px;
  border: 1px solid var(--border-active);
  background: var(--surface-card-btn);
}

.stage-seed-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  white-space: nowrap;
}

.stage-seed-input {
  width: 140px;
  height: 30px;
  padding: 0 8px;
  border: 1px solid var(--border-hairline);
  border-radius: 6px;
  background: rgba(8, 23, 17, 0.9);
  color: var(--text-primary);
  font-family: var(--font-ui);
  font-size: 16px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.04em;
  user-select: text;
  -webkit-user-select: text;
}

.stage-seed-input::placeholder {
  color: rgba(164, 183, 173, 0.45);
  font-weight: 400;
  font-size: 13px;
}

.stage-seed-input:focus {
  outline: none;
  border-color: var(--accent-gold);
}

.title-action-button {
  min-width: 220px;
  min-height: 48px;
  padding: 12px 44px;
  border-radius: 8px;
  border: 1px solid var(--accent-gold);
  background: var(--accent-gold);
  color: #0b1913;
  font-family: var(--font-ui);
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.08em;
  cursor: pointer;
  white-space: nowrap;
  transition: transform 150ms cubic-bezier(0.16, 1, 0.3, 1), opacity 150ms ease;
}

.title-action-button:hover,
.title-action-button:focus-visible {
  opacity: 0.92;
  transform: translateY(-1px);
  outline: 2px solid var(--text-primary);
  outline-offset: 2px;
}

/* ============================================
   Game Screen & Corner HUDs
============================================ */
.game-screen {
  position: relative;
}

#canvas-container {
  width: 100%;
  height: 100%;
  touch-action: pinch-zoom;
}

#canvas-container canvas {
  display: block;
  width: 100% !important;
  height: 100% !important;
}

.hud-top-left,
.hud-top-right,
.hud-bottom-left,
.hud-bottom-right {
  position: absolute;
  z-index: 10;
  display: flex;
  pointer-events: none;
}

.hud-top-left {
  top: 12px;
  left: 14px;
  align-items: center;
  gap: 8px;
}

.hud-top-right {
  top: 12px;
  right: 14px;
  align-items: center;
  gap: 8px;
}

.hud-bottom-left {
  bottom: 14px;
  left: 14px;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
}

.hud-bottom-right {
  bottom: 14px;
  right: 14px;
  align-items: flex-end;
  justify-content: flex-end;
}

.hud-elapsed-time {
  font-family: var(--font-ui);
  font-size: 14px;
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: 0.04em;
  font-variant-numeric: tabular-nums;
  color: rgba(240, 238, 233, 0.72);
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.72);
  white-space: nowrap;
}

.hud-bottom-row {
  display: flex;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}

.hud-top-left > *,
.hud-top-right > *,
.hud-bottom-row > * {
  pointer-events: auto;
}

.hud-status-box {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  gap: 2px;
  padding: 2px 4px;
  background: transparent;
  border: none;
  border-radius: 0;
  white-space: nowrap;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.72);
}

.hud-status-suit {
  font-size: 13px;
  font-weight: 700;
  line-height: 1.2;
  font-variant-numeric: tabular-nums;
  color: var(--text-primary);
}

.hud-status-stage {
  font-size: 11px;
  font-weight: 600;
  line-height: 1.2;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
}

.edit-settings-button {
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: solid 1px rgba(255, 255, 255, 0.2);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.9);
  cursor: pointer;
  pointer-events: auto;
  transition: border-color 150ms ease, background-color 150ms ease;
}

.edit-settings-button:hover,
.edit-settings-button:focus-visible {
  border-color: rgba(255, 255, 255, 1);
  background: rgba(255, 250, 250, 1);
  outline: none;
}

.edit-settings-button img {
  width: 19px;
  height: 19px;
}

body:not(.suit-count-1) .suit-label-1,
body:not(.suit-count-2) .suit-label-2,
body:not(.suit-count-4) .suit-label-4 {
  display: none;
}

.sound-button {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: background-color 150ms ease, opacity 150ms ease;
}

.sound-button:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.08);
}

.sound-button:disabled {
  opacity: 0.38;
  cursor: default;
}

.sound-button:focus-visible:not(:disabled) {
  outline: 2px solid var(--accent-gold);
  outline-offset: 2px;
}

.sound-button img {
  width: 20px;
  height: 20px;
  filter: brightness(0) invert(1);
}

body.sound-enabled .sound-button.sound-disabled-button,
body.sound-disabled .sound-button.sound-enabled-button {
  display: none;
}

.pause-button {
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  margin: 0 4px;
  border: solid 1px #ffffff;
  border-radius: 50%;
  cursor: pointer;
}

.pause-button img {
  width: 18px;
  height: 18px;
  filter: brightness(0) invert(1);
}

.game-sub-button {
  height: 40px;
  padding: 0 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border-radius: 8px;
  border: 1px solid var(--border-hairline);
  background: var(--surface-hud);
  color: var(--text-primary);
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: border-color 150ms ease, opacity 150ms ease, background-color 150ms ease;
}

.game-sub-button img {
  width: 16px;
  height: 16px;
  filter: brightness(0) invert(1);
}

.game-sub-button:hover:not(:disabled),
.game-sub-button:focus-visible:not(:disabled) {
  border-color: var(--accent-gold);
  outline: none;
}

.game-sub-button:disabled {
  opacity: 0.38;
  cursor: default;
}

body.stage-cleared .hud-top-right > *,
body.stage-cleared .hud-bottom-row > * {
  pointer-events: none;
}

.restart-button {
  background: #6b1d24;
  border-color: rgba(232, 128, 136, 0.42);
}

.restart-button:hover:not(:disabled),
.restart-button:focus-visible:not(:disabled) {
  background: #80232b;
  border-color: #e88088;
}

.back-to-title-button {
  background: #174c34;
  border-color: rgba(116, 198, 157, 0.42);
}

.back-to-title-button:hover:not(:disabled),
.back-to-title-button:focus-visible:not(:disabled) {
  background: #1d5e41;
  border-color: #74c69d;
}

.give-up-button {
  background: #6b1d24;
  border-color: rgba(232, 128, 136, 0.42);
}

.give-up-button:hover:not(:disabled),
.give-up-button:focus-visible:not(:disabled) {
  background: #80232b;
  border-color: #e88088;
}

.undo-button {
  color: #ff6b6b;
}

.hud-cat-companion {
  position: relative;
  width: 108px;
  height: 70px;
  margin-left: 0;
  margin-bottom: -4px;
  padding: 0;
  border: none;
  background: transparent;
  cursor: pointer;
  pointer-events: auto;
  opacity: 1;
}

.hud-cat-companion:focus-visible {
  outline: 2px solid var(--accent-gold);
  outline-offset: 2px;
  border-radius: 8px;
}

.hud-cat-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: none;
  pointer-events: none;
}

.hud-cat-tail {
  z-index: 1;
  transform-origin: 64% 86%;
}

.hud-cat-ear {
  z-index: 2;
  transform-origin: 62% 28%;
}

.hud-cat-open,
.hud-cat-blink {
  z-index: 3;
}

body.hud-cat-tabby .hud-cat-tail.hud-cat-tabby,
body.hud-cat-tabby .hud-cat-ear.hud-cat-tabby,
body.hud-cat-tabby:not(.hud-cat-blinking) .hud-cat-open.hud-cat-tabby,
body.hud-cat-tabby.hud-cat-blinking .hud-cat-blink.hud-cat-tabby,
body.hud-cat-calico .hud-cat-tail.hud-cat-calico,
body.hud-cat-calico .hud-cat-ear.hud-cat-calico,
body.hud-cat-calico:not(.hud-cat-blinking) .hud-cat-open.hud-cat-calico,
body.hud-cat-calico.hud-cat-blinking .hud-cat-blink.hud-cat-calico,
body.hud-cat-white .hud-cat-tail.hud-cat-white,
body.hud-cat-white .hud-cat-ear.hud-cat-white,
body.hud-cat-white:not(.hud-cat-blinking) .hud-cat-open.hud-cat-white,
body.hud-cat-white.hud-cat-blinking .hud-cat-blink.hud-cat-white,
body.hud-cat-black .hud-cat-tail.hud-cat-black,
body.hud-cat-black .hud-cat-ear.hud-cat-black,
body.hud-cat-black:not(.hud-cat-blinking) .hud-cat-open.hud-cat-black,
body.hud-cat-black.hud-cat-blinking .hud-cat-blink.hud-cat-black {
  display: block;
}

@keyframes hudCatTailSwish {
  0% { transform: rotate(0deg); }
  22% { transform: rotate(-14deg); }
  52% { transform: rotate(9deg); }
  78% { transform: rotate(-7deg); }
  100% { transform: rotate(0deg); }
}

@keyframes hudCatEarTwitch {
  0% { transform: rotate(0deg); }
  22% { transform: rotate(13deg); }
  44% { transform: rotate(-2deg); }
  66% { transform: rotate(9deg); }
  100% { transform: rotate(0deg); }
}

body.hud-cat-tail-moving .hud-cat-tail {
  animation: hudCatTailSwish 0.9s cubic-bezier(0.37, 0, 0.63, 1);
}

body.hud-cat-ear-moving .hud-cat-ear {
  animation: hudCatEarTwitch 0.52s cubic-bezier(0.25, 0.8, 0.25, 1);
}

/* Hint toggle state */
body.hint-enabled .hint-icon-off,
body.hint-enabled .hint-label-off,
body.hint-disabled .hint-icon-on,
body.hint-disabled .hint-label-on {
  display: none;
}

body.hint-enabled .hint-toggle-button {
  border-color: rgba(194, 163, 102, 0.55);
}

/* Solve mode state */
body.solving-active .solve-icon-play,
body.solving-active .solve-label-idle,
body:not(.solving-active) .solve-icon-stop,
body:not(.solving-active) .solve-label-active {
  display: none;
}

body.solving-active .solve-toggle-button {
  border-color: var(--accent-gold);
  background: rgba(194, 163, 102, 0.24);
}

@media (max-width: 600px) {
  .hud-top-left {
    top: 10px;
    left: 10px;
    gap: 6px;
  }
  .hud-top-right {
    top: 10px;
    right: 10px;
    gap: 6px;
  }
  .hud-bottom-left {
    bottom: 10px;
    left: 10px;
    gap: 6px;
  }
  .hud-bottom-right {
    bottom: 10px;
    right: 10px;
  }
  .hud-elapsed-time {
    font-size: 13px;
  }
  .hud-bottom-row {
    gap: 6px;
  }
  .hud-status-box {
    padding: 2px;
  }
  .hud-status-suit {
    font-size: 12px;
  }
  .hud-status-stage {
    font-size: 10px;
  }
  .game-sub-button {
    height: 36px;
    padding: 0 10px;
    font-size: 12px;
  }
  .sound-button {
    width: 36px;
    height: 36px;
  }
  .edit-settings-button {
    width: 32px;
    height: 32px;
  }
  .hud-cat-companion {
    width: 87px;
    height: 57px;
    margin-left: 0;
    margin-bottom: -3px;
  }
}

@media (orientation: landscape) {
  .hud-bottom-left {
    flex-direction: row;
    align-items: flex-end;
    gap: 8px;
  }
  .hud-cat-companion {
    margin-bottom: 0;
  }
}

/* Rule Toast */
.rule-toast {
  position: absolute;
  top: 62px;
  left: 50%;
  transform: translateX(-50%) translateY(-6px);
  z-index: 15;
  padding: 8px 16px;
  border-radius: 8px;
  background: rgba(9, 24, 17, 0.94);
  border: 1px solid var(--border-active);
  color: var(--text-primary);
  font-size: 13px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease, transform 180ms ease;
}

body.rule-toast-visible .rule-toast {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

body.onboarding-toast-visible .onboarding-toast {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.onboarding-toast .onboarding-suit-1,
.onboarding-toast .onboarding-suit-many {
  display: none;
}

.onboarding-toast.show-suit-1 .onboarding-suit-1,
.onboarding-toast.show-suit-many .onboarding-suit-many {
  display: inline;
}

/* ============================================
   Pause Overlay
============================================ */
.pause-overlay {
  position: absolute;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  border: 0;
  background: rgba(4, 12, 8, 0.78);
  color: var(--text-primary);
  font-family: var(--font-display);
  font-size: clamp(28px, 6vw, 42px);
  font-weight: 700;
  cursor: pointer;
}

body:not(.game-paused) .pause-overlay {
  display: none;
}

.pause-overlay:focus-visible {
  outline: 2px solid var(--accent-gold);
  outline-offset: -6px;
}

/* ============================================
   Solve Mode Selection Dialog
============================================ */
.solve-dialog-overlay,
.giveup-dialog-overlay,
.settings-dialog-overlay {
  position: absolute;
  inset: 0;
  z-index: 25;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(4, 12, 8, 0.56);
}

body:not(.solve-dialog-open) .solve-dialog-overlay {
  display: none;
}

body:not(.giveup-dialog-open) .giveup-dialog-overlay {
  display: none;
}

body:not(.settings-dialog-open) .settings-dialog-overlay {
  display: none;
}

.solve-dialog-panel {
  position: relative;
  width: min(340px, 100%);
  padding: 46px 24px 20px;
  border-radius: 12px;
  background: rgba(14, 34, 25, 0.96);
  border: 1px solid var(--border-active);
  box-shadow: 0 18px 44px rgba(0, 0, 0, 0.56);
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 16px;
}

.settings-dialog-panel {
  width: min(440px, 100%);
  max-height: calc(100dvh - 40px);
  overflow-y: auto;
}

.settings-dialog-panel .luck-value-readout .luck-desc {
  display: none;
}

.settings-dialog-panel.luck-level-1 .luck-desc-1,
.settings-dialog-panel.luck-level-2 .luck-desc-2,
.settings-dialog-panel.luck-level-3 .luck-desc-3,
.settings-dialog-panel.luck-level-4 .luck-desc-4,
.settings-dialog-panel.luck-level-5 .luck-desc-5 {
  display: inline;
}

.settings-dialog-panel .solve-dialog-actions {
  margin-top: 2px;
}

.settings-dialog-panel .solve-dialog-btn {
  white-space: normal;
}

.solve-dialog-close-btn {
  position: absolute;
  top: 12px;
  left: 12px;
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  border: 1px solid var(--border-hairline);
  background: rgba(255, 255, 255, 0.08);
  cursor: pointer;
  transition: border-color 150ms ease, background-color 150ms ease;
}

.solve-dialog-close-btn:hover,
.solve-dialog-close-btn:focus-visible {
  border-color: var(--accent-gold);
  background: rgba(255, 255, 255, 0.14);
  outline: none;
}

.solve-dialog-close-btn img {
  width: 18px;
  height: 18px;
  filter: brightness(0) invert(1);
}

.solve-dialog-title {
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 700;
  line-height: 1.35;
  color: var(--text-primary);
}

.solve-dialog-actions {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  width: 100%;
}

.solve-dialog-btn {
  flex: 1;
  min-height: 46px;
  padding: 10px 16px;
  border-radius: 8px;
  font-family: var(--font-ui);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  transition: border-color 150ms ease, background-color 150ms ease, transform 150ms ease;
}

.solve-dialog-btn:focus-visible {
  outline: 2px solid var(--text-primary);
  outline-offset: 2px;
}

.solve-dialog-btn-manual {
  border: 1px solid rgba(194, 163, 102, 0.65);
  background: rgba(194, 163, 102, 0.14);
  color: var(--text-primary);
}

.solve-dialog-btn-manual:hover {
  border-color: var(--accent-gold);
  background: rgba(194, 163, 102, 0.24);
}

.solve-dialog-btn-auto {
  border: 1px solid var(--accent-gold);
  background: var(--accent-gold);
  color: #0b1913;
}

.solve-dialog-btn-auto:hover {
  background: #cfa96e;
}

.solve-dialog-note {
  font-size: 12px;
  line-height: 1.5;
  color: var(--text-secondary);
}

/* ============================================
   Stage Clear Overlay
============================================ */
.clear-overlay {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(360px, calc(100% - 40px));
  z-index: 30;
}

body:not(.stage-cleared) .clear-overlay {
  display: none;
}

.clear-panel {
  position: relative;
  width: 100%;
  padding: 32px 24px;
  border-radius: 12px;
  background: rgba(14, 34, 25, 0.94);
  border: 1px solid var(--border-active);
  box-shadow: 0 18px 44px rgba(0, 0, 0, 0.56);
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 24px;
}

.clear-cat-perch {
  position: absolute;
  bottom: calc(100% - 12px);
  left: 50%;
  transform: translateX(-50%);
  width: 135px;
  height: 72px;
  pointer-events: none;
  filter: drop-shadow(0 4px 10px rgba(0, 0, 0, 0.4));
}

.clear-cat-img {
  display: none;
  width: 100%;
  height: 100%;
}

body.clear-cat-tabby .clear-cat-tabby,
body.clear-cat-calico .clear-cat-calico,
body.clear-cat-white .clear-cat-white,
body.clear-cat-black .clear-cat-black {
  display: block;
}

.clear-title {
  font-family: var(--font-display);
  font-size: 28px;
  font-weight: 700;
  color: var(--text-primary);
}

.clear-actions {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  width: 100%;
  opacity: 1;
  transition: opacity 150ms ease;
}

body.clear-process-paused .clear-actions {
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
}

.clear-btn {
  flex: 1;
  min-height: 44px;
  padding: 10px 18px;
  border-radius: 8px;
  font-family: var(--font-ui);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}

.clear-btn-secondary {
  border: 1px solid var(--border-hairline);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-primary);
}

.clear-btn-primary {
  border: 1px solid var(--accent-gold);
  background: var(--accent-gold);
  color: #0b1913;
}

@media (prefers-reduced-motion: reduce) {
  .suit-option-btn,
  .luck-slider::-webkit-slider-thumb,
  .luck-slider::-moz-range-thumb,
  .title-action-button,
  .game-sub-button,
  .rule-toast,
  .clear-actions {
    transition: none;
  }
  body.hud-cat-tail-moving .hud-cat-tail,
  body.hud-cat-ear-moving .hud-cat-ear {
    animation: none;
  }
}
