:root {
  font-family:
    system-ui,
    -apple-system,
    sans-serif;
  color: #373b39;
  background: #f5f3ee;
  font-synthesis: none;
}
* {
  box-sizing: border-box;
}
body {
  margin: 0;
}
/* The game is a fixed viewport; login and dialog scrolling stay independent. */
html.app-page,
.app-page body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}
.app-page body {
  position: fixed;
  inset: 0;
}
main {
  touch-action: none;
  height: 100vh;
  height: 100dvh;
  width: 100%;
  padding: max(6px, env(safe-area-inset-top))
    max(16px, env(safe-area-inset-right)) max(9px, env(safe-area-inset-bottom))
    max(16px, env(safe-area-inset-left));
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 6px;
  text-align: center;
}
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
/* Keep the standalone header below the system's translucent top area. */
@media (display-mode: standalone) {
  .app-header {
    padding-top: 12px;
  }
}
h1 {
  font-size: 1.08rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  margin: 0;
}
button,
select {
  font: inherit;
  color: inherit;
  background: #fffefa;
  border: 1px solid #d2d1c9;
  border-radius: 12px;
  padding: 10px 15px;
  min-height: 44px;
}
button {
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
button:disabled {
  opacity: 0.45;
  cursor: default;
}
button:focus-visible,
[role="button"]:focus-visible,
input:focus-visible,
select:focus-visible,
summary:focus-visible {
  outline: 3px solid #477f9d;
  outline-offset: 2px;
}
.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
#menu-open,
#settings-open {
  width: 44px;
  height: 44px;
  padding: 10px;
  flex-shrink: 0;
}
#menu-open svg,
#settings-open svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
}
.playfield {
  grid-row: 2;
  min-width: 0;
  min-height: 0;
  container-type: size;
  display: grid;
  --controls-height: 54px;
  --control-gap: 8px;
  grid-template-rows: auto auto;
  gap: var(--control-gap);
  place-content: center;
  justify-items: center;
}
/* The toy uses a contrast-adjusted solid color; LCD expansion uses the base. */
html.app-page[data-display-mode="toy"] {
  background: var(--toy-background, #f5f3ee);
}
/* App mode uses the LCD's own frame and a shared responsive layout. */
html.app-page[data-display-mode="app"] {
  background: var(--shell-theme, #f5f3ee);
}
/* Only the title sits directly on the shell-colored background. */
.app-page[data-display-mode="app"] .app-header h1 {
  color: var(--app-title-color, #373b39);
}
.app-page[data-display-mode="app"] .playfield {
  --controls-height: 72px;
  --control-gap: 24px;
}
.app-page[data-display-mode="app"] #device {
  width: min(
    100cqw,
    calc(
      (100cqh - var(--controls-height) - var(--control-gap)) * 1408.55 / 1403.58
    )
  );
  aspect-ratio: 1408.55 / 1403.58;
  border-radius: 7.75% / 7.78%;
  overflow: hidden;
  box-shadow: 0 3px 12px #0002;
}
.app-page[data-display-mode="app"] #device [data-hit-area] {
  display: none;
}
.app-page[data-display-mode="app"] .buttons {
  gap: clamp(12px, 5cqw, 24px);
  align-items: center;
  padding: 0;
}
.app-page[data-display-mode="app"] .buttons button {
  width: 66px;
  height: 66px;
  border-radius: 50%;
  border-color: #0002;
  font-size: 18px;
  box-shadow: 0 3px 0 #0002;
}
.app-page[data-display-mode="app"] .buttons button.pressed {
  box-shadow: 0 1px 0 #0002;
}
@media (max-height: 400px) {
  .app-page[data-display-mode="app"] .playfield {
    --controls-height: 50px;
    --control-gap: 10px;
  }
  .app-page[data-display-mode="app"] .buttons button {
    width: 48px;
    height: 48px;
  }
}
label:has(#display-mode) {
  margin-top: 12px;
}
#device {
  width: min(
    100cqw,
    calc((100cqh - var(--controls-height) - var(--control-gap)) * 2466 / 2898)
  );
  aspect-ratio: 2466 / 2898;
  position: relative;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
#device > svg {
  width: 100%;
  height: 100%;
  display: block;
}
#device [data-hit-area] {
  fill: transparent;
  cursor: pointer;
  touch-action: none;
}
#device [data-hit-area].pressed {
  fill: #00000014;
}
#device [data-hit-area][aria-disabled="true"] {
  pointer-events: none;
}
#loading {
  position: absolute;
  inset: 40% 0 auto;
  color: #68756a;
}
.buttons {
  grid-row: 2;
  height: var(--controls-height);
  display: flex;
  gap: 25px;
  justify-content: center;
  padding: 2px 0 4px;
}
.buttons button {
  width: 62px;
  height: 48px;
  border-radius: 28px;
  background: var(--button-color, #e8e4d7);
  color: var(--button-ink, #373b39);
  font-weight: 600;
  box-shadow: 0 3px 0 #0002;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  touch-action: none;
}
.buttons button.pressed {
  transform: translateY(2px);
  box-shadow: 0 1px 0 #0002;
}
dialog {
  border: 1px solid #d2d1c9;
  border-radius: 18px;
  width: min(430px, calc(100vw - 24px));
  max-height: calc(
    100dvh - max(12px, env(safe-area-inset-top)) -
      max(12px, env(safe-area-inset-bottom))
  );
  margin: auto;
  overflow-y: auto;
  overscroll-behavior: contain;
  text-align: left;
  background: #fffef8;
  padding: 18px;
}
dialog::backdrop {
  background: #0005;
}
.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
dialog h2 {
  font-size: 1.1rem;
  margin: 0;
}
dialog h3 {
  font-size: 0.95rem;
  margin: 0 0 10px;
}
dialog section,
dialog details {
  border-top: 1px solid #e6e2d8;
  padding-top: 16px;
  margin-top: 16px;
}
dialog p {
  font-size: 0.85rem;
  line-height: 1.7;
  margin: 8px 0;
}
label {
  display: grid;
  gap: 8px;
}
select {
  width: 100%;
  min-width: 0;
}
.volume-label {
  display: flex;
  justify-content: space-between;
}
#volume {
  width: 100%;
  margin: 8px 0;
  min-height: 44px;
  accent-color: #547b74;
}
dialog section > button {
  width: 100%;
}
.settings-actions > button + button {
  margin-top: 8px;
}
#menu summary {
  min-height: 44px;
  align-content: center;
  font-weight: 600;
}
#menu-notice-status {
  white-space: pre-line;
}
#menu .app-info {
  overflow-wrap: anywhere;
}
.help,
.app-info {
  color: #657067;
}
summary {
  cursor: pointer;
  min-height: 36px;
}
#diagnostics {
  font:
    0.73rem/1.6 ui-monospace,
    monospace;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  margin-bottom: 0;
}
[hidden] {
  display: none !important;
}
@media (max-height: 400px) {
  main {
    gap: 3px;
    padding-top: max(3px, env(safe-area-inset-top));
    padding-bottom: max(5px, env(safe-area-inset-bottom));
  }
}

