/* global React */
/* Single-piece detail page — reusable template for all eight pieces.
   Layout: hero (60/40 image+info, 1200px), then 800px editorial column. */

// ---- placeholder data for Piece I -------------------------------------------
const PIECE = {
  roman: 'I',
  index: 1,
  total: 8,
  name: 'The Veil Coat',
  descriptor: 'Italian wool · raw silk lining · twenty made.',
  price: 4200,
  editionSize: 20,
  story: [
    'Cut in a single panel from undyed Italian wool, then dipped in three obsidian baths over nine days. The lining is raw silk — matte, unwashed, the colour of bone.',
    'There is no closure on the front. The coat falls from the shoulder and stays. It was drawn over fourteen fittings in the Marchi atelier in Florence and finished by Stefano Marchi and one apprentice.',
    'Each piece carries a hand-stitched edition mark at the inside hem. After the twentieth, the pattern is destroyed.',
  ],
  pull: 'The coat is the shape of standing still.',
  measurements: [
    ['Material',  'Undyed Italian wool · obsidian-dyed in three baths'],
    ['Lining',    'Raw silk · matte bone'],
    ['Cut',       'Florence · Marchi Atelier'],
    ['Length',    '124 cm at shoulder · floor on a six-foot frame'],
    ['Drop',      '38 cm shoulder · single uncut panel'],
    ['Weight',    '1.85 kg'],
    ['Origin',    'Hand-cut and finished in Italy'],
  ],
  sizes: ['I', 'II', 'III', 'IV'],
  care: 'No washing. Air on a wide hanger after wear. The wool repairs itself in two days. For deeper service the house arranges atelier maintenance once a year by reservation.',
  provenance: 'Each coat is registered to its first owner. The certificate is delivered separately, in a sealed envelope, ten days after the piece.',
};

const RELATED = [
  { roman: 'II',  name: 'The Architect Trouser',  price: 2400, tint: 'cool' },
  { roman: 'III', name: 'The Cathedral Cloak',    price: 6000, tint: 'door' },
];

