/* BUTTON MAYHEM! · arcade pop-art menus over the canvas. */

@font-face {
  font-family: 'Dela Gothic One';
  src: url('../fonts/DelaGothicOne-Regular.ttf') format('truetype');
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: 'M PLUS Rounded 1c';
  src: url('../fonts/MPLUSRounded1c-Regular.ttf') format('truetype');
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: 'M PLUS Rounded 1c';
  src: url('../fonts/MPLUSRounded1c-Bold.ttf') format('truetype');
  font-weight: 700;
  font-display: swap;
}
@font-face {
  font-family: 'M PLUS Rounded 1c';
  src: url('../fonts/MPLUSRounded1c-Black.ttf') format('truetype');
  font-weight: 800 900;
  font-display: swap;
}

:root {
  --ink: #1a1033;
  --navy: #241b45;
  --cream: #fff6e0;
  --pink: #ff2e8a;
  --yellow: #ffd21f;
  --red: #ff2e4d;
  --green: #2be36b;
  --blue: #2f7bff;
  --cyan: #7cf2ff;
  --display: 'Dela Gothic One', 'M PLUS Rounded 1c', 'Arial Black', sans-serif;
  --body: 'M PLUS Rounded 1c', 'Segoe UI', system-ui, -apple-system, sans-serif;
  --s: 1;
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

html,
body {
  margin: 0;
  height: 100%;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  background: var(--ink);
  color: var(--cream);
  font-family: var(--body);
  font-weight: 800;
  overflow: hidden;
  user-select: none;
}

body {
  display: flex;
  align-items: center;
  justify-content: center;
}

#stage {
  position: relative;
  --s: 1;
}

#game {
  display: block;
  width: 100%;
  height: 100%;
  background: var(--ink);
}

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

.screen {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease;
}

.screen.dim {
  background: rgba(26, 16, 51, 0.72);
}

.screen.visible {
  opacity: 1;
  pointer-events: auto;
}

.screen.bottom {
  align-items: flex-end;
  padding-bottom: calc(var(--s) * 22px);
}

h1,
h2,
h3,
p {
  margin: 0;
}

h2 {
  font-family: var(--display);
  font-weight: 400;
  font-size: calc(var(--s) * 48px);
  line-height: 1;
  letter-spacing: 0.01em;
  color: var(--yellow);
  text-transform: uppercase;
  text-shadow: calc(var(--s) * 4px) calc(var(--s) * 4px) 0 var(--pink);
}

h3 {
  font-family: var(--display);
  font-weight: 400;
  font-size: calc(var(--s) * 18px);
  color: var(--yellow);
  margin: calc(var(--s) * 16px) 0 calc(var(--s) * 8px);
  text-transform: uppercase;
}

.note {
  font-size: calc(var(--s) * 14px);
  line-height: 1.4;
  color: rgba(255, 246, 224, 0.75);
}

.row {
  margin-top: calc(var(--s) * 18px);
  display: flex;
  justify-content: center;
}

.row-inline {
  display: flex;
  gap: calc(var(--s) * 12px);
  justify-content: center;
}

/* --------------------------------------------------------------- buttons */

.btn {
  font-family: var(--display);
  font-weight: 400;
  font-size: calc(var(--s) * 26px);
  text-transform: uppercase;
  letter-spacing: 0.01em;
  color: var(--ink);
  background: var(--cream);
  border: calc(var(--s) * 4px) solid var(--ink);
  border-radius: calc(var(--s) * 16px);
  box-shadow: calc(var(--s) * 6px) calc(var(--s) * 6px) 0 var(--ink);
  padding: calc(var(--s) * 12px) calc(var(--s) * 34px);
  min-width: calc(var(--s) * 330px);
  cursor: pointer;
  outline: none;
  transition: transform 0.08s, box-shadow 0.08s, background 0.1s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: calc(var(--s) * 10px);
  text-decoration: none;
}

.btn:hover,
.btn:focus-visible,
.btn:focus {
  transform: translate(calc(var(--s) * -2px), calc(var(--s) * -2px));
  box-shadow: calc(var(--s) * 8px) calc(var(--s) * 8px) 0 var(--ink), 0 0 0 calc(var(--s) * 4px) rgba(255, 255, 255, 0.55);
}

.btn:active {
  transform: translate(calc(var(--s) * 4px), calc(var(--s) * 4px));
  box-shadow: calc(var(--s) * 2px) calc(var(--s) * 2px) 0 var(--ink);
}

