@font-face {
  font-family: "Press Start 2P";
  src: url("../fonts/PressStart2P-Regular.ttf") format("truetype");
  font-display: block;
}

/* The page uses these 10 colours and nothing else. Dice materials have their
   own colours, set in js/display/render.js. */
:root {
  --ink: #1a1c2c;
  --panel: #333c57;
  --slate: #566c86;
  --mist: #94b0c2;
  --white: #f4f4f4;
  --gold: #ffcd75;
  --copper: #b86f50;
  --violet: #5d275d;
  --red: #b13e53;
  --green: #38b764;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--ink);
  color: var(--white);
  font-family: "Press Start 2P", monospace;
  -webkit-user-select: none;
  user-select: none;
  overflow: hidden;
}

button,
textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

button:disabled {
  cursor: default;
}

[hidden] {
  display: none !important;
}

/* Phone first: points, the prestige panel, the tray, then the shop. */
.app {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  height: 100dvh;
  max-width: 1280px;
  margin: 0 auto;
  padding: 12px;
  gap: 12px;
}

.hud {
  position: relative;
  text-align: center;
  padding-top: 8px;
}

.hud-label {
  font-size: 8px;
  letter-spacing: 2px;
  color: var(--mist);
  margin-bottom: 12px;
}

.hud-points {
  font-size: 32px;
  color: var(--gold);
  text-shadow: 4px 4px 0 var(--panel);
}

.hud-points.pop {
  animation: pop 0.18s steps(3);
}

@keyframes pop {
  from { transform: scale(1.3); }
  to { transform: scale(1); }
}

.menu-open {
  position: absolute;
  top: 0;
  right: 0;
  padding: 8px;
  font-size: 8px;
  color: var(--mist);
  background: var(--panel);
  border: 2px solid var(--slate);
}

/* On/off switches for Auto-roll and Auto-buy. */
.switches {
  display: flex;
  flex-shrink: 0;
  gap: 8px;
}

.switches:not(:has(.switch:not([hidden]))) {
  display: none;
}

.switch {
  flex: 1;
  padding: 8px;
  font-size: 8px;
  color: var(--green);
  background: var(--ink);
  border: 2px solid var(--green);
}

.switch.off {
  color: var(--mist);
  border-color: var(--slate);
}

.panel-title {
  display: none;
  font-size: 8px;
  letter-spacing: 2px;
  color: var(--mist);
}

/* --- Prestige panel --- */

.prestige-panel {
  display: flex;
  gap: 8px;
  align-items: stretch;
}

/* The readout: Pips held, Pips this run would pay, and the countdown. */
.prestige-info {
  display: grid;
  flex: 1;
  grid-template-columns: 1fr;
  gap: 8px;
  align-content: center;
  padding: 10px;
  font-size: 8px;
  color: var(--mist);
  background: var(--panel);
  border: 2px solid var(--slate);
}

.stat {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  white-space: nowrap;
}

.stat-wide,
.pip-bar {
  grid-column: 1 / -1;
}

.stat-value {
  color: var(--green);
  text-align: right;
}

.pip-bar {
  height: 8px;
  background: var(--ink);
  border: 2px solid var(--slate);
}

.pip-bar-fill {
  width: 0;
  height: 100%;
  background: var(--green);
}

.prestige-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.prestige {
  display: flex;
  flex: 1;
  flex-direction: column;
  justify-content: center;
  gap: 6px;
  padding: 10px;
  font-size: 10px;
  line-height: 1.4;
  text-align: center;
  color: var(--ink);
  background: var(--green);
  border: 4px solid var(--white);
}

.prestige-sub {
  font-size: 8px;
  line-height: 1.5;
}

.prestige:disabled {
  color: var(--slate);
  background: var(--ink);
  border-color: var(--panel);
}

/* The first Pip: the loudest thing on screen. */
.prestige.first {
  padding: 16px 10px;
  font-size: 12px;
  background: var(--gold);
  animation: beckon 0.8s steps(2) infinite;
}

@keyframes beckon {
  from { background: var(--gold); }
  to { background: var(--white); }
}

.tree-open {
  padding: 10px;
  font-size: 10px;
  text-align: center;
  color: var(--green);
  background: var(--ink);
  border: 2px solid var(--green);
}

/* --- Tray --- */

