:root {
  --ink: #15120e;
  --ink-2: #221d17;
  --paper: #f3eee4;
  --paper-2: #e7dfd0;
  --text: #1c1813;
  --muted: #7b7163;
  --on-ink: #efe8da;
  --on-ink-muted: #9c9282;
  --accent: #e2552b;
  --line: rgba(28, 24, 19, 0.14);

  --serif: 'Instrument Serif', 'Times New Roman', Georgia, serif;
  --sans: 'IBM Plex Sans KR', 'Malgun Gothic', 'Apple SD Gothic Neo', sans-serif;
  --mono: 'IBM Plex Mono', Consolas, 'Courier New', monospace;
}

* { box-sizing: border-box; }

html { background: var(--ink); }

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--sans);
  color: var(--on-ink);
  background:
    radial-gradient(1200px 600px at 85% -10%, rgba(226, 85, 43, 0.16), transparent 60%),
    radial-gradient(900px 500px at -10% 30%, rgba(215, 199, 162, 0.08), transparent 60%),
    var(--ink);
  padding: 0 clamp(16px, 4vw, 56px) 40px;
}

.grain {
  position: fixed; inset: 0; pointer-events: none; z-index: 100; opacity: 0.07;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

button { font: inherit; cursor: pointer; }
kbd {
  font-family: var(--mono); font-size: 0.85em;
  border: 1px solid currentColor; border-radius: 3px; padding: 0 4px; opacity: 0.8;
}
code { font-family: var(--mono); font-size: 0.95em; }

/* ---------- masthead ---------- */

.masthead {
  max-width: 1180px; margin: 0 auto;
  padding: clamp(40px, 8vw, 96px) 0 36px;
  border-bottom: 1px solid rgba(239, 232, 218, 0.14);
  animation: rise 0.8s cubic-bezier(.2, .7, .2, 1) both;
}
.eyebrow {
  margin: 0 0 12px; font-family: var(--mono); font-size: 12px;
  letter-spacing: 0.18em; text-transform: uppercase; color: var(--accent);
}
h1 {
  margin: 0; font-family: var(--serif); font-weight: 400;
  font-size: clamp(56px, 11vw, 140px); line-height: 0.88; letter-spacing: -0.02em;
}
h1 em { font-style: italic; color: var(--paper-2); }
.lede {
  max-width: 620px; margin: 22px 0 0; line-height: 1.75;
  color: var(--on-ink-muted); font-size: 15px;
}

main { max-width: 1180px; margin: 0 auto; }

/* ---------- drop zone ---------- */

.drop {
  position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 10px; margin: 36px 0 28px; padding: 48px 20px; text-align: center; cursor: pointer;
  border: 1.5px dashed rgba(239, 232, 218, 0.28); border-radius: 4px;
  background: rgba(239, 232, 218, 0.025);
  transition: border-color .2s, background .2s, transform .2s;
  animation: rise 0.8s 0.12s cubic-bezier(.2, .7, .2, 1) both;
}
.drop:hover, .drop:focus-visible { border-color: var(--accent); background: rgba(226, 85, 43, 0.06); outline: none; }
.drop.over { border-color: var(--accent); background: rgba(226, 85, 43, 0.12); transform: scale(1.01); }
.drop-title { font-family: var(--serif); font-size: clamp(26px, 4vw, 38px); line-height: 1.1; }
.drop-sub { color: var(--on-ink-muted); font-size: 14px; }
.drop-chips { display: flex; gap: 6px; margin-bottom: 8px; }
.drop-chips i {
  display: block; width: 22px; height: 34px; border-radius: 2px;
  transition: transform .35s cubic-bezier(.3, 1.6, .5, 1);
}
.drop-chips i:nth-child(1) { background: #694432; }
.drop-chips i:nth-child(2) { background: #d7c7a2; transition-delay: .03s; }
.drop-chips i:nth-child(3) { background: var(--accent); transition-delay: .06s; }
.drop-chips i:nth-child(4) { background: #b1a08a; transition-delay: .09s; }
.drop-chips i:nth-child(5) { background: #f2ead2; transition-delay: .12s; }
.drop:hover .drop-chips i, .drop.over .drop-chips i { transform: translateY(-6px) rotate(-4deg); }

/* ---------- toolbar ---------- */

.toolbar {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  margin-bottom: 16px; font-family: var(--mono); font-size: 12px;
  letter-spacing: 0.08em; text-transform: uppercase; color: var(--on-ink-muted);
}
.ghost {
  background: none; border: 1px solid rgba(239, 232, 218, 0.25); color: var(--on-ink);
  padding: 6px 12px; border-radius: 3px; font-size: 13px;
}
.ghost:hover { border-color: var(--accent); color: var(--accent); }
.ghost:disabled { opacity: .45; pointer-events: none; }
.toolbar-actions { display: flex; gap: 8px; }

.menu-wrap { position: relative; }
.menu {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 20; min-width: 220px;
  display: flex; flex-direction: column; padding: 6px; border-radius: 4px;
  background: var(--paper); box-shadow: 0 18px 40px -16px rgba(0, 0, 0, .8);
  text-transform: none; letter-spacing: 0;
  animation: rise .18s cubic-bezier(.2, .7, .2, 1) both;
}
.menu[hidden] { display: none; }
.menu button {
  display: flex; justify-content: space-between; align-items: baseline; gap: 16px;
  border: 0; background: none; color: var(--text); text-align: left;
  padding: 9px 12px; border-radius: 3px; font-family: var(--sans); font-size: 14px;
}
.menu button small { font-family: var(--mono); font-size: 10px; letter-spacing: .08em; color: var(--muted); }
.menu button:hover, .menu button:focus-visible { background: var(--paper-2); outline: none; }
.menu button[data-kind="all"] { border-top: 1px solid var(--line); border-radius: 0 0 3px 3px; margin-top: 4px; padding-top: 11px; }

/* ---------- result cards ---------- */

.results { display: grid; gap: 22px; }

.card {
  position: relative; display: grid; grid-template-columns: minmax(0, 300px) minmax(0, 1fr);
  background: var(--paper); color: var(--text); border-radius: 4px; overflow: hidden;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.4) inset, 0 24px 60px -30px rgba(0, 0, 0, 0.8);
  animation: rise 0.6s cubic-bezier(.2, .7, .2, 1) both;
}
.card-photo { position: relative; background: var(--ink-2); min-height: 220px; }
.card-photo img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.card-name {
  position: absolute; left: 0; right: 0; bottom: 0; padding: 26px 14px 10px;
  font-family: var(--mono); font-size: 11px; color: #fff; word-break: break-all;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.65));
}
.card-body { padding: 22px 24px 20px; display: flex; flex-direction: column; gap: 16px; min-width: 0; }

.status { font-family: var(--mono); font-size: 13px; color: var(--muted); }
.status.error { color: #b3261e; }

.swatches { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px; }
.swatch {
  display: flex; flex-direction: column; border: 0; padding: 0; text-align: left;
  background: #fff; border-radius: 3px; overflow: hidden; width: 100%;
  box-shadow: 0 0 0 1px var(--line);
  transition: transform .2s cubic-bezier(.3, 1.4, .5, 1), box-shadow .2s;
  animation: chip .5s cubic-bezier(.2, .8, .2, 1) both;
}
.swatch:hover { transform: translateY(-4px); box-shadow: 0 0 0 1px var(--line), 0 12px 24px -12px rgba(0, 0, 0, 0.45); }
.swatch:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.swatch-color { height: 96px; position: relative; }
.swatch-color .copy-hint {
  position: absolute; right: 8px; top: 8px; font-size: 11px; font-family: var(--mono);
  opacity: 0; transition: opacity .2s;
}
.swatch:hover .copy-hint { opacity: .85; }
.swatch-meta { padding: 8px 10px 10px; display: grid; gap: 2px; }
.swatch-hex { font-family: var(--mono); font-weight: 500; font-size: 14px; text-transform: uppercase; color: var(--text); }
.swatch-sub { font-family: var(--mono); font-size: 11px; color: var(--muted); }

.ratio-bar { display: flex; height: 6px; border-radius: 3px; overflow: hidden; box-shadow: 0 0 0 1px var(--line); }
.ratio-bar span { display: block; height: 100%; }

.keywords { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0; margin: 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.keywords div { padding: 10px 12px 10px 0; }
.keywords div + div { padding-left: 12px; border-left: 1px solid var(--line); }
.keywords dt { font-family: var(--mono); font-size: 10px; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); }
.keywords dd { margin: 2px 0 0; font-family: var(--serif); font-size: 24px; line-height: 1.1; }

.card-foot { display: flex; gap: 16px; align-items: stretch; flex-wrap: wrap; }
.art-thumb {
  position: relative; flex: 0 0 180px; height: 84px; border: 0; padding: 0; border-radius: 3px;
  overflow: hidden; background: #000;
}
.art-thumb canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.art-thumb span {
  position: absolute; left: 10px; bottom: 8px; font-size: 12px; color: #fff;
  font-family: var(--mono); letter-spacing: .04em; text-shadow: 0 1px 4px rgba(0, 0, 0, .6);
}
.art-thumb:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.actions { display: flex; flex-wrap: wrap; gap: 8px; align-content: center; flex: 1 1 260px; }
.actions button {
  border: 1px solid var(--text); background: transparent; color: var(--text);
  padding: 8px 14px; border-radius: 999px; font-size: 13px; font-weight: 500;
  transition: background .15s, color .15s;
}
.actions button:hover { background: var(--text); color: var(--paper); }
.actions button[data-act="prompt"] { background: var(--accent); border-color: var(--accent); color: #fff; }
.actions button[data-act="prompt"]:hover { background: var(--text); border-color: var(--text); }
.actions button:disabled { opacity: .35; pointer-events: none; }

.remove {
  position: absolute; top: 8px; left: 8px; width: 28px; height: 28px; border-radius: 50%;
  border: 0; background: rgba(0, 0, 0, .5); color: #fff; font-size: 18px; line-height: 1;
  opacity: 0; transition: opacity .2s;
}
.card:hover .remove, .remove:focus-visible { opacity: 1; }

.card.loading .swatches, .card.loading .ratio-bar, .card.loading .keywords, .card.loading .card-foot { display: none; }
.card:not(.loading) .status:not(.error) { display: none; }

/* ---------- viewer ---------- */

.viewer { position: fixed; inset: 0; z-index: 50; background: #000; }
.viewer canvas { width: 100%; height: 100%; display: block; }
.viewer-bar {
  position: absolute; left: 50%; bottom: 24px; transform: translateX(-50%);
  display: flex; gap: 8px; align-items: center; padding: 8px 8px 8px 16px; border-radius: 999px;
  background: rgba(20, 17, 13, .6); backdrop-filter: blur(12px); color: #fff;
  font-family: var(--mono); font-size: 12px; max-width: calc(100% - 32px);
}
.viewer-bar span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-right: 6px; }
.viewer-bar button {
  border: 1px solid rgba(255, 255, 255, .35); background: transparent; color: #fff;
  padding: 6px 12px; border-radius: 999px; font-size: 12px; white-space: nowrap;
}
.viewer-bar button:hover { background: #fff; color: #000; }

/* ---------- toast ---------- */

.toast {
  position: fixed; left: 50%; bottom: 28px; z-index: 60; transform: translate(-50%, 20px);
  background: var(--paper); color: var(--text); padding: 10px 18px; border-radius: 999px;
  font-size: 14px; box-shadow: 0 10px 30px -10px rgba(0, 0, 0, .6);
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.colophon {
  max-width: 1180px; margin: 56px auto 0; padding-top: 18px;
  border-top: 1px solid rgba(239, 232, 218, 0.1);
  font-family: var(--mono); font-size: 11px; color: var(--on-ink-muted); letter-spacing: .04em;
}

@keyframes rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
@keyframes chip { from { opacity: 0; transform: translateY(10px) scale(.96); } to { opacity: 1; transform: none; } }

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

@media (max-width: 760px) {
  .card { grid-template-columns: 1fr; }
  .card-photo { min-height: 200px; }
  .swatches { grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 5px; }
  .swatch-color { height: 64px; }
  .swatch-meta { padding: 6px; }
  .swatch-hex { font-size: 11px; }
  .swatch-sub { display: none; }
  .keywords { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .keywords div:nth-child(3) { border-left: 0; padding-left: 0; }
  .keywords div:nth-child(n+3) { border-top: 1px solid var(--line); }
  .keywords dd { font-size: 20px; }
  .art-thumb { flex: 1 1 100%; }
  .remove { opacity: 1; }
}