.btn.red { background: var(--red); color: #fff; }
.btn.yellow { background: var(--yellow); }
.btn.green { background: var(--green); }
.btn.cream { background: var(--cream); }
.btn.blue { background: var(--blue); color: #fff; }
.btn.pink { background: var(--pink); color: #fff; }

.btn.small {
  font-size: calc(var(--s) * 18px);
  min-width: 0;
  padding: calc(var(--s) * 8px) calc(var(--s) * 18px);
  border-radius: calc(var(--s) * 12px);
  box-shadow: calc(var(--s) * 4px) calc(var(--s) * 4px) 0 var(--ink);
}

.btn.big {
  font-size: calc(var(--s) * 40px);
  padding: calc(var(--s) * 10px) calc(var(--s) * 40px);
  min-width: calc(var(--s) * 360px);
}

.btn.icon {
  min-width: 0;
  padding: calc(var(--s) * 10px) calc(var(--s) * 16px);
}

.btn.icon svg {
  width: calc(var(--s) * 30px);
  height: calc(var(--s) * 30px);
  fill: none;
  stroke: var(--ink);
  stroke-width: 2.6;
  stroke-linecap: round;
}

.btn .play {
  display: inline-block;
  width: 0;
  height: 0;
  border-top: calc(var(--s) * 14px) solid transparent;
  border-bottom: calc(var(--s) * 14px) solid transparent;
  border-left: calc(var(--s) * 22px) solid var(--ink);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
  box-shadow: calc(var(--s) * 6px) calc(var(--s) * 6px) 0 var(--ink);
}

.btn.corner {
  position: absolute;
  top: calc(var(--s) * 18px);
  right: calc(var(--s) * 24px);
}

.menu {
  display: flex;
  flex-direction: column;
  gap: calc(var(--s) * 14px);
  align-items: center;
}

.menu.horizontal {
  flex-direction: row;
  gap: calc(var(--s) * 20px);
}

/* Segmented controls (rounds, difficulty, language, sound). */
.seg {
  display: inline-flex;
  gap: calc(var(--s) * 8px);
}

.seg.wrap {
  flex-wrap: wrap;
}

.seg-btn {
  font-family: var(--display);
  font-weight: 400;
  font-size: calc(var(--s) * 18px);
  text-transform: uppercase;
  color: var(--cream);
  background: transparent;
  border: calc(var(--s) * 3px) solid var(--cream);
  border-radius: calc(var(--s) * 12px);
  padding: calc(var(--s) * 6px) calc(var(--s) * 16px);
  cursor: pointer;
  outline: none;
  transition: background 0.1s, color 0.1s, transform 0.08s;
}

.seg-btn:hover,
.seg-btn:focus-visible {
  transform: translateY(calc(var(--s) * -2px));
  background: rgba(255, 255, 255, 0.12);
}

.seg-btn.on {
  background: var(--yellow);
  border-color: var(--yellow);
  color: var(--ink);
}

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

.panel {
  background: var(--ink);
  border: calc(var(--s) * 5px) solid var(--cream);
  border-radius: calc(var(--s) * 24px);
  box-shadow: calc(var(--s) * 10px) calc(var(--s) * 10px) 0 var(--pink);
  padding: calc(var(--s) * 30px) calc(var(--s) * 44px);
  text-align: center;
}

.menu-panel {
  min-width: calc(var(--s) * 460px);
}

.menu-panel h2 {
  margin-bottom: calc(var(--s) * 22px);
}

/* ----------------------------------------------------------------- title */

#screen-title {
  flex-direction: column;
  justify-content: flex-start;
  padding-top: calc(var(--s) * 28px);
}

.title-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
}

.jp-pill {
  font-family: var(--display);
  font-size: calc(var(--s) * 20px);
  color: var(--yellow);
  background: var(--ink);
  border-radius: 999px;
  padding: calc(var(--s) * 6px) calc(var(--s) * 26px);
  letter-spacing: 0.1em;
}

.logo {
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 0.86;
  font-family: var(--display);
  font-weight: 400;
  font-size: calc(var(--s) * 150px);
  margin-top: calc(var(--s) * 6px);
  transform: rotate(-3deg);
  letter-spacing: -0.01em;
}

.logo-a,
.logo-b {
  -webkit-text-stroke: calc(var(--s) * 7px) var(--ink);
  paint-order: stroke fill;
  text-shadow: calc(var(--s) * 10px) calc(var(--s) * 10px) 0 var(--ink);
}

.logo-a {
  color: var(--yellow);
}

.logo-b {
  color: #fff;
  font-size: 0.92em;
}

.badge {
  position: absolute;
  /* Outside the logo's right edge so it never covers a letter. */
  top: calc(var(--s) * 40px);
  right: calc(var(--s) * -178px);
  width: calc(var(--s) * 150px);
  height: calc(var(--s) * 150px);
  border-radius: 50%;
  background: var(--yellow);
  border: calc(var(--s) * 6px) solid var(--ink);
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-family: var(--display);
  font-size: calc(var(--s) * 22px);
  line-height: 1.05;
  color: var(--ink);
  padding: calc(var(--s) * 10px);
  /* The texts carry their own line breaks ("100 / MINI / GAMES!"). */
  white-space: pre-line;
  transform: rotate(10deg);
  animation: badge-wobble 2.4s ease-in-out infinite;
}

.free-sticker {
  position: absolute;
  /* Under the badge, tilted the same way: what the "100" means for now. */
  top: calc(var(--s) * 202px);
  right: calc(var(--s) * -178px);
  width: calc(var(--s) * 150px);
  font-family: var(--display);
  font-weight: 400;
  font-size: calc(var(--s) * 16px);
  line-height: 1.15;
  letter-spacing: 0.02em;
  text-align: center;
  /* Exactly the two lines of the text; Game.fitTitle shrinks a long one. */
  white-space: pre;
  overflow: hidden;
  color: #fff;
  background: var(--pink);
  border: calc(var(--s) * 4px) solid var(--ink);
  border-radius: calc(var(--s) * 12px);
  box-shadow: calc(var(--s) * 4px) calc(var(--s) * 4px) 0 var(--ink);
  padding: calc(var(--s) * 7px) calc(var(--s) * 8px);
  transform: rotate(6deg);
  cursor: pointer;
  outline: none;
  transition: transform 0.1s, box-shadow 0.1s;
}

.free-sticker:hover,
.free-sticker:focus-visible {
  transform: rotate(4deg) scale(1.06);
  box-shadow: calc(var(--s) * 6px) calc(var(--s) * 6px) 0 var(--ink), 0 0 0 calc(var(--s) * 4px) rgba(255, 255, 255, 0.55);
}

.free-sticker:active {
  transform: rotate(6deg) translate(calc(var(--s) * 3px), calc(var(--s) * 3px));
  box-shadow: calc(var(--s) * 1px) calc(var(--s) * 1px) 0 var(--ink);
}

@keyframes badge-wobble {
  0%, 100% { transform: rotate(8deg) scale(1); }
  50% { transform: rotate(14deg) scale(1.06); }
}

#screen-title .menu {
  margin-top: calc(var(--s) * 18px);
  gap: calc(var(--s) * 12px);
}

