:root {
  --wood: #2a1a10;
  --wood-2: #3b2516;
  --red: #b8322a;
  --gold: #e0a64a;
  --gold-2: #f3c977;
  --cream: #f6ead2;
  --muted: #cbb593;
  --bar-h: 56px;
  --ad-w: 300px;
  --ad-h: 250px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--wood);
  color: var(--cream);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
}
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- Landing ---------- */
.landing {
  position: relative;
  height: 100%;
  overflow: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 48px 20px 140px;
  background:
    /* buffalo plaid */
    repeating-linear-gradient(90deg, rgba(184, 50, 42, .16) 0 40px, transparent 40px 80px),
    repeating-linear-gradient(0deg, rgba(184, 50, 42, .16) 0 40px, transparent 40px 80px),
    radial-gradient(1000px 500px at 50% 0%, #4a2e1a, transparent 70%),
    var(--wood);
}
.hero { position: relative; z-index: 2; text-align: center; max-width: 900px; width: 100%; margin: auto 0; }
.logo {
  font-family: "Rye", Georgia, serif;
  font-weight: 400;
  font-size: clamp(52px, 11vw, 112px);
  line-height: 1;
  margin: 0 0 16px;
  color: var(--gold);
  letter-spacing: 2px;
  text-shadow: 0 4px 0 #6b3a12, 0 0 30px rgba(224, 166, 74, .35);
}
.tagline { font-size: clamp(17px, 2.4vw, 21px); color: var(--muted); margin: 0 auto 28px; max-width: 560px; }

.url-form { display: flex; gap: 8px; width: 100%; }
.hero .url-form { max-width: 680px; margin: 0 auto; }
.url-form input {
  flex: 1; min-width: 0;
  padding: 10px 14px;
  font: inherit;
  color: var(--cream);
  background: rgba(0, 0, 0, .25);
  border: 1.5px solid rgba(203, 181, 147, .4);
  border-radius: 10px;
  outline: none;
}
.url-form input:focus { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(224, 166, 74, .3); }
.url-form button, .tool, #styleSel {
  font: inherit;
  font-weight: 600;
  border-radius: 10px;
  border: 0;
  cursor: pointer;
}
.url-form button {
  padding: 10px 18px;
  color: #2a1406;
  background: linear-gradient(var(--gold-2), var(--gold));
  white-space: nowrap;
}
.url-form button:hover { filter: brightness(1.08); }
.url-form.big input { padding: 16px 18px; font-size: 18px; border-radius: 14px; }
.url-form.big button { padding: 16px 24px; font-size: 18px; border-radius: 14px; }

.examples { margin: 18px 0 0; color: var(--muted); font-size: 15px; }
.chip {
  font: inherit; font-size: 14px;
  margin: 4px 2px;
  padding: 4px 12px;
  color: var(--cream);
  background: rgba(184, 50, 42, .35);
  border: 1px solid rgba(203, 181, 147, .3);
  border-radius: 999px;
  cursor: pointer;
}
.chip:hover { background: rgba(184, 50, 42, .6); }

.pick-title { font-family: "Rye", Georgia, serif; font-weight: 400; color: var(--gold); font-size: 24px; margin: 36px 0 14px; }
.picker {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 12px;
}
.pick {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 10px 6px 8px;
  font: inherit; font-size: 14px; font-weight: 600;
  color: var(--cream);
  background: rgba(0, 0, 0, .25);
  border: 2px solid rgba(203, 181, 147, .25);
  border-radius: 14px;
  cursor: pointer;
  transition: transform .15s, border-color .15s, background .15s;
}
.pick svg { width: 100%; max-width: 110px; height: auto; display: block; }
.pick:hover { transform: translateY(-3px); border-color: rgba(224, 166, 74, .6); }
.pick[aria-checked="true"] { border-color: var(--gold); background: rgba(224, 166, 74, .18); box-shadow: 0 0 0 3px rgba(224, 166, 74, .25); }
.pick:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }

.hint { margin-top: 24px; color: var(--muted); font-size: 14px; opacity: .8; }
.foot {
  position: absolute; bottom: 14px; left: 16px;
  right: calc(var(--ad-w) + 40px);
  font-size: 12px; color: var(--muted); opacity: .6;
  z-index: 2;
}

/* ---------- Viewer ---------- */
.viewer { height: 100%; display: flex; flex-direction: column; }
.bar {
  height: var(--bar-h);
  flex: none;
  display: flex; align-items: center; gap: 12px;
  padding: 0 12px;
  background: linear-gradient(#3b2516, #24160c);
  border-bottom: 2px solid var(--red);
  position: relative; z-index: 40;
}
.bar-logo {
  font-family: "Rye", Georgia, serif;
  font-size: 24px;
  color: var(--gold);
  text-decoration: none;
  white-space: nowrap;
  text-shadow: 0 2px 0 #6b3a12;
}
.bar .url-form { max-width: 560px; }
.bar-tools { display: flex; align-items: center; gap: 6px; margin-left: auto; }
#styleSel, .tool {
  height: 40px;
  padding: 0 10px;
  color: var(--cream);
  background: rgba(255, 255, 255, .08);
  border: 1px solid rgba(203, 181, 147, .3);
}
#styleSel option { color: #000; }
.tool { min-width: 40px; }
.tool[aria-pressed="true"] { background: var(--red); }
.size { width: 90px; accent-color: var(--gold); cursor: pointer; }

