:root {
  --blue: #075991;
  --blue-dark: #06395f;
  --cream: #d9d3b3;
  --cream-light: #ece8cf;
  --lcd: #a8a8a1;
  --ink: #161716;
  --red: #df0d1c;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #202326;
  color: var(--ink);
  font-family: Arial, Helvetica, sans-serif;
  touch-action: none;
  user-select: none;
}

button {
  font: inherit;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
}

.stage {
  position: relative;
  width: 100vw;
  height: 100dvh;
  display: grid;
  place-items: center;
  padding: max(10px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
}

.fullscreen-button {
  position: fixed;
  z-index: 20;
  top: max(8px, env(safe-area-inset-top));
  right: max(8px, env(safe-area-inset-right));
  min-height: 34px;
  padding: 0 12px;
  border: 2px solid rgba(255, 255, 255, .7);
  border-radius: 999px;
  background: rgba(7, 89, 145, .92);
  color: #fff;
  font-weight: 700;
  font-size: 12px;
  line-height: 1;
  box-shadow: 0 5px 14px rgba(0, 0, 0, .28);
  cursor: pointer;
}

.fullscreen-button:active {
  transform: translateY(2px);
}

.fullscreen-button[hidden] {
  display: none;
}

.review-mode .fullscreen-button {
  display: none;
}

.console {
  width: min(calc(100vw - 20px), calc((100dvh - 20px) * 1.78));
  max-height: calc(100dvh - 20px);
  aspect-ratio: 1.78 / 1;
  display: grid;
  grid-template-columns: minmax(112px, .78fr) minmax(390px, 4fr) minmax(116px, .82fr);
  gap: clamp(7px, 1.2vw, 20px);
  padding: clamp(18px, 2.35vw, 34px);
  border: clamp(8px, 1.4vw, 18px) solid var(--blue);
  border-radius: 7px;
  background:
    radial-gradient(ellipse at 50% 3%, rgba(255,255,255,.56), transparent 17%),
    linear-gradient(95deg, rgba(255,255,255,.28), transparent 19%, rgba(255,255,255,.14) 50%, transparent 78%),
    linear-gradient(180deg, #eee9cc, var(--cream) 48%, #c4bd9e);
  box-shadow:
    0 26px 50px rgba(0,0,0,.42),
    inset 0 0 0 2px rgba(255,255,255,.58),
    inset 0 0 28px rgba(58,45,19,.22);
  direction: ltr;
}

.side-panel,
.center-panel {
  min-width: 0;
  min-height: 0;
}

.side-panel {
  display: grid;
  align-content: space-between;
  justify-items: center;
  padding-block: clamp(7px, 1.4vw, 18px);
}

.center-panel {
  display: grid;
  place-items: center;
  padding-block: clamp(6px, 1.1vw, 18px);
}

.screen-shell {
  position: relative;
  width: min(82%, 690px);
  max-width: 880px;
  aspect-ratio: 1.58 / 1;
  display: grid;
  place-items: center;
  padding: clamp(19px, 2.25vw, 34px) clamp(12px, 1.3vw, 20px);
  border: 3px solid rgba(28, 28, 23, .92);
  border-radius: 11px;
  background:
    linear-gradient(180deg, rgba(255,255,255,.42), transparent 18%, rgba(83,70,42,.13) 84%, rgba(65,48,25,.28)),
    rgba(223, 218, 188, .24);
  box-shadow:
    inset 0 12px 16px rgba(255,255,255,.62),
    inset 0 -16px 20px rgba(81,67,38,.24),
    0 16px 18px rgba(79,58,30,.26),
    0 -4px 6px rgba(255,255,255,.55);
}

.screen-title,
.wide-label {
  position: absolute;
  left: 0;
  right: 0;
  text-align: center;
  font-weight: 700;
  letter-spacing: 0;
  line-height: 1;
  font-size: clamp(13px, 1.9vw, 24px);
}

.screen-title {
  top: clamp(6px, .85vw, 11px);
}

.screen-title::before,
.screen-title::after,
.wide-label::before,
.wide-label::after {
  content: "";
  position: absolute;
  top: 50%;
  width: min(25%, 190px);
  border-top: 2px solid rgba(22, 23, 22, .88);
}

.screen-title::before,
.wide-label::before {
  right: calc(50% + 48px);
}

.screen-title::after,
.wide-label::after {
  left: calc(50% + 48px);
}

.wide-label {
  bottom: clamp(6px, .8vw, 11px);
  font-size: clamp(11px, 1.45vw, 18px);
  opacity: .78;
}

.screen-bezel {
  width: 94%;
  aspect-ratio: 13 / 9;
  display: grid;
  place-items: center;
  padding: clamp(5px, .75vw, 9px);
  border: clamp(7px, 1vw, 13px) solid var(--blue);
  border-radius: 13px;
  background: #041923;
  box-shadow:
    inset 0 0 0 2px rgba(255,255,255,.18),
    inset 0 4px 9px rgba(255,255,255,.2),
    inset 0 -5px 12px rgba(0,0,0,.68),
    0 4px 0 rgba(255,255,255,.23);
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  aspect-ratio: 13 / 9;
  background: var(--lcd);
  image-rendering: auto;
  border: 4px solid #111;
}

.brand-panel {
  width: min(112px, 88%);
  text-align: center;
  font-weight: 700;
}

.brand-box {
  padding: .5em .25em;
  border: 2px solid #788283;
  border-radius: 5px;
  background: #edf4ef;
  color: #111;
  font-size: clamp(18px, 2.05vw, 29px);
  line-height: .88;
  font-style: italic;
}

.nintendo {
  margin-top: 12px;
  font-size: clamp(15px, 1.55vw, 21px);
}

.action-cluster {
  width: 100%;
  min-width: 0;
  display: grid;
  justify-items: center;
  gap: clamp(8px, 1.2vw, 14px);
}

.round-button {
  width: clamp(68px, 8vw, 104px);
  max-width: 100%;
  aspect-ratio: 1;
  border: clamp(6px, 1vw, 12px) solid var(--blue-dark);
  border-radius: 50%;
  background: radial-gradient(circle at 38% 32%, #ff4851 0 20%, var(--red) 58%, #910510 100%);
  box-shadow:
    inset 0 8px 10px rgba(255,255,255,.28),
    inset 0 -9px 12px rgba(0,0,0,.28),
    0 8px 12px rgba(0,0,0,.33);
  cursor: pointer;
}

.round-button.pressed,
.round-button:active {
  transform: translateY(4px);
  filter: brightness(.88);
}

.button-label {
  min-height: 1.1em;
  text-align: center;
  font-weight: 700;
  font-size: clamp(15px, 1.75vw, 22px);
  line-height: 1;
}

.mode-panel {
  width: 100%;
  display: grid;
  gap: clamp(8px, 1.35vw, 16px);
  justify-items: center;
}

.mode-button {
  width: 100%;
  min-height: clamp(40px, 5dvh, 58px);
  display: grid;
  grid-template-columns: 1fr;
  justify-items: center;
  align-content: center;
  gap: 2px;
  padding: 0;
  border: 0;
  background: transparent;
  color: #111;
  font-weight: 700;
  font-size: clamp(10px, 1.08vw, 15px);
  line-height: 1;
  cursor: pointer;
  position: relative;
}

.mode-button span {
  width: min(72px, 74%);
  max-width: 100%;
  aspect-ratio: 2.2 / 1;
  border: clamp(4px, .55vw, 7px) solid var(--blue-dark);
  border-radius: 999px;
  background: linear-gradient(#f0f1ec, #9ea6a3);
  box-shadow: inset 0 2px 2px rgba(255,255,255,.7), 0 2px 2px rgba(0,0,0,.32);
}

.mode-button strong {
  min-width: 0;
  text-align: center;
  white-space: normal;
}

.mode-button[data-mode="A"]::before,
.mode-button[data-mode="B"]::before {
  content: "";
  position: absolute;
  right: clamp(0px, .45vw, 8px);
  top: 34%;
  width: clamp(8px, .9vw, 13px);
  aspect-ratio: 1;
  border-radius: 50%;
  border: 2px solid rgba(40, 41, 38, .65);
  background: radial-gradient(circle at 35% 30%, #d9d6ca, #77756e 70%);
}

.mode-button[data-mode="A"]::after,
.mode-button[data-mode="B"]::after {
  position: absolute;
  right: clamp(-3px, .2vw, 3px);
  top: 62%;
  font-size: clamp(7px, .62vw, 9px);
  font-weight: 700;
  color: rgba(20, 20, 17, .75);
}

.mode-button[data-mode="A"]::after {
  content: "ALARM";
}

.mode-button[data-mode="B"]::after {
  content: "ACL";
}

.mode-button.pressed span,
.mode-button:active span {
  transform: translateY(2px);
  filter: brightness(.88);
}

.portrait-message {
  display: none;
  direction: rtl;
  color: #f1f1ec;
  font-size: 20px;
  text-align: center;
  padding: 24px;
}

@media (orientation: portrait) and (max-width: 760px) {
  .console {
    display: grid;
    width: min(calc(100vw - 12px), calc((100dvh - 70px) * 1.74));
    max-height: calc(100dvh - 70px);
    grid-template-columns: minmax(54px, .62fr) minmax(208px, 4fr) minmax(58px, .74fr);
    gap: 4px;
    padding: 8px;
  }

  .side-panel {
    padding-block: 5px;
  }

  .brand-panel {
    width: 52px;
  }

  .brand-box {
    font-size: 10px;
    line-height: .9;
    padding: .35em .1em;
  }

  .nintendo {
    margin-top: 4px;
    font-size: 9px;
  }

  .round-button {
    width: 42px;
    border-width: 5px;
  }

  .button-label {
    font-size: 12px;
  }

  .screen-shell {
    width: 88%;
    padding: 12px 4px;
    border-width: 3px;
  }

  .screen-bezel {
    width: 96%;
    padding: 4px;
    border-width: 6px;
    border-radius: 10px;
  }

  canvas {
    border-width: 2px;
  }

  .screen-title,
  .wide-label {
    font-size: 11px;
  }

  .mode-panel {
    gap: 5px;
  }

  .mode-button {
    grid-template-columns: 28px 1fr;
    min-height: 27px;
    gap: 3px;
    font-size: 9px;
  }

  .mode-button span {
    border-width: 4px;
  }

  .portrait-message {
    display: block;
    position: absolute;
    left: 8px;
    right: 8px;
    bottom: 12px;
    font-size: 16px;
    pointer-events: none;
  }
}

@media (max-height: 470px), (max-width: 900px) {
  .stage {
    padding: 6px;
  }

  .console {
    width: min(calc(100vw - 12px), calc((100dvh - 12px) * 1.74));
    max-height: calc(100dvh - 12px);
    grid-template-columns: minmax(76px, .62fr) minmax(360px, 4.5fr) minmax(84px, .72fr);
    gap: 6px;
    padding: 12px;
  }

  .brand-panel {
    width: 82px;
  }

  .brand-box {
    font-size: clamp(15px, 2.4vw, 24px);
  }

  .nintendo {
    font-size: clamp(12px, 1.8vw, 18px);
  }

  .round-button {
    width: clamp(58px, 8.2vw, 84px);
  }

  .mode-button {
    font-size: clamp(9px, 1.4vw, 13px);
    min-height: 40px;
  }
}

@media (orientation: landscape) and (max-height: 620px) {
  .stage {
    padding: max(4px, env(safe-area-inset-top)) max(4px, env(safe-area-inset-right)) max(4px, env(safe-area-inset-bottom)) max(4px, env(safe-area-inset-left));
    place-items: center;
  }

  .console {
    width: min(calc(100vw - 12px), calc((100dvh - 8px) * 1.78));
    max-height: calc(100dvh - 8px);
    grid-template-columns: minmax(82px, .84fr) minmax(270px, 4.05fr) minmax(82px, .84fr);
    gap: 5px;
    padding: 7px;
    border-width: 6px;
    border-radius: 5px;
    overflow: hidden;
  }

  .side-panel {
    padding-block: 3px;
  }

  .center-panel {
    padding-block: 2px;
  }

  .screen-shell {
    width: 88%;
    padding: 12px 6px;
    border-width: 3px;
    border-radius: 9px;
    box-shadow:
      inset 0 8px 10px rgba(255,255,255,.55),
      inset 0 -10px 12px rgba(81,67,38,.2),
      0 7px 8px rgba(79,58,30,.2);
  }

  .screen-bezel {
    width: 96%;
    padding: 4px;
    border-width: 6px;
    border-radius: 10px;
  }

  canvas {
    border-width: 3px;
  }

  .screen-title {
    top: 4px;
  }

  .wide-label {
    bottom: 4px;
  }

  .screen-title,
  .wide-label {
    font-size: 12px;
  }

  .screen-title::before,
  .screen-title::after,
  .wide-label::before,
  .wide-label::after {
    width: min(21%, 150px);
    border-top-width: 1px;
  }

  .screen-title::before,
  .wide-label::before {
    right: calc(50% + 37px);
  }

  .screen-title::after,
  .wide-label::after {
    left: calc(50% + 37px);
  }

  .brand-panel {
    width: 68px;
  }

  .brand-box {
    font-size: 14px;
    line-height: .88;
    padding: .42em .12em;
  }

  .nintendo {
    margin-top: 6px;
    font-size: 12px;
  }

  .round-button {
    width: min(clamp(56px, 14.5dvh, 78px), calc(100% - 8px));
    border-width: clamp(6px, 1.35dvh, 9px);
  }

  .button-label {
    font-size: clamp(13px, 3.4dvh, 18px);
  }

  .mode-panel {
    gap: clamp(2px, 1dvh, 5px);
  }

  .mode-button {
    grid-template-columns: 1fr;
    min-height: clamp(34px, 10.5dvh, 48px);
    gap: 1px;
    font-size: clamp(8px, 2.35dvh, 12px);
  }

  .mode-button span {
    width: min(clamp(46px, 12.5dvh, 66px), 86%);
    border-width: clamp(4px, 1dvh, 6px);
  }

  .mode-button[data-mode="A"]::before,
  .mode-button[data-mode="B"]::before,
  .mode-button[data-mode="A"]::after,
  .mode-button[data-mode="B"]::after {
    display: none;
  }
}

@media (orientation: landscape) and (max-height: 620px) and (min-height: 360px) {
  .console {
    grid-template-columns: minmax(112px, 1fr) minmax(320px, 4fr) minmax(112px, 1fr);
    gap: 6px;
    padding: 8px;
  }

  .round-button {
    width: min(clamp(76px, 19dvh, 104px), calc(100% - 4px));
    border-width: clamp(7px, 1.8dvh, 11px);
  }

  .mode-button span {
    width: min(clamp(72px, 17.5dvh, 96px), 90%);
    border-width: clamp(5px, 1.35dvh, 8px);
  }

  .mode-button {
    min-height: clamp(50px, 15.5dvh, 72px);
    font-size: clamp(10px, 3.2dvh, 15px);
  }

  .button-label {
    font-size: clamp(15px, 4.3dvh, 21px);
  }
}

@media (orientation: portrait) and (max-width: 760px) {
  .console {
    grid-template-columns: minmax(54px, .62fr) minmax(208px, 4fr) minmax(58px, .74fr);
    gap: 4px;
    padding: 8px;
  }

  .mode-button {
    grid-template-columns: 28px 1fr;
    min-height: 27px;
    gap: 3px;
    font-size: 9px;
  }
}