// ---- atmospheric placeholder image ------------------------------------------
function Plate({ tint = 'cool', label, aspect = '4 / 5', children, style }) {
  const bg = {
    cool:   'radial-gradient(ellipse 60% 50% at 50% 52%, rgba(232,232,227,0.10) 0%, rgba(232,232,227,0.03) 20%, transparent 46%), linear-gradient(180deg, #0c0c0c 0%, #050505 100%)',
    warm:   'radial-gradient(ellipse 70% 60% at 50% 56%, rgba(139,0,0,0.35) 0%, rgba(139,0,0,0.10) 22%, transparent 50%), linear-gradient(180deg, #0c0606 0%, #060404 100%)',
    door:   'radial-gradient(ellipse 14% 36% at 50% 56%, rgba(139,0,0,0.85) 0%, rgba(139,0,0,0.32) 14%, transparent 30%), linear-gradient(180deg, #0a0a0a 0%, #050505 100%)',
    drape:  'linear-gradient(102deg, #050505 0%, #0a0a0a 38%, #1a0a0a 58%, #0a0606 78%, #050505 100%)',
    atelier:'radial-gradient(ellipse 80% 30% at 50% 88%, rgba(139,0,0,0.18) 0%, transparent 60%), linear-gradient(180deg, #050505 0%, #0a0a0a 50%, #060606 100%)',
    hands:  'radial-gradient(ellipse 30% 22% at 36% 44%, rgba(232,232,227,0.16) 0%, rgba(232,232,227,0.04) 26%, transparent 50%), linear-gradient(180deg, #060606 0%, #0a0a0a 100%)',
    seam:   'linear-gradient(180deg, #060606 0%, #0a0a0a 100%)',
  }[tint] || 'linear-gradient(180deg, #0a0a0a, #050505)';

  return (
    <div style={{
      position: 'relative', width: '100%', aspectRatio: aspect, overflow: 'hidden',
      background: bg, ...style,
    }}>
      {/* subject silhouette — varies subtly per tint */}
      {tint === 'cool' && (
        <div style={{
          position: 'absolute', left: '50%', top: '54%',
          transform: 'translate(-50%,-50%)', width: '26%', height: '74%',
          background: 'linear-gradient(180deg, rgba(232,232,227,0.14) 0%, rgba(232,232,227,0.05) 38%, transparent 95%)',
        }}/>
      )}
      {tint === 'warm' && (
        <div style={{
          position: 'absolute', left: '50%', top: '60%',
          transform: 'translate(-50%,-50%)', width: '34%', height: '52%',
          background: 'linear-gradient(180deg, rgba(232,232,227,0.10) 0%, rgba(232,232,227,0.02) 60%, transparent 100%)',
        }}/>
      )}
      {tint === 'door' && (
        <div style={{
          position: 'absolute', left: '50%', top: '50%',
          transform: 'translate(-50%,-50%)', width: '6%', height: '38%',
          background: 'linear-gradient(180deg, rgba(232,232,227,0.20) 0%, transparent 100%)',
          mixBlendMode: 'screen',
        }}/>
      )}
      {tint === 'drape' && (
        <>
          <div style={{
            position: 'absolute', left: '14%', top: 0, width: '2%', height: '100%',
            background: 'linear-gradient(180deg, transparent, rgba(232,232,227,0.06), transparent)',
          }}/>
          <div style={{
            position: 'absolute', left: '34%', top: 0, width: '2%', height: '100%',
            background: 'linear-gradient(180deg, transparent, rgba(232,232,227,0.04), transparent)',
          }}/>
          <div style={{
            position: 'absolute', left: '58%', top: 0, width: '2%', height: '100%',
            background: 'linear-gradient(180deg, transparent, rgba(232,232,227,0.05), transparent)',
          }}/>
          <div style={{
            position: 'absolute', left: '82%', top: 0, width: '2%', height: '100%',
            background: 'linear-gradient(180deg, transparent, rgba(232,232,227,0.03), transparent)',
          }}/>
        </>
      )}
      {tint === 'atelier' && (
        <>
          <div style={{
            position: 'absolute', left: '20%', top: '30%', width: '18%', height: '40%',
            background: 'linear-gradient(180deg, rgba(232,232,227,0.06) 0%, rgba(232,232,227,0.02) 60%, transparent 100%)',
          }}/>
          <div style={{
            position: 'absolute', left: '60%', top: '32%', width: '16%', height: '38%',
            background: 'linear-gradient(180deg, rgba(232,232,227,0.05) 0%, rgba(232,232,227,0.02) 60%, transparent 100%)',
          }}/>
        </>
      )}
      {tint === 'hands' && (
        <div style={{
          position: 'absolute', left: '32%', top: '40%', width: '14%', height: '20%',
          background: 'radial-gradient(ellipse 60% 60% at 50% 50%, rgba(232,232,227,0.18), transparent 70%)',
        }}/>
      )}
      {tint === 'seam' && (
        <div style={{
          position: 'absolute', left: 0, right: 0, top: '50%',
          height: 1, background: 'linear-gradient(90deg, transparent, rgba(232,232,227,0.30) 30%, rgba(232,232,227,0.45) 50%, rgba(232,232,227,0.30) 70%, transparent)',
        }}/>
      )}

      {/* top + bottom fade for legibility */}
      <div style={{
        position: 'absolute', inset: 0, pointerEvents: 'none',
        background: 'linear-gradient(180deg, rgba(10,10,10,0.35) 0%, transparent 18%, transparent 80%, rgba(10,10,10,0.55) 100%)',
      }}/>

      {label && (
        <div style={{
          position: 'absolute', left: 20, bottom: 18,
          fontFamily: 'Inter, sans-serif', fontWeight: 500, fontSize: 10,
          letterSpacing: 4, textTransform: 'uppercase',
          color: 'rgba(232,232,227,0.55)',
        }}>{label}</div>
      )}
      {children}
    </div>
  );
}

