* {
  box-sizing: border-box;
}
html {
  color-scheme: dark;
}
body {
  margin: 0;
  padding: 12px;
  background: #0b1525;
  color: #f5e4b9;
  font-family: Georgia, "Noto Serif SC", serif;
}
button {
  font: inherit;
  font-weight: 700;
  color: #32231e;
  cursor: pointer;
  min-height: 48px;
  padding: 10px 24px;
  border: 16px solid transparent;
  border-image: url("../button.png") 65 95 fill / 16px 24px / 0 stretch;
  background: transparent;
  line-height: 1.25;
  touch-action: manipulation;
}
button:hover,
button:focus-visible {
  border-image-source: url("../button-hover.png");
  color: #1b302c;
  outline: none;
  filter: drop-shadow(0 0 3px rgba(232, 210, 154, 0.95));
}
button:active,
button[aria-pressed="true"] {
  border-image-source: url("../button-pressed.png");
  color: #fff6da;
}
button:disabled {
  filter: saturate(0.35);
  opacity: 0.6;
  cursor: wait;
}
#game {
  max-width: 1100px;
  margin: auto;
  border: 22px solid transparent;
  border-image: url("../panel-frame.png") 95 fill / 22px / 0 stretch;
  position: relative;
  padding: 0 8px 7px;
  overflow: hidden;
}
.top {
  display: flex;
  gap: 12px;
  align-items: center;
  min-height: 76px;
}
.top img {
  width: 200px;
  height: 64px;
  object-fit: contain;
}
.top span {
  flex: 1;
  font-size: 13px;
  letter-spacing: 0.08em;
}
.top button {
  padding: 6px 18px;
  min-width: 52px;
  font-size: 21px;
}
.hud {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 9px;
  margin: 0 0 10px;
}
.hud > div {
  border: 12px solid transparent;
  border-image: url("../panel-clean.png") 95 fill / 12px / 0 stretch;
  text-align: center;
  padding: 0 4px;
  min-width: 0;
}
.hud small {
  display: block;
  font: 11px/1.4 system-ui;
  color: #c6c8ca;
  text-transform: uppercase;
  letter-spacing: 0.12em;
}
.hud strong {
  font:
    600 23px/1.5 Georgia,
    serif;
  font-variant-numeric: tabular-nums;
  direction: ltr;
  unicode-bidi: isolate;
  display: inline-block;
}
.stage {
  position: relative;
  isolation: isolate;
  max-width: 960px;
  margin-inline: auto;
  height: clamp(300px, calc(100svh - 330px), 600px);
  border-radius: 13px;
  overflow: hidden;
  background: #1b3246 url("../background.webp") center/cover;
}
#canvas {
  height: 100%;
  width: 100%;
  touch-action: none;
  outline: none;
}
canvas {
  display: block;
}
.overlay {
  position: absolute;
  inset: 0;
  background: #07122499;
  display: grid;
  place-items: center;
  padding: 20px;
  backdrop-filter: blur(3px);
  z-index: 3;
}
.overlay[hidden] {
  display: none;
}
.panel {
  width: min(560px, 100%);
  max-height: 100%;
  overflow: auto;
  border: 28px solid transparent;
  border-image: url("../panel-clean.png") 95 fill / 28px / 0 stretch;
  padding: 18px 20px;
  text-align: center;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: #bca569 #22233d;
}
.hero-logo {
  display: block;
  width: min(330px, 100%);
  height: 92px;
  object-fit: contain;
  margin: 0 auto 8px;
}
.hero-logo[hidden] {
  display: none;
}
.panel h1 {
  font-size: 23px;
  margin: 5px 0 12px;
  color: #f2d993;
}
.panel p {
  white-space: pre-line;
  font: 14px/1.8 system-ui;
  margin: 0 auto 18px;
  color: #e4e5df;
  max-width: 420px;
}
.panel button {
  margin: 4px;
  max-width: 100%;
  border-width: 10px;
  border-image-width: 10px 18px;
  padding: 8px 16px;
  font-size: 14px;
  overflow-wrap: anywhere;
}
.panel[data-screen="nights"] #modal-actions,
.panel[data-screen="ready"] #modal-actions,
.panel[data-screen="result"] #modal-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}
.panel[data-screen="nights"] button,
.panel[data-screen="ready"] button,
.panel[data-screen="result"] button {
  margin: 0;
  width: 100%;
  min-width: 0;
  padding-inline: 6px;
}
#modal-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 4px;
}
.setting {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 44px 44px;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  font: 14px system-ui;
}
.setting button {
  min-width: 0;
  width: 44px;
  margin: 0;
  padding: 4px;
  border-width: 8px;
  border-image-width: 8px 12px;
}
.setting > span {
  flex: 1;
  min-width: 0;
  text-align: start;
  overflow-wrap: anywhere;
}
.console {
  display: flex;
  align-items: center;
  gap: 22px;
  padding: 14px 12px 0;
}
.console p {
  flex: 1;
  margin: 0;
  font: 13px/1.7 system-ui;
  color: #d1d7d7;
}
.light {
  min-width: 180px;
  min-height: 68px;
  touch-action: none;
  user-select: none;
}
.light[aria-pressed="true"] {
  filter: drop-shadow(0 0 13px #f1ca73);
}
#toast {
  position: absolute;
  left: 50%;
  top: 12px;
  transform: translateX(-50%);
  text-align: center;
  pointer-events: none;
  font: 600 14px/1.5 system-ui;
  color: #fff5bc;
  text-shadow: 0 2px 5px #081321;
  min-width: 80%;
  z-index: 2;
}
.sr {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
}
@media (max-width: 600px) {
  body {
    padding: 4px;
  }
  #game {
    border-width: 14px;
    border-image-width: 14px;
    padding: 0 0 5px;
  }
  .top {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 54px 54px;
    gap: 4px;
    min-height: 64px;
  }
  .top img {
    width: min(160px, 100%);
    height: 38px;
    grid-column: 1;
    grid-row: 1;
  }
  .top span {
    font-size: 10px;
    grid-column: 1;
    grid-row: 2;
    align-self: start;
    overflow-wrap: anywhere;
  }
  .top button {
    padding: 4px;
    border-width: 10px;
    border-image-width: 10px 14px;
    min-width: 0;
    width: 54px;
    height: 54px;
    grid-row: 1 / 3;
  }
  .hud {
    gap: 3px;
    margin-bottom: 7px;
  }
  .hud > div {
    padding: 0;
    border-width: 9px;
    border-image-width: 9px;
  }
  .hud small {
    font-size: 9px;
    letter-spacing: 0;
  }
  .hud strong {
    font-size: 18px;
  }
  .stage {
    aspect-ratio: auto;
    height: clamp(300px, calc(100svh - 280px), 390px);
  }
  .overlay {
    padding: 7px;
  }
  .panel {
    padding: 12px 6px;
    border-width: 19px;
    border-image-width: 19px;
  }
  .hero-logo {
    height: 68px;
  }
  .panel h1 {
    font-size: 21px;
  }
  .panel p {
    font-size: 12px;
    line-height: 1.7;
    margin-bottom: 10px;
  }
  .panel button {
    padding: 8px 16px;
  }
  .console {
    display: block;
    padding: 9px 5px 0;
  }
  .console p {
    font-size: 11px;
    line-height: 1.5;
    margin-bottom: 8px;
  }
  .light {
    width: 100%;
    min-height: 58px;
  }
  .setting {
    gap: 2px;
  }
  .setting button {
    padding: 4px;
  }
}
@media (max-height: 700px) {
  .panel[data-screen="settings"] #modal-text,
  .panel[data-screen="pause"] #modal-text {
    display: none;
  }
  body {
    padding: 4px;
  }
  #game {
    border-width: 12px;
    border-image-width: 12px;
  }
  .top {
    min-height: 50px;
  }
  .top img {
    height: 38px;
  }
  .stage {
    height: clamp(260px, calc(100svh - 310px), 390px);
  }
  .panel {
    padding-block: 8px;
  }
  .hero-logo {
    height: 54px;
    margin-bottom: 2px;
  }
  .panel h1 {
    margin: 2px 0 5px;
  }
  .panel p {
    margin-bottom: 6px;
    line-height: 1.45;
  }
  .console {
    padding-top: 7px;
  }
  .console p {
    line-height: 1.35;
  }
  .light {
    min-height: 48px;
  }
}
@media (max-width: 600px) {
  .panel[data-screen="pause"] #modal-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
  }
  .panel[data-screen="pause"] button {
    min-width: 0;
    margin: 0;
    padding-inline: 4px;
    overflow-wrap: anywhere;
  }
  .panel[data-screen="pause"] button:last-child {
    grid-column: 1 / -1;
  }
}
@media (max-height: 800px) {
  .panel .hero-logo {
    display: none;
  }
  .panel {
    padding: 10px 16px;
    border-width: 20px;
    border-image-width: 20px;
  }
  .panel h1 {
    font-size: 21px;
    margin: 4px 0 8px;
  }
  .panel p {
    font-size: 13px;
    line-height: 1.55;
    margin-bottom: 10px;
  }
  .panel button {
    border-width: 10px;
    border-image-width: 10px 18px;
    padding: 8px 16px;
    font-size: 14px;
  }
}
.panel .setting button {
  width: 44px;
  min-width: 0;
  min-height: 40px;
  height: 40px;
  padding: 4px;
  border-width: 8px;
  border-image-width: 8px 12px;
  margin: 0;
}
@media (min-width: 600px) and (max-height: 500px) {
  .top { min-height: 44px; }
  .top img { width: 130px; height: 34px; }
  .top button { min-height: 40px; border-width: 8px; border-image-width: 8px 14px; padding: 3px 8px; }
  .hud { margin-bottom: 5px; }
  .hud > div { border-width: 7px; border-image-width: 7px; }
  .hud strong { font-size: 17px; line-height: 1.2; }
  .hud small { font-size: 9px; }
  .stage { height: max(160px, calc(100svh - 218px)); }
  .stage:has(.overlay:not([hidden])) { overflow: visible; isolation: auto; }
  .overlay { position: fixed; inset: 12px; z-index: 20; }
  .console { padding-top: 5px; }
  .console p { font-size: 11px; }
  .light { min-height: 44px; border-width: 8px; border-image-width: 8px 18px; padding-block: 4px; }
}
@media (max-height: 700px) {
  .panel[data-screen="settings"] h1 {
    font-size: 20px;
    line-height: 1.2;
    margin: 0 0 6px;
  }
  .panel[data-screen="settings"] #modal-actions > button {
    min-height: 40px;
    padding-block: 4px;
  }
}