#screen-title .btn {
  min-width: calc(var(--s) * 340px);
  border-radius: calc(var(--s) * 14px);
}

#screen-title .row-inline .btn.cream {
  min-width: calc(var(--s) * 200px);
  padding-left: calc(var(--s) * 22px);
  padding-right: calc(var(--s) * 22px);
}

#screen-title .row-inline .btn.icon {
  min-width: 0;
  padding-left: calc(var(--s) * 16px);
  padding-right: calc(var(--s) * 16px);
}

.btn svg.cog {
  fill: var(--ink);
  stroke: none;
  transition: transform 0.3s ease;
}

.btn:hover svg.cog,
.btn:focus svg.cog {
  transform: rotate(45deg);
}

.stats-btn svg {
  width: calc(var(--s) * 28px);
  height: calc(var(--s) * 28px);
  flex-shrink: 0;
  fill: none;
  stroke: var(--ink);
  stroke-width: 2.2;
  stroke-linecap: round;
}

.stats-btn svg .solid {
  fill: var(--yellow);
  stroke: var(--ink);
  stroke-width: 1.6;
  stroke-linejoin: round;
}

.press {
  margin-top: calc(var(--s) * 26px);
  font-family: var(--display);
  font-size: calc(var(--s) * 20px);
  letter-spacing: 0.14em;
  color: var(--yellow);
  animation: blink 1.4s steps(2, start) infinite;
}

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

.version {
  position: absolute;
  right: calc(var(--s) * 18px);
  bottom: calc(var(--s) * 10px);
  font-size: calc(var(--s) * 12px);
  color: rgba(255, 246, 224, 0.6);
}

/* ------------------------------------------------------- character select */

#screen-setup,
#screen-practice,
#screen-online {
  flex-direction: column;
  justify-content: flex-start;
  align-items: stretch;
  padding: 0 calc(var(--s) * 36px);
}

.setup-head {
  display: flex;
  align-items: baseline;
  white-space: nowrap;
  gap: calc(var(--s) * 22px);
  height: calc(var(--s) * 100px);
  padding-top: calc(var(--s) * 10px);
  background: var(--ink);
  margin: 0 calc(var(--s) * -36px);
  padding-left: calc(var(--s) * 48px);
  padding-right: calc(var(--s) * 48px);
  clip-path: polygon(0 0, 100% 0, 100% 78%, 0 100%);
}

.setup-head .jp {
  font-family: var(--display);
  font-size: calc(var(--s) * 18px);
  color: var(--cream);
  letter-spacing: 0.2em;
}

.setup-head h2 {
  font-size: calc(var(--s) * 42px);
  flex-shrink: 0;
}

.setup-head .hint {
  margin-left: auto;
  margin-right: calc(var(--s) * 130px);
  font-family: var(--display);
  font-size: calc(var(--s) * 15px);
  color: var(--cream);
  letter-spacing: 0.04em;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

.cards {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: calc(var(--s) * 22px);
  margin-top: calc(var(--s) * 12px);
  flex: 1;
  min-height: 0;
}

.card {
  display: flex;
  flex-direction: column;
  background: var(--cream);
  border: calc(var(--s) * 5px) solid var(--ink);
  border-radius: calc(var(--s) * 22px);
  box-shadow: calc(var(--s) * 8px) calc(var(--s) * 8px) 0 var(--ink);
  overflow: hidden;
  color: var(--ink);
  transition: transform 0.12s, box-shadow 0.12s;
}

.card.off {
  opacity: 0.6;
}

.card.ready {
  box-shadow: calc(var(--s) * 8px) calc(var(--s) * 8px) 0 var(--ink), 0 0 0 calc(var(--s) * 5px) var(--yellow);
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(var(--s) * 10px) calc(var(--s) * 16px);
  border-bottom: calc(var(--s) * 5px) solid var(--ink);
  background: var(--pc);
}

.card-head .pn {
  font-family: var(--display);
  font-size: calc(var(--s) * 34px);
  line-height: 1;
}

.tag {
  font-family: var(--body);
  font-weight: 900;
  font-size: calc(var(--s) * 15px);
  color: var(--cream);
  background: var(--ink);
  border: none;
  border-radius: 999px;
  padding: calc(var(--s) * 5px) calc(var(--s) * 14px);
  cursor: pointer;
  outline: none;
  letter-spacing: 0.04em;
}

.tag:hover,
.tag:focus-visible {
  background: var(--navy);
  box-shadow: 0 0 0 calc(var(--s) * 3px) rgba(255, 255, 255, 0.6);
}

.card-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: calc(var(--s) * 8px) calc(var(--s) * 16px) calc(var(--s) * 14px);
  min-height: 0;
}

