html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: black;
  font-family: "Segoe UI", Arial, sans-serif;
  color-scheme: dark;
}

a {
  color: #ff4c4c;
}

a:active, a:focus {
  color: #ffff00;
}

.page { display: none; }
body.page-game #page-game,
body.page-settings #page-settings,
body.page-controls #page-controls,
body.page-log #page-log { display: block; }

#canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  border: 0;
  box-sizing: border-box;
  background: black;
  outline: none;
  image-rendering: smooth;
}

#pages > .page {
  width: 100%;
  height: 100%;
  box-sizing: border-box;
  pointer-events: auto;
}

#output {
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 8px;
  border: 0;
  box-sizing: border-box;
  background: black;
  color: lightgray;
  font-family: 'Lucida Console', Monaco, monospace;
  font-size: 13px;
  resize: none;
  outline: none;
}

.settings-panel {
  width: 100%;
  height: 100%;
  box-sizing: border-box;
  margin: 0;
  padding: 16px;
  background: black;
  color: rgba(255, 217, 76, 0.9);
  font-size: 13px;
  overflow-y: auto;
}

.settings-panel fieldset {
  border: 1px solid rgba(255, 217, 76, 0.25);
  border-radius: 4px;
  margin: 0 0 12px;
  padding: 4px 12px 12px;
  max-width: 420px;
}

.settings-panel legend {
  padding: 0 6px;
  color: rgba(255, 217, 76, 0.85);
  font-weight: bold;
}

.settings-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
}

.settings-label {
  flex: 1 1 auto;
  color: rgba(255, 217, 76, 0.75);
}

.settings-row select,
.settings-row input {
  flex: 0 0 auto;
  width: 160px;
  box-sizing: border-box;
  background-color: #241d06;
  color: #ffd94c;
  border: 1px solid rgba(255, 217, 76, 0.3);
  border-radius: 3px;
  padding: 2px 4px;
  font: inherit;
}

.settings-row select option {
  background-color: #241d06;
  color: #ffd94c;
}

.settings-row select:disabled,
.settings-row input:disabled {
  opacity: 0.5;
}

.controls-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 4px 0;
}

.controls-key {
  flex: 0 0 auto;
  min-width: 170px;
  color: #ffd94c;
}

.controls-desc {
  flex: 1 1 auto;
  color: rgba(255, 217, 76, 0.75);
}

#ui-container {
  position: fixed;
  inset: 0;
  z-index: 2;
  display: flex;
  flex-direction: column;
  pointer-events: none;
}

#topbar {
  position: relative;
  flex: 0 0 auto;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  padding: 8px;
  box-sizing: border-box;
  min-height: 32px;
  pointer-events: none;
  font-size: 13px;
  color: rgba(255, 217, 76, 0.85);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
  opacity: 1;
  transition: opacity 0.25s ease;
}

body.page-game.ui-idle:not(.start-pending) #topbar {
  opacity: 0;
  transition: opacity 1.2s ease 2s;
}

body.is-phone.page-game.ui-idle #topbar {
  opacity: 1;
}

#topbar .buttons,
#topbar .end-group {
  display: contents;
}

#topbar button {
  pointer-events: auto;
  background: rgba(0, 0, 0, 0.35);
  color: inherit;
  border: 1px solid rgba(255, 217, 76, 0.25);
  border-radius: 3px;
  padding: 3px 10px;
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
}

#topbar button.active {
  background: rgba(255, 217, 76, 0.25);
}

#btn-export-saves { margin-left: 8px; }

#btn-fullscreen { margin-left: auto; }

#topbar .phone-only { display: none; }
body.is-phone #topbar .phone-only { display: inline-block; }

#mobile-kbd-trigger {
  position: fixed;
  top: 0;
  left: 0;
  width: 1px;
  height: 1px;
  opacity: 0;
  border: 0;
  padding: 0;
  pointer-events: none;
}

#status-text {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  opacity: 0.85;
  white-space: nowrap;
}

#credits {
  pointer-events: auto;
  opacity: 0.8;
}

body.video-blocking #btn-export-saves,
body.video-blocking #btn-import-saves,
body.video-blocking #btn-mobile-menu,
body.video-blocking #btn-mobile-map,
body.video-blocking #btn-mobile-selection {
  pointer-events: none;
  opacity: 0.4;
}

#pages {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  pointer-events: none;
}

@media (min-aspect-ratio: 3/2) {
  #ui-container {
    flex-direction: row;
  }

  #topbar {
    flex-direction: column;
    flex-wrap: nowrap;
    align-items: stretch;
    min-height: 0;
  }

  #topbar button {
    display: block;
    width: 100%;
  }

  #btn-fullscreen {
    margin-left: 0;
    margin-top: auto;
  }

  #btn-export-saves {
    margin-left: 0;
    margin-top: 8px;
  }

  #status-text {
    position: absolute;
    left: 0;
    top: 50%;
    width: 100%;
    transform: translateY(-50%);
    white-space: normal;
    overflow-wrap: break-word;
    text-align: center;
  }

  #credits {
    text-align: center;
  }
}

#video-overlay {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: black;
  z-index: 1;
  opacity: 1;
  visibility: hidden;
  cursor: none;
  image-rendering: smooth;
}

body.show-video #video-overlay { visibility: visible; }
body.show-video #canvas { visibility: hidden; }
body.show-video.fading #canvas { visibility: visible; }
body.fading #video-overlay { pointer-events: none; }

#start-overlay {
  position: fixed;
  inset: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: black;
}

#start-overlay.hidden { display: none; }

#btn-start {
  background: rgba(255, 217, 76, 0.12);
  color: rgba(255, 217, 76);
  border: 1px solid rgba(255, 217, 76, 0.4);
  border-radius: 6px;
  padding: 16px 40px;
  font-size: 20px;
  cursor: pointer;
  outline-color: rgba(255, 217, 76);
}

#btn-start:hover { background: rgba(255, 217, 76, 0.22); }
