/* Block Maze phone controller: the same bright cartoon look as the TV (thick dark outlines,
   chunky buttons with a lip, Lilita One). */

@font-face {
  font-family: 'Lilita One';
  src: url('fonts/LilitaOne-Regular.ttf') format('truetype');
  font-display: swap;
}

:root {
  color-scheme: light;
  --ink: #21170f;
  --sky-top: #5dabf2;
  --sky-bottom: #b8e2ff;
  --grass: #4f9a2b;
  --panel: #2e6ecc;
  --card: #fff4d9;
  --card-lip: #c9b48a;
  --green: #78c940;
  --green-lip: #3b7a1a;
  --yellow: #ffc533;
  --yellow-lip: #b87d0f;
  --red: #e5463b;
  --red-lip: #94211a;
  --fg: #ffffff;
  --muted: #d4e6ff;
  --good: #8cf06a;
  --bad: #ff8073;
  --radius: 16px;
  --border: 4px solid var(--ink);
  --outline: 0 3px 0 var(--ink), 2px 2px 0 var(--ink), -2px 2px 0 var(--ink), 2px -2px 0 var(--ink), -2px -2px 0 var(--ink),
    2px 0 0 var(--ink), -2px 0 0 var(--ink), 0 -2px 0 var(--ink);
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  background: var(--sky-top);
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  color: var(--ink);
  font: 19px/1.3 'Lilita One', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  letter-spacing: 0.01em;
  -webkit-tap-highlight-color: transparent;
}

/* Sky with rolling hills, fixed behind everything. */
body::before {
  content: '';
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: -1;
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 400 120' preserveAspectRatio='none'%3E%3Cpath d='M0 60 Q50 20 100 50 T200 45 T300 40 T400 50 V120 H0Z' fill='%236bbd3f' stroke='%2321170f' stroke-width='4'/%3E%3Cpath d='M0 85 Q60 55 130 80 T260 75 T400 80 V120 H0Z' fill='%234f9a2b' stroke='%2321170f' stroke-width='4'/%3E%3C/svg%3E") bottom / 100% 26vh no-repeat,
    linear-gradient(var(--sky-top), var(--sky-bottom));
}

main {
  display: flex;
  flex-direction: column;
  gap: 14px;
  max-width: 520px;
  margin: 0 auto;
  padding: 16px 16px 24px;
  padding: max(16px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom));
}

h1,
h2 {
  margin: 0;
  font-weight: 400;
}

.title,
.outlined,
.big-message,
.total {
  color: var(--fg);
  text-shadow: var(--outline);
}

.title {
  text-align: center;
  font-size: 34px;
  margin-top: 8px;
}

/* Older smart-TV browsers (before Chromium 84) ignore gap in flex layouts. They also lack
   inset, so that marks them: give the page's blocks some space there. */
@supports not (inset: 0) {
  main > * + * {
    margin-top: 14px;
  }
}

/* index.html's message for a browser too old to run app.js. */
.too-old {
  margin-top: 20vh;
  padding: 16px;
  border: var(--border);
  border-radius: var(--radius);
  background: var(--card);
  text-align: center;
}

.center {
  text-align: center;
}

.muted {
  color: #2c4b78;
}

.good {
  color: #2f8a12;
}

.bad {
  color: #c4291e;
}

.card {
  padding: 16px;
  border: var(--border);
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: 0 6px 0 rgb(33 23 15 / 0.45);
}

.error {
  margin: 0;
  padding: 10px 12px;
  border: 3px solid var(--ink);
  border-radius: 12px;
  background: var(--red);
  color: var(--fg);
  text-shadow: 0 2px 0 var(--ink);
}

.banner {
  position: sticky;
  top: 0;
  z-index: 10;
  padding: 10px 16px;
  border-bottom: var(--border);
  background: var(--yellow);
  color: var(--ink);
  text-align: center;
}

.big-message {
  padding: 28px 16px;
  border: var(--border);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: 0 6px 0 rgb(33 23 15 / 0.45);
  text-align: center;
  font-size: 28px;
}

/* --- Logo --- */

.logo {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 14px;
  margin: 10px 0 4px;
}

