:root {
  --orange: #dc6e16;
  --orange-bright: #f7931a;
  --charcoal: #242424;
  --panel: #303030;
  --panel-dark: #191919;
  --line: #555;
  --text: #fff;
  --muted: #bdbdbd;
  --canvas-backdrop: #111;
  --blank-pixel: #303030;
}

* { box-sizing: border-box; }
html { background: #161616; }
body {
  min-height: 100vh;
  margin: 0;
  color: var(--text);
  background: #242424;
  font-family: "VT323", "Courier New", ui-monospace, monospace;
  font-size: 20px;
}
button, input, textarea { font: inherit; }

.background-grid {
  position: fixed;
  inset: 0;
  background:
    linear-gradient(90deg, rgba(255,255,255,.05) 1px, transparent 1px),
    linear-gradient(rgba(255,255,255,.05) 1px, transparent 1px),
    #202020;
  background-size: 52px 52px;
}
.page-shell {
  position: relative;
  width: min(1180px, 78%);
  min-height: 100vh;
  margin: auto;
  background: var(--charcoal);
  box-shadow: 0 0 60px rgba(0,0,0,.38);
}
.site-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 20px 24px 0;
  background: #343a40;
}
.pixel-logo {
  display: flex;
  margin-bottom: 10px;
  color: white;
  text-decoration: none;
  font-size: clamp(42px, 7vw, 64px);
  font-weight: 900;
  line-height: 1;
}
.pixel-logo span { animation: colour-cycle 2s infinite alternate; }
.pixel-logo span:nth-child(2) { animation-delay: .1s; }
.pixel-logo span:nth-child(3) { animation-delay: .2s; }
.pixel-logo span:nth-child(4) { animation-delay: .3s; }
.pixel-logo span:nth-child(5) { animation-delay: .4s; }
.pixel-logo span:nth-child(6) { animation-delay: .5s; }
.pixel-logo span:nth-child(7) { animation-delay: .6s; }
.pixel-logo span:nth-child(8) { animation-delay: .7s; }
.pixel-logo span:nth-child(9) { animation-delay: .8s; }
.pixel-logo span:nth-child(10) { animation-delay: .9s; }
@keyframes colour-cycle {
  0% { color: red; }
  25% { color: orange; }
  50% { color: yellow; }
  75% { color: #32d45c; }
  100% { color: #3996ff; }
}
.site-header nav { display: flex; width: 100%; }
.site-header nav a {
  flex: 1;
  padding: 12px;
  color: white;
  text-align: center;
  text-decoration: none;
}
.site-header nav a:hover { color: var(--orange-bright); }
.site-header nav a.nav-cta { background: var(--orange); color: white; }
.site-header nav a.nav-cta:hover { background: var(--orange-bright); }

main { padding: 34px clamp(16px, 4vw, 52px) 70px; }
.intro { max-width: 850px; margin: 0 auto 28px; text-align: center; }
.intro h1 { margin: 3px 0 8px; font-size: clamp(35px, 6vw, 58px); }
.intro > p:last-child { color: var(--muted); line-height: 1.55; }
.eyebrow { margin: 0; color: var(--orange-bright); font-size: 15px; font-weight: 900; letter-spacing: 2px; }
.layout { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(280px, .65fr); gap: 22px; align-items: start; }
.canvas-card, .controls-card, dialog {
  border: 2px solid var(--orange);
  background: var(--panel);
  box-shadow: 8px 8px 0 rgba(0,0,0,.25);
}
.canvas-card { padding: 18px; }
.canvas-topline { display: flex; justify-content: space-between; gap: 15px; margin-bottom: 12px; color: var(--muted); font-size: 12px; }
.canvas-topline b { color: var(--orange-bright); }
.canvas {
  display: grid;
  grid-template-columns: repeat(32, minmax(0, 1fr));
  grid-template-rows: repeat(32, minmax(0, 1fr));
  gap: 1px;
  width: 100%;
  aspect-ratio: 1;
  padding: 6px;
  overflow: hidden;
  background: var(--canvas-backdrop);
  border: 4px solid #111;
  image-rendering: pixelated;
  touch-action: none;
  user-select: none;
}
.pixel {
  min-width: 0;
  min-height: 0;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  appearance: none;
  cursor: crosshair;
  background: var(--blank-pixel);
}
.pixel:hover { outline: 2px solid white; z-index: 2; }
.pixel.selected { outline: 2px solid var(--orange-bright); z-index: 1; }
.canvas-help { margin-top: 10px; color: var(--muted); text-align: center; font-size: 11px; }

.controls-card { padding: 22px; }
.controls-card h2 { margin: 5px 0 18px; }
.colour-row { display: grid; grid-template-columns: 70px 1fr; gap: 10px; }
input, textarea {
  width: 100%;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 0;
  background: var(--panel-dark);
  color: white;
}
input[type="color"] { height: 50px; padding: 3px; cursor: pointer; }
label { display: block; margin: 20px 0 7px; color: white; font-size: 13px; font-weight: 900; }
.tool-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 12px; }
.tool, .secondary, .primary {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 0;
  font-weight: 900;
  cursor: pointer;
}
.tool, .secondary { background: #252525; color: white; }
.tool.active { border-color: var(--orange); background: #543219; color: var(--orange-bright); }
.selection-summary { margin: 22px 0 12px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.selection-summary div { display: flex; justify-content: space-between; gap: 12px; padding: 12px 0; }
.selection-summary div + div { border-top: 1px solid #464646; }
.selection-summary span { color: var(--muted); font-size: 12px; }
.selection-summary strong { color: var(--orange-bright); text-align: right; }
.primary { width: 100%; margin-top: 9px; border-color: var(--orange); background: var(--orange); color: white; }
.primary:hover { background: var(--orange-bright); }
.primary:disabled { cursor: not-allowed; opacity: .45; }
.secondary { width: 100%; }
.fine-print { color: var(--muted); font-size: 11px; line-height: 1.5; }
.error { padding: 10px; border: 1px solid #f77; background: #4b2525; color: #ffb2b2; font-size: 12px; }

.donation-cta { display: flex; align-items: center; justify-content: space-between; gap: 26px; margin-top: 34px; padding: 24px; border: 2px solid var(--orange); background: var(--panel); box-shadow: 8px 8px 0 rgba(0,0,0,.25); }
.donation-cta h2 { margin: 4px 0 7px; }
.donation-cta p:last-child { margin: 0; color: var(--muted); }
.cta-button { width: auto; min-width: 285px; margin: 0; text-align: center; text-decoration: none; }
.support-section { display: grid; grid-template-columns: minmax(280px, .75fr) minmax(0, 1.25fr); gap: 22px; margin-top: 34px; }
.standalone-support { margin-top: 0; }
.tip-card, .leaderboard-card { padding: 22px; border: 2px solid var(--orange); background: var(--panel); box-shadow: 8px 8px 0 rgba(0,0,0,.25); }
.tip-card h2, .leaderboard-card h2 { margin: 5px 0 10px; }
.section-copy { color: var(--muted); line-height: 1.5; }
.tip-presets { display: grid; grid-template-columns: repeat(4, 1fr); gap: 7px; }
.tip-presets button { padding: 10px 3px; border: 1px solid var(--line); background: #252525; color: white; cursor: pointer; font-weight: 900; }
.tip-presets button:hover { border-color: var(--orange); color: var(--orange-bright); }
.sats-input { position: relative; margin-top: 8px; }
.sats-input input { padding-right: 60px; }
.sats-input span { position: absolute; top: 50%; right: 14px; transform: translateY(-50%); color: var(--muted); }
label span { color: var(--muted); font-weight: 400; }
.check-row { display: flex; align-items: center; gap: 9px; margin: 16px 0; color: var(--muted); font-weight: 400; }
.check-row input { width: 18px; height: 18px; margin: 0; accent-color: var(--orange); }
.leaderboard-heading { display: flex; justify-content: space-between; gap: 18px; align-items: start; }
.tip-total { text-align: right; }
.tip-total strong, .tip-total span { display: block; }
.tip-total strong { color: var(--orange-bright); font-size: 21px; }
.tip-total span { margin-top: 3px; color: var(--muted); font-size: 10px; }
.tip-leaderboard { margin: 18px 0; padding: 0; list-style: none; }
.tip-leaderboard li { display: grid; grid-template-columns: 46px minmax(0,1fr) auto; gap: 12px; align-items: center; padding: 13px 4px; border-bottom: 1px solid #494949; }
.tip-leaderboard li b { color: var(--orange-bright); }
.tip-leaderboard li strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tip-leaderboard li span { color: var(--muted); text-align: right; font-size: 11px; }
.tip-leaderboard li.empty { display: block; color: var(--muted); text-align: center; }

.site-footer { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px 28px; padding: 24px; border-top: 1px solid #454545; background: #1b1b1b; }
.site-footer a { color: var(--muted); text-decoration: none; }
.site-footer a:hover { color: var(--orange-bright); }

.confetti-layer { position: fixed; inset: 0; z-index: 999999; width: 100%; height: 100%; pointer-events: none; image-rendering: pixelated; }
body.tip-celebration .background-grid { animation: background-party 1.8s ease-out; }
body.tip-celebration .pixel { animation: pixel-wave .6s ease-out var(--wave-delay, 0ms) 1; }
@keyframes background-party {
  0%, 100% { filter: none; }
  18% { filter: hue-rotate(45deg) brightness(1.8); }
  38% { filter: hue-rotate(140deg) brightness(1.3); }
  65% { filter: hue-rotate(260deg) brightness(1.5); }
}
@keyframes pixel-wave {
  0%, 100% { transform: scale(1); filter: none; }
  45% { transform: scale(.68); filter: brightness(2.2) saturate(1.7); }
}

dialog { width: min(500px, calc(100% - 28px)); padding: 26px; color: white; text-align: center; }
dialog::backdrop { background: rgba(0,0,0,.78); }
.dialog-close { position: absolute; top: 7px; right: 11px; border: 0; background: transparent; color: white; font-size: 28px; cursor: pointer; }
dialog h2 { margin: 6px 0 18px; }
.invoice-amount { display: flex; justify-content: space-between; margin-bottom: 15px; }
.invoice-amount strong { color: var(--orange-bright); font-size: 23px; }
.qr { width: min(330px, 100%); margin: auto; padding: 10px; background: white; }
.qr img { display: block; width: 100%; }
.link-button { display: block; text-decoration: none; }
dialog textarea { height: 72px; margin-top: 10px; resize: none; font-size: 10px; }
.waiting { display: flex; align-items: center; justify-content: center; gap: 10px; margin-top: 15px; color: var(--muted); }
.waiting i { width: 15px; height: 15px; border: 2px solid #666; border-top-color: var(--orange); border-radius: 50%; animation: spin 1s linear infinite; }
.waiting i.paid { border-color: #35d967; animation: none; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 950px) {
  .page-shell { width: min(100%, 760px); }
  .layout { grid-template-columns: 1fr; }
  .support-section { grid-template-columns: 1fr; }
  .donation-cta { align-items: stretch; flex-direction: column; }
  .cta-button { width: 100%; min-width: 0; }
}
@media (max-width: 600px) {
  .page-shell { width: 100%; }
  .site-header { padding-inline: 8px; }
  .pixel-logo { font-size: clamp(34px, 11vw, 52px); }
  .site-header nav a { padding: 10px 4px; font-size: 13px; }
  main { padding: 24px 10px 50px; }
  .canvas-card { padding: 9px; }
  .canvas { gap: 1px; padding: 4px; }
  .canvas-topline { font-size: 10px; }
  .tip-leaderboard li { grid-template-columns: 38px minmax(0,1fr); }
  .tip-leaderboard li span { grid-column: 2; text-align: left; }
}

@media (prefers-reduced-motion: reduce) {
  .pixel-logo span, .waiting i, body.tip-celebration .background-grid,
  body.tip-celebration .pixel { animation: none !important; }
}