// ---- twenty-mark tally ------------------------------------------------------
function Tally({ remaining, total = 20 }) {
  return (
    <div style={{
      display: 'flex', gap: 4, alignItems: 'center',
      marginTop: 4,
    }}>
      {Array.from({ length: total }).map((_, i) => {
        const held = i >= remaining;
        return (
          <span key={i} style={{
            display: 'inline-block', width: 8, height: 1,
            background: held ? 'rgba(232,232,227,0.12)' : 'rgba(139,0,0,0.85)',
            transition: 'background 200ms ease',
          }}/>
        );
      })}
    </div>
  );
}

// ---- small text-button (matches Drop page Btn) ------------------------------
function Btn({ children, onClick, href, kind = 'wine', style, disabled }) {
  const baseColor = disabled ? 'rgba(232,232,227,0.18)' : kind === 'wine' ? '#8b0000' : 'rgba(232,232,227,0.55)';
  const baseBorder = disabled ? 'rgba(232,232,227,0.10)' : kind === 'wine' ? 'rgba(139,0,0,0.40)' : 'rgba(232,232,227,0.30)';
  const props = {
    onClick: disabled ? undefined : onClick,
    style: {
      display: 'inline-block', fontFamily: 'Inter, sans-serif', fontWeight: 500,
      fontSize: 10, letterSpacing: 4, textTransform: 'uppercase',
      color: baseColor, background: 'transparent', border: 0,
      borderBottom: `1px solid ${baseBorder}`, padding: '4px 0',
      cursor: disabled ? 'not-allowed' : 'pointer', textDecoration: 'none',
      transition: 'color 200ms ease, border-color 200ms ease', ...style,
    },
    onMouseEnter: disabled ? undefined : e => {
      e.currentTarget.style.color = '#e8e8e3';
      e.currentTarget.style.borderBottomColor = 'rgba(232,232,227,0.85)';
    },
    onMouseLeave: disabled ? undefined : e => {
      e.currentTarget.style.color = baseColor;
      e.currentTarget.style.borderBottomColor = baseBorder;
    },
  };
  return href
    ? <a href={href} {...props}>{children}</a>
    : <button {...props}>{children}</button>;
}

// ---- top nav ----------------------------------------------------------------
function PageNav({ onBack }) {
  return (
    <header style={{
      maxWidth: 1200, margin: '0 auto', padding: '32px 32px 0',
      display: 'flex', alignItems: 'center', justifyContent: 'space-between',
      position: 'relative', zIndex: 5,
    }}>
      <a href="#" onClick={e => { e.preventDefault(); onBack && onBack(); }}
        style={{
          fontFamily: 'Inter, sans-serif', fontWeight: 500,
          fontSize: 10, letterSpacing: 4, textTransform: 'uppercase',
          color: 'rgba(232,232,227,0.55)', textDecoration: 'none',
          transition: 'color 200ms ease',
        }}
        onMouseEnter={e => e.currentTarget.style.color = '#e8e8e3'}
        onMouseLeave={e => e.currentTarget.style.color = 'rgba(232,232,227,0.55)'}
      >← All pieces</a>

      <div style={{
        fontFamily: 'Playfair Display, serif', fontWeight: 500, fontSize: 16,
        letterSpacing: 6, color: '#e8e8e3',
      }}>OBSKIRA</div>

      <div style={{
        fontFamily: 'Inter, sans-serif', fontWeight: 500,
        fontSize: 10, letterSpacing: 4, textTransform: 'uppercase',
        color: 'rgba(232,232,227,0.35)',
      }}>Drop IX · MMXXVI</div>
    </header>
  );
}

