:root {
  --bg: #17110c;
  --bg2: #22180f;
  --wood: #2c1f14;
  --ink: #f3e9d6;
  --muted: #b8a68a;
  --dim: #8a7a62;
  --gold: #d6aa4f;
  --gold2: #f2d58a;
  --line: rgba(243, 233, 214, 0.12);
  --good: #8fd16a;
  --bad: #ff6a5a;
  --warn: #ffb13b;
  --card: #241a11;
  --serif: 'Cormorant Garamond', Georgia, serif;
  --sans: 'Work Sans', system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  background-image:
    radial-gradient(ellipse at 50% 40%, rgba(255, 200, 120, 0.09), transparent 60%),
    repeating-linear-gradient(92deg, rgba(0,0,0,0.12) 0 3px, transparent 3px 11px),
    linear-gradient(#20160e, #140e09);
  color: var(--ink);
  font: 15px/1.45 var(--sans);
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  display: flex; flex-direction: column;
  height: 100dvh;
}
button { font: inherit; color: inherit; cursor: pointer; }
kbd {
  font: 600 10px var(--sans); padding: 1px 5px; border-radius: 4px;
  border: 1px solid var(--line); background: rgba(255,255,255,0.06); color: var(--muted);
}
em { font-style: italic; color: var(--gold2); }
.eyebrow { font: 600 11px var(--sans); letter-spacing: 0.14em; text-transform: uppercase; color: var(--gold); }
h1, h2 { font-family: var(--serif); font-weight: 700; margin: 0; line-height: 1.05; }

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px; border-bottom: 1px solid var(--line); background: rgba(0,0,0,0.25);
  flex: none;
}
.brand { display: flex; align-items: center; gap: 10px; font: 700 22px var(--serif); }
.brand-mark {
  width: 22px; height: 22px; border-radius: 3px;
  background: radial-gradient(circle at 65% 40%, #ffd34a 0 18%, #3d6fb8 19% 45%, #6b5a3a 46%);
  box-shadow: 0 0 0 3px var(--gold), 0 0 0 4px #5a3f12;
}
.top-right { display: flex; align-items: center; gap: 10px; }
.bank { display: flex; flex-direction: column; align-items: flex-end; line-height: 1.1; margin-right: 4px; }
.bank span { font-size: 10px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--dim); }
.bank b { font: 700 20px var(--serif); color: var(--gold2); }

