:root {
  --ink: #111;
  --paper: #f6f1ea;
  --coffee: #6b4226;
  --coffee-dark: #573520;
  --crema: #c8a27a;
  --muted: #d8cfc4;
  --ink-soft: rgba(17, 17, 17, 0.68);
  --serif: Georgia, "Times New Roman", Times, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

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

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  height: 100%;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

body {
  position: fixed;
  inset: 0;
  overflow: hidden;
  touch-action: manipulation;
}

#stage {
  position: absolute;
  left: 0;
  top: 0;
  width: 360px;
  height: 640px;
  overflow: hidden;
  background: var(--paper);
}

/* ---- sponsor banner (6:1 strip above the stage, sized by fit()) -------- */
.ad-banner {
  position: absolute;
  left: 0;
  top: 0;
  width: 360px;
  height: 60px;
  overflow: hidden;
  background: var(--paper);
  border-bottom: 2px solid var(--ink);
  container-type: size;
}

.ad-banner.is-locked {
  pointer-events: none;
}

.ad-layer {
  position: absolute;
  inset: 0;
  opacity: 0;
  visibility: hidden;
  transition: opacity 300ms ease, visibility 0s linear 300ms;
}

.ad-layer.is-on {
  z-index: 1;
  opacity: 1;
  visibility: visible;
  transition: opacity 300ms ease, visibility 0s linear 0s;
}

@media (prefers-reduced-motion: reduce) {
  .ad-layer,
  .ad-layer.is-on {
    transition: none;
  }
}

.ad-item {
  position: absolute;
  inset: 0;
  display: block;
  overflow: hidden;
}

.ad-item:focus-visible {
  outline-offset: -3px;
}

.ad-media {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.ad-label {
  position: absolute;
  left: 0;
  top: 0;
  padding: 2px 6px;
  border-bottom-right-radius: 4px;
  background: rgba(17, 17, 17, 0.55);
  color: #fff;
  font: 10px/1.2 var(--sans);
  pointer-events: none;
}

.ad-house {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 10px;
  color: var(--ink);
  font-family: var(--serif);
  font-size: clamp(13px, 4vw, 18px);
  line-height: 1.15;
  text-align: center;
}

.ad-mustache {
  flex: none;
  width: 34px;
  height: auto;
}

/* Fit the strip, not the viewport, where container units exist (e.g. short landscape screens). */
@supports (width: 1cqw) {
  .ad-house {
    font-size: clamp(9px, 4cqw, 18px);
  }
  .ad-mustache {
    width: clamp(20px, 9cqw, 34px);
  }
}

#game {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

/* ---- overlays ---------------------------------------------------------- */
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow-y: auto;
  padding: 24px 16px;
  background: rgba(246, 241, 234, 0.92);
  touch-action: pan-y;
  -webkit-overflow-scrolling: touch;
}

.overlay[hidden] {
  display: none;
}

.card {
  margin: auto;
  width: 100%;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  text-align: center;
}

.card p {
  margin: 0;
}

.logo {
  margin: 0;
  font-family: var(--serif);
  font-weight: 700;
  font-size: 76px;
  line-height: 1;
  letter-spacing: 0.12em;
  padding-left: 0.12em;
}

.logo-sub {
  display: block;
  margin-top: 6px;
  font-size: 15px;
  font-weight: 400;
  letter-spacing: 0.45em;
  padding-left: 0.45em;
}

.mustache {
  width: 120px;
  height: auto;
  color: var(--ink);
}

.title {
  margin: 0;
  font-family: var(--serif);
  font-size: 30px;
  line-height: 1.15;
}

.lead {
  max-width: 32ch;
  font-size: 17px;
  line-height: 1.45;
}

.score-big {
  margin: 0;
  font-family: var(--serif);
  font-size: 46px;
  line-height: 1.1;
}

.best {
  font-family: var(--serif);
  font-size: 20px;
}

.record {
  font-family: var(--serif);
  font-style: italic;
  font-weight: 700;
  font-size: 22px;
  color: var(--coffee);
}

.reason {
  font-size: 18px;
  font-weight: 600;
}

/* ---- buttons ----------------------------------------------------------- */
.btn {
  appearance: none;
  -webkit-appearance: none;
  width: 100%;
  max-width: 320px;
  min-height: 52px;
  padding: 14px 20px;
  border: 2px solid transparent;
  border-radius: 14px;
  font: 600 18px/1.2 var(--sans);
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 80ms ease, background-color 120ms ease;
}

.btn:active {
  transform: scale(0.98);
}

.btn[hidden] {
  display: none;
}

.btn-primary {
  background: var(--coffee);
  color: var(--paper);
}

.btn-primary:hover {
  background: var(--coffee-dark);
}

.btn-primary:disabled {
  opacity: 0.6;
  cursor: progress;
}

.btn-secondary {
  background: transparent;
  color: var(--ink);
  border-color: var(--ink);
}

.btn-secondary:hover {
  background: rgba(17, 17, 17, 0.05);
}

.link {
  appearance: none;
  -webkit-appearance: none;
  min-height: 48px;
  padding: 12px 16px;
  border: 0;
  background: none;
  color: var(--coffee);
  font: 600 16px/1.2 var(--sans);
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
  touch-action: manipulation;
}

:focus-visible {
  outline: 3px solid var(--crema);
  outline-offset: 3px;
}

/* ---- form -------------------------------------------------------------- */
.field {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 6px;
  text-align: left;
}

.field > label {
  font-weight: 600;
  font-size: 16px;
}

.field input[type="text"],
.field input[type="url"],
.field input[type="date"],
.field input[type="number"] {
  width: 100%;
  min-height: 48px;
  padding: 12px 14px;
  border: 2px solid var(--ink);
  border-radius: 12px;
  background: #fff;
  color: var(--ink);
  font: 16px/1.2 var(--sans);
}

.field input[aria-invalid="true"] {
  border-color: var(--coffee);
  box-shadow: 0 0 0 2px var(--crema);
}

.check {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  min-height: 48px;
  padding: 4px 0;
  font-weight: 400 !important;
  font-size: 14px !important;
  line-height: 1.4;
  cursor: pointer;
}

.check input {
  flex: none;
  width: 24px;
  height: 24px;
  margin: 0;
  accent-color: var(--coffee);
}

.hint {
  font-size: 13px;
  color: var(--ink-soft);
}

.error {
  font-size: 14px;
  font-weight: 700;
  color: var(--coffee);
}

.error:empty {
  display: none;
}

/* ---- leaderboard ------------------------------------------------------- */
.range {
  font-size: 15px;
  color: var(--ink-soft);
}

.board {
  width: 100%;
  margin: 0;
  padding: 0;
  list-style: none;
}

.board li {
  display: grid;
  grid-template-columns: 36px 1fr auto;
  gap: 12px;
  align-items: center;
  min-height: 44px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--muted);
  font-size: 17px;
  text-align: left;
}

.board .rank {
  font-family: var(--serif);
  font-weight: 700;
}

.board .nick {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.board .pts {
  font-family: var(--serif);
  font-weight: 700;
  font-size: 20px;
}

.board li.you {
  border-radius: 10px;
  background: rgba(200, 162, 122, 0.32);
  font-weight: 700;
}

.note {
  font-size: 14px;
  color: var(--ink-soft);
}