.logo-stack {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.cube {
  position: relative;
  width: 26px;
  height: 26px;
  border: 3px solid var(--ink);
  border-radius: 4px;
  background: var(--color);
  box-shadow: 0 3px 0 rgb(33 23 15 / 0.5);
}

.cube::after {
  content: '';
  position: absolute;
  top: 6px;
  right: 3px;
  width: 3px;
  height: 6px;
  background: var(--ink);
  box-shadow: 6px 0 0 var(--ink);
  right: 9px;
}

.cube:nth-child(2) {
  transform: translateX(3px);
}

.cube:nth-child(4) {
  transform: translateX(-2px);
}

.logo-words {
  display: flex;
  flex-direction: column;
  line-height: 0.9;
  font-size: 58px;
  text-transform: uppercase;
  text-shadow: 0 5px 0 var(--ink), 3px 3px 0 var(--ink), -3px 3px 0 var(--ink), 3px -3px 0 var(--ink), -3px -3px 0 var(--ink),
    3px 0 0 var(--ink), -3px 0 0 var(--ink), 0 -3px 0 var(--ink);
}

.logo-word-1 {
  color: #ffd133;
  transform: rotate(-3deg);
}

.logo-word-2 {
  color: #f25a47;
  margin-left: 40px;
  transform: rotate(2deg);
}

/* --- Landing --- */

.choice {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 18px 20px;
  text-align: left;
  text-decoration: none;
}

.choice.host {
  border: var(--border);
  border-radius: var(--radius);
  background: var(--green);
  box-shadow: 0 7px 0 var(--green-lip);
  color: var(--fg);
}

.choice.join {
  background: var(--yellow);
  box-shadow: 0 7px 0 var(--yellow-lip);
  color: var(--fg);
}

.choice:active {
  transform: translateY(5px);
  box-shadow: 0 2px 0 var(--ink);
}

.choice-title {
  font-size: 32px;
  text-transform: uppercase;
  text-shadow: var(--outline);
}

.choice-text {
  font-size: 18px;
  color: var(--ink);
}

.how {
  padding: 14px 18px;
  border: var(--border);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--fg);
  box-shadow: 0 6px 0 rgb(33 23 15 / 0.45);
}

.how h2 {
  font-size: 22px;
  text-shadow: var(--outline);
}

.how ol {
  margin: 8px 0 0;
  padding-left: 22px;
  color: var(--fg);
  text-shadow: 0 2px 0 var(--ink);
}

.how li + li {
  margin-top: 4px;
}

/* --- Navigation --- */

button.back {
  align-self: flex-start;
  min-height: 46px;
  padding: 0 16px;
  font-size: 18px;
}

button.leave,
button.danger {
  background: var(--red);
  box-shadow: 0 6px 0 var(--red-lip);
  color: var(--fg);
  text-shadow: 0 2px 0 var(--ink);
}

button.leave {
  margin-top: 6px;
}

button.leave:active:not(:disabled),
button.danger:active:not(:disabled) {
  box-shadow: 0 2px 0 var(--red-lip);
}

.bar button.menu {
  min-height: 38px;
  width: 38px;
  padding: 0;
  border-width: 3px;
  border-radius: 10px;
  font-size: 18px;
  text-shadow: none;
  box-shadow: 0 3px 0 var(--card-lip);
}

.bar-title {
  flex: 1;
}

.overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgb(0 0 0 / 0.5);
}

.dialog {
  width: min(420px, 100%);
}

.dialog h2 {
  font-size: 26px;
}

.dialog p {
  margin: 10px 0 16px;
  font-size: 18px;
}

.dialog > button {
  width: 100%;
  margin-top: 0;
}

.dialog-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

/* --- Language switch --- */

.languages {
  display: flex;
  justify-content: center;
  gap: 8px;
}

button.language {
  min-height: 40px;
  padding: 0 14px;
  border-width: 3px;
  font-size: 16px;
  box-shadow: 0 3px 0 var(--card-lip);
}

button.language.active {
  background: var(--yellow);
  box-shadow: 0 3px 0 var(--yellow-lip);
}

/* --- Install --- */

.install-wrap {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

button.install {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  min-height: 64px;
  padding: 10px 18px;
  background: #b86df0;
  box-shadow: 0 6px 0 #6b2fa3;
  color: var(--fg);
  text-align: left;
}

button.install:active:not(:disabled) {
  box-shadow: 0 2px 0 #6b2fa3;
}

.install-title {
  font-size: 22px;
  text-transform: uppercase;
  text-shadow: var(--outline);
}

.install-text {
  font-size: 16px;
  color: var(--ink);
}

.install-steps {
  margin: 0;
  padding-left: 40px;
  font-size: 17px;
}

.install-steps li + li {
  margin-top: 6px;
}

/* --- Forms and buttons --- */

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

label {
  font-size: 17px;
  margin-top: 4px;
}

input {
  width: 100%;
  min-height: 56px;
  padding: 0 14px;
  border: var(--border);
  border-radius: 14px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-size: 24px;
}

input#code {
  text-transform: uppercase;
  letter-spacing: 0.3em;
}