#settings-open {
  position: relative;
}
#settings-open[data-update="true"]::after {
  content: "";
  position: absolute;
  right: 3px;
  top: 3px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #ba5827;
}
#toast {
  position: fixed;
  z-index: 5;
  bottom: max(80px, calc(env(safe-area-inset-bottom) + 70px));
  left: 50%;
  transform: translateX(-50%);
  width: max-content;
  max-width: calc(100vw - 32px);
  padding: 10px 16px;
  border-radius: 12px;
  background: #333e;
  color: white;
  font-size: 0.85rem;
  pointer-events: none;
}
.notification-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  flex-wrap: wrap;
}
#health {
  display: grid;
  grid-template-columns: 1fr 1.4fr;
  gap: 8px;
  font-size: 0.85rem;
}
#health dd {
  margin: 0;
}
#health [data-state="error"] {
  color: #9a321a;
}
#health [data-state="ok"] {
  color: #34634b;
}
.login-page {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
}
#login-form {
  max-width: 360px;
  width: 100%;
  display: grid;
  gap: 12px;
}
#login-form h1 {
  margin-bottom: 8px;
}
#login-form label {
  margin-top: 4px;
}
#login-form input {
  appearance: none;
  font: inherit;
  font-size: max(16px, 1rem);
  color: inherit;
  background: #fff;
  height: 44px;
  min-width: 0;
  width: 100%;
  padding: 10px;
  border: 1px solid #aaa;
  border-radius: 8px;
}
#login-status {
  margin: 0;
  overflow-wrap: anywhere;
}
#login-form a,
#login-form a:visited {
  color: inherit;
}
#login-form a {
  min-height: 44px;
  display: flex;
  align-items: center;
  overflow-wrap: anywhere;
}

#admin-recovery summary {
  color: inherit;
  cursor: pointer;
  text-decoration: underline;
  min-height: 44px;
  align-content: center;
  overflow-wrap: anywhere;
}
#admin-recovery p {
  margin: 4px 0 0;
  line-height: 1.6;
  overflow-wrap: anywhere;
}

#settings .push-setting {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  min-height: 44px;
  padding-block: 0.25rem;
}

#settings .push-setting p {
  margin-block: 0.125rem 0;
}

#settings .push-setting input {
  appearance: none;
  display: grid;
  flex: 0 0 auto;
  place-items: center start;
  width: 3rem;
  height: 1.875rem;
  margin: 0;
  padding: 0 0.1875rem;
  color: #192721;
  background: #d8ddd9;
  border: 1px solid #617369;
  border-radius: 1rem;
  cursor: pointer;
}

#settings .push-setting input::before {
  content: "";
  width: 1.25rem;
  height: 1.25rem;
  border-radius: 50%;
  background: currentColor;
}

#settings .push-setting input:checked {
  justify-items: end;
  color: #fff;
  background: #315e48;
  border-color: #315e48;
}

#settings .push-setting input:disabled {
  opacity: 0.55;
  cursor: default;
}

#settings #push-settings [role="status"]:empty {
  display: none;
}
