:root {
  --bg: #0e0c0a;
  --bg-2: #1a1612;
  --ink: #f3ece2;
  --ink-dim: #a99d8e;
  --gold: #e7b75f;
  --gold-2: #f6d69a;
  --accent: #ff8a5c;
  --line: rgba(243, 236, 226, .12);
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, "Times New Roman", serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --gutter: clamp(12px, 3vw, 32px);
  --ease: cubic-bezier(.65, 0, .35, 1);
  color-scheme: dark;
}

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

html, body { height: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  height: 100dvh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  background:
    radial-gradient(120% 80% at 50% 40%, #2a2219 0%, var(--bg) 70%) fixed,
    var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

/* ---------- header ---------- */
.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: clamp(10px, 2vh, 20px) var(--gutter) 0;
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: .5em;
  color: var(--gold-2);
  text-decoration: none;
  font-family: var(--serif);
  font-size: clamp(1rem, .9rem + .5vw, 1.25rem);
  letter-spacing: .04em;
}
.brand-icon { width: 1.25em; height: 1.25em; color: var(--gold); }
.hint {
  margin: 0;
  color: var(--ink-dim);
  font-size: .8rem;
}
kbd {
  font: inherit;
  font-size: .75rem;
  padding: .1em .45em;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: rgba(255, 255, 255, .04);
}
@media (hover: none), (max-width: 720px) { .hint { display: none; } }

/* ---------- stage & frame ---------- */
.stage {
  container-type: size;
  display: grid;
  place-items: center;
  padding: clamp(10px, 2.5vh, 28px) var(--gutter);
  min-height: 0;
  position: relative;
}

.frame {
  --ar: 4 / 5;
  --ar-n: .8;
  position: relative;
  margin: 0;
  aspect-ratio: var(--ar);
  width: min(100cqw, 100cqh * var(--ar-n));
  max-width: 100%;
  overflow: hidden;
  border-radius: 3px;
  background: var(--bg-2) center / cover no-repeat;
  box-shadow:
    0 0 0 1px rgba(231, 183, 95, .35),
    0 0 0 clamp(4px, .8vw, 10px) #15110d,
    0 0 0 calc(clamp(4px, .8vw, 10px) + 1px) rgba(231, 183, 95, .25),
    0 30px 80px -20px rgba(0, 0, 0, .8),
    0 10px 30px rgba(0, 0, 0, .5);
  touch-action: pan-y;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  transform: translateZ(0);
}

.layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  opacity: 0;
  transition: opacity .35s ease;
  will-change: transform;
}
.layer.loaded { opacity: 1; }
.layer.cat {
  clip-path: circle(0 at 50% 50%);
  will-change: clip-path, transform;
}
.frame.is-cat .layer.cat { clip-path: inset(0); }

.ring {
  position: absolute;
  left: 0;
  top: 0;
  width: 0;
  height: 0;
  border-radius: 50%;
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, -50%);
  border: 3px solid var(--gold-2);
  box-shadow: 0 0 24px 6px rgba(246, 214, 154, .55), inset 0 0 24px 4px rgba(246, 214, 154, .4);
}

.status {
  position: absolute;
  inset: auto 0 50%;
  text-align: center;
  color: var(--ink-dim);
  margin: 0;
}

/* ---------- panel ---------- */
.panel {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: clamp(10px, 2vh, 18px) clamp(16px, 4vw, 48px);
  padding: 0 var(--gutter) clamp(14px, 3vh, 28px);
}
.caption {
  text-align: center;
  min-width: 0;
  max-width: 100%;
}
.title {
  margin: 0;
  font-family: var(--serif);
  font-weight: 500;
  font-style: italic;
  font-size: clamp(1.15rem, .95rem + 1.1vw, 1.9rem);
  line-height: 1.15;
  letter-spacing: .01em;
  text-wrap: balance;
}
.artist {
  margin: .3em 0 0;
  color: var(--gold);
  font-size: clamp(.72rem, .68rem + .25vw, .85rem);
  letter-spacing: .18em;
  text-transform: uppercase;
}
.caption.swap { animation: caption-in .5s var(--ease) both; }
@keyframes caption-in {
  from { opacity: 0; transform: translateY(6px); }
}

.controls {
  display: flex;
  gap: 10px;
  flex: 0 0 auto;
}

.btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .55em;
  min-height: 48px;
  padding: 0 1.4em;
  border-radius: 999px;
  font: 600 1rem/1 var(--sans);
  letter-spacing: .01em;
  cursor: pointer;
  transition: transform .15s ease, background-color .2s ease, box-shadow .2s ease, color .2s ease, opacity .2s;
  white-space: nowrap;
}
.btn svg { width: 1.2em; height: 1.2em; flex: none; }
.btn:active { transform: scale(.96); }
.btn:disabled { opacity: .45; cursor: default; }
.btn:focus-visible { outline: 2px solid var(--gold-2); outline-offset: 3px; }

.btn.primary {
  border: 0;
  color: #1d130a;
  background: linear-gradient(135deg, var(--gold-2), var(--gold) 55%, var(--accent));
  box-shadow: 0 8px 24px -8px rgba(231, 183, 95, .7), inset 0 1px 0 rgba(255, 255, 255, .5);
  min-width: 9.5em;
}
.btn.primary:hover:not(:disabled) { box-shadow: 0 10px 30px -6px rgba(255, 138, 92, .75), inset 0 1px 0 rgba(255, 255, 255, .5); }
.btn.primary[aria-pressed="true"] {
  color: var(--ink);
  background: linear-gradient(135deg, #3a2f24, #261e17);
  box-shadow: inset 0 0 0 1px rgba(231, 183, 95, .5);
}
.btn.primary .paw { transition: transform .5s var(--ease); }
.btn.primary[aria-pressed="true"] .paw { transform: rotate(-25deg) scale(1.1); }

.btn.ghost {
  color: var(--ink);
  background: rgba(255, 255, 255, .05);
  border: 1px solid var(--line);
}
.btn.ghost:hover:not(:disabled) { background: rgba(255, 255, 255, .1); }

/* phones: stacked caption, full-width buttons */
@media (max-width: 560px) {
  .panel { flex-direction: column; align-items: stretch; }
  .controls { width: 100%; }
  .controls .btn { flex: 1 1 0; padding: 0 .9em; min-width: 0; }
  .btn.ghost .label { font-size: .95rem; }
}
@media (max-width: 360px) {
  .btn.ghost .label { display: none; }
  .controls .btn.ghost { flex: 0 0 56px; }
}

/* landscape phones: put the panel beside the painting */
@media (orientation: landscape) and (max-height: 520px) {
  body {
    grid-template-columns: minmax(0, 1fr) minmax(220px, 34%);
    grid-template-rows: auto minmax(0, 1fr);
  }
  .top { grid-column: 1 / -1; padding-top: 8px; }
  .stage { grid-row: 2; padding: 8px var(--gutter); }
  .panel {
    grid-row: 2;
    flex-direction: column;
    align-items: stretch;
    justify-content: center;
    padding: 8px var(--gutter) 8px 0;
  }
  .controls { flex-direction: column; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
