/* SPDX-License-Identifier: GPL-3.0-or-later */
/*
 * Game page of DENY BY DEFAULT.
 * Colors come from ss-tokens.css. Field is black, text is white.
 * Red is for fills and for the focus ring. Red is never the color of text.
 * Every shape that uses red also has a text label.
 */

:root {
  color-scheme: dark;
  --pb-field: var(--ss-brand-field, #000000);
  --pb-edge: var(--ss-brand-edge, #ffffff);
  --pb-mark: var(--ss-brand, #ff0000);
  --pb-track: #333333;
  --pb-dim: rgba(255, 255, 255, 0.4);
  --pb-touch: 44px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  height: 100%;
  margin: 0;
  background: var(--pb-field);
  color: var(--pb-edge);
  font-family: var(--ss-font-ui, system-ui, sans-serif);
  font-size: var(--ss-fs-md, 16px);
  line-height: 1.4;
}

body {
  overscroll-behavior: none;
}

a {
  color: var(--pb-edge);
  text-decoration: underline;
}

/* Focus: a 3 px ring in the mark color with a 1 px white line outside it. */
:focus-visible {
  outline: 3px solid var(--ss-focus-ring, #ff0000);
  outline-offset: 0;
  box-shadow: 0 0 0 4px var(--pb-edge);
}

/*
 * The stage takes the focus after a dialog closes, so the keys go to the table. It is not a
 * control: it shows no ring and no white band during play. Controls keep the red ring above.
 */
.stage:focus,
.stage:focus-visible {
  outline: none;
  box-shadow: none;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.skip {
  position: absolute;
  left: 8px;
  top: -64px;
  padding: 12px 16px;
  background: var(--pb-field);
  border: 2px solid var(--pb-edge);
  z-index: 50;
}

.skip:focus {
  top: 8px;
}

.shell {
  display: grid;
  grid-template-rows: auto 1fr auto;
  height: 100%;
  height: 100dvh;
}

.bar {
  position: relative;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--pb-dim);
}

.title {
  margin: 0;
  font-size: var(--ss-fs-lg, 20px);
  letter-spacing: 0.04em;
}

.tools {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

/* The items of the menu show in the row. The Menu button shows on a phone only (see below). */
.menu-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.btn.menu-toggle {
  display: none;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: var(--pb-touch);
  min-height: var(--pb-touch);
  padding: 8px 16px;
  background: var(--pb-field);
  color: var(--pb-edge);
  border: 2px solid var(--pb-edge);
  border-radius: var(--ss-radius-md, 8px);
  font: inherit;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
}

.btn:hover {
  background: #1a1a1a;
}

/* The primary button is a red fill with black text (5:1 contrast). */
.btn.primary {
  background: var(--pb-mark);
  color: var(--ss-brand-on, #000000);
  border-color: var(--pb-edge);
}

.btn.primary:hover {
  background: var(--pb-mark);
  filter: brightness(1.1);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/*
 * The stage is a column: the HUD first, then the playfield. The playfield starts below the HUD,
 * so the HUD never covers the table.
 */
.stage {
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.playfield {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
}

.table {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.hud {
  position: relative;
  flex: none;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 12px;
  background: rgba(0, 0, 0, 0.78);
  border-bottom: 1px solid var(--pb-dim);
  pointer-events: none;
}

.hud p {
  margin: 0;
}

.hud-label {
  font-size: var(--ss-fs-xs, 12px);
  letter-spacing: 0.08em;
}

.hud-score {
  font-size: 28px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.hud-line {
  font-size: var(--ss-fs-sm, 14px);
  font-weight: 700;
}

.hud-side {
  min-width: 0;
  text-align: right;
}

.hud-mode {
  font-size: var(--ss-fs-sm, 14px);
  font-weight: 700;
}

.hud-small {
  font-size: var(--ss-fs-xs, 12px);
  font-variant-numeric: tabular-nums;
}

.hud-timer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

/* A bar: a dark track, a white edge, a red fill. The number sits beside it. */
.bar-track {
  --bar: 0%;
  position: relative;
  width: 120px;
  height: 10px;
  background: var(--pb-track);
  border: 1px solid var(--pb-edge);
}

.bar-track::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: var(--bar);
  background: var(--pb-mark);
}

/* The plunger power bar: a label, a dark track, a white edge, a red fill. It sits in a corner of the playfield. */
.power {
  position: absolute;
  top: 8px;
  right: 8px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 8px;
  background: rgba(0, 0, 0, 0.78);
  border: 1px solid var(--pb-dim);
  pointer-events: none;
}

/* The callout is plain white text on black. It never uses red text. */
.callout {
  position: absolute;
  left: 50%;
  top: 38%;
  transform: translate(-50%, -50%);
  max-width: 90%;
  margin: 0;
  padding: 10px 18px;
  background: var(--pb-field);
  border: 2px solid var(--pb-edge);
  font-size: 22px;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-align: center;
  pointer-events: none;
  animation: pb-pop 220ms var(--ss-ease, ease-out);
}

@keyframes pb-pop {
  from {
    transform: translate(-50%, -50%) scale(0.9);
    opacity: 0;
  }

  to {
    transform: translate(-50%, -50%) scale(1);
    opacity: 1;
  }
}

.error {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  max-width: 90%;
  margin: 0;
  padding: 16px 20px;
  background: var(--pb-field);
  border: 2px solid var(--pb-edge);
  font-weight: 700;
  text-align: center;
}

/* Touch controls show on a touch screen. Every target is 44 px or more. */
.touch {
  display: none;
  position: absolute;
  inset: auto 0 0 0;
  height: 40%;
  pointer-events: none;
}

.touch-zone,
.touch-btn {
  position: absolute;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 8px;
  border: 1px dashed var(--pb-dim);
  background: rgba(255, 255, 255, 0.04);
  font-size: var(--ss-fs-xs, 12px);
  font-weight: 700;
  letter-spacing: 0.08em;
  pointer-events: auto;
  touch-action: none;
}

/* The zone label sits above the row of the two buttons, so no button covers it. */
.touch-zone {
  bottom: 0;
  top: 0;
  width: 50%;
  min-height: var(--pb-touch);
  padding-bottom: 76px;
}

.touch-left {
  left: 0;
}

.touch-right {
  right: 0;
}

/*
 * The buttons are translucent: the plunger lane and the ball stay visible under HOLD TO LAUNCH.
 * The white edge and the label keep the button easy to find.
 */
.touch-btn {
  align-items: center;
  min-width: calc(var(--pb-touch) + 20px);
  min-height: calc(var(--pb-touch) + 12px);
  background: rgba(0, 0, 0, 0.35);
  border: 2px solid var(--pb-edge);
  border-radius: var(--ss-radius-md, 8px);
  text-align: center;
}

/*
 * The buttons sit at the bottom corners of the touch area, below the flippers. They do not cover
 * the upper lane exit or the orbit rails (at 390 x 844 the top of the touch area is on those
 * rails). HOLD TO LAUNCH sits on the foot of the plunger lane and on the margin beside it. The
 * button is translucent, so the plunger and the ball rest stay visible. The label has two lines.
 * The test test/client/render/touch-layout.test.ts checks these places against the table.
 */
.touch-plunger {
  right: 8px;
  bottom: 8px;
  width: 88px;
}

.touch-nudge {
  left: 8px;
  bottom: 8px;
}

.touch-zone:active {
  background: #262626;
}

.touch-btn:active {
  background: rgba(255, 255, 255, 0.3);
}

@media (pointer: coarse) {
  .touch {
    display: block;
  }
}

/* The start dialog shows the touch help on a touch-only device, and the keys and pad help elsewhere. */
.touch-help {
  display: none;
}

@media (hover: none) and (pointer: coarse) {
  .touch-help {
    display: block;
  }

  .desktop-help {
    display: none;
  }
}

.foot {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 12px;
  border-top: 1px solid var(--pb-dim);
  font-size: var(--ss-fs-xs, 12px);
}

.foot p {
  margin: 0;
}

/* Dialogs */
.dlg {
  width: min(92vw, 520px);
  max-height: 88vh;
  overflow: auto;
  padding: 20px;
  background: var(--pb-field);
  color: var(--pb-edge);
  border: 2px solid var(--pb-edge);
  border-radius: var(--ss-radius-lg, 10px);
}

.dlg.wide {
  width: min(94vw, 680px);
}

.dlg::backdrop {
  background: rgba(0, 0, 0, 0.82);
}

.dlg h2 {
  margin: 0 0 8px;
  font-size: var(--ss-fs-xl, 24px);
}

.dlg h3 {
  margin: 16px 0 4px;
  font-size: var(--ss-fs-md, 16px);
  letter-spacing: 0.04em;
}

.dlg ul {
  margin: 0;
  padding-left: 20px;
}

.dlg li {
  margin: 2px 0;
}

.big {
  font-size: 32px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.keys,
.note {
  font-size: var(--ss-fs-sm, 14px);
}

.row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 16px;
}

.field {
  display: block;
  width: 100%;
  min-height: var(--pb-touch);
  padding: 8px 10px;
  background: var(--pb-field);
  color: var(--pb-edge);
  border: 2px solid var(--pb-edge);
  border-radius: var(--ss-radius-sm, 6px);
  font: inherit;
}

/* The key list of the settings dialog: one row for each command, a Change button at the end. */
.keylist {
  list-style: none;
  padding-left: 0;
}

.dlg .keylist {
  padding-left: 0;
}

.dlg .keylist li {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: 6px 0;
}

.check {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.check input {
  width: 24px;
  height: 24px;
  margin: 2px 0 0;
  flex: none;
}

/* Reduced motion: no pop, no transition, a static callout box. */
:root[data-reduced-motion="true"] .callout {
  animation: none;
}

:root[data-reduced-motion="true"] * {
  transition: none !important;
  animation: none !important;
}

@media (prefers-reduced-motion: reduce) {
  .callout {
    animation: none;
  }
}

@media (max-width: 560px) {
  .hud-score {
    font-size: 22px;
  }

  .bar-track {
    width: 72px;
  }

  /*
   * Compact header: one row (the title, Pause and Menu), so the table gets more height.
   * How to play, Featured turns and Settings go behind the Menu button.
   */
  .bar {
    flex-wrap: nowrap;
    padding: 4px 8px;
  }

  .title {
    min-width: 0;
    overflow: hidden;
    font-size: var(--ss-fs-md, 16px);
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .tools {
    flex: none;
    flex-wrap: nowrap;
  }

  .tools .btn {
    padding: 8px 12px;
  }

  .btn.menu-toggle {
    display: inline-flex;
  }

  .menu-list {
    display: none;
    position: absolute;
    top: 100%;
    right: 8px;
    z-index: 20;
    flex-direction: column;
    flex-wrap: nowrap;
    padding: 8px;
    background: var(--pb-field);
    border: 2px solid var(--pb-edge);
    border-radius: var(--ss-radius-md, 8px);
  }

  .menu-list[data-open] {
    display: flex;
  }

  .power .bar-track {
    width: 56px;
  }
}
