﻿/* Frank's Game - the whole site is one full-screen game.
   System font stack on purpose: no external font host, so the CSP stays at
   'self' and it loads instantly on a tablet over phone data. */

/* Black and tan, after the dogs. Black carries the structure (buttons, text,
   the selected state) and tan carries everything that wants attention (level,
   nuggets, anything buyable). Nothing else gets a hue, so the one green tick
   and the one red warning still read instantly when they appear. */
:root {
  --surface: #fbf7f1;
  --surface-2: #f0e6d8;
  --ink: #241f26;
  --ink-soft: #6f6257;
  --accent: #2f2b30;          /* black: primary actions and selection */
  --accent-dark: #100e12;
  --tan: #b5763a;
  --tan-dark: #86532a;
  --tan-light: #e8d3b6;
  --nugget: #d99a4e;
  --nugget-dark: #a06b2d;
  --good: #6d8a4a;
  --line: #ddceba;
  --radius: 20px;
  --shadow: 0 2px 0 rgba(36, 31, 38, 0.10), 0 12px 32px rgba(36, 31, 38, 0.28);
  --tap: 48px;
}

* { box-sizing: border-box; }

/* The UA rule for [hidden] is display:none at the lowest specificity, so any
   class that sets a display value silently beats it. That is how the "New
   best!" pill once showed on every run. Anything toggled with the attribute
   needs this to actually hide. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  background: #bfe6ff;
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 17px;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}

/* No pull-to-refresh, no double-tap zoom eating jumps, no text selection from
   a held tap. All three are ways a tablet turns a game input into a browser
   gesture. */
body.playing { touch-action: none; user-select: none; -webkit-user-select: none; }

#game {
  position: fixed;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

h1, h2, h3 { line-height: 1.15; margin: 0 0 0.4em; }
h2 { font-size: 1.5rem; }
h3 { font-size: 1.05rem; margin-top: 1.1em; }
p { margin: 0 0 0.9em; }

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

.screen {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
  background: rgba(24, 20, 26, 0.58);
  backdrop-filter: blur(3px);
  z-index: 10;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.panel {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
  width: 100%;
  max-width: 400px;
  text-align: center;
  margin: auto;
}

.panel.wide { max-width: 720px; text-align: left; }

/* Standalone pages (404) have no game canvas behind them to dim. */
.screen.plain { background: var(--surface-2); backdrop-filter: none; }

/* Available to screen readers, invisible on screen. A class, not a style
   attribute: the CSP drops style attributes, so an inline version of this
   leaves the label sitting visibly on the page. */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

.num { text-align: right; }

.panelhead {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.logo {
  font-size: 2rem;
  letter-spacing: -0.03em;
  margin-bottom: 14px;
}
.logo span { color: var(--tan); }

/* ---------------------------------------------------------------- wallet -- */

.wallet {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  margin-bottom: 18px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 14px;
}

.walletbars { flex: 1 1 auto; text-align: left; }

.levelbadge {
  display: grid;
  place-items: center;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-weight: 800;
  line-height: 1;
  flex: 0 0 auto;
}
.levelbadge small { display: block; font-size: 0.55rem; opacity: 0.85; }
.levelbadge b { font-size: 1.4rem; }

.xpbar {
  height: 12px;
  border-radius: 999px;
  background: var(--tan-light);
  border: 1px solid var(--line);
  overflow: hidden;
  margin-bottom: 4px;
}
.xpbar i {
  display: block;
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--tan), var(--nugget));
  transition: width 0.5s ease;
}
.xptext { font-size: 0.78rem; color: var(--ink-soft); }

