:root {
  color-scheme: dark;
  --ink: #171b22;
  --panel: #24303b;
  --panel-2: #31404c;
  --cream: #fff0c8;
  --mint: #7dd87d;
  --sky: #61c9e8;
  --berry: #ef5b6f;
  --gold: #ffd166;
  --shadow: rgba(0, 0, 0, 0.32);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background:
    linear-gradient(135deg, rgba(97, 201, 232, 0.16), transparent 34%),
    linear-gradient(225deg, rgba(125, 216, 125, 0.12), transparent 36%),
    #141820;
  color: var(--cream);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  letter-spacing: 0;
}

button {
  border: 0;
  border-radius: 6px;
  background: var(--cream);
  color: var(--ink);
  cursor: pointer;
  font: 700 0.86rem/1 ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  min-height: 40px;
  padding: 0 14px;
  box-shadow: 0 4px 0 #c9a35c;
  transition: transform 120ms ease, box-shadow 120ms ease, filter 120ms ease;
}

button:hover {
  filter: brightness(1.05);
}

button:active,
button.is-pressed {
  transform: translateY(3px);
  box-shadow: 0 1px 0 #c9a35c;
}

.layout {
  width: min(1180px, calc(100vw - 28px));
  min-height: 100vh;
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(0, 820px) minmax(250px, 1fr);
  gap: 18px;
  align-items: center;
  padding: 20px 0 100px;
}

.arcade {
  min-width: 0;
}

.topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 12px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--sky);
  font-size: clamp(0.7rem, 1.8vw, 0.82rem);
  text-transform: uppercase;
}

h1 {
  margin: 0;
  color: #fff8dc;
  font-size: clamp(1.7rem, 4.4vw, 3.2rem);
  line-height: 0.95;
  text-shadow: 0 4px 0 #613b35, 0 7px 20px var(--shadow);
}

.status-strip {
  max-width: 260px;
  min-height: 34px;
  display: grid;
  place-items: center;
  border: 2px solid #485968;
  border-radius: 6px;
  background: #1d2630;
  color: var(--mint);
  padding: 8px 10px;
  text-align: center;
  font-size: 0.78rem;
  overflow-wrap: anywhere;
}

.screen-shell {
  width: 100%;
  aspect-ratio: 4 / 3;
  border: 10px solid #2a3440;
  border-radius: 8px;
  background: #0b1018;
  box-shadow: 0 20px 60px var(--shadow), inset 0 0 0 4px #111924;
  overflow: hidden;
}

#game {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background: #0b1018;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  padding-top: 14px;
}

#saveButton {
  background: var(--mint);
  box-shadow: 0 4px 0 #3e8f55;
}

#menuButton {
  background: var(--sky);
  box-shadow: 0 4px 0 #287f9b;
}

#sfxButton {
  background: var(--gold);
  box-shadow: 0 4px 0 #ad7f25;
}

#musicButton {
  background: var(--berry);
  color: #fff8dc;
  box-shadow: 0 4px 0 #8e2d3e;
}

.view-mode-control {
  min-height: 40px;
  display: flex;
  align-items: center;
  gap: 8px;
  border: 2px solid #485968;
  border-radius: 6px;
  background: #1d2630;
  color: var(--cream);
  padding: 0 8px 0 10px;
  font-size: 0.76rem;
  font-weight: 700;
}

.view-mode-control select {
  min-height: 28px;
  border: 0;
  border-radius: 4px;
  background: var(--cream);
  color: var(--ink);
  font: 700 0.78rem/1 ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  padding: 0 8px;
}

.journal {
  align-self: stretch;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 12px;
  min-width: 0;
}

.journal-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--gold);
  font-size: 0.85rem;
  text-transform: uppercase;
}

.journal-text {
  min-height: 150px;
  border-left: 4px solid var(--berry);
  background: rgba(36, 48, 59, 0.82);
  padding: 16px;
  color: #e8f6ff;
  line-height: 1.55;
  box-shadow: 0 14px 34px var(--shadow);
}

.tiny-roster {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(86px, 1fr));
  gap: 8px;
}

.tiny-roster span {
  display: block;
  border: 1px solid #435666;
  border-radius: 6px;
  background: rgba(20, 24, 32, 0.8);
  padding: 8px;
  color: #fff6d9;
  font-size: 0.76rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.touch-pad {
  position: fixed;
  right: 14px;
  bottom: 14px;
  left: 14px;
  display: none;
  justify-content: space-between;
  pointer-events: none;
}

.touch-pad button {
  min-width: 58px;
  min-height: 46px;
  padding: 0 10px;
  pointer-events: auto;
}

.dpad {
  display: grid;
  grid-template-columns: repeat(3, 58px);
  grid-template-rows: repeat(3, 46px);
  gap: 6px;
}

.dpad button:nth-child(1) {
  grid-column: 2;
}

.dpad button:nth-child(2) {
  grid-column: 1;
  grid-row: 2;
}

.dpad button:nth-child(3) {
  grid-column: 2;
  grid-row: 3;
}

.dpad button:nth-child(4) {
  grid-column: 3;
  grid-row: 2;
}

.actions {
  display: flex;
  align-items: end;
  gap: 8px;
}

.save-modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(8, 11, 16, 0.72);
}