// ---- reservation modal ------------------------------------------------------
function Reservation({ piece, onClose, onConfirm }) {
  const [size, setSize] = React.useState(null);
  const [email, setEmail] = React.useState('');
  const valid = size && /\S+@\S+\.\S+/.test(email);

  React.useEffect(() => {
    const onKey = e => e.key === 'Escape' && onClose();
    document.addEventListener('keydown', onKey);
    return () => document.removeEventListener('keydown', onKey);
  }, [onClose]);

  return (
    <div
      onClick={onClose}
      style={{
        position: 'fixed', inset: 0, zIndex: 100,
        background: 'rgba(0,0,0,0.88)', backdropFilter: 'blur(6px)',
        WebkitBackdropFilter: 'blur(6px)',
        display: 'flex', alignItems: 'center', justifyContent: 'center',
        padding: 24, animation: 'obskiraFadeUp 200ms ease both',
      }}>
      <div
        onClick={e => e.stopPropagation()}
        style={{
          background: '#0a0a0a', border: '1px solid rgba(139,0,0,0.40)',
          maxWidth: 520, width: '100%', padding: '40px 40px 32px',
        }}>
        <div style={{
          fontFamily: 'Inter, sans-serif', fontWeight: 500,
          fontSize: 10, letterSpacing: 4, textTransform: 'uppercase',
          color: 'rgba(232,232,227,0.35)',
        }}>{piece.roman} · Reservation</div>
        <div style={{
          fontFamily: 'Playfair Display, serif', fontWeight: 500,
          fontSize: 30, color: '#e8e8e3', marginTop: 10, lineHeight: 1.15,
        }}>Hold {piece.name}</div>
        <p style={{
          fontFamily: 'Inter, sans-serif', fontWeight: 300, fontSize: 14,
          lineHeight: 1.75, color: 'rgba(232,232,227,0.82)', margin: '16px 0 0',
        }}>
          The piece is held for seventy-two hours. The house confirms separately. Payment is settled in full at confirmation.
        </p>

        {/* Size */}
        <div style={{ marginTop: 28 }}>
          <div style={{
            fontFamily: 'Inter, sans-serif', fontSize: 9,
            letterSpacing: 3, textTransform: 'uppercase',
            color: 'rgba(232,232,227,0.35)', marginBottom: 12,
          }}>Size</div>
          <div style={{ display: 'flex', gap: 0 }}>
            {piece.sizes.map(s => (
              <button key={s}
                onClick={() => setSize(s)}
                style={{
                  flex: 1, padding: '14px 0',
                  fontFamily: 'Playfair Display, serif', fontSize: 18, fontWeight: 500,
                  color: size === s ? '#e8e8e3' : 'rgba(232,232,227,0.55)',
                  background: size === s ? 'rgba(139,0,0,0.10)' : 'transparent',
                  border: '1px solid rgba(139,0,0,0.18)',
                  borderRightWidth: 0,
                  borderLeftWidth: s === piece.sizes[0] ? 1 : 0,
                  cursor: 'pointer',
                  transition: 'all 200ms ease',
                }}
                onMouseEnter={e => { if (size !== s) e.currentTarget.style.color = '#e8e8e3'; }}
                onMouseLeave={e => { if (size !== s) e.currentTarget.style.color = 'rgba(232,232,227,0.55)'; }}
              >{s}</button>
            ))}
            <div style={{
              borderRight: '1px solid rgba(139,0,0,0.18)',
            }}/>
          </div>
        </div>

        {/* Email */}
        <div style={{ marginTop: 28 }}>
          <label style={{
            display: 'block', fontFamily: 'Inter, sans-serif', fontSize: 9,
            letterSpacing: 3, textTransform: 'uppercase',
            color: 'rgba(232,232,227,0.35)', marginBottom: 6,
          }}>Email</label>
          <input
            type="email"
            value={email}
            onChange={e => setEmail(e.target.value)}
            placeholder="surname@domain"
            style={{
              background: 'transparent', border: 0,
              borderBottom: '1px solid rgba(232,232,227,0.30)',
              fontFamily: 'Inter, sans-serif', fontWeight: 300,
              fontSize: 14, padding: '10px 0', color: '#e8e8e3',
              width: '100%', outline: 0,
              transition: 'border-color 200ms ease',
            }}
            onFocus={e => e.target.style.borderBottomColor = '#8b0000'}
            onBlur={e => e.target.style.borderBottomColor = 'rgba(232,232,227,0.30)'}
          />
        </div>

        <div style={{ display: 'flex', gap: 32, marginTop: 36 }}>
          <Btn onClick={() => valid && onConfirm({ size, email })} disabled={!valid}>
            Continue
          </Btn>
          <Btn onClick={onClose} kind="bone">Close</Btn>
        </div>
      </div>
    </div>
  );
}

