:root {
  --yellow: #ffff00;
  --olive: #6e6e00;
  --hand: 'Kalam', 'Segoe Print', 'Comic Sans MS', cursive;
  --ui: Verdana, Geneva, 'DejaVu Sans', sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: #000;
  color: #fff;
  font-family: var(--ui);
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
}

[hidden] { display: none !important; }

/* ------------------------------------------------------------ stage --- */

#app {
  position: relative;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  background: #000;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

/* The game is laid out on the original 904x768 stage and scaled to fit. */
#stage {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 904px;
  height: 768px;
  transform: translate(-50%, -50%) scale(var(--scale, 1));
  transform-origin: 50% 50%;
}

.screen {
  position: absolute;
  inset: 0;
}

.logo {
  position: absolute;
  background: url('../img/logo.svg') no-repeat left center / contain;
}

.box-btn {
  position: absolute;
  border: 3px solid var(--yellow);
  color: var(--yellow);
  font-weight: bold;
  background: #111;
  padding: 2px 8px;
  white-space: nowrap;
}
.box-btn:hover, .box-btn:focus-visible { background: #2a2a00; outline: none; }

/* ------------------------------------------------------------- menu --- */

.menu-logo { left: 24px; top: 16px; width: 190px; height: 64px; }
.tutorial-btn { right: 26px; top: 26px; font-size: 20px; }

.col-head {
  position: absolute;
  top: 120px;
  font-size: 26px;
  font-weight: bold;
  color: #ccc;
}
.left-head { left: 300px; }
.right-head { left: 435px; }

#player-rows {
  position: absolute;
  left: 30px;
  top: 172px;
  width: 560px;
}

.row {
  position: relative;
  height: 60px;
  display: flex;
  align-items: center;
  font-size: 26px;
  font-weight: bold;
  color: var(--c);
}
.row > * { opacity: .25; transition: opacity .12s; }
.row.active > *, .row.editing > * { opacity: 1; }
.row:not(.editing):hover > .num, .row:not(.editing):hover > .name { opacity: .625; }
.row.active:not(.editing):hover > * { opacity: 1; }
.row .num { width: 50px; text-align: center; cursor: pointer; }
.row .name { width: 205px; padding-left: 14px; cursor: pointer; }
.row .key {
  width: 135px;
  text-align: left;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.row .key.prompt {
  font-family: var(--hand);
  font-size: 15px;
  font-weight: normal;
  color: var(--yellow);
  white-space: normal;
  line-height: 1.1;
  animation: blink 1s steps(2, start) infinite;
}
.row .cpu {
  font-size: 13px;
  border: 2px solid currentColor;
  border-radius: 4px;
  padding: 1px 6px;
  margin-left: 4px;
}
.row .cpu.on { opacity: 1; background: color-mix(in srgb, var(--c) 30%, transparent); }
.row:not(.active):not(.editing) .cpu:hover { opacity: .8; }
.row.bot .key { overflow: visible; font-style: italic; font-weight: normal; }

@keyframes blink { to { visibility: hidden; } }

.demo-box {
  position: absolute;
  left: 588px;
  top: 168px;
  width: 300px;
}
.demo-title {
  font-size: 22px;
  font-weight: bold;
  color: #ccc;
  margin-bottom: 6px;
}
#demo {
  display: block;
  width: 300px;
  height: 300px;
  border: 2px solid #444;
  background: #000;
}

.mode-btns {
  position: absolute;
  left: 588px;
  top: 500px;
  display: flex;
  gap: 16px;
}
.mode-btn {
  font-family: var(--hand);
  font-weight: bold;
  font-size: 26px;
  color: #000;
  background: var(--yellow);
  border: 3px solid #000;
  outline: 2px solid var(--yellow);
  padding: 0 16px;
  opacity: .5;
}
.mode-btn[aria-checked='true'] { opacity: 1; }
.mode-btn:hover { opacity: .85; }