.portrait {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1;
  min-height: calc(var(--s) * 150px);
}

.portrait canvas {
  width: calc(var(--s) * 190px);
  height: calc(var(--s) * 190px);
  max-width: 100%;
}

.arrow {
  position: absolute;
  top: 50%;
  width: calc(var(--s) * 40px);
  height: calc(var(--s) * 40px);
  margin-top: calc(var(--s) * -20px);
  border: calc(var(--s) * 4px) solid var(--ink);
  border-radius: 50%;
  background: var(--yellow);
  cursor: pointer;
  outline: none;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: transform 0.08s;
}

.arrow:hover,
.arrow:focus-visible {
  transform: scale(1.12);
}

.arrow.left { left: 0; }
.arrow.right { right: 0; }

.arrow svg {
  width: 60%;
  height: 60%;
  fill: none;
  stroke: var(--ink);
  stroke-width: 3.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.card-name {
  font-family: var(--display);
  font-size: calc(var(--s) * 32px);
  line-height: 1;
}

/* Player name on a human card; empty shows the placeholder. */
.name-input {
  display: block;
  width: 100%;
  box-sizing: border-box;
  font-family: var(--display);
  font-size: calc(var(--s) * 20px);
  line-height: 1.2;
  color: var(--ink);
  background: #fff;
  border: calc(var(--s) * 3px) dashed var(--ink);
  border-radius: calc(var(--s) * 12px);
  padding: calc(var(--s) * 5px) calc(var(--s) * 10px);
  margin-bottom: calc(var(--s) * 8px);
  outline: none;
}

.name-input::placeholder {
  color: rgba(26, 16, 51, 0.4);
}

.name-input:focus {
  border-style: solid;
  box-shadow: 0 0 0 calc(var(--s) * 4px) var(--pc);
}

.card-blurb {
  font-size: calc(var(--s) * 15px);
  line-height: 1.35;
  margin-top: calc(var(--s) * 6px);
  min-height: calc(var(--s) * 60px);
}

.card-foot {
  display: flex;
  gap: calc(var(--s) * 8px);
  margin-top: calc(var(--s) * 10px);
}

.chip {
  flex: 1;
  font-family: var(--body);
  font-weight: 900;
  font-size: calc(var(--s) * 12px);
  color: var(--ink);
  background: #fff;
  border: calc(var(--s) * 3px) solid var(--ink);
  border-radius: calc(var(--s) * 12px);
  padding: calc(var(--s) * 8px) calc(var(--s) * 2px);
  text-align: center;
  cursor: pointer;
  outline: none;
  letter-spacing: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: transform 0.08s;
}

.chip:hover,
.chip:focus-visible {
  transform: translateY(calc(var(--s) * -2px));
}

.chip.on {
  background: var(--ink);
  color: var(--cream);
}

.chip.ready {
  background: var(--yellow);
}

.chip.keys {
  cursor: default;
  font-size: calc(var(--s) * 13px);
}

/* The controls chip on a human card: click to cycle keyboard sets and pads. */
.chip.keys.pick {
  cursor: pointer;
  border-style: dashed;
  /* "← · → · ENTER + PAD 2" wraps instead of being cut off. */
  white-space: normal;
  line-height: 1.15;
  padding-top: calc(var(--s) * 4px);
  padding-bottom: calc(var(--s) * 4px);
}

.chip.keys.pick:hover,
.chip.keys.pick:focus-visible {
  border-style: solid;
  background: var(--cream);
}

.setup-foot {
  display: flex;
  align-items: center;
  gap: calc(var(--s) * 24px);
  height: calc(var(--s) * 110px);
  padding-bottom: calc(var(--s) * 10px);
}

.rounds-box {
  display: flex;
  align-items: center;
  gap: calc(var(--s) * 16px);
  background: var(--ink);
  border-radius: calc(var(--s) * 18px);
  padding: calc(var(--s) * 12px) calc(var(--s) * 22px);
  font-family: var(--display);
  font-size: calc(var(--s) * 24px);
  color: var(--cream);
}

/* Rounds and heats share one box: tighter buttons keep START on screen. */
.setup-foot .rounds-box {
  gap: calc(var(--s) * 12px);
  padding-left: calc(var(--s) * 18px);
  padding-right: calc(var(--s) * 18px);
}

.setup-foot .rounds-box .seg {
  gap: calc(var(--s) * 6px);
}

.setup-foot .rounds-box .seg-btn {
  padding-left: calc(var(--s) * 12px);
  padding-right: calc(var(--s) * 12px);
}

html.compact .setup-foot .rounds-box {
  padding-left: 10px;
  padding-right: 10px;
  gap: 6px;
}

.rounds-box .box-sep {
  align-self: stretch;
  width: calc(var(--s) * 3px);
  border-radius: 2px;
  background: rgba(255, 246, 224, 0.25);
}

#btn-phones,
#btn-start,
#btn-online-start {
  flex-shrink: 0;
}

/* START is as wide as its label (BM.fitRow shrinks a long one). */
.setup-foot #btn-start,
.setup-foot #btn-online-start {
  min-width: 0;
  padding-left: calc(var(--s) * 30px);
  padding-right: calc(var(--s) * 30px);
}