// ---- after-reserve toast ----------------------------------------------------
function HeldToast({ piece, onClose }) {
  React.useEffect(() => {
    const t = setTimeout(onClose, 4200);
    return () => clearTimeout(t);
  }, [onClose]);
  return (
    <div style={{
      position: 'fixed', left: '50%', bottom: 40,
      transform: 'translateX(-50%)', zIndex: 90,
      background: '#0a0a0a', border: '1px solid rgba(139,0,0,0.40)',
      padding: '20px 28px', display: 'flex', alignItems: 'center', gap: 28,
      animation: 'obskiraFadeUp 300ms ease both', maxWidth: '92vw',
    }}>
      <div>
        <div style={{
          fontFamily: 'Inter, sans-serif', fontSize: 9,
          letterSpacing: 3, textTransform: 'uppercase',
          color: 'rgba(232,232,227,0.35)',
        }}>{piece.roman} · Held</div>
        <div style={{
          fontFamily: 'Playfair Display, serif', fontSize: 18, color: '#e8e8e3',
          marginTop: 4,
        }}>{piece.name} is held for seventy-two hours.</div>
      </div>
      <button onClick={onClose} style={{
        background: 'transparent', border: 0, color: 'rgba(232,232,227,0.55)',
        fontFamily: 'Inter, sans-serif', fontSize: 16, cursor: 'pointer',
        padding: 0, lineHeight: 1,
      }}>×</button>
    </div>
  );
}

