html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #14100b;
  font-family: 'Courier New', Courier, monospace;
}

#game {
  display: block;
  width: 100vw;
  height: 100vh;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  cursor: default;
}

/* Subtle vignette to give the canvas an old-console feel */
body::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(ellipse at center, rgba(0,0,0,0) 55%, rgba(0,0,0,0.35) 100%);
  z-index: 2;
}

.info-box {
  position: fixed;
  z-index: 3;
  color: #eae2c8;
  background: rgba(20, 16, 11, 0.55);
  border: 2px solid #5a4a2f;
  border-radius: 4px;
  padding: 6px 10px;
  font-size: 13px;
  letter-spacing: 1px;
  text-shadow: 1px 1px 0 #000;
  user-select: none;
}

#hud {
  top: 12px;
  left: 12px;
  opacity: 0.5;
}

#sitename {
  bottom: 12px;
  right: 12px;
  opacity: 1;
  font-weight: bold;
}

#instructions {
  position: fixed;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 3;
  color: #eae2c8;
  background: rgba(20, 16, 11, 0.6);
  border: 2px solid #5a4a2f;
  border-radius: 6px;
  padding: 10px 18px;
  text-align: center;
  font-size: 14px;
  letter-spacing: 1px;
  text-shadow: 1px 1px 0 #000;
  user-select: none;
  transition: opacity 1s ease;
  pointer-events: none;
}

#instructions p {
  margin: 2px 0;
}

#instructions .small {
  font-size: 11px;
  opacity: 0.75;
}

#instructions.hidden {
  opacity: 0;
}

/* Virtual joystick — only shown on touch/mobile devices, via JS toggling
   the "active-device" class on #joystick */
#joystick {
  display: none;
  position: fixed;
  bottom: 28px;
  left: 28px;
  z-index: 4;
  touch-action: none;
}

#joystick.active-device {
  display: block;
}

#joystick-base {
  width: 108px;
  height: 108px;
  border-radius: 50%;
  background: rgba(20, 16, 11, 0.45);
  border: 2px solid rgba(234, 226, 200, 0.35);
  position: relative;
  box-sizing: border-box;
}

#joystick-nub {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: rgba(234, 226, 200, 0.8);
  border: 2px solid rgba(20, 16, 11, 0.5);
  position: absolute;
  top: 50%;
  left: 50%;
  margin: -24px 0 0 -24px;
  transition: transform 0.08s linear;
  box-shadow: 1px 1px 0 rgba(0,0,0,0.3);
}

/* ------------------------------------------------------------------------
   Menu, minimap, toast
   ------------------------------------------------------------------------ */
.is-hidden {
  display: none !important;
}

button.info-box {
  font-family: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

#menu-button {
  top: 12px;
  right: 12px;
  z-index: 6;
  font-weight: bold;
  padding: 8px 12px;
}

#menu-button:hover,
.menu-item:hover {
  background-color: rgba(70, 58, 36, 0.85);
}

#menu-panel {
  top: 52px;
  right: 12px;
  z-index: 6;
  min-width: 170px;
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  background: rgba(20, 16, 11, 0.9);
  max-height: calc(100vh - 80px);
  overflow-y: auto;
}

.menu-item {
  background: transparent;
  border: none;
  border-radius: 3px;
  color: inherit;
  font-family: inherit;
  font-size: 14px;
  letter-spacing: 1px;
  text-align: left;
  text-shadow: 1px 1px 0 #000;
  padding: 8px 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 10px;
  -webkit-tap-highlight-color: transparent;
}

.menu-icon canvas {
  display: block;
  width: 32px;
  height: 32px;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.menu-sep {
  height: 2px;
  margin: 4px 0;
  background: #5a4a2f;
}

/* Minimap: sits under the position box. The canvas is drawn 1px per tile
   and scaled up with crisp pixels (3x desktop, 2x mobile). */
#minimap-wrap {
  top: 72px;
  left: 12px;
  padding: 4px;
  line-height: 0;
  opacity: 0.92;
  pointer-events: none;
}

#minimap {
  --mm-size: 153px;
  display: block;
  width: var(--mm-size);
  height: var(--mm-size);
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