.setup-foot .note {
  flex: 1;
  min-width: 0;
  color: var(--ink);
  font-size: calc(var(--s) * 15px);
  line-height: 1.3;
  /* Never taller than the footer, however narrow it gets. */
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 4;
  overflow: hidden;
}

#screen-setup {
  background: linear-gradient(-55deg, #2f7bff 0 24px, #4a8dff 24px 48px);
  background-size: calc(var(--s) * 68px) calc(var(--s) * 68px);
}

#screen-practice {
  background: linear-gradient(-55deg, #ff5fa2 0 24px, #f23e8a 24px 48px);
  background-size: calc(var(--s) * 68px) calc(var(--s) * 68px);
}

/* ----------------------------------------------------------- practice */

.cards.practice {
  grid-template-columns: repeat(auto-fill, minmax(min(100%, calc(var(--s) * 260px)), 1fr));
  align-content: start;
  overflow-x: hidden;
  overflow-y: auto;
  /* Room for the card shadows on the right and at the bottom. */
  padding: 0 calc(var(--s) * 10px) calc(var(--s) * 12px) 0;
}

.gcard {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: calc(var(--s) * 6px);
  background: var(--cream);
  border: calc(var(--s) * 5px) solid var(--ink);
  border-radius: calc(var(--s) * 22px);
  box-shadow: calc(var(--s) * 8px) calc(var(--s) * 8px) 0 var(--ink);
  padding: calc(var(--s) * 14px);
  color: var(--ink);
  cursor: pointer;
  outline: none;
  text-align: center;
  transition: transform 0.1s, box-shadow 0.1s;
  font-family: var(--body);
  font-weight: 800;
}

.gcard:hover,
.gcard:focus-visible {
  transform: translate(calc(var(--s) * -3px), calc(var(--s) * -3px));
  box-shadow: calc(var(--s) * 11px) calc(var(--s) * 11px) 0 var(--ink), 0 0 0 calc(var(--s) * 5px) var(--yellow);
}

.gcard canvas {
  width: calc(var(--s) * 180px);
  height: calc(var(--s) * 120px);
}

.gcard {
  min-width: 0;
}

/* Names wrap between words; a single word too long for the card is shrunk by UI.fitPracticeNames. */
.gcard .gname {
  font-family: var(--display);
  font-size: calc(var(--s) * 24px);
  line-height: 1.05;
  max-width: 100%;
  overflow-wrap: normal;
  word-break: keep-all;
}

.gcard .gbest {
  font-size: calc(var(--s) * 14px);
  color: rgba(26, 16, 51, 0.7);
}

/* ------------------------------------------------------------ settings */

.settings-panel {
  width: calc(var(--s) * 1100px);
  max-height: calc(var(--s) * 680px);
  overflow-y: auto;
  text-align: left;
}

.settings-panel h2 {
  text-align: center;
}

.settings-grid {
  display: grid;
  grid-template-columns: 1fr 1.3fr;
  gap: calc(var(--s) * 40px);
}

.controls {
  border-collapse: separate;
  border-spacing: calc(var(--s) * 6px);
  width: 100%;
}

.controls th {
  font-family: var(--display);
  font-weight: 400;
  font-size: calc(var(--s) * 14px);
  color: rgba(255, 246, 224, 0.7);
  text-align: left;
  padding: 0 calc(var(--s) * 6px);
}

.controls td.pl {
  font-family: var(--display);
  font-size: calc(var(--s) * 18px);
  color: var(--pc);
  white-space: nowrap;
}

.key {
  font-family: var(--display);
  font-weight: 400;
  font-size: calc(var(--s) * 16px);
  color: var(--ink);
  background: var(--cream);
  border: calc(var(--s) * 3px) solid var(--ink);
  border-radius: calc(var(--s) * 10px);
  box-shadow: 0 calc(var(--s) * 4px) 0 var(--ink);
  padding: calc(var(--s) * 6px) calc(var(--s) * 14px);
  min-width: calc(var(--s) * 110px);
  cursor: pointer;
  outline: none;
  width: 100%;
}

.key:hover,
.key:focus-visible {
  background: var(--yellow);
}

.key.waiting {
  background: var(--pink);
  color: #fff;
  animation: blink 0.8s steps(2, start) infinite;
}

/* --------------------------------------------------------------- stats */

.stats-panel {
  width: calc(var(--s) * 1080px);
  max-height: calc(var(--s) * 680px);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: calc(var(--s) * 14px);
}

.stats-head {
  display: flex;
  align-items: baseline;
  gap: calc(var(--s) * 18px);
}

.stats-head .jp {
  font-family: var(--display);
  font-size: calc(var(--s) * 18px);
  color: var(--cream);
  letter-spacing: 0.2em;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: calc(var(--s) * 14px);
  width: 100%;
}

.stat-tile {
  --tc: var(--yellow);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: calc(var(--s) * 6px);
  min-width: 0;
  min-height: calc(var(--s) * 116px);
  padding: calc(var(--s) * 12px) calc(var(--s) * 10px);
  background: var(--navy);
  border: calc(var(--s) * 4px) solid var(--tc);
  border-radius: calc(var(--s) * 18px);
  box-shadow: calc(var(--s) * 5px) calc(var(--s) * 5px) 0 var(--tc);
}