.tray-frame {
  position: relative;
  min-height: 0;
  background: var(--panel);
  border: 4px solid var(--slate);
  box-shadow: inset 0 0 0 4px var(--ink);
}

/* A crit shakes the tray. */
.tray-frame.shake {
  animation: shake 0.25s steps(1);
}

@keyframes shake {
  0% { transform: translate(4px, -3px); }
  20% { transform: translate(-4px, 3px); }
  40% { transform: translate(3px, 4px); }
  60% { transform: translate(-3px, -2px); }
  80% { transform: translate(2px, 1px); }
  100% { transform: translate(0, 0); }
}

#tray {
  display: block;
  width: 100%;
  height: 100%;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

/* --- Run shop --- */

.side {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 0;
  max-height: 36dvh;
}

.shop {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 0;
  overflow-y: auto;
}

.shop-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-shrink: 0;
  padding: 10px;
  text-align: left;
  background: var(--panel);
  border: 4px solid var(--gold);
}

.shop-row:active:not(:disabled) {
  transform: translateY(2px);
}

.shop-row:disabled {
  border-color: var(--slate);
}

.shop-main {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.shop-name {
  font-size: 10px;
}

.shop-detail {
  font-size: 8px;
  line-height: 1.5;
  color: var(--mist);
}

.shop-cost {
  font-size: 12px;
  color: var(--gold);
}

.shop-row:disabled .shop-name,
.shop-row:disabled .shop-cost {
  color: var(--mist);
}

.shop-mystery {
  flex-shrink: 0;
  padding: 12px;
  text-align: center;
  font-size: 12px;
  color: var(--slate);
  border: 4px dashed var(--slate);
}

/* --- Windows --- */

.menu {
  width: min(92vw, 420px);
  padding: 16px;
  color: var(--white);
  background: var(--panel);
  border: 4px solid var(--slate);
}

.menu::backdrop {
  background: var(--ink);
  opacity: 0.8;
}

.menu h2 {
  margin: 0 0 12px;
  font-size: 16px;
  color: var(--gold);
}

.menu p {
  margin: 0 0 12px;
  font-size: 8px;
  line-height: 1.8;
  color: var(--mist);
}

.menu-message {
  min-height: 14px;
}

.menu textarea {
  display: block;
  width: 100%;
  margin-bottom: 12px;
  padding: 8px;
  font-size: 8px;
  line-height: 1.6;
  resize: none;
  background: var(--ink);
  border: 2px solid var(--slate);
  -webkit-user-select: text;
  user-select: text;
}

.menu-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.menu-actions button,
.tree-close,
#tree-buy {
  padding: 10px 8px;
  font-size: 8px;
  background: var(--ink);
  border: 2px solid var(--mist);
}

.menu-settings {
  margin-bottom: 12px;
}

.volume {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
  font-size: 8px;
  color: var(--mist);
}

.volume input {
  width: 100%;
  height: 16px;
  margin: 0;
  accent-color: var(--green);
  cursor: pointer;
}

.menu-settings button {
  color: var(--green);
  border-color: var(--green);
}

.menu-settings button.off {
  color: var(--mist);
  border-color: var(--slate);
}

.menu-actions .danger {
  border-color: var(--red);
  color: var(--red);
}

/* --- Prestige tree --- */

.tree[open] {
  display: flex;
  flex-direction: column;
  width: min(98vw, 1360px);
  height: min(94dvh, 860px);
  max-width: none;
  max-height: none;
}

.tree-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.tree-canvas {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 16px 0;
  background: var(--ink);
  border: 2px solid var(--slate);
}

/* The Pips count is the root every branch grows from. */
.tree-root {
  position: relative;
  width: max-content;
  margin: 0 auto 20px;
  padding: 10px 14px;
  font-size: 12px;
  color: var(--green);
  background: var(--panel);
  border: 4px solid var(--green);
}

.tree-root::after {
  content: "";
  position: absolute;
  left: calc(50% - 2px);
  top: calc(100% + 4px);
  width: 4px;
  height: 16px;
  background: var(--slate);
}

/* Six branches side by side. */
.tree-columns {
  position: relative;
  display: grid;
  grid-template-columns: repeat(6, minmax(204px, 1fr));
  min-width: max-content;
}

