:root {
  color-scheme: light dark;
  --bg: #f5f4f1; --surface: #fff; --border: #ddd7c9; --text: #211f1a; --text-dim: #6b6559;
  --accent: #0f6e6e; --danger: #a13d2f; --danger-bg: #f4ded9; --warn: #b45309; --ribbon: #4a9e3f;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #14181a; --surface: #1b2124; --border: #313a3d; --text: #e8e6e0; --text-dim: #9aa09b; --accent: #4fd1c5; --danger: #e6a196; --danger-bg: #3a241f; --warn: #f59e0b; --ribbon: #5bb450; }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body { margin: 0; overflow-x: hidden; background: var(--bg); color: var(--text); font: 14px/1.5 system-ui, sans-serif; }
main { max-width: 900px; min-width: 0; margin: 0 auto; padding: 32px 20px 80px; }
h1 { font-size: 22px; margin: 0; }
.title-row { display: flex; align-items: center; gap: 12px; margin: 0 0 8px; }
.title-row img { width: 56px; height: 56px; flex: none; }
.sub { color: var(--text-dim); margin: 0 0 10px; }
.disclaimer { color: var(--warn); font-size: 12.5px; font-weight: 500; margin: 0 0 24px; }

.promo { margin: 0 0 24px; }
.promo label { display: block; font-weight: 600; margin-bottom: 6px; }
.promo-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.code-field { position: relative; flex: 1 1 200px; max-width: 320px; display: inline-flex; }
.promo-row input {
  width: 100%; padding-right: 38px; font: inherit; font-size: 16px; /* 16px+ stops iOS Safari zooming in on focus */ padding-top: 7px; padding-bottom: 7px; padding-left: 10px; border-radius: 7px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
}
.promo-row input:focus-visible, .btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.promo-status { min-height: 20px; margin-top: 6px; font-size: 13px; color: var(--text-dim); }
.promo-status.ok { color: var(--accent); }
.promo-status.bad { color: var(--danger); }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(220px, 100%), 1fr)); gap: 14px; }
.card { position: relative; min-width: 0; overflow: hidden; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 16px; display: flex; flex-direction: column; }
/* A quiet diagonal band across the top-right corner marks an app shown because of the visitor's promo code.
   The card clips it to its rounded corner. The gradient runs along the corner's diagonal: transparent, the
   band (8px to 18px in from the corner point), transparent. */