// ---- main page --------------------------------------------------------------
function PiecePage() {
  const [held, setHeld] = React.useState(0); // number of holds the user has placed
  const [reserving, setReserving] = React.useState(false);
  const [toast, setToast] = React.useState(false);

  // restore from localStorage so refresh keeps state
  React.useEffect(() => {
    const v = parseInt(localStorage.getItem('obskira:piece01:held') || '0', 10);
    if (!Number.isNaN(v)) setHeld(v);
  }, []);
  React.useEffect(() => {
    localStorage.setItem('obskira:piece01:held', String(held));
  }, [held]);

  const remaining = PIECE.editionSize - held;

  function confirmHold() {
    setHeld(h => Math.min(PIECE.editionSize, h + 1));
    setReserving(false);
    setToast(true);
  }

  return (
    <>
      <PageNav onBack={() => alert('Back to all pieces (stub for prototype)')} />

      {/* HERO — 1200px breakout, 60/40 split */}
      <section className="hero-row" style={{
        maxWidth: 1200, margin: '0 auto', padding: '56px 32px 0',
        position: 'relative', zIndex: 5,
      }}>
        <div className="hero-grid" style={{
          display: 'grid',
          gridTemplateColumns: 'minmax(0, 1.5fr) minmax(0, 1fr)',
          gap: 56, alignItems: 'start',
        }}>
          {/* Primary image */}
          <div>
            <Plate tint="cool" aspect="4 / 5" label={`${PIECE.roman} · No Studio Light`} />
          </div>

          {/* Info column */}
          <div style={{ paddingTop: 8 }}>
            {/* Edition mark */}
            <div style={{ display: 'flex', alignItems: 'baseline', gap: 16 }}>
              <div style={{
                fontFamily: 'Playfair Display, serif', fontStyle: 'italic',
                fontWeight: 400, fontSize: 80, lineHeight: 0.9,
                color: 'rgba(232,232,227,0.55)',
              }}>{String(PIECE.index).padStart(2, '0')}</div>
              <div style={{
                fontFamily: 'Inter, sans-serif', fontWeight: 500,
                fontSize: 10, letterSpacing: 4, textTransform: 'uppercase',
                color: 'rgba(232,232,227,0.35)',
              }}>of {String(PIECE.total).padStart(2, '0')}<br/>Drop IX</div>
            </div>

            {/* Name */}
            <h1 style={{
              fontFamily: 'Playfair Display, serif', fontWeight: 500,
              fontSize: 'clamp(34px, 4vw, 44px)', letterSpacing: 1,
              lineHeight: 1.1, color: '#e8e8e3', margin: '40px 0 0',
            }}>{PIECE.name}</h1>

            {/* Single descriptor */}
            <div style={{
              fontFamily: 'Inter, sans-serif', fontWeight: 300, fontSize: 15,
              lineHeight: 1.7, color: 'rgba(232,232,227,0.55)',
              marginTop: 18, maxWidth: 380,
            }}>
              {PIECE.descriptor}
            </div>

            {/* Hairline */}
            <div style={{
              width: 56, height: 1, marginTop: 40,
              background: 'rgba(139,0,0,0.40)',
            }}/>

            {/* Price */}
            <div style={{
              fontFamily: 'Playfair Display, serif', fontWeight: 500,
              fontSize: 28, color: '#e8e8e3', marginTop: 24,
            }}>USD {PIECE.price.toLocaleString()}</div>

            {/* Remaining tally */}
            <div style={{ marginTop: 24 }}>
              <div style={{
                fontFamily: 'Inter, sans-serif', fontWeight: 500,
                fontSize: 10, letterSpacing: 4, textTransform: 'uppercase',
                color: 'rgba(232,232,227,0.35)',
              }}>{remaining > 0
                  ? `${remaining} of ${PIECE.editionSize} remaining`
                  : 'Edition closed'
              }</div>
              <Tally remaining={remaining} total={PIECE.editionSize} />
            </div>

            {/* Reserve button */}
            <div style={{ marginTop: 40, display: 'flex', gap: 40, alignItems: 'center' }}>
              <Btn
                onClick={() => setReserving(true)}
                disabled={remaining === 0}
                style={{ fontSize: 11, padding: '8px 0' }}
              >
                {remaining === 0 ? 'Closed' : 'Reserve'}
              </Btn>
              <a href="#story" style={{
                fontFamily: 'Inter, sans-serif', fontWeight: 500,
                fontSize: 10, letterSpacing: 4, textTransform: 'uppercase',
                color: 'rgba(232,232,227,0.35)', textDecoration: 'none',
                transition: 'color 200ms ease',
              }}
              onMouseEnter={e => e.currentTarget.style.color = '#e8e8e3'}
              onMouseLeave={e => e.currentTarget.style.color = 'rgba(232,232,227,0.35)'}
              >The material story ↓</a>
            </div>
          </div>
        </div>
      </section>

      {/* MATERIAL STORY — 800px column */}
      <div className="column">
        <div style={{
          width: '100%', height: 1, margin: '120px 0 0',
          background: 'linear-gradient(90deg, transparent 0%, rgba(139,0,0,0.3) 20%, rgba(139,0,0,0.4) 50%, rgba(139,0,0,0.3) 80%, transparent 100%)',
        }}/>

        <section id="story" style={{ padding: '80px 0 0' }}>
          <div style={{
            fontFamily: 'Inter, sans-serif', fontWeight: 500,
            fontSize: 10, letterSpacing: 4, textTransform: 'uppercase',
            color: 'rgba(232,232,227,0.35)', marginBottom: 32,
          }}>I · Material</div>

          {PIECE.story.map((p, i) => (
            <p key={i} style={{
              fontFamily: 'Inter, sans-serif', fontWeight: 300, fontSize: 18,
              lineHeight: 1.75, color: 'rgba(232,232,227,0.82)',
              margin: '0 0 28px', maxWidth: 640,
            }}>{p}</p>
          ))}

          <blockquote style={{
            fontFamily: 'Playfair Display, serif', fontStyle: 'italic',
            fontWeight: 400, fontSize: 28, lineHeight: 1.4,
            color: 'rgba(232,232,227,0.82)',
            borderLeft: '2px solid #8b0000', paddingLeft: 24,
            margin: '48px 0 0', maxWidth: 600,
          }}>{PIECE.pull}</blockquote>
        </section>
      </div>

      {/* GALLERY — column-width, stacked, generous breathing */}
      <div className="column">
        <section style={{ padding: '120px 0 0' }}>
          <div style={{
            fontFamily: 'Inter, sans-serif', fontWeight: 500,
            fontSize: 10, letterSpacing: 4, textTransform: 'uppercase',
            color: 'rgba(232,232,227,0.35)', marginBottom: 40,
          }}>II · Plates</div>

          <div style={{ display: 'flex', flexDirection: 'column', gap: 80 }}>
            <Plate tint="drape"   aspect="3 / 4" label="II · Front · Standing" />
            <Plate tint="warm"    aspect="16 / 11" label="III · Seam · Inside hem" />

            {/* two-up row for rhythm */}
            <div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 24 }}>
              <Plate tint="hands"  aspect="3 / 4" label="IV · Stitch · Marchi Atelier" />
              <Plate tint="seam"   aspect="3 / 4" label="V · Lining · Raw silk" />
            </div>

            <Plate tint="door"    aspect="16 / 9" label="VI · Worn · No motion" />
            <Plate tint="atelier" aspect="3 / 2"  label="VII · Cutting Floor · Florence" />
          </div>
        </section>
      </div>

      {/* MEASUREMENTS — column-width */}
      <div className="column">
        <section style={{ padding: '120px 0 0' }}>
          <div style={{
            fontFamily: 'Inter, sans-serif', fontWeight: 500,
            fontSize: 10, letterSpacing: 4, textTransform: 'uppercase',
            color: 'rgba(232,232,227,0.35)', marginBottom: 32,
          }}>III · Measurement</div>

          <table style={{ width: '100%', borderCollapse: 'collapse' }}>
            <tbody>
              {PIECE.measurements.map(([k, v]) => (
                <tr key={k} style={{ borderBottom: '1px solid rgba(255,255,255,0.04)' }}>
                  <td style={{
                    padding: '20px 0', width: '32%',
                    fontFamily: 'Inter, sans-serif', fontWeight: 500,
                    fontSize: 10, letterSpacing: 3, textTransform: 'uppercase',
                    color: 'rgba(232,232,227,0.35)', verticalAlign: 'top',
                  }}>{k}</td>
                  <td style={{
                    padding: '20px 0',
                    fontFamily: 'Playfair Display, serif', fontWeight: 500,
                    fontSize: 19, color: '#e8e8e3', lineHeight: 1.4,
                  }}>{v}</td>
                </tr>
              ))}
            </tbody>
          </table>

          <div style={{ marginTop: 32, display: 'flex', gap: 40, alignItems: 'center' }}>
            <Btn href="#" kind="bone" style={{ fontSize: 10 }}>The sizing chart →</Btn>
            <span style={{
              fontFamily: 'Inter, sans-serif', fontWeight: 300, fontSize: 13,
              color: 'rgba(232,232,227,0.55)', lineHeight: 1.6,
            }}>Four sizes. Italian cut. Run true.</span>
          </div>
        </section>
      </div>

      {/* CARE + PROVENANCE — column-width, smaller text */}
      <div className="column">
        <section style={{ padding: '120px 0 0' }}>
          <div style={{
            display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 56,
          }} className="care-grid">
            <div>
              <div style={{
                fontFamily: 'Inter, sans-serif', fontWeight: 500,
                fontSize: 10, letterSpacing: 4, textTransform: 'uppercase',
                color: 'rgba(232,232,227,0.35)', marginBottom: 18,
              }}>IV · Care</div>
              <p style={{
                fontFamily: 'Inter, sans-serif', fontWeight: 300, fontSize: 14,
                lineHeight: 1.8, color: 'rgba(232,232,227,0.82)', margin: 0,
              }}>{PIECE.care}</p>
            </div>
            <div>
              <div style={{
                fontFamily: 'Inter, sans-serif', fontWeight: 500,
                fontSize: 10, letterSpacing: 4, textTransform: 'uppercase',
                color: 'rgba(232,232,227,0.35)', marginBottom: 18,
              }}>V · Provenance</div>
              <p style={{
                fontFamily: 'Inter, sans-serif', fontWeight: 300, fontSize: 14,
                lineHeight: 1.8, color: 'rgba(232,232,227,0.82)', margin: 0,
              }}>{PIECE.provenance}</p>
            </div>
          </div>
        </section>
      </div>

      {/* RELATED — column-width, quiet */}
      <div className="column">
        <section style={{ padding: '120px 0 80px' }}>
          <div style={{
            fontFamily: 'Inter, sans-serif', fontWeight: 500,
            fontSize: 10, letterSpacing: 4, textTransform: 'uppercase',
            color: 'rgba(232,232,227,0.35)', marginBottom: 40,
          }}>VI · Also in Drop IX</div>

          <div style={{
            display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 32,
          }}>
            {RELATED.map(r => (
              <RelatedTile key={r.roman} piece={r} />
            ))}
          </div>

          <div style={{ marginTop: 80, textAlign: 'center' }}>
            <Btn href="#" kind="bone" style={{ fontSize: 10 }}>← All eight pieces</Btn>
          </div>
        </section>
      </div>

      {/* Footer */}
      <footer style={{
        maxWidth: 800, margin: '0 auto', padding: '32px',
        borderTop: '1px solid rgba(139,0,0,0.18)',
        display: 'flex', justifyContent: 'space-between',
        fontFamily: 'Inter, sans-serif', fontWeight: 500,
        fontSize: 10, letterSpacing: 4, textTransform: 'uppercase',
        color: 'rgba(232,232,227,0.18)', position: 'relative', zIndex: 5,
      }}>
        <span>Obskira Runway · MMXXVI</span>
        <span>Hold the line</span>
      </footer>

      {reserving && (
        <Reservation
          piece={PIECE}
          onClose={() => setReserving(false)}
          onConfirm={confirmHold}
        />
      )}
      {toast && <HeldToast piece={PIECE} onClose={() => setToast(false)} />}
    </>
  );
}