input:focus {
  outline: none;
  border-color: var(--panel);
}

button {
  min-height: 56px;
  border: var(--border);
  border-radius: var(--radius);
  font: inherit;
  color: var(--ink);
  background: var(--card);
  box-shadow: 0 6px 0 var(--card-lip);
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.05s;
}

button:active:not(:disabled) {
  transform: translateY(4px);
  box-shadow: 0 2px 0 var(--card-lip);
}

button:disabled {
  opacity: 0.45;
  cursor: default;
}

button.primary {
  margin-top: 10px;
  background: var(--green);
  box-shadow: 0 6px 0 var(--green-lip);
  color: var(--fg);
  font-size: 24px;
  text-transform: uppercase;
  text-shadow: var(--outline);
}

button.primary:active:not(:disabled) {
  box-shadow: 0 2px 0 var(--green-lip);
}

button.link {
  min-height: 40px;
  border: 0;
  background: none;
  box-shadow: none;
  color: var(--fg);
  text-decoration: underline;
  text-shadow: 0 2px 0 var(--ink);
}

/* --- Lobby --- */

.players,
.scoreboard {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.players li {
  padding: 12px 14px;
  border: var(--border);
  border-radius: 12px;
  background: var(--card);
}

.players li.me {
  background: #fff;
  box-shadow: 0 4px 0 rgb(33 23 15 / 0.35);
}

.you {
  margin-left: 8px;
  padding: 1px 8px;
  border: 2px solid var(--ink);
  border-radius: 8px;
  background: var(--panel);
  color: var(--fg);
  font-size: 14px;
  text-shadow: 0 1px 0 var(--ink);
  vertical-align: 2px;
}

/* --- Turn screens --- */

.bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border: var(--border);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--fg);
  text-shadow: 0 2px 0 var(--ink);
  box-shadow: 0 5px 0 rgb(33 23 15 / 0.45);
}

.countdown {
  min-width: 44px;
  font-size: 30px;
  text-align: right;
  font-variant-numeric: tabular-nums;
  text-shadow: var(--outline);
}

.countdown.urgent {
  color: var(--bad);
}

/* Your seat color down the left of the bar. */
main.game .bar {
  padding-left: 10px;
  border-left: 12px solid var(--color);
}