.purse {
  flex: 0 0 auto;
  text-align: center;
  color: var(--nugget-dark);
  font-weight: 800;
}
.purse b { display: block; font-size: 1.4rem; line-height: 1; }
.purse small { font-size: 0.6rem; text-transform: uppercase; letter-spacing: 0.05em; }
.purse.small { font-size: 0.95rem; }
.purse.small b { display: inline; font-size: 1.1rem; }

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

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: var(--tap);
  padding: 0 20px;
  border: none;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  text-decoration: none;   /* .btn is used on anchors too */
  box-shadow: 0 3px 0 var(--accent-dark);
  transition: transform 0.06s ease, box-shadow 0.06s ease;
}
.btn:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--accent-dark); }
.btn:focus-visible { outline: 3px solid var(--ink); outline-offset: 3px; }

.btn.secondary { background: var(--surface-2); color: var(--ink); box-shadow: 0 3px 0 var(--line); }
.btn.secondary:active { box-shadow: 0 1px 0 var(--line); }

/* The one place a warm red is used, so it means exactly one thing: this is
   destructive. */
.btn.danger { background: #a3402f; box-shadow: 0 3px 0 #732518; }
.btn.danger:active { box-shadow: 0 1px 0 #732518; }

.confirm {
  margin-top: 10px;
  padding: 12px;
  border: 2px solid #a3402f;
  border-radius: 14px;
  background: #fbeae5;
  text-align: left;
}
.confirm .note.warn { color: #7d2c1f; margin-bottom: 8px; }
.confirm .menurow { margin-top: 0; }

.btn.big { min-height: 62px; font-size: 1.2rem; }
.btn.block { display: flex; width: 100%; margin-top: 12px; }

.menurow { display: flex; gap: 8px; margin-top: 12px; }
.menurow .btn { flex: 1 1 0; padding: 0 8px; font-size: 0.92rem; }

/* ---------------------------------------------------------------- levels -- */

.levels {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 10px;
  max-height: 52vh;
  overflow-y: auto;
  padding-right: 4px;
  margin: 12px 0;
}

.level {
  min-height: 96px;
  padding: 12px 14px;
  border-radius: 14px;
  border: 2px solid var(--line);
  background: var(--surface-2);
  color: var(--ink);
  font: inherit;
  text-align: left;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.level b { font-size: 1.05rem; }
.level small { color: var(--ink-soft); font-size: 0.83rem; line-height: 1.3; }

.levelfoot { margin-top: auto; display: flex; gap: 8px; }
.levelfoot em {
  font-style: normal;
  font-size: 0.74rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--tan-dark);
}

.level.current { border-color: var(--accent); background: var(--tan-light); }
.level.locked { opacity: 0.55; cursor: not-allowed; }
.level.locked b { color: var(--ink-soft); }

/* ------------------------------------------------------------------ shop -- */

.slots { display: flex; gap: 8px; flex-wrap: wrap; margin: 14px 0; }

.slottab {
  min-height: 44px;
  padding: 0 16px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--ink);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}
.slottab[aria-selected="true"] { background: var(--ink); color: #fff; border-color: var(--ink); }

.items {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px;
  max-height: 46vh;
  overflow-y: auto;
  padding-right: 4px;
}

.item {
  min-height: 84px;
  padding: 10px 12px;
  border-radius: 14px;
  border: 2px solid var(--line);
  background: var(--surface-2);
  color: var(--ink);
  font: inherit;
  text-align: left;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
}
.item b { font-size: 0.95rem; }
.item small { font-size: 0.8rem; font-weight: 700; }

/* Action on the left, ownership on the right, on one baseline. */
.itemfoot {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-top: auto;
}

/* Named ownedtag, not owned: `.item.owned` is already a card state, and a bare
   `.owned` rule silently restyled the whole card. */
.ownedtag {
  font-style: normal;
  font-size: 0.66rem;
  font-weight: 800;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--tan-dark);
  white-space: nowrap;
  opacity: 0.85;
}

.swatch { height: 14px; border-radius: 999px; border: 1px solid rgba(36, 31, 38, 0.20); }

/* Four states, each readable at a glance. */
.item.worn   { border-color: var(--accent); background: var(--tan-light); }
.item.worn small { color: var(--accent); }
.item.owned small { color: var(--ink-soft); }
.item.buy    { border-color: var(--tan); background: #fdf0dc; }
.item.buy small { color: var(--nugget-dark); }
.item.poor   { opacity: 0.75; cursor: not-allowed; }
.item.poor small { color: var(--nugget-dark); }
.item.locked { opacity: 0.55; cursor: not-allowed; }
.item.locked b, .item.locked small { color: var(--ink-soft); }

/* ---------------------------------------------------------- leaderboard -- */

.board { width: 100%; border-collapse: collapse; margin-bottom: 8px; }
.board th, .board td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); }
.board th { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--ink-soft); }
.board td.score { text-align: right; font-weight: 800; font-variant-numeric: tabular-nums; }
.board td.rank { width: 2.5rem; color: var(--ink-soft); font-weight: 700; }
.board tr.me { background: var(--tan-light); }
.board tr.me td { font-weight: 800; }