.stat-tile b {
  display: block;
  max-width: 100%;
  font-family: var(--display);
  font-weight: 400;
  font-size: calc(var(--s) * 40px);
  line-height: 1.05;
  color: var(--tc);
  white-space: nowrap;
  overflow: hidden;
}

.stat-tile.text b {
  font-size: calc(var(--s) * 26px);
}

.stat-tile span {
  font-size: calc(var(--s) * 15px);
  font-weight: 800;
  line-height: 1.2;
  color: var(--cream);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.stat-tile.pink { --tc: var(--pink); }
.stat-tile.blue { --tc: #5C9BFF; }
.stat-tile.green { --tc: var(--green); }
.stat-tile.red { --tc: var(--red); }
.stat-tile.cream { --tc: var(--cream); }

.stats-panel .row-inline {
  align-items: center;
}

#stats-msg:empty {
  display: none;
}

html.compact .stats-panel {
  gap: 8px;
  padding: 14px 18px;
}

html.compact .stats-grid {
  gap: 8px;
}

html.compact .stat-tile {
  min-height: 0;
  padding: 6px;
}

html.compact .stat-tile b {
  font-size: max(18px, calc(var(--s) * 40px));
}

html.compact .stat-tile.text b {
  font-size: max(14px, calc(var(--s) * 26px));
}

html.compact .stat-tile span {
  font-size: max(10px, calc(var(--s) * 15px));
}

/* ------------------------------------------------------------- confirm */

.confirm-panel {
  max-width: calc(var(--s) * 860px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: calc(var(--s) * 16px);
}

.confirm-panel h2 {
  margin-bottom: 0;
  font-size: calc(var(--s) * 44px);
}

.confirm-panel .note {
  font-size: calc(var(--s) * 18px);
  max-width: calc(var(--s) * 560px);
}

.confirm-panel .btn {
  min-width: calc(var(--s) * 260px);
  white-space: nowrap;
}

/* Arabic and other right-to-left languages. */
[dir='rtl'] .setup-head .hint {
  margin-left: 0;
  margin-right: auto;
  text-align: left;
}

[dir='rtl'] .btn.corner {
  right: auto;
  left: calc(var(--s) * 24px);
}

[dir='rtl'] .controls th,
[dir='rtl'] .settings-panel {
  text-align: right;
}

/* ------------------------------------------------------ touch controls */
/* Zones are generated per round by js/core/touch.js and cover the stage. */

#touch {
  display: none;
  position: fixed;
  pointer-events: none;
  z-index: 5;
}

html.touch[data-mode='playing'] #touch {
  display: block;
}

/* The instruction card is dismissed by a tap anywhere: no buttons over it. */
html.touch[data-mode='playing'].intro #touch {
  display: none;
}

/* One player: the layer covers the window, the buttons sit in the bottom
   corners that Game.resize keeps free of the stage (CORNER_W x CORNER_H). */
#touch.solo .tz-row {
  bottom: max(10px, env(safe-area-inset-bottom));
  padding: 0 max(12px, env(safe-area-inset-right)) 0 max(12px, env(safe-area-inset-left));
}

#touch.solo .tz-btn {
  width: 54px;
  height: 54px;
}

#touch.solo .tz-btn.tz-action,
#touch.solo .tz-tap b {
  width: 68px;
  height: 68px;
}

#touch.solo .tz-action {
  padding: 0 max(12px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) 0;
}

#touch.solo .tz-tap i {
  display: none;
}

.tz {
  position: absolute;
  pointer-events: auto;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

.tz-action {
  display: flex;
  align-items: flex-end;
  justify-content: flex-end;
  padding: 0 4% 4%;
}

.tz.tz-action.pressed {
  background: radial-gradient(circle at 88% 80%, rgba(255, 255, 255, 0.22), rgba(255, 255, 255, 0) 45%);
}

/* ACTION-only games: the whole zone reacts, the visible button sits where
   ACTION always is (bottom right, like in the LEFT/RIGHT + ACTION games). */
.tz-tap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  pointer-events: none;
  opacity: 0.85;
  transition: transform 0.08s, opacity 0.08s;
}

.tz-tap b {
  display: block;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--pc);
  border: 4px solid var(--ink);
  box-shadow: 0 6px 0 var(--ink);
}

.tz-tap i {
  font-style: normal;
  font-family: var(--display);
  font-size: 14px;
  color: var(--cream);
  letter-spacing: 0.1em;
  text-shadow: 0 2px 0 var(--ink);
}

.tz.pressed .tz-tap {
  transform: scale(0.9) translateY(4px);
  opacity: 1;
}

.tz.pressed .tz-tap b {
  box-shadow: 0 2px 0 var(--ink);
}

.tz-row {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 4%;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  padding: 0 4%;
  pointer-events: none;
}

.tz-flip .tz-row {
  bottom: auto;
  top: 4%;
  transform: rotate(180deg);
}

.tz-flip.tz-action {
  align-items: flex-start;
  justify-content: flex-start;
  padding: 4% 4% 0;
}

.tz-flip .tz-tap {
  transform: rotate(180deg);
}

.tz-pad {
  display: flex;
  gap: 6px;
  pointer-events: auto;
  touch-action: none;
}

.tz-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 60px;
  height: 60px;
  border-radius: 18px;
  background: rgba(255, 246, 224, 0.18);
  border: 3px solid rgba(255, 246, 224, 0.55);
  color: var(--cream);
  transition: background 0.08s, transform 0.08s;
}