#minimap-dot {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 9px;
  height: 9px;
  margin: -4.5px 0 0 -4.5px;
  border-radius: 50%;
  background: #e23b3b;
  border: 2px solid #fff;
  box-sizing: border-box;
  box-shadow: 0 0 0 1px rgba(0,0,0,0.6);
}

@media (pointer: coarse), (max-width: 600px) {
  #minimap { --mm-size: 102px; }
  #menu-button { padding: 11px 14px; }
  .menu-item { padding: 10px 10px; font-size: 15px; }
  #menu-panel { top: 58px; }
  #minimap-wrap { top: 72px; }
  #instructions { bottom: 160px; }
}

#toast {
  position: fixed;
  top: 30%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 7;
  padding: 10px 18px;
  color: #eae2c8;
  background: rgba(20, 16, 11, 0.85);
  border: 2px solid #5a4a2f;
  border-radius: 6px;
  font-size: 14px;
  letter-spacing: 1px;
  text-shadow: 1px 1px 0 #000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

#toast.show {
  opacity: 1;
}

/* ------------------------------------------------------------------------
   RPG-style dialog
   ------------------------------------------------------------------------ */
#dialog-overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: min(14vh, 110px) 14px 14px;
  box-sizing: border-box;
  overflow-y: auto;
  background: rgba(8, 6, 3, 0.6);
}

#dialog {
  width: min(430px, 100%);
  box-sizing: border-box;
  padding: 14px 16px 16px;
  color: #eae2c8;
  background: #1b140c;
  border: 3px solid #eae2c8;
  border-radius: 4px;
  box-shadow: 0 0 0 3px #1b140c, 0 0 0 6px #7a6238, 0 14px 40px rgba(0, 0, 0, 0.6);
  font-family: 'Courier New', Courier, monospace;
  text-shadow: 1px 1px 0 #000;
}

#dialog-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
  padding-bottom: 10px;
  border-bottom: 2px solid #5a4a2f;
}

#dialog-icon canvas {
  display: block;
  width: 32px;
  height: 32px;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

#dialog-title {
  margin: 0;
  min-width: 0;
  font-size: 18px;
  letter-spacing: 1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.dlg-field {
  display: block;
  margin-bottom: 12px;
}

.dlg-label {
  display: block;
  margin-bottom: 4px;
  font-size: 12px;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: #c9b27c;
}

.dlg-field input {
  width: 100%;
  box-sizing: border-box;
  padding: 10px;
  font-family: inherit;
  font-size: 16px; /* 16px stops iOS from zooming on focus */
  color: #f4ecd0;
  background: #0e0a05;
  border: 2px solid #5a4a2f;
  border-radius: 3px;
  outline: none;
}

.dlg-field input:focus {
  border-color: #e0c060;
}

.dlg-text {
  margin: 0 0 6px;
  font-size: 14px;
  line-height: 1.4;
}

.dlg-url {
  margin: 0;
  font-size: 14px;
  word-break: break-all;
  color: #9fd0ff;
}

.dlg-hint {
  margin: 0 0 10px;
  font-size: 12px;
  line-height: 1.4;
  color: #c9b27c;
}

.dlg-error {
  min-height: 16px;
  margin-bottom: 8px;
  font-size: 13px;
  color: #ff8a7a;
}

.dlg-status {
  min-height: 18px;
  margin: 6px 0 14px;
  font-size: 13px;
  color: #c9b27c;
}

.countdown {
  height: 10px;
  margin: 12px 0 6px;
  background: #0e0a05;
  border: 2px solid #5a4a2f;
}

.countdown-fill {
  height: 100%;
  width: 100%;
  background: #c9a13c;
}

#dialog-buttons {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
}