.goal {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.goal-icon {
  width: 44px;
  height: 44px;
  padding: 3px;
  border: 3px solid var(--ink);
  border-radius: 10px;
  background: var(--card);
}

.goal-text {
  display: flex;
  flex-direction: column;
  line-height: 1.05;
  min-width: 0;
}

.goal-name {
  overflow: hidden;
  font-size: 24px;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-shadow: var(--outline);
}

.goal-left {
  font-size: 16px;
  color: var(--muted);
}

/* "Return home!": a little start tile in your color. */
.home-icon {
  width: 40px;
  height: 40px;
  border: 3px solid var(--ink);
  border-radius: 8px;
  background: var(--card);
  box-shadow: inset 0 0 0 5px var(--color);
}

/* --- Game: board and controls --- */

main.game {
  gap: 10px;
  padding-top: max(10px, env(safe-area-inset-top));
}

.play {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* The board stays square and fits under the bar with room for the buttons below it. */
.board-wrap {
  width: 100%;
  max-width: max(260px, calc(100vh - 290px));
  max-width: max(260px, calc(100dvh - 290px));
  margin: 0 auto;
}

.board {
  display: block;
  width: 100%;
  height: auto;
  user-select: none;
  -webkit-user-select: none;
}

.side {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.status {
  margin: 0;
  color: var(--fg);
  text-align: center;
  font-size: 22px;
  text-shadow: var(--outline);
}

.board-base {
  fill: var(--ink);
}

.hedge {
  fill: #3f8a2e;
}

.hedge.fixed {
  fill: #868c98;
}

.path {
  fill: #f6e2a8;
}

.home {
  fill: none;
  stroke-width: 1.3;
}

.pushed-line {
  fill: none;
  stroke: #fff;
  stroke-width: 0.9;
  stroke-dasharray: 2 1.4;
}

.dim {
  fill: rgb(18 12 6 / 0.64);
  pointer-events: none;
}

.target-ring {
  fill: none;
  stroke: #ffd133;
  stroke-width: 1.3;
  animation: ring-pulse 1.1s ease-in-out infinite alternate;
}

@keyframes ring-pulse {
  from {
    stroke-opacity: 1;
  }
  to {
    stroke-opacity: 0.35;
  }
}

.pick-ring {
  fill: rgb(255 255 255 / 0.18);
  stroke: #fff;
  stroke-width: 1.2;
}

.tile-hit {
  fill: transparent;
  cursor: pointer;
}

.pawn-body {
  stroke: var(--ink);
  stroke-width: 0.55;
}

.pawn-eye {
  fill: var(--ink);
}

.pawn.mine .pawn-body {
  stroke: #fff;
  stroke-width: 0.7;
}

.pawn.gone {
  opacity: 0.35;
}

.pawn.ghost {
  opacity: 0.55;
  pointer-events: none;
}

.pawns {
  pointer-events: none;
}

.arrow {
  cursor: pointer;
}

.arrow-hit {
  fill: transparent;
}

.arrow-head {
  fill: var(--yellow);
  stroke: var(--ink);
  stroke-width: 0.6;
  stroke-linejoin: round;
}

.arrow.chosen .arrow-head {
  fill: var(--green);
  stroke: #fff;
}

.arrow.forbidden {
  cursor: default;
  opacity: 0.4;
}

.arrow.forbidden .arrow-head {
  fill: #9aa0aa;
}

.arrow-cross {
  stroke: var(--red-lip);
  stroke-width: 1;
  stroke-linecap: round;
}

/* The spare tile (tap it, or Turn, to turn it a quarter), Turn and Push in one row. */
.push-row {
  display: grid;
  grid-template-columns: auto auto 1fr;
  align-items: center;
  gap: 10px;
}

button.spare {
  width: 84px;
  height: 84px;
  min-height: 0;
  padding: 4px;
  border-radius: 14px;
  background: var(--ink);
  box-shadow: 0 5px 0 rgb(33 23 15 / 0.45);
}

.spare-tile {
  display: block;
  width: 100%;
  height: 100%;
}

button.rotate {
  min-height: 64px;
  padding: 0 14px;
  font-size: 20px;
  white-space: nowrap;
}

button.confirm {
  margin-top: 0;
  min-height: 64px;
}

.move-buttons {
  display: grid;
  grid-template-columns: 1fr 1.6fr;
  gap: 10px;
}

.move-buttons button {
  min-height: 64px;
  font-size: 22px;
}

.toast {
  position: fixed;
  left: 50%;
  top: max(84px, calc(env(safe-area-inset-top) + 74px));
  z-index: 15;
  width: min(440px, calc(100% - 32px));
  padding: 12px 16px;
  border: var(--border);
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: 0 6px 0 rgb(33 23 15 / 0.45);
  text-align: center;
  font-size: 20px;
  transform: translateX(-50%);
  animation: toast-in 0.25s ease-out;
  pointer-events: none;
}

.toast.mine {
  background: var(--yellow);
}

@keyframes toast-in {
  from {
    transform: translate(-50%, -16px);
    opacity: 0;
  }
}

/* --- Treasures left (in the game and at the end) --- */

.scores {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.scores li {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 8px 12px;
  border: 3px solid var(--ink);
  border-radius: 12px;
  background: var(--card);
}

.scores li.me {
  background: #fff;
}

.scores li.active {
  box-shadow: 0 0 0 3px var(--yellow);
}

.scores li.dim {
  opacity: 0.6;
}

.score-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.score-left {
  font-size: 22px;
}

.big-message.win {
  background: var(--yellow);
  color: var(--fg);
}

/* Tablets and phones on their side: the board on the left, everything else on the right. */
@media (orientation: landscape) and (min-width: 600px) {
  main.game {
    max-width: 1100px;
  }

  main.game .play {
    flex-direction: row;
    align-items: flex-start;
  }

  main.game .board-wrap {
    flex: none;
    width: min(60vw, calc(100vh - 110px));
    width: min(60vw, calc(100dvh - 110px));
    max-width: none;
    margin: 0;
  }

  main.game .side {
    flex: 1;
    min-width: 0;
  }
}

.dot {
  display: inline-block;
  width: 16px;
  height: 16px;
  margin-right: 8px;
  border: 2px solid var(--ink);
  border-radius: 4px;
  background: var(--color);
  vertical-align: -2px;
}

.total {
  text-align: center;
  font-size: 34px;
}

/* --- Small phones --- */

@media (max-width: 360px), (max-height: 640px) {
  main {
    gap: 10px;
    padding-top: max(10px, env(safe-area-inset-top));
  }

  .logo-words {
    font-size: 44px;
  }

  .actions button {
    min-height: 56px;
  }
}