.badge {
  position: absolute; top: 0; right: 0; width: 44px; height: 44px;
  background: linear-gradient(to bottom left, transparent 0 8px, var(--ribbon) 8px 18px, transparent 18px);
}
.card.fallback { opacity: 0.6; }
.card.loading .card-name { opacity: 0.7; }
.card-head { display: flex; gap: 10px; align-items: center; margin-bottom: 10px; }
.card-head img { width: 40px; height: 40px; border-radius: 8px; object-fit: cover; background: var(--bg); flex: none; }
.card-titles { min-width: 0; }
.card-name { font-weight: 600; overflow-wrap: anywhere; }
.card-meta { color: var(--text-dim); font-size: 12px; overflow-wrap: anywhere; }
.card-desc {
  font-size: 13px; color: var(--text-dim); margin: 6px 0 12px;
  display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden;
}
.card-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: auto; }
a.btn, button.btn {
  font: inherit; font-size: 12.5px; font-weight: 600; padding: 6px 10px; border-radius: 7px;
  border: 1px solid var(--border); background: var(--bg); color: var(--text);
  text-decoration: none; cursor: pointer; line-height: 1.4; white-space: normal; text-align: center;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
@media (prefers-color-scheme: dark) { .btn.primary { color: #0b1112; } }
.btn.gold { background: #f2b632; border-color: #d99a0b; color: #2b1d00; margin-left: auto; padding: 7px 14px; }
.btn.gold:hover { background: #f7c452; }
.btn:disabled { opacity: 0.6; cursor: default; }
.message { color: var(--text-dim); padding: 20px 0; }
.message .btn { margin-left: 8px; }

/* Install help page */
.back { margin: 0 0 18px; font-size: 13px; }
.back a { color: var(--accent); text-decoration: none; font-weight: 600; }
.back a:hover { text-decoration: underline; }
.page-title { font-size: 18px; margin: 18px 0 8px; }
.lead { margin: 0 0 14px; font-size: 14.5px; }
.note { background: var(--surface); border: 1px solid var(--border); border-left: 4px solid #f2b632; border-radius: 10px; padding: 4px 16px; margin: 0 0 20px; }
.note p { margin: 10px 0; color: var(--text-dim); }
.note strong { color: var(--text); }
.help-list { display: grid; gap: 12px; margin: 0 0 24px; }
.help-card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 0 16px; }
.help-card.mine { border-color: var(--accent); }
.help-card summary { cursor: pointer; font-weight: 600; padding: 13px 0; }
.help-card[open] summary { border-bottom: 1px solid var(--border); }
.help-card .here {
  margin-left: 8px; font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.02em;
  padding: 2px 7px; border-radius: 999px; color: var(--accent); border: 1px solid var(--accent);
}
.help-body { padding: 12px 0 14px; color: var(--text-dim); font-size: 14px; line-height: 1.6; }
.help-body ul { margin: 6px 0 10px; padding-left: 22px; }
.help-body li { margin: 2px 0; }

/* Game badge: bottom-right corner of a card whose manifest lists "game" or "games" */
.game-badge { position: absolute; right: 10px; bottom: 10px; width: 32px; height: 32px; pointer-events: auto; }
.grid[hidden], .loading[hidden] { display: none; }

/* Loading: a pill of five colored dots that flash one after another, left to right, then start over. */
.loading { display: flex; justify-content: center; padding: 36px 0; }
.pill { display: inline-flex; gap: 9px; padding: 11px 16px; border-radius: 999px; background: var(--surface); border: 1px solid var(--border); }
.pill i { width: 11px; height: 11px; border-radius: 50%; opacity: 0.2; animation: dot-flash 1.5s infinite; }
.pill i:nth-child(1) { background: #ff3da6; animation-delay: 0s; }
.pill i:nth-child(2) { background: #ffd100; animation-delay: 0.15s; }
.pill i:nth-child(3) { background: #1ee3ff; animation-delay: 0.3s; }
.pill i:nth-child(4) { background: #4cd964; animation-delay: 0.45s; }
.pill i:nth-child(5) { background: #8a5cff; animation-delay: 0.6s; }
@keyframes dot-flash { 0%, 40%, 100% { opacity: 0.2; transform: scale(1); } 12% { opacity: 1; transform: scale(1.3); } }
@media (prefers-reduced-motion: reduce) { .pill i { animation: none; opacity: 1; } }

/* The promo code is hidden as it is typed (dots instead of letters) until the eye is pressed. Plain text
   masking, not type=password, so browsers don't offer to save it as a password. */
.promo-row input.masked { -webkit-text-security: disc; }
.eye {
  position: absolute; right: 4px; top: 50%; transform: translateY(-50%); width: 30px; height: 30px; padding: 0;
  border: 0; border-radius: 6px; background: transparent; cursor: pointer;
}
.eye::before {
  content: ""; display: block; width: 20px; height: 20px; margin: 0 auto; background-color: var(--accent);
  -webkit-mask: url(eye.png) center / contain no-repeat; mask: url(eye.png) center / contain no-repeat;
}
.eye[aria-pressed="true"]::before { -webkit-mask-image: url(eye-off.png); mask-image: url(eye-off.png); }
.eye:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* Phone portrait: everything must reflow inside the screen width. The promo field takes a full row and its
   buttons wrap beneath it. App cards stay one per row, in the same layout as on wider screens. */
@media (max-width: 640px) {
  main { padding: 20px 16px 64px; }
  .sub, .disclaimer { overflow-wrap: anywhere; }
  .promo-row > * { min-width: 0; }
  .code-field { flex: 1 1 100%; max-width: none; }
  .promo-row .btn { flex: 1 1 auto; text-align: center; }
  .btn.gold { margin-left: 0; flex: 1 1 100%; }
  .grid { grid-template-columns: minmax(0, 1fr); }
  /* Larger fine print for phone reading */
  body { font-size: 16px; }
  .sub { font-size: 16px; }
  .disclaimer { font-size: 14.5px; }
  .promo label { font-size: 16px; }
  .promo-status { font-size: 15px; }
  .card { padding: 18px; }
  .card-name { font-size: 17.5px; }
  .card-meta { font-size: 14px; }
  .card-desc { font-size: 15.5px; line-height: 1.5; -webkit-line-clamp: 6; }
  a.btn, button.btn { font-size: 15px; padding: 9px 14px; }
  .btn.gold { padding: 10px 14px; }
  .message { font-size: 15.5px; }
}