.rpg-btn {
  min-height: 44px;
  padding: 10px 16px;
  font-family: inherit;
  font-size: 14px;
  letter-spacing: 1px;
  color: #eae2c8;
  background: #2b2114;
  border: 2px solid #eae2c8;
  border-radius: 3px;
  text-shadow: 1px 1px 0 #000;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.rpg-btn:hover,
.rpg-btn:focus-visible {
  background: #4a3a20;
  outline: none;
}

.rpg-btn.primary {
  font-weight: bold;
  color: #1b140c;
  background: #c9a13c;
  border-color: #f4e2a0;
  text-shadow: none;
}

.rpg-btn.primary:hover,
.rpg-btn.primary:focus-visible {
  background: #e0b84a;
}

/* ------------------------------------------------------------------------
   Color picker, danger button, flag + train stop dialogs
   ------------------------------------------------------------------------ */
.swatches {
  display: grid;
  grid-template-columns: repeat(10, 1fr);
  gap: 6px;
}

.swatch {
  aspect-ratio: 1;
  min-height: 26px;
  padding: 0;
  border: 2px solid #0e0a05;
  border-radius: 3px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.swatch.selected {
  border-color: #ffffff;
  box-shadow: 0 0 0 2px #0e0a05, 0 0 0 4px #e0c060;
}

.swatch:focus-visible {
  outline: 2px solid #e0c060;
  outline-offset: 2px;
}

@media (max-width: 520px) {
  .swatches { grid-template-columns: repeat(5, 1fr); gap: 8px; }
}

.rpg-btn.danger {
  color: #ffb0a5;
  border-color: #ff8a7a;
}

.rpg-btn.danger:hover,
.rpg-btn.danger:focus-visible {
  background: #5a2019;
}

.welcome-banner {
  margin-bottom: 6px;
  padding: 12px 14px;
  background: #0e0a05;
  border: 2px solid #5a4a2f;
  border-left-width: 10px;
}

.welcome-small {
  display: block;
  font-size: 13px;
  letter-spacing: 1px;
  color: #c9b27c;
}

.welcome-name {
  display: block;
  margin-top: 2px;
  font-size: 22px;
  font-weight: bold;
  word-break: break-word;
}

/* Train stop: a station-style sign board in the chosen color */
.station-sign {
  margin-bottom: 14px;
  padding: 14px 12px 12px;
  text-align: center;
  text-shadow: none;
  border: 4px solid #ffffff;
  border-radius: 8px;
  box-shadow: 0 0 0 3px #0e0a05;
}

.station-caption {
  font-size: 11px;
  font-weight: bold;
  letter-spacing: 3px;
  opacity: 0.85;
}

.station-name {
  margin-top: 4px;
  font-size: 24px;
  font-weight: bold;
  letter-spacing: 1px;
  word-break: break-word;
}

.station-rail {
  height: 8px;
  margin-top: 12px;
  border-top: 3px solid currentColor;
  opacity: 0.7;
  background: repeating-linear-gradient(90deg, currentColor 0 3px, transparent 3px 12px) 0 3px / 100% 5px no-repeat;
}

/* ------------------------------------------------------------------------
   Worlds: HUD lines, name picker, world list
   ------------------------------------------------------------------------ */
#hud {
  max-width: min(280px, 62vw);
  box-sizing: border-box;
}

#coords,
#world-line {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#dialog.wide {
  width: min(560px, 100%);
}

.name-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 14px;
}

.name-chip {
  min-height: 44px;
  padding: 6px 8px;
  font-family: inherit;
  font-size: 13px;
  line-height: 1.25;
  text-align: center;
  color: #eae2c8;
  background: #2b2114;
  border: 2px solid #5a4a2f;
  border-radius: 3px;
  text-shadow: 1px 1px 0 #000;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.name-chip:hover {
  background: #3a2d1a;
}

/* the highlighted (pre-selected / chosen) suggestion */
.name-chip.selected {
  color: #ffffff;
  background: #4a3a20;
  border-color: #f4e2a0;
  box-shadow: 0 0 0 2px #0e0a05, 0 0 0 4px #e0c060, 0 0 14px 2px rgba(224, 192, 96, 0.45);
}

.name-chip:focus-visible {
  outline: 2px solid #ffffff;
  outline-offset: 3px;
}

@media (max-width: 520px) {
  .name-grid { grid-template-columns: repeat(2, 1fr); }
}

.world-list {
  max-height: 210px;
  margin-bottom: 14px;
  overflow-y: auto;
  background: #0e0a05;
  border: 2px solid #5a4a2f;
}