.save-modal[hidden] {
  display: none;
}

.save-dialog {
  width: min(360px, 100%);
  border: 3px solid var(--ink);
  border-radius: 8px;
  background: var(--cream);
  color: var(--ink);
  padding: 18px;
  box-shadow: 0 18px 44px var(--shadow), inset 0 0 0 2px rgba(255, 255, 255, 0.42);
}

.save-dialog label {
  display: block;
  margin-bottom: 10px;
  color: var(--panel-2);
  font-size: 0.86rem;
  font-weight: 700;
  text-transform: uppercase;
}

.save-dialog input {
  width: 100%;
  min-height: 42px;
  border: 2px solid var(--ink);
  border-radius: 6px;
  background: #fff8dc;
  color: var(--ink);
  font: 700 1rem/1 ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  padding: 0 10px;
}

.save-actions {
  display: flex;
  justify-content: end;
  gap: 10px;
  margin-top: 14px;
}

#toast {
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%) translateY(calc(100% + 42px));
  z-index: 3;
  max-width: min(420px, calc(100vw - 24px));
  border: 2px solid #4c5d6c;
  border-radius: 6px;
  background: #fff0c8;
  color: #171b22;
  padding: 10px 14px;
  font-weight: 700;
  text-align: center;
  box-shadow: 0 12px 30px var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: transform 180ms ease, opacity 180ms ease;
}

#toast.is-visible {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

@media (max-width: 900px) {
  .layout {
    grid-template-columns: 1fr;
    align-items: start;
    padding-top: 14px;
  }

  .journal {
    justify-content: start;
  }

  .journal-text {
    min-height: 86px;
  }
}

@media (max-width: 680px) {
  .layout {
    width: min(100vw - 16px, 620px);
    padding-bottom: 170px;
  }

  .topbar {
    align-items: start;
    flex-direction: column;
  }

  .status-strip {
    max-width: none;
    width: 100%;
  }

  .screen-shell {
    border-width: 6px;
  }

  .controls {
    justify-content: start;
  }

  .touch-pad {
    display: flex;
  }
}

@media (pointer: coarse) {
  body[data-view-mode="auto"] .layout {
    grid-template-columns: 1fr;
    align-items: start;
    padding-top: 14px;
    padding-bottom: 170px;
  }

  body[data-view-mode="auto"] .journal {
    justify-content: start;
  }

  body[data-view-mode="auto"] .journal-text {
    min-height: 86px;
  }

  body[data-view-mode="auto"] .touch-pad {
    display: flex;
  }
}

body[data-view-mode="mobile"] .layout {
  width: min(100vw - 16px, 620px);
  grid-template-columns: 1fr;
  align-items: start;
  padding-top: 14px;
  padding-bottom: 170px;
}

body[data-view-mode="mobile"] .topbar {
  align-items: start;
  flex-direction: column;
}

body[data-view-mode="mobile"] .status-strip {
  max-width: none;
  width: 100%;
}

body[data-view-mode="mobile"] .screen-shell {
  border-width: 6px;
}

body[data-view-mode="mobile"] .controls {
  justify-content: start;
}

body[data-view-mode="mobile"] .journal {
  justify-content: start;
}

body[data-view-mode="mobile"] .journal-text {
  min-height: 86px;
}

body[data-view-mode="mobile"] .touch-pad {
  display: flex;
}

body[data-view-mode="desktop"] .layout {
  width: min(1180px, calc(100vw - 28px));
  grid-template-columns: minmax(0, 820px) minmax(250px, 1fr);
  align-items: center;
  padding: 20px 0 100px;
}

body[data-view-mode="desktop"] .topbar {
  align-items: end;
  flex-direction: row;
}

body[data-view-mode="desktop"] .status-strip {
  max-width: 260px;
  width: auto;
}

body[data-view-mode="desktop"] .screen-shell {
  border-width: 10px;
}

body[data-view-mode="desktop"] .controls {
  justify-content: center;
}

body[data-view-mode="desktop"] .journal {
  justify-content: center;
}

body[data-view-mode="desktop"] .journal-text {
  min-height: 150px;
}

body[data-view-mode="desktop"] .touch-pad {
  display: none;
}