.toggles {
  position: absolute;
  font-family: var(--hand);
  font-size: 20px;
  color: var(--yellow);
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}
.toggle b { font-weight: normal; display: inline-block; min-width: 2.2em; padding-left: .4em; }
.toggle:hover { color: #fff; }
.menu-toggles { left: 778px; top: 562px; }

.play-btn {
  position: absolute;
  left: 130px;
  top: 606px;
  width: 590px;
  height: 96px;
  border: 4px solid var(--olive);
  background: #111;
  color: #555;
  font-size: 28px;
  font-weight: bold;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  line-height: 1.25;
}
.play-btn.ready {
  border-color: var(--yellow);
  color: var(--yellow);
}
.play-btn.ready:hover { background: #2a2a00; }

.touch-btn { left: 130px; top: 548px; width: 590px; font-size: 20px; }

.hint {
  position: absolute;
  left: 16px;
  bottom: 4px;
  margin: 0;
  font-size: 12px;
  color: #999;
  max-width: 520px;
}
.credits {
  position: absolute;
  right: 8px;
  bottom: 4px;
  margin: 0;
  font-size: 11px;
  font-style: italic;
  color: #777;
}
.credits a { color: #999; }

.dialog {
  position: absolute;
  left: 120px;
  top: 170px;
  width: 664px;
  height: 430px;
  background: #fff;
  border: 4px solid #f00;
  color: #000;
  font-family: var(--hand);
  font-size: 17px;
  padding: 10px 18px;
  z-index: 5;
}
.dialog h2 {
  color: #f00;
  font-size: 50px;
  font-weight: normal;
  margin: 10px 0 14px;
  line-height: 1.1;
}
.dialog em { color: #f00; font-style: normal; }
.dialog p { margin: 0 0 18px; line-height: 1.75; }
.dialog-btns {
  display: flex;
  justify-content: space-around;
  margin-top: 30px;
}
.yellow-btn {
  font-family: var(--hand);
  font-size: 32px;
  color: #f00;
  background: var(--yellow);
  border: 3px solid #000;
  width: 170px;
  height: 70px;
}
.yellow-btn:hover, .yellow-btn:focus-visible { background: #ffff80; outline: none; }

/* ------------------------------------------------------------- game --- */

#field-wrap {
  position: absolute;
  left: 0;
  top: 0;
  width: 768px;
  height: 768px;
  border: 4px solid var(--yellow);
}
#field-wrap.open { animation: border-blink .8s linear infinite; }
@keyframes border-blink {
  0%, 100% { border-color: var(--yellow); }
  50% { border-color: rgba(255, 255, 0, .12); }
}

#field {
  position: relative;
  width: 760px;
  height: 760px;
  overflow: hidden;
  background: #000;
}
#field canvas {
  position: absolute;
  inset: 0;
  width: 760px;
  height: 760px;
}

.field-msg {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--hand);
  font-size: 72px;
  color: var(--yellow);
  background: rgba(0, 0, 0, .35);
  text-shadow: 0 0 12px #000;
}

.win {
  position: absolute;
  left: 0;
  right: 0;
  top: 220px;
  height: 317px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: color-mix(in srgb, var(--c, #fff) 22%, rgba(0, 0, 0, .78));
  border-top: 3px solid var(--c, #fff);
  border-bottom: 3px solid var(--c, #fff);
  animation: win-in .5s cubic-bezier(.2, 1.4, .4, 1);
}
#win-text {
  font-family: var(--hand);
  font-weight: bold;
  font-size: 88px;
  color: var(--c, #fff);
  text-shadow: 0 0 24px color-mix(in srgb, var(--c, #fff) 60%, transparent);
}
.win-sub { font-size: 18px; color: #ddd; margin-top: 8px; }
@keyframes win-in { from { transform: scale(.6); opacity: 0; } }

.touch-zone {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 50%;
}
#touch-left { left: 0; }
#touch-right { right: 0; }

#sidebar {
  position: absolute;
  left: 768px;
  top: 0;
  width: 136px;
  height: 768px;
  text-align: center;
}
.side-logo { left: 8px; top: 10px; width: 122px; height: 44px; }
.goal-label {
  position: absolute;
  top: 78px;
  width: 100%;
  font-size: 18px;
  color: #aaa;
}
.goal {
  position: absolute;
  top: 98px;
  width: 100%;
  font-size: 56px;
  font-weight: bold;
  color: #fff;
}
.goal.bump { animation: bump .6s; }
@keyframes bump { 30% { transform: scale(1.35); color: var(--yellow); } }
.goal-sub {
  position: absolute;
  top: 166px;
  width: 100%;
  font-size: 12px;
  color: #888;
}
.scores {
  position: absolute;
  top: 196px;
  left: 0;
  width: 100%;
  margin: 0;
  padding: 0;
  list-style: none;
}
.scores li {
  position: absolute;
  left: 0;
  width: 100%;
  height: 48px;
  padding: 0 8px;
  color: var(--c);
  transition: transform .35s ease;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}
.scores .pname { font-size: 15px; font-weight: bold; white-space: nowrap; }
.scores .pname small { font-size: 10px; opacity: .7; margin-left: 4px; }
.scores .pscore { font-size: 22px; font-weight: bold; line-height: 1; align-self: flex-end; }
.scores li.dead { opacity: .45; }
.side-toggles { left: 10px; top: 520px; font-size: 18px; }
.space-msg {
  position: absolute;
  top: 640px;
  width: 100%;
  font-family: var(--hand);
  font-size: 20px;
  color: var(--yellow);
  line-height: 1.1;
  padding: 0 4px;
}
.space-msg.blink { animation: blink 1s steps(2, start) infinite; }
.menu-btn { left: 10px; bottom: 12px; font-size: 14px; border-width: 2px; }

/* --------------------------------------------------------- tutorial --- */

.help {
  background: #000;
  z-index: 10;
  padding: 24px 40px;
}
.help-text {
  font-size: 15px;
  color: var(--yellow);
  line-height: 1.55;
}
.help-text b, .help-pu b {
  font-family: var(--hand);
  font-weight: normal;
  color: #f00;
  font-size: 19px;
}
.help-text em { color: #0f0; font-style: normal; }
.help-text p { margin: 0 0 10px; }
.help-pu { color: var(--yellow); font-size: 15px; }
#pu-legend {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px 14px;
}
.pu-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: #ddd;
}
.pu-item img { width: 34px; height: 34px; flex: none; }
.help-back { right: 30px; bottom: 18px; font-size: 18px; }

/* ------------------------------------------------------------ about --- */

.about {
  max-width: 820px;
  margin: 0 auto;
  padding: 48px 20px 24px;
  line-height: 1.6;
  color: #ddd;
}
.about h1 { font-size: 30px; line-height: 1.25; color: #fff; }
.about h2 { font-size: 22px; color: var(--yellow); margin-top: 36px; }
.about h3 { font-size: 17px; color: #fff; margin-bottom: 4px; }
.about a { color: #6cf; }
.about table { border-collapse: collapse; }
.about th, .about td { border: 1px solid #333; padding: 4px 12px; text-align: left; }
.about kbd {
  border: 1px solid #666;
  border-radius: 4px;
  padding: 0 5px;
  font-size: .9em;
  background: #111;
}
.pu-list { list-style: none; padding: 0; }
.pu-list li { display: flex; align-items: center; gap: 10px; margin: 6px 0; }
.pu-list li > span { display: contents; }
.pu-list img { width: 30px; height: 30px; flex: none; }
.site-footer { margin-top: 48px; border-top: 1px solid #222; font-size: 14px; color: #888; }
.noscript { text-align: center; color: var(--yellow); }

@media (prefers-reduced-motion: reduce) {
  .row .key.prompt, .space-msg.blink, #field-wrap.open { animation: none; }
}