.world-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  min-height: 44px;
  padding: 8px 12px;
  font-family: inherit;
  font-size: 14px;
  text-align: left;
  color: #eae2c8;
  background: transparent;
  border: none;
  border-bottom: 1px solid #2b2114;
  text-shadow: 1px 1px 0 #000;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}


.world-row:hover:not(:disabled),
.world-row:focus-visible {
  background: #3a2d1a;
  outline: none;
}

.world-row.here {
  cursor: default;
  color: #c9b27c;
  background: #1b140c;
}

.world-row-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.world-row-meta {
  flex: none;
  font-size: 12px;
  color: #c9b27c;
}

/* phones: put a world's details under its name so long names stay readable */
@media (max-width: 520px) {
  .world-row {
    flex-direction: column;
    align-items: flex-start;
    justify-content: center;
    gap: 2px;
    padding: 8px 12px;
  }
  .world-row-name { max-width: 100%; }
}

/* ------------------------------------------------------------------------
   Delete world, Deleted Worlds
   ------------------------------------------------------------------------ */
.world-item {
  display: flex;
  align-items: stretch;
  border-bottom: 1px solid #2b2114;
}

.world-item:last-child {
  border-bottom: none;
}

.world-item .world-row {
  flex: 1;
  width: auto;
  min-width: 0;
  border-bottom: none;
}

.world-del {
  flex: none;
  padding: 0 14px;
  font-family: inherit;
  font-size: 12px;
  letter-spacing: 1px;
  color: #ffb0a5;
  background: transparent;
  border: none;
  border-left: 1px solid #2b2114;
  text-shadow: 1px 1px 0 #000;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.world-del:hover,
.world-del:focus-visible {
  background: #5a2019;
  outline: none;
}

.bin-item {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  padding: 8px 12px;
  border-bottom: 1px solid #2b2114;
}

.bin-item:last-child {
  border-bottom: none;
}

.bin-info {
  display: flex;
  flex: 1 1 200px;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  font-size: 14px;
}

.bin-info .world-row-meta {
  flex: none;
  white-space: normal;
}

.bin-actions {
  display: flex;
  flex: none;
  gap: 8px;
}

.world-act {
  min-height: 36px;
  padding: 6px 10px;
  font-family: inherit;
  font-size: 12px;
  letter-spacing: 1px;
  color: #eae2c8;
  background: #2b2114;
  border: 2px solid #eae2c8;
  border-radius: 3px;
  text-shadow: 1px 1px 0 #000;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.world-act:hover,
.world-act:focus-visible {
  background: #4a3a20;
  outline: none;
}

.world-act.danger {
  color: #ffb0a5;
  border-color: #ff8a7a;
}

.world-act.danger:hover,
.world-act.danger:focus-visible {
  background: #5a2019;
}

.bin-empty {
  margin: 14px 0 18px;
  padding: 18px 12px;
  font-size: 14px;
  text-align: center;
  color: #c9b27c;
  background: #0e0a05;
  border: 2px dashed #5a4a2f;
}

.dlg-names {
  margin: 0 0 10px;
  font-size: 14px;
  font-weight: bold;
  color: #f4e2a0;
  word-break: break-word;
}

/* ------------------------------------------------------------------------
   Language buttons (corner of the first-visit dialog)
   ------------------------------------------------------------------------ */
#dialog-title {
  flex: 1 1 auto;
}

#dialog-tools {
  flex: none;
}

.lang-switch {
  display: flex;
  gap: 6px;
}

.lang-btn {
  min-width: 40px;
  min-height: 32px;
  padding: 4px 8px;
  font-family: inherit;
  font-size: 12px;
  letter-spacing: 1px;
  color: #eae2c8;
  background: #2b2114;
  border: 2px solid #5a4a2f;
  border-radius: 3px;
  text-shadow: 1px 1px 0 #000;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.lang-btn:hover:not(:disabled),
.lang-btn:focus-visible {
  background: #4a3a20;
  outline: none;
}

.lang-btn.active,
.lang-btn:disabled {
  font-weight: bold;
  color: #1b140c;
  text-shadow: none;
  background: #c9a13c;
  border-color: #f4e2a0;
  cursor: default;
}