/* ---------- buttons ---------- */
.btn {
  border: 1px solid var(--line); background: rgba(255,255,255,0.05); border-radius: 10px;
  padding: 10px 16px; font-weight: 600; transition: transform .08s, background .2s, opacity .2s;
}
.btn:hover:not(:disabled) { background: rgba(255,255,255,0.1); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: 0.38; cursor: not-allowed; }
.btn.small { padding: 7px 12px; font-size: 13px; }
.btn.icon { padding: 7px 9px; display: grid; place-items: center; }
.btn.big { padding: 14px 26px; font-size: 17px; }
.btn.primary {
  background: linear-gradient(#e7c06a, #b8862f); color: #2a1a06; border-color: #f2d58a;
  box-shadow: 0 2px 0 #6e4a14, 0 6px 20px rgba(214,170,79,0.25);
}
.btn.primary:hover:not(:disabled) { background: linear-gradient(#f2cf7e, #c79537); }
.btn.primary.ready { animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { box-shadow: 0 2px 0 #6e4a14, 0 0 0 8px rgba(242,213,138,0.25); } }
#btn-sound .mute { display: none; }
#btn-sound.off .mute { display: block; }
#btn-sound.off .wave { display: none; }

/* ---------- layout ---------- */
.studio {
  flex: 1; min-height: 0;
  display: grid; grid-template-columns: 104px 1fr 290px; gap: 0;
}
.tools {
  display: flex; flex-direction: column; gap: 8px; padding: 14px 10px;
  border-right: 1px solid var(--line); background: rgba(0,0,0,0.18);
}
.tool {
  position: relative; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 4px 6px; border-radius: 12px; border: 1px solid transparent; background: transparent;
  transition: background .15s, border-color .15s, transform .1s;
  user-select: none; -webkit-user-select: none; touch-action: none;
}
.tool svg { width: 40px; height: 40px; }
.tool .t-name { font-size: 12px; font-weight: 600; }
.tool kbd { font-size: 9px; }
.tool:hover { background: rgba(255,255,255,0.05); }
.tool.active { background: rgba(214,170,79,0.16); border-color: rgba(214,170,79,0.6); }
.tool.uv.active { background: rgba(160,110,255,0.25); border-color: #b28cff; box-shadow: 0 0 18px rgba(178,140,255,0.5); }
.tool.saturated::after {
  content: 'R'; position: absolute; top: 4px; right: 6px; width: 16px; height: 16px; border-radius: 50%;
  background: var(--warn); color: #241400; font: 700 10px/16px var(--sans); animation: pulse 1s infinite;
}
.size { display: flex; flex-direction: column; gap: 6px; align-items: center; margin-top: 6px; font-size: 11px; color: var(--muted); }
.size input { width: 80px; accent-color: var(--gold); }

.bench { touch-action: none; position: relative; display: grid; place-items: center; min-width: 0; min-height: 0; overflow: hidden; }
.frame {
  position: relative; padding: 18px; border-radius: 3px;
  background:
    linear-gradient(135deg, #f6dc8e, #b8862f 25%, #f2d58a 45%, #8a5f1e 70%, #e7c06a);
  box-shadow:
    inset 0 0 0 2px #5a3c10, inset 0 0 0 6px #e7c06a, inset 0 0 0 8px #7a5418,
    inset 0 0 14px 10px rgba(0,0,0,0.25),
    0 30px 60px rgba(0,0,0,0.6), 0 0 0 1px #3a260a;
}
.frame canvas { display: block; }
#cv { box-shadow: inset 0 0 0 1px #000, 0 0 0 1px #3a260a; touch-action: none; cursor: none; }
#ov { position: absolute; left: 18px; top: 18px; pointer-events: none; }
.frame.uv { box-shadow: inset 0 0 0 2px #2a1050, 0 0 60px rgba(160,110,255,0.35), 0 30px 60px rgba(0,0,0,0.6); filter: saturate(0.6) hue-rotate(-10deg); }
.frame.shake { animation: shake .25s; }
@keyframes shake { 25% { transform: translateX(-4px) rotate(-0.3deg); } 75% { transform: translateX(4px) rotate(0.3deg); } }
.shine { position: absolute; inset: 18px; pointer-events: none; overflow: hidden; }
.frame.reveal .shine::after {
  content: ''; position: absolute; top: -20%; bottom: -20%; width: 40%; left: -60%;
  background: linear-gradient(100deg, transparent, rgba(255,250,220,0.55), transparent);
  animation: sweep 1.1s ease-in-out forwards;
}
.frame.reveal { animation: glow 1.3s ease-out; }
@keyframes sweep { to { left: 120%; } }
@keyframes glow { 40% { box-shadow: 0 0 80px 10px rgba(255,220,140,0.55), 0 30px 60px rgba(0,0,0,0.6); } }

.toast {
  position: absolute; top: 18px; left: 50%; transform: translate(-50%, -12px);
  background: rgba(20,14,9,0.92); border: 1px solid var(--line); border-radius: 999px;
  padding: 8px 18px; font-weight: 600; opacity: 0; transition: opacity .2s, transform .2s; pointer-events: none;
  white-space: nowrap; max-width: calc(100% - 32px); overflow: hidden; text-overflow: ellipsis;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.good { border-color: rgba(143,209,106,0.6); color: #d8f5c4; }
.toast.bad { border-color: rgba(255,106,90,0.7); color: #ffd2cc; }
.hint {
  position: absolute; bottom: 14px; left: 50%; transform: translate(-50%, 12px);
  width: min(560px, calc(100% - 32px)); background: rgba(36,26,17,0.96); border: 1px solid rgba(214,170,79,0.5);
  border-radius: 12px; padding: 10px 14px; font-size: 14px; opacity: 0; transition: opacity .25s, transform .25s; pointer-events: none;
  box-shadow: 0 10px 30px rgba(0,0,0,0.5);
}
.hint::before { content: 'Tip '; font-weight: 700; color: var(--gold); }
.hint.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- side panel ---------- */
.panel {
  display: flex; flex-direction: column; gap: 14px; padding: 16px;
  border-left: 1px solid var(--line); background: rgba(0,0,0,0.18); overflow-y: auto;
}
.lot-card { padding: 14px; border-radius: 12px; background: #f1e6cc; color: #2a1e12; box-shadow: 0 6px 20px rgba(0,0,0,0.4); transform: rotate(-0.6deg); }
.lot-card .eyebrow { color: #8a5f1e; }
.lot-card h2 { font-size: 24px; margin: 4px 0 6px; }
.prov { margin: 0 0 8px; font-style: italic; font-family: var(--serif); font-size: 16px; }
.lot-card .prov { color: #5a4630; }
.paid { font-size: 13px; color: #5a4630; }
.paid b { color: #2a1e12; }
.meters { display: flex; flex-direction: column; gap: 12px; }
.m-head { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); margin-bottom: 5px; }
.m-head b { color: var(--ink); }
.bar { height: 10px; border-radius: 999px; background: rgba(255,255,255,0.08); overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, #b8862f, #f2d58a); border-radius: inherit; transition: width .2s; }
.meter.danger .bar i { background: linear-gradient(90deg, #ff9a5a, #ff4d4d); }
.layers { display: flex; flex-direction: column; gap: 6px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; font-size: 12.5px; color: var(--muted); }
.l-row { display: grid; grid-template-columns: 12px 70px 1fr; align-items: center; gap: 8px; }
.l-row[hidden] { display: none; }
.sw { width: 12px; height: 12px; border-radius: 3px; }
.sw.dust { background: #8a7c66; } .sw.over { background: linear-gradient(135deg, #e01e2b, #3a8c8c); } .sw.varn { background: #b8862f; }
.mini { height: 5px; border-radius: 9px; background: rgba(255,255,255,0.08); overflow: hidden; }
.mini i { display: block; height: 100%; width: 100%; background: var(--muted); transition: width .2s; }
.est { display: flex; justify-content: space-between; align-items: baseline; font-size: 13px; color: var(--muted); }
.est b { font: 700 22px var(--serif); color: var(--gold2); }
.actions { display: flex; flex-direction: column; gap: 10px; margin-top: auto; }
.btn.hunch { background: rgba(178,140,255,0.12); border-color: rgba(178,140,255,0.45); }
.btn.hunch:hover:not(:disabled) { background: rgba(178,140,255,0.22); }
.hunch-result { font-size: 13px; min-height: 0; color: var(--muted); }
.hunch-result.good { color: var(--good); } .hunch-result.bad { color: var(--bad); }

/* ---------- loading ---------- */
.loading {
  position: fixed; inset: 0; display: none; place-items: center; align-content: center; gap: 14px;
  background: rgba(15,10,6,0.85); z-index: 60; font-family: var(--serif); font-size: 22px;
}
.loading.show { display: grid; }
.spinner { width: 36px; height: 36px; border-radius: 50%; border: 3px solid rgba(214,170,79,0.25); border-top-color: var(--gold); animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- modals ---------- */
.modal {
  position: fixed; inset: 0; z-index: 50; display: none; place-items: center; padding: 16px;
  background: rgba(10,7,4,0.62); backdrop-filter: blur(3px); overflow-y: auto;
}
.modal.open { display: grid; animation: fade .25s; }
@keyframes fade { from { opacity: 0; } }
.card {
  background: var(--card); border: 1px solid rgba(214,170,79,0.35); border-radius: 18px;
  box-shadow: 0 30px 80px rgba(0,0,0,0.7); padding: 26px; width: min(560px, 100%);
  animation: rise .3s cubic-bezier(.2,.9,.3,1.2);
}
@keyframes rise { from { transform: translateY(16px) scale(0.97); opacity: 0; } }
.card h2 { font-size: 32px; margin: 6px 0 10px; }
.card p { color: var(--muted); }
.row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 18px; }

.title-card { width: min(920px, 100%); display: grid; grid-template-columns: 300px 1fr; gap: 28px; align-items: center; }
.title-art { position: relative; aspect-ratio: 1013/1200; border-radius: 4px; overflow: hidden;
  box-shadow: 0 0 0 10px #c9a14a, 0 0 0 12px #5a3c10, 0 20px 40px rgba(0,0,0,0.6); margin: 12px; }
.title-art img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.ta-dirty {
  filter: sepia(1) saturate(0.6) brightness(0.45) contrast(0.85);
  -webkit-mask-image: radial-gradient(circle at var(--mx, 30%) var(--my, 40%), transparent 0 18%, #000 32%);
  mask-image: radial-gradient(circle at var(--mx, 30%) var(--my, 40%), transparent 0 18%, #000 32%);
  animation: wander 9s ease-in-out infinite;
}
@property --mx { syntax: '<percentage>'; inherits: false; initial-value: 30%; }
@property --my { syntax: '<percentage>'; inherits: false; initial-value: 40%; }
@keyframes wander {
  0%, 100% { --mx: 30%; --my: 38%; } 25% { --mx: 62%; --my: 30%; } 50% { --mx: 55%; --my: 62%; } 75% { --mx: 35%; --my: 70%; }
}
.title-body h1 { font-size: clamp(44px, 7vw, 72px); margin: 6px 0 12px; }
.title-body p { font-size: 16px; color: var(--muted); margin: 0 0 12px; }
.how { margin: 0; padding-left: 18px; color: var(--muted); display: grid; gap: 4px; }
.how b { color: var(--ink); }

.lot-intro { text-align: center; background: #f1e6cc; color: #2a1e12; border-color: #c9a14a; transform: rotate(-0.4deg); }
.lot-intro .eyebrow { color: #8a5f1e; }
.lot-intro .prov { color: #5a4630; font-size: 19px; }
.lot-intro .tag { display: inline-block; margin: 6px 0 10px; padding: 6px 14px; border: 2px dashed #8a5f1e; border-radius: 6px; transform: rotate(1.5deg); font-weight: 600; }
.lot-intro .cond { color: #3d2e1d; margin: 6px 0 2px; font-weight: 500; }
.lot-intro .note { color: #6b5538; font-style: italic; margin: 0 0 18px; }

.hunch-card .opts { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 16px 0; }
.opt { text-align: left; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line); background: rgba(255,255,255,0.04); display: flex; flex-direction: column; gap: 2px; transition: background .15s, border-color .15s; }
.opt:hover { background: rgba(178,140,255,0.15); border-color: rgba(178,140,255,0.6); }
.opt b { font: 700 18px var(--serif); }
.opt span { font-size: 12.5px; color: var(--muted); }
.hunch-card p b { color: #c8b0ff; font-size: 18px; }

.result-card { width: min(1000px, 100%); display: grid; grid-template-columns: minmax(0, 1.1fr) 1fr; gap: 26px; align-items: center; }
.compare { position: relative; border-radius: 3px; overflow: hidden; box-shadow: 0 0 0 10px #c9a14a, 0 0 0 12px #5a3c10, 0 20px 40px rgba(0,0,0,0.6); margin: 12px; user-select: none; }
.compare img { display: block; width: 100%; height: auto; max-height: 68vh; object-fit: contain; background: #000; }
.before-wrap { position: absolute; inset: 0; }
.before-wrap img { width: 100%; height: 100%; }
.handle { position: absolute; top: 0; bottom: 0; width: 2px; background: #fff; transform: translateX(-1px); pointer-events: none; box-shadow: 0 0 8px rgba(0,0,0,0.6); }
.handle span { position: absolute; top: 50%; left: 50%; width: 34px; height: 34px; margin: -17px; border-radius: 50%; background: #fff; box-shadow: 0 2px 8px rgba(0,0,0,0.5); }
.handle span::before { content: '‹ ›'; position: absolute; inset: 0; display: grid; place-items: center; color: #333; font-weight: 700; letter-spacing: 2px; }
.compare input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: ew-resize; margin: 0; }
.lbl { position: absolute; top: 10px; font: 600 11px var(--sans); letter-spacing: 0.1em; text-transform: uppercase; background: rgba(0,0,0,0.6); padding: 4px 8px; border-radius: 6px; pointer-events: none; }
.lbl.l { left: 10px; } .lbl.r { right: 10px; }
.result-info h2 { font-size: 36px; margin-bottom: 2px; }
.artist { font: italic 500 20px var(--serif); color: var(--gold2); }
.fact { font-size: 14.5px; }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 12px 0; }
.stats div { padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px; }
.stats dt { font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--dim); }
.stats dd { margin: 0; font-weight: 600; font-size: 16px; }
.stars { font-size: 30px; letter-spacing: 4px; color: rgba(255,255,255,0.15); }
.stars .on { color: var(--gold2); text-shadow: 0 0 12px rgba(242,213,138,0.6); }
.hammer { display: flex; justify-content: space-between; align-items: baseline; border-top: 1px solid var(--line); padding-top: 10px; margin-top: 6px; }
.hammer span { color: var(--muted); font-size: 13px; text-transform: uppercase; letter-spacing: 0.1em; }
.hammer b { font: 700 38px var(--serif); color: var(--gold2); }
.hammer b.pop { animation: pop .35s; }
@keyframes pop { 50% { transform: scale(1.15); } }
.profit { font-size: 13px; color: var(--good); text-align: right; }

.gallery-card { width: min(1100px, 100%); }
.g-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; }
.g-head p { margin: 4px 0 0; }
.g-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 18px; margin-top: 20px; }
.g-item { background: none; border: none; padding: 0; text-align: left; display: flex; flex-direction: column; gap: 8px; }
.g-item:disabled { cursor: not-allowed; opacity: 0.5; }
.g-frame { aspect-ratio: 4/5; padding: 7px; background: linear-gradient(135deg, #f6dc8e, #b8862f 30%, #f2d58a 50%, #8a5f1e 80%); border-radius: 2px; box-shadow: 0 8px 20px rgba(0,0,0,0.5); transition: transform .15s; }
.g-item:not(:disabled):hover .g-frame { transform: translateY(-3px) rotate(-0.5deg); }
.g-frame img { width: 100%; height: 100%; object-fit: cover; display: block; }
.g-mystery { width: 100%; height: 100%; display: grid; place-items: center; font: 700 44px var(--serif); color: rgba(255,255,255,0.35);
  background: radial-gradient(circle at 40% 35%, #6b5a3a, #2e2214); }
.g-cap b { display: block; font: 700 16px var(--serif); line-height: 1.15; }
.g-cap span { font-size: 12px; color: var(--muted); }
.g-item.done .g-cap span { color: var(--gold2); }
.credit { font-size: 12px; color: var(--dim); margin: 22px 0 0; }

/* ---------- responsive ---------- */
@media (max-width: 900px) {
  .studio { grid-template-columns: 1fr; grid-template-rows: auto 1fr auto; }
  .panel { order: 0; flex-direction: row; flex-wrap: wrap; align-items: center; gap: 8px 12px; padding: 8px 16px; border-left: none; border-bottom: 1px solid var(--line); overflow: visible; }
  .lot-card, .layers, .est { display: none; }
  .meters { flex: 1 1 200px; flex-direction: row; gap: 12px; }
  .meter { flex: 1; }
  .m-head { font-size: 11.5px; margin-bottom: 3px; }
  .actions { flex-direction: row; margin: 0; flex: 1 1 260px; }
  .actions .btn { flex: 1; padding: 8px 10px; font-size: 13px; }
  .hunch-result { display: none; }
  .bench { order: 1; }
  .frame { padding: 10px; }
  #ov { left: 10px; top: 10px; }
  .shine { inset: 10px; }
  .tools { order: 2; flex-direction: row; justify-content: center; border-right: none; border-top: 1px solid var(--line); padding: 6px 16px calc(6px + env(safe-area-inset-bottom)); gap: 4px; }
  .tool { flex: 1; max-width: 90px; padding: 4px 2px; }
  .tool svg { width: 30px; height: 30px; }
  .tool kbd { display: none; }
  .size { margin: 0; justify-content: center; }
  .size input { width: 64px; }
  .title-card { grid-template-columns: 1fr; text-align: center; }
  .title-art { width: 180px; margin: 12px auto; }
  .how { text-align: left; }
  .title-card .row { justify-content: center; }
  .result-card { grid-template-columns: 1fr; }
  .compare img { max-height: 42vh; }
  .hunch-card .opts { grid-template-columns: 1fr; }
}
@media (max-width: 520px) {
  .brand { font-size: 18px; }
  .bank b { font-size: 17px; }
  #btn-gallery { padding: 6px 9px; }
  .card { padding: 20px; }
  .card h2 { font-size: 26px; }
  .size span { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; }
}
