.cm-device-overlay {
  position: fixed;
  z-index: 12000;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 18px;
  background: radial-gradient(ellipse at center, #1a0e07bd, #080503f2);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  pointer-events: auto;
}

.cm-device-panel {
  width: min(620px, 96vw);
  padding: clamp(20px, 4vw, 34px);
  color: #503019;
  text-align: center;
  background: linear-gradient(180deg, #fff8ea, #f3dfbd);
  border: 9px solid #8a522b;
  outline: 2px solid #3a1f10;
  box-shadow: inset 0 0 0 2px #d9b77b, 0 18px 60px #000b;
  clip-path: polygon(16px 0, calc(100% - 16px) 0, 100% 16px, 100% calc(100% - 16px), calc(100% - 16px) 100%, 16px 100%, 0 calc(100% - 16px), 0 16px);
  font-family: system-ui, sans-serif;
}

.cm-device-brand {
  color: #a54126;
  font-size: 12px;
  font-weight: 900;
  letter-spacing: .22em;
}

.cm-device-panel h1 {
  margin: 5px 0 4px;
  color: #492713;
  font: 900 clamp(25px, 5vw, 36px)/1.1 var(--xcv-font-display, system-ui, sans-serif);
}

.cm-device-panel > p {
  margin: 0 0 22px;
  color: #77583c;
  font-size: 14px;
}

.cm-device-options {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.cm-device-option {
  min-height: 164px;
  display: grid;
  justify-items: center;
  align-content: center;
  gap: 6px;
  padding: 14px 10px;
  color: #fff1d3;
  cursor: pointer;
  border: 4px solid #3a1f10;
  background: linear-gradient(180deg, #986039, #60371e);
  box-shadow: inset 0 3px #ffffff35, inset 0 -4px #0005, 0 4px #3a1f10;
  transition: transform .15s, filter .15s;
}

.cm-device-option:hover,
.cm-device-option:focus-visible {
  filter: brightness(1.12);
  transform: translateY(-2px);
  outline: 3px solid #d6452c;
  outline-offset: 2px;
}

.cm-device-option.is-selected {
  border-color: #d6452c;
  box-shadow: inset 0 0 0 2px #f5d28b, 0 4px #7d2112;
}

.cm-device-icon {
  color: #ffdc8d;
  font-size: 38px;
  line-height: 1;
}

.cm-device-option strong {
  font-size: 20px;
}

.cm-device-option small {
  color: #f1d8b1;
  font-size: 12px;
}

.cm-device-foot {
  margin-top: 18px;
  color: #8a7254;
  font-size: 12px;
}

.cm-install-overlay {
  position: fixed;
  z-index: 12001;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 18px;
  background: radial-gradient(ellipse at center, #1a0e07bd, #080503f2);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  pointer-events: auto;
}

.cm-install-panel {
  width: min(680px, 96vw);
  max-height: 90dvh;
  overflow-y: auto;
  padding: clamp(20px, 3.5vw, 32px);
  color: #503019;
  text-align: left;
  background: linear-gradient(180deg, #fff8ea, #f3dfbd);
  border: 9px solid #8a522b;
  outline: 2px solid #3a1f10;
  box-shadow: inset 0 0 0 2px #d9b77b, 0 18px 60px #000b;
  clip-path: polygon(16px 0, calc(100% - 16px) 0, 100% 16px, 100% calc(100% - 16px), calc(100% - 16px) 100%, 16px 100%, 0 calc(100% - 16px), 0 16px);
  font-family: system-ui, sans-serif;
}

.cm-install-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid #cbb58f;
}

.cm-install-title {
  margin: 4px 0 5px;
  color: #492713;
  font: 900 clamp(24px, 4vw, 34px)/1.1 var(--xcv-font-display, system-ui, sans-serif);
}

.cm-install-intro {
  margin: 0;
  color: #77583c;
  font-size: 14px;
  line-height: 1.5;
}

.cm-install-close {
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  margin: -4px -4px 0 0;
  color: #fff1d3;
  cursor: pointer;
  border: 2px solid #3a1f10;
  background: linear-gradient(180deg, #986039, #60371e);
  box-shadow: 0 3px #3a1f10;
  font: 400 25px/1 system-ui, sans-serif;
}

.cm-install-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.cm-install-actions button {
  min-width: 0;
  min-height: 96px;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 14px;
  padding: 14px 18px;
  color: #fff1d3;
  cursor: pointer;
  border: 3px solid #3a1f10;
  background: linear-gradient(180deg, #986039, #60371e);
  box-shadow: inset 0 3px #ffffff35, inset 0 -4px #0005, 0 3px #3a1f10;
  font: 800 clamp(17px, 2vw, 22px)/1.2 var(--xcv-font-display, system-ui, sans-serif);
  text-align: left;
  transition: transform .15s, filter .15s;
}

.cm-install-actions button:last-child {
  color: #fff0ca;
  background: linear-gradient(180deg, #a93222, #702018);
  border-color: #8b4b24;
}

.cm-install-actions button:hover,
.cm-install-actions button:focus-visible,
.cm-install-close:hover,
.cm-install-close:focus-visible {
  filter: brightness(1.12);
  transform: translateY(-2px);
  outline: 3px solid #d6452c;
  outline-offset: 2px;
}

.cm-install-actions svg {
  flex: 0 0 36px;
  width: 36px;
  height: 36px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.cm-install-guide {
  margin: 16px 0 0;
  padding: 13px 15px;
  color: #57361f;
  white-space: pre-line;
  background: #ead6b2;
  border-left: 4px solid #bd3d2b;
  font-size: 14px;
  line-height: 1.6;
}

.cm-install-guide[hidden] { display: none; }

@media (max-width: 520px) {
  .cm-device-panel { padding: 18px 14px; border-width: 6px; }
  .cm-device-options { gap: 9px; }
  .cm-device-option { min-height: 132px; padding: 10px 6px; }
  .cm-device-option small { font-size: 10px; }
  .cm-install-panel { padding: 18px 14px; border-width: 6px; }
  .cm-install-heading { gap: 8px; margin-bottom: 15px; padding-bottom: 12px; }
  .cm-install-close { width: 36px; height: 36px; font-size: 23px; }
  .cm-install-actions { grid-template-columns: minmax(0, 1fr); gap: 10px; }
  .cm-install-actions button { min-height: 72px; padding: 12px 14px; gap: 12px; }
  .cm-install-actions svg { flex-basis: 32px; width: 32px; height: 32px; }
}

/* CSS fallback for browsers that reject ScreenOrientation.lock(). The game
   keeps a landscape-sized layout and rotates into the available portrait view. */
@media (orientation: portrait) {
  html.cm-landscape-simulation,
  html.cm-landscape-simulation body { overflow: hidden !important; }

  html.cm-landscape-simulation #app,
  html.cm-landscape-simulation #ui {
    position: fixed !important;
    inset: auto !important;
    top: 50% !important;
    left: 50% !important;
    right: auto !important;
    bottom: auto !important;
    width: 100vh !important;
    height: 100vw !important;
    transform: translate(-50%, -50%) rotate(90deg);
    transform-origin: center center;
  }

  html.cm-landscape-simulation #app canvas {
    width: 100% !important;
    height: 100% !important;
  }

  html.cm-landscape-simulation .menu-cover-img { background-image: var(--cover) !important; }
  html.cm-landscape-simulation .menu-logo {
    top: 8% !important;
    left: 5% !important;
    width: min(30vh, 300px) !important;
    transform: none !important;
  }
  html.cm-landscape-simulation .menu-list {
    top: 26% !important;
    bottom: auto !important;
    left: 5% !important;
    width: min(36vh, 340px) !important;
    gap: clamp(5px, 1.2vh, 10px) !important;
    transform: none !important;
  }
  html.cm-landscape-simulation .menu-btn {
    min-height: clamp(36px, 5.8vh, 52px) !important;
    padding: 5px 16px !important;
    font-size: clamp(15px, 2.4vh, 19px) !important;
  }
  html.cm-landscape-simulation .menu-btn.primary {
    min-height: clamp(44px, 7vh, 60px) !important;
    font-size: clamp(19px, 3vh, 24px) !important;
  }
  html.cm-landscape-simulation .menu-btn.menu-tile {
    min-height: clamp(48px, 7vh, 62px) !important;
    font-size: clamp(13px, 2vh, 16px) !important;
  }
  html.cm-landscape-simulation .menu-foot { bottom: 6% !important; left: 5% !important; transform: none !important; }
  html.cm-landscape-simulation .press-start { bottom: 12% !important; font-size: clamp(28px, 6vh, 46px) !important; }
  html.cm-landscape-simulation .cover-bottom { bottom: 2% !important; width: 80vh !important; }
  html.cm-landscape-simulation .modal-backdrop { padding: 12px !important; }
  html.cm-landscape-simulation .modal,
  html.cm-landscape-simulation .modal.wide {
    width: min(88vh, 760px) !important;
    max-height: 90vw !important;
    padding: 24px 14px 12px !important;
  }
  html.cm-landscape-simulation .modal-body { max-height: calc(90vw - 56px) !important; }
}

@supports (height: 100dvh) {
  @media (orientation: portrait) {
    html.cm-landscape-simulation #app,
    html.cm-landscape-simulation #ui { width: 100dvh !important; height: 100dvw !important; }
  }
}