function RelatedTile({ piece }) {
  const [hover, setHover] = React.useState(false);
  return (
    <a href="#"
      onClick={e => e.preventDefault()}
      onMouseEnter={() => setHover(true)}
      onMouseLeave={() => setHover(false)}
      style={{
        textDecoration: 'none', display: 'block',
        border: `1px solid ${hover ? 'rgba(139,0,0,0.40)' : 'rgba(139,0,0,0.18)'}`,
        background: hover ? 'rgba(139,0,0,0.04)' : 'transparent',
        padding: 24, transition: 'all 200ms ease',
      }}>
      <Plate tint={piece.tint} aspect="3 / 4" />
      <div style={{
        display: 'flex', justifyContent: 'space-between', alignItems: 'baseline',
        marginTop: 20,
      }}>
        <div>
          <div style={{
            fontFamily: 'Inter, sans-serif', fontWeight: 500,
            fontSize: 9, letterSpacing: 3, textTransform: 'uppercase',
            color: 'rgba(232,232,227,0.35)',
          }}>{piece.roman} · Of VIII</div>
          <div style={{
            fontFamily: 'Playfair Display, serif', fontWeight: 500,
            fontSize: 20, color: '#e8e8e3', marginTop: 8,
          }}>{piece.name}</div>
        </div>
        <div style={{
          fontFamily: 'Inter, sans-serif', fontWeight: 500,
          fontSize: 10, letterSpacing: 2, textTransform: 'uppercase',
          color: 'rgba(232,232,227,0.55)',
        }}>USD {piece.price.toLocaleString()}</div>
      </div>
    </a>
  );
}

window.PiecePage = PiecePage;