.stage { position: relative; flex: 1; background: #fff; overflow: hidden; }
#frame { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; background: #fff; }
.loading {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: var(--wood);
  color: var(--muted);
  z-index: 5;
}
.loading-beard { font-size: 72px; animation: bob 1s ease-in-out infinite alternate; }
@keyframes bob { to { transform: translateY(-14px) rotate(8deg); } }

/* ---------- Beard overlay ---------- */
.beard-layer { position: absolute; inset: 0; pointer-events: none; z-index: 10; }
.beard {
  position: absolute;
  aspect-ratio: 240 / 260;
  pointer-events: auto;
  cursor: grab;
  touch-action: none;
  user-select: none;
  filter: drop-shadow(0 8px 14px rgba(0, 0, 0, .35));
}
.beard.dragging { cursor: grabbing; }
.beard svg { display: block; width: 100%; height: 100%; overflow: visible; transform-origin: 50% 0; animation: sway 4s ease-in-out infinite alternate; }
.beard.dragging svg { animation-play-state: paused; }
.beard.pop svg { animation: pop .35s ease-out, sway 4s ease-in-out .35s infinite alternate; }
.beard.shaved { display: none; }
@keyframes sway { from { transform: rotate(-1.5deg); } to { transform: rotate(1.5deg); } }
@keyframes pop { 0% { transform: scale(.6); opacity: 0; } 70% { transform: scale(1.08); opacity: 1; } 100% { transform: scale(1); } }
@media (prefers-reduced-motion: reduce) {
  .beard svg, .beard.pop svg, .loading-beard { animation: none; }
}

/* ---------- Ad ---------- */
.ad {
  position: fixed;
  right: 12px; bottom: 12px;
  z-index: 50;
  width: calc(var(--ad-w) + 12px);
  padding: 4px 6px 6px;
  background: rgba(42, 26, 16, .94);
  border: 1px solid rgba(203, 181, 147, .3);
  border-radius: 10px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, .45);
}
.ad-label { display: block; font-size: 10px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); opacity: .7; margin-bottom: 3px; }
.ad-slot { width: var(--ad-w); height: var(--ad-h); overflow: hidden; border-radius: 6px; }
.ad-disclosure { margin: 4px 0 0; font-size: 10px; line-height: 1.3; color: var(--muted); opacity: .7; }

/* Amazon affiliate promo */
.promo {
  height: 100%;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 8px;
  padding: 14px;
  text-align: center;
  text-decoration: none;
  color: var(--cream);
  border-radius: 6px;
  background:
    repeating-linear-gradient(90deg, rgba(184, 50, 42, .25) 0 20px, transparent 20px 40px),
    repeating-linear-gradient(0deg, rgba(184, 50, 42, .25) 0 20px, transparent 20px 40px),
    #3b2516;
  border: 1px solid rgba(224, 166, 74, .45);
  transition: border-color .2s;
}
.promo:hover { border-color: var(--gold); }
.promo:hover .promo-art { transform: rotate(-6deg) scale(1.06); }
.promo:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
.promo-art { width: 80px; flex: none; filter: drop-shadow(0 4px 8px rgba(0, 0, 0, .5)); transition: transform .2s; }
.promo-art svg { display: block; width: 100%; height: auto; }
.promo-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.promo-title { font-family: "Rye", Georgia, serif; font-weight: 400; font-size: 24px; line-height: 1.1; color: var(--gold); }
.promo-sub { font-size: 14px; color: var(--cream); }
.promo-btn {
  flex: none;
  padding: 7px 16px;
  font-size: 14px; font-weight: 700;
  color: #2a1406;
  background: linear-gradient(var(--gold-2), var(--gold));
  border-radius: 999px;
  white-space: nowrap;
}

.toast {
  position: fixed; left: 50%; bottom: 24px;
  transform: translate(-50%, 20px);
  padding: 10px 16px;
  background: var(--red);
  color: #fff;
  border-radius: 10px;
  opacity: 0;
  transition: opacity .2s, transform .2s;
  z-index: 60;
  pointer-events: none;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Small screens ---------- */
@media (max-width: 860px) {
  .picker { grid-template-columns: repeat(5, 1fr); gap: 8px; }
  .pick { font-size: 12px; }
}
@media (max-width: 720px) {
  :root { --ad-w: 320px; --ad-h: 50px; --bar-h: 104px; }
  .bar { flex-wrap: wrap; height: auto; min-height: var(--bar-h); padding: 8px 10px; gap: 8px; }
  .bar-tools { order: 1; flex-basis: 100%; margin-left: 0; gap: 4px; }
  .bar-logo { order: 2; font-size: 18px; }
  .bar .url-form { order: 3; flex: 1 1 0; min-width: 0; max-width: none; }
  #styleSel { flex: 1; min-width: 0; }
  .size { width: 80px; flex: none; }
  .picker { grid-template-columns: repeat(2, 1fr); }
  .ad { right: 8px; bottom: 8px; max-width: calc(100vw - 16px); }
  .ad-slot { max-width: 100%; }
  .promo { flex-direction: row; justify-content: flex-start; gap: 8px; padding: 0 8px; text-align: left; }
  .promo-art { width: 32px; }
  .promo-title { font-size: 15px; }
  .promo-sub { font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .promo-btn { margin-left: auto; padding: 5px 10px; font-size: 12px; }
  .ad-disclosure { font-size: 9px; }
  .foot { position: static; margin-top: 24px; text-align: center; }
  .url-form.big { flex-direction: column; }
}
@media (max-width: 340px) {
  :root { --ad-w: 300px; }
}