/* The bar joining the root to the top of each branch. */
.tree-columns::before {
  content: "";
  position: absolute;
  top: 0;
  left: calc(100% / 12 - 2px);
  right: calc(100% / 12 - 2px);
  height: 4px;
  background: var(--slate);
}

.tree-branch {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-top: 4px;
}

/* The branch name, at the top of the branch. */
.tree-branch h3 {
  margin: 0;
  padding: 6px 0;
  font-size: 10px;
  letter-spacing: 2px;
  color: var(--gold);
}

.tree-link-short {
  height: 10px;
}

/* After its first node, a branch splits into two paths. */
.tree-fork {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 1fr;
  width: 100%;
  margin-top: 12px;
}

/* The stem down from the first node, and the bar across to both paths. */
.tree-fork::before {
  content: "";
  position: absolute;
  top: -12px;
  left: calc(50% - 2px);
  width: 4px;
  height: 12px;
  background: var(--slate);
}

.tree-fork::after {
  content: "";
  position: absolute;
  top: 0;
  left: calc(25% - 2px);
  right: calc(25% - 2px);
  height: 4px;
  background: var(--slate);
}

.tree-path {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.tree-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100px;
}

.tree-link {
  width: 4px;
  height: 22px;
  background: var(--slate);
}

.tree-node {
  display: grid;
  place-items: center;
  width: 56px;
  height: 56px;
  padding: 0;
  background: var(--panel);
  border: 4px solid var(--slate);
}

.tree-node canvas {
  width: 27px;
  height: 27px;
  image-rendering: pixelated;
}

.tree-node.affordable {
  border-color: var(--gold);
}

.tree-node.owned {
  border-color: var(--green);
}

/* Owned, with another level ready to buy. */
.tree-node.owned.affordable {
  border-color: var(--gold);
}

.tree-node.next {
  border-style: dashed;
  background: var(--ink);
}

.tree-node.selected {
  outline: 4px solid var(--white);
  outline-offset: 2px;
}

.tree-node:hover {
  background: var(--slate);
}

.tree-name {
  margin-top: 8px;
  font-size: 8px;
  line-height: 1.4;
  text-align: center;
}

.tree-cost {
  min-height: 26px;
  margin-top: 4px;
  font-size: 8px;
  line-height: 1.6;
  text-align: center;
  white-space: pre-line;
  color: var(--mist);
}

.tree-detail {
  margin-top: 12px;
  padding: 12px;
  background: var(--ink);
  border: 2px solid var(--slate);
}

.tree-detail-name {
  margin-bottom: 10px;
  font-size: 12px;
  color: var(--gold);
}

.tree-detail p {
  min-height: 30px;
}

.tree-detail-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 36px;
  font-size: 8px;
  color: var(--mist);
}

#tree-buy {
  color: var(--ink);
  background: var(--gold);
  border-color: var(--white);
}

#tree-buy:disabled {
  color: var(--mist);
  background: var(--panel);
  border-color: var(--slate);
}

/* --- Debug panel --- */

.debug {
  position: fixed;
  left: 8px;
  bottom: 8px;
  z-index: 10;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 8px;
  background: var(--ink);
  border: 2px solid var(--red);
}

.debug button {
  padding: 6px;
  font-size: 8px;
  text-align: left;
  background: var(--panel);
  border: 2px solid var(--slate);
}

/* Wide screens: prestige on the left, tray in the middle, shop on the
   right. */
@media (min-width: 900px) {
  .app {
    grid-template-columns: 230px minmax(0, 1fr) 290px;
    grid-template-rows: auto minmax(0, 1fr);
    padding: 16px;
    gap: 16px;
  }

  .hud {
    grid-column: 1 / -1;
  }

  .panel-title {
    display: block;
  }

  .prestige-panel {
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-start;
    gap: 16px;
  }

  .prestige-info {
    flex: none;
  }

  .prestige {
    flex: none;
    padding: 14px 10px;
  }

  .tree-open {
    padding: 14px 10px;
  }

  .side {
    max-height: none;
  }
}

/* Section headings inside the menu. */
.menu > h3 {
  margin: 0 0 8px;
  font-size: 8px;
  letter-spacing: 2px;
  color: var(--mist);
}

/* After a prestige, the tree's close button starts the next run. */
.tree-close.go {
  color: var(--ink);
  background: var(--green);
  border-color: var(--white);
}