/* Front-screen board: tighter, and it shows how far ahead each name is. */
.minitable { margin: 14px 0 10px; }
.minitable h3 {
  margin: 0 0 4px;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-soft);
}
.board.mini { margin-bottom: 4px; }
.board.mini td { padding: 5px 6px; font-size: 0.92rem; }
.board.mini td.rank { width: 1.6rem; }
.board.mini td.gap {
  width: 3.6rem;
  text-align: right;
  font-size: 0.76rem;
  font-weight: 700;
  color: var(--tan-dark);
  font-variant-numeric: tabular-nums;
}

.linkish {
  border: none;
  background: none;
  padding: 4px 0;
  font: inherit;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--tan-dark);
  text-decoration: underline;
  cursor: pointer;
}

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

.setting {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: var(--tap);
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
  text-align: left;
}
.setting label { font-weight: 700; }
.setting small { display: block; font-weight: 400; color: var(--ink-soft); font-size: 0.8rem; }

.switch { position: relative; width: 62px; height: 34px; flex: 0 0 auto; }
.switch input { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.switch span {
  position: absolute; inset: 0; border-radius: 999px;
  background: var(--line); transition: background 0.15s ease; pointer-events: none;
}
.switch span::after {
  content: ""; position: absolute; top: 4px; left: 4px;
  width: 26px; height: 26px; border-radius: 50%; background: #fff;
  transition: transform 0.15s ease; box-shadow: 0 1px 3px rgba(0,0,0,0.25);
}
.switch input:checked + span { background: var(--good); }
.switch input:checked + span::after { transform: translateX(28px); }
.switch input:focus-visible + span { outline: 3px solid var(--ink); outline-offset: 3px; }

.codeform { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.codeform input {
  flex: 1 1 160px;
  min-height: var(--tap);
  padding: 0 16px;
  font: inherit;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  border: 2px solid var(--line);
  border-radius: 12px;
  background: var(--surface-2);
  color: var(--ink);
}
.codeform input:focus { outline: none; border-color: var(--accent); }

.note { font-size: 0.86rem; color: var(--ink-soft); }
.note.warn { color: #b4622f; }

/* --------------------------------------------------------------- results -- */

.bigscore { font-size: 3rem; font-weight: 800; line-height: 1; margin: 6px 0; font-variant-numeric: tabular-nums; }
.bigscore small { display: block; font-size: 0.72rem; font-weight: 700; color: var(--ink-soft); letter-spacing: 0.08em; text-transform: uppercase; }

.pill {
  display: inline-block;
  padding: 5px 14px;
  border-radius: 999px;
  background: var(--good);
  color: #fff;
  font-weight: 800;
  font-size: 0.85rem;
  margin-bottom: 8px;
}

.zonereached { margin: 0 0 6px; font-weight: 800; color: var(--tan-dark); }

.nameentry {
  margin-top: 14px;
  padding: 14px;
  border: 2px solid var(--tan);
  border-radius: 14px;
  background: #fdf0dc;
}

.highscore {
  margin: 0 0 10px;
  font-weight: 800;
  font-size: 1.05rem;
  color: var(--tan-dark);
}

/* Stacked and full width: easier to hit on a tablet than a field and a small
   button sharing a line. The uppercase transform is dropped here because this
   is a person's name, not a code, and "LOLA" is not how she writes it. */
.nameentry .codeform { flex-direction: column; align-items: stretch; }
.nameentry .codeform input {
  /* flex-basis is the height in a column, and the shared .codeform rule sets
     it to 160px for the row layout. Left alone the field is 160px tall. */
  flex: 0 0 auto;
  height: var(--tap);
  text-transform: none;
  letter-spacing: 0.02em;
  text-align: center;
  font-size: 1.1rem;
}
.nameentry .codeform .btn { width: 100%; }
.nameentry .note { margin: 8px 0 0; text-align: center; }

.unlocks { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin: 10px 0 0; padding: 0; list-style: none; }
.unlocks li {
  padding: 5px 12px; border-radius: 999px;
  background: #fdf0dc; border: 1px solid var(--line);
  font-size: 0.82rem; font-weight: 700;
}
/* A whole new level is a bigger deal than a hat going on sale. */
.unlocks li.big {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-size: 0.9rem;
}

/* -------------------------------------------------------------------- hud -- */

.hud {
  position: fixed;
  top: max(10px, env(safe-area-inset-top));
  left: 12px;
  right: 12px;
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  pointer-events: none;
  z-index: 5;
}

/* Chips, not bare text: the sky changes colour with the zone, and white on a
   pale beach was unreadable. */
.hud span {
  padding: 5px 13px;
  border-radius: 999px;
  background: rgba(24, 20, 26, 0.68);
  color: #fff;
  font-size: 0.95rem;
}
.hud .nuggets { color: #f0c98c; }
.hud .hearts { color: #e0996f; letter-spacing: 3px; }
.hud .height { color: #dcc7a8; }

.zonebanner {
  position: fixed;
  top: 22%;
  left: 50%;
  transform: translateX(-50%);
  margin: 0;
  padding: 10px 26px;
  border-radius: 999px;
  background: rgba(24, 20, 26, 0.78);
  color: #fff;
  font-weight: 800;
  font-size: 1.2rem;
  white-space: nowrap;
  pointer-events: none;
  z-index: 5;
  animation: zonefade 2.2s ease both;
}

@keyframes zonefade {
  0% { opacity: 0; } 15% { opacity: 1; } 75% { opacity: 1; } 100% { opacity: 0; }
}

/* The throw pad: sized for a thumb, in the corner a right hand already rests. */
.throwpad {
  position: fixed;
  right: max(20px, env(safe-area-inset-right));
  bottom: max(20px, env(safe-area-inset-bottom));
  width: 82px;
  height: 82px;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.85);
  background: var(--nugget);
  box-shadow: 0 4px 0 var(--nugget-dark), 0 6px 18px rgba(24, 20, 26, 0.32);
  cursor: pointer;
  display: grid;
  place-items: center;
  touch-action: none;
  z-index: 6;
}

/* The nugget shape, in CSS, so there is no image to load. */
.throwpad span {
  width: 36px;
  height: 26px;
  border-radius: 15px 12px 14px 13px;
  background: #ffd9a0;
  box-shadow: inset -3px -3px 0 rgba(201, 130, 42, 0.35);
}

.throwpad:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--nugget-dark); }
.throwpad:focus-visible { outline: 3px solid #fff; outline-offset: 3px; }

/* Disabled rather than hidden: a control that vanishes is a control a player
   stops trusting. Out of nuggets should read as "not now", not "gone". */
.throwpad:disabled { opacity: 0.38; cursor: default; box-shadow: none; }

/* Short landscape screens, which is exactly how a tablet gets held. */
@media (max-height: 520px) {
  .panel { padding: 16px; }
  .logo { font-size: 1.5rem; margin-bottom: 8px; }
  .wallet { margin-bottom: 10px; }
  .btn.big { min-height: 52px; }
  .items { max-height: 38vh; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