.tz-btn svg {
  width: 48%;
  height: 48%;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.tz-btn.pressed {
  background: rgba(255, 246, 224, 0.5);
  transform: scale(0.94);
}

.tz-btn.tz-action {
  width: 76px;
  height: 76px;
  border-radius: 50%;
  background: var(--pc);
  border-color: var(--ink);
  box-shadow: 0 6px 0 var(--ink);
  pointer-events: auto;
  touch-action: none;
  padding: 0;
}

.tz-btn.tz-action.pressed {
  box-shadow: 0 2px 0 var(--ink);
  transform: translateY(4px);
}

/* Phones: the katakana subtitle gives its room to the hint, and the setup
   note (long, squeezed between the buttons) only shows when it is a warning. */
html.compact .setup-head .jp,
html.compact .setup-foot .note:not(.warn) {
  display: none;
}

.chip.lvl-one,
html.compact .chip.lvl-full {
  display: none;
}

html.compact .chip.lvl-one {
  display: block;
}

#btn-start {
  white-space: nowrap;
}

html.compact .setup-foot {
  gap: 10px;
}

html.compact .setup-head .hint {
  white-space: normal;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  font-size: 10.5px;
  line-height: 1.2;
  align-self: center;
}

.tag .cycle,
.chip .cycle {
  width: 1.05em;
  height: 1.05em;
  margin-inline-start: 0.35em;
  vertical-align: -0.18em;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

html.compact .setup-head .hint {
  /* The corner button keeps its readable size on phones, so leave it real pixels. */
  margin-right: 150px;
}

html.touch .press,
html.touch .setup-head .hint {
  letter-spacing: 0.06em;
}

#safe-probe {
  position: fixed;
  visibility: hidden;
  pointer-events: none;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

/* ------------------------------------------------------ portrait warning */

#rotate {
  display: none;
}

@media (orientation: portrait) and (max-width: 700px) {
  html.touch #rotate {
    display: flex;
    position: fixed;
    inset: 0;
    z-index: 20;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 22px;
    padding: 32px;
    text-align: center;
    background: var(--ink);
    color: var(--cream);
    font-size: 17px;
  }
}

.rotate-phone {
  width: 46px;
  height: 80px;
  border: 4px solid var(--yellow);
  border-radius: 10px;
  animation: rotate-hint 2.2s ease-in-out infinite;
}

@keyframes rotate-hint {
  0%, 25% { transform: rotate(0); }
  60%, 100% { transform: rotate(-90deg); }
}

/* ------------------------------------------------------- small screens */
/* Phones: keep buttons tappable and texts readable when --s is small. */

html.compact .btn {
  min-height: 40px;
  font-size: max(15px, calc(var(--s) * 26px));
}

html.compact .btn.big {
  font-size: max(20px, calc(var(--s) * 40px));
}

html.compact .seg-btn,
html.compact .chip,
html.compact .tag {
  font-size: max(12px, calc(var(--s) * 15px));
  min-height: 32px;
}

html.compact .card-blurb {
  display: none;
}

html.compact .note {
  font-size: max(11px, calc(var(--s) * 14px));
}

html.compact .press {
  font-size: max(13px, calc(var(--s) * 20px));
}

/* ---------------------------------------------------------- phone lobby */

.lobby-panel {
  width: calc(var(--s) * 980px);
  text-align: left;
}

.lobby-panel h2 {
  text-align: center;
  margin-bottom: calc(var(--s) * 16px);
}

.lobby-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: calc(var(--s) * 32px);
  align-items: start;
}

#lobby-qr {
  width: calc(var(--s) * 360px);
  height: calc(var(--s) * 360px);
  border-radius: calc(var(--s) * 16px);
  border: calc(var(--s) * 5px) solid var(--cream);
  background: #fff;
  image-rendering: pixelated;
}

.lobby-url {
  font-family: var(--display);
  font-size: calc(var(--s) * 20px);
  color: var(--cyan);
  overflow-wrap: anywhere;
  margin: calc(var(--s) * 4px) 0 calc(var(--s) * 14px);
}

.lobby-code {
  font-family: var(--display);
  font-size: calc(var(--s) * 64px);
  letter-spacing: 0.2em;
  color: var(--yellow);
  line-height: 1;
  margin: calc(var(--s) * 4px) 0 calc(var(--s) * 14px);
}

.lobby-phones {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: calc(var(--s) * 8px);
}

.lobby-phones li {
  font-family: var(--display);
  font-size: calc(var(--s) * 16px);
  color: var(--ink);
  background: var(--pc, var(--cream));
  border: calc(var(--s) * 3px) solid var(--ink);
  border-radius: 999px;
  padding: calc(var(--s) * 6px) calc(var(--s) * 14px);
}

.tag.phone {
  background: var(--cyan);
  color: var(--ink);
}

#btn-phones {
  display: none;
}

html.net #btn-phones {
  display: inline-flex;
}

/* ------------------------------------------------------------ online play */

#screen-online {
  background: linear-gradient(-55deg, #2f7bff 0 24px, #4a8dff 24px 48px);
  background-size: calc(var(--s) * 68px) calc(var(--s) * 68px);
}

#btn-online {
  display: none;
}

html.online #btn-online {
  display: inline-flex;
}

.online-entry,
.online-room {
  display: none;
  flex: 1;
  min-height: 0;
  flex-direction: column;
}

.online-entry.on,
.online-room.on {
  display: flex;
}

.online-entry {
  align-items: center;
  justify-content: center;
}

.online-door {
  width: calc(var(--s) * 620px);
  text-align: center;
}

.online-door .note {
  margin: calc(var(--s) * 8px) 0;
}

.online-or {
  font-family: var(--display);
  color: var(--yellow);
}

.online-join {
  justify-content: center;
  align-items: stretch;
}

.code-input {
  width: calc(var(--s) * 220px);
  font-family: var(--display);
  font-size: calc(var(--s) * 40px);
  letter-spacing: 0.2em;
  text-align: center;
  text-transform: uppercase;
  color: var(--ink);
  background: #fff;
  border: calc(var(--s) * 5px) solid var(--ink);
  border-radius: calc(var(--s) * 18px);
  padding: 0 calc(var(--s) * 12px);
  outline: none;
}

.code-input:focus {
  box-shadow: 0 0 0 calc(var(--s) * 4px) var(--yellow);
}

.online-codebar {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: calc(var(--s) * 18px);
  margin-top: calc(var(--s) * 4px);
}

.online-codebar .lobby-code {
  font-size: calc(var(--s) * 48px);
  margin: 0;
}

.card.mine {
  box-shadow: calc(var(--s) * 8px) calc(var(--s) * 8px) 0 var(--ink), 0 0 0 calc(var(--s) * 5px) var(--cyan);
}

.card.mine.ready {
  box-shadow: calc(var(--s) * 8px) calc(var(--s) * 8px) 0 var(--ink), 0 0 0 calc(var(--s) * 5px) var(--yellow);
}

.tag.peer {
  background: var(--blue);
  color: #fff;
}

.tag:disabled {
  cursor: default;
}

.tag:disabled:hover {
  background: var(--ink);
  box-shadow: none;
}

.tag.peer:disabled:hover {
  background: var(--blue);
}

#net-wait {
  display: none;
  position: fixed;
  left: 50%;
  top: 14%;
  transform: translateX(-50%);
  z-index: 6;
  pointer-events: none;
}

#net-wait.on {
  display: block;
}

#net-wait span {
  display: inline-block;
  white-space: nowrap;
  font-family: var(--display);
  font-size: calc(var(--s) * 26px);
  color: var(--ink);
  background: var(--yellow);
  border: calc(var(--s) * 5px) solid var(--ink);
  border-radius: 999px;
  padding: calc(var(--s) * 10px) calc(var(--s) * 28px);
  box-shadow: calc(var(--s) * 6px) calc(var(--s) * 6px) 0 var(--ink);
  animation: net-wait-pulse 0.9s ease-in-out infinite alternate;
}

@keyframes net-wait-pulse {
  from { transform: scale(1); }
  to { transform: scale(1.05); }
}

html.compact .online-door {
  width: min(92vw, calc(var(--s) * 620px));
}

html.compact .code-input {
  font-size: max(22px, calc(var(--s) * 40px));
  min-height: 44px;
}

/* Full-game unlock: the catalog remains browseable while paid games are locked. */
.gcard.locked { position: relative; }
.gcard.locked canvas { opacity: .55; }
.gcard.locked .gbest { color: var(--pink); font-weight: 900; }
.unlock-panel { max-width: 820px; max-height: 90%; overflow-y: auto; display: flex; flex-direction: column; gap: 16px; }
.unlock-panel .row-inline { flex-wrap: wrap; justify-content: center; gap: 12px; }
.unlock-panel .note { margin: 0; }
.practice-bar { display: flex; align-items: center; justify-content: space-between; gap: calc(var(--s) * 16px); margin-bottom: 8px; }
.practice-bar .rounds-box { gap: calc(var(--s) * 12px); padding-top: calc(var(--s) * 8px); padding-bottom: calc(var(--s) * 8px); }
/* The full game is owned: no more "unlock all games" buttons anywhere. */
html.unlocked [data-action='unlock'] { display: none !important; }

/* Practice seats: P1 is you, P2-P4 cycle CPU / player / off. */
.seg-btn.seat { white-space: nowrap; }
.seg-btn.seat i { font-style: normal; opacity: .7; }
.seg-btn.seat.on { background: var(--pc); color: var(--ink); border-color: var(--ink); }
.seg-btn.seat:disabled { opacity: 1; cursor: default; }
button:disabled { cursor: default; opacity: .55; }

/* "Play on a TV" (title button and help panel, only in the apps). */
#btn-tv { display: none; }
html.app-ios #btn-tv,
html.app-android #btn-tv { display: inline-flex; }
html.tv #btn-tv { display: none; }
.tv-panel { max-width: 860px; max-height: 90%; overflow-y: auto; display: flex; flex-direction: column; gap: 14px; }
.tv-panel .note { margin: 0; }
.tv-steps { margin: 0; padding-inline-start: 1.6em; text-align: start; font-size: 1.15em; line-height: 1.4; }
.tv-steps li { margin: 6px 0; }
.tv-steps li::marker { font-family: var(--display); color: var(--pink); }
.tv-panel .for-ios,
.tv-panel .for-android { display: none; }
html.app-ios .tv-panel li.for-ios,
html.app-android .tv-panel li.for-android { display: list-item; }
html.app-ios .tv-panel p.for-ios { display: block; }
