:root {
  --bg: #0f1115;
  --bg-elev: #181b22;
  --bg-hover: #1e2330;
  --border: #2a3140;
  --text: #e8ecf4;
  --muted: #9aa3b5;
  --accent: #6ea8fe;
  --accent-2: #8bdc9d;
  --danger: #f07178;
  --section: #c2a2f5;
  --shadow: 0 8px 28px rgba(0,0,0,.35);
  --radius: 14px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, sans-serif;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f6fa;
    --bg-elev: #ffffff;
    --bg-hover: #eef2f8;
    --border: #d5dbe8;
    --text: #1a2030;
    --muted: #5c677a;
    --accent: #2f6fed;
    --accent-2: #1f9d55;
    --danger: #c0392b;
    --section: #6b3fa0;
    --shadow: 0 8px 24px rgba(20,30,60,.08);
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--sans);
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
  min-height: 100vh;
}
.wrap { max-width: 1120px; width: 100%; margin: 0 auto; padding: 24px 16px 64px; }
header h1 { font-size: 1.45rem; margin: 0 0 6px; letter-spacing: -.02em; }
header p { margin: 0 0 18px; color: var(--muted); font-size: .95rem; }
.privacy {
  display: inline-flex; gap: 8px; align-items: center;
  background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: 999px; padding: 6px 12px; font-size: .8rem; color: var(--accent-2);
  margin-bottom: 16px;
}
.drop {
  border: 2px dashed var(--border);
  background: var(--bg-elev);
  border-radius: var(--radius);
  padding: 36px 20px;
  text-align: center;
  transition: border-color .15s, background .15s, transform .15s;
  cursor: pointer;
  box-shadow: var(--shadow);
}
.drop:hover, .drop.dragover {
  border-color: var(--accent);
  background: var(--bg-hover);
}
.drop strong { display: block; font-size: 1.05rem; margin-bottom: 6px; }
.drop span { color: var(--muted); font-size: .9rem; }
.drop-wrap { position: relative; }
.drop-wrap .btn-row { margin-top: 12px; display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
button, .btn {
  appearance: none; border: 1px solid var(--border); background: var(--bg);
  color: var(--text); border-radius: 10px; padding: 8px 14px; font: inherit;
  font-size: .9rem; cursor: pointer;
}
button.primary { background: var(--accent); border-color: transparent; color: #081018; font-weight: 600; }
button:hover { filter: brightness(1.08); }
button:focus-visible, .drop:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button.ghost { background: transparent; }
.toolbar {
  display: flex; gap: 8px; flex-wrap: wrap; align-items: center;
  margin: 18px 0 8px; color: var(--muted); font-size: .85rem;
}
.toolbar .spacer { flex: 1; }
#results { display: flex; flex-direction: column; gap: 18px; margin-top: 18px; }
.card {
  background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow);
}
.card-head {
  display: flex; gap: 10px; align-items: flex-start; justify-content: space-between;
  padding: 12px 14px; border-bottom: 1px solid var(--border); background: var(--bg-hover);
}
.card-head .fname {
  font-family: var(--mono); font-size: .92rem; color: var(--text); font-weight: 600;
  word-break: break-all;
}
.card-actions { display: flex; gap: 6px; flex-shrink: 0; }
.card-actions button { padding: 6px 10px; font-size: .8rem; }
table.meta {
  width: 100%; border-collapse: collapse; font-size: .92rem;
}
table.meta th, table.meta td {
  text-align: left; padding: 8px 14px; vertical-align: top;
  border-bottom: 1px solid var(--border);
}
table.meta tr:last-child th, table.meta tr:last-child td { border-bottom: none; }
table.meta th {
  width: 28%; max-width: 180px; color: var(--muted); font-weight: 500;
  white-space: nowrap;
}
table.meta td { word-break: break-word; }
table.meta tr.section th {
  background: transparent; color: var(--section); font-weight: 700;
  font-size: .78rem; letter-spacing: .04em; text-transform: uppercase;
  padding-top: 14px; border-bottom: none;
}
table.meta tr.section td { border-bottom: none; padding: 0; }
table.meta tr.label-row td {
  font-weight: 650; font-size: 1.02rem;
}
.label-edit {
  width: 100%; border: 1px dashed var(--border); background: transparent; cursor: text;
  color: inherit; font: inherit; font-weight: 650; font-size: 1.02rem;
  padding: 2px 26px 2px 4px; border-radius: 6px; resize: none; overflow: hidden;
}
.label-edit:hover { border-color: var(--accent); background: var(--bg); }
.label-edit:focus { border: 1px solid var(--accent); outline: 2px solid var(--accent); outline-offset: 1px; background: var(--bg); }
.label-hint { display: block; font-size: .75rem; font-weight: 400; color: var(--muted); margin-top: 2px; }
.label-cell { position: relative; }
.label-cell::after { content: "✎"; position: absolute; right: 22px; top: 10px; color: var(--muted); pointer-events: none; font-weight: 400; }
.label-cell:hover::after, .label-cell:focus-within::after { color: var(--accent); }
.card.error { border-color: var(--danger); }
.card.error .card-head { background: color-mix(in srgb, var(--danger) 14%, var(--bg-hover)); }
.err-badge { display: inline-block; margin-left: 8px; padding: 1px 8px; border-radius: 999px; background: var(--danger); color: #fff; font-family: var(--sans); font-size: .72rem; font-weight: 700; }
.empty {
  text-align: center; color: var(--muted); padding: 28px 12px; font-size: .95rem;
}
.toast {
  position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 8px 14px; border-radius: 999px;
  font-size: .85rem; opacity: 0; pointer-events: none; transition: opacity .2s;
  z-index: 50;
}
.toast.show { opacity: 1; }
footer {
  margin-top: 36px; color: var(--text); opacity: .85; font-size: .9rem; text-align: center;
}
footer code { font-family: var(--mono); font-size: .78rem; }
@media (max-width: 560px) {
  table.meta th { width: 34%; white-space: normal; }
  .card-head { flex-direction: column; }
}

/* Label/keywords hero above the metadata table */
.hero { padding: 14px 16px 10px; border-bottom: 1px solid var(--border, #ddd); }
.hero .label-edit { font-size: 1.45rem; font-weight: 650; line-height: 1.3; width: 100%; }
.hero-keywords { margin: 10px 0 2px; display: flex; flex-wrap: wrap; gap: 8px; }
.hero-keywords .chip { font-size: 1.08rem; font-weight: 600; padding: 5px 12px; border-radius: 999px;
  background: color-mix(in srgb, var(--accent) 16%, transparent); color: var(--text, inherit);
  border: 1px solid color-mix(in srgb, var(--accent) 45%, transparent); }
.hero-keywords.none { font-size: 1rem; font-style: italic; color: var(--muted); padding: 5px 0; }
.hero.label-cell::after { top: 20px; right: 22px; font-size: 1.1rem; }

/* One hero band: label + keyword pills wrap together */
.hero { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; }
.hero .label-edit { width: auto; max-width: 100%; flex: 0 1 auto; padding-right: 8px; }
.hero .hero-keywords { margin: 0; display: contents; }
.hero .hero-keywords.none { display: inline; }
.hero .label-hint { flex-basis: 100%; margin-top: 0; }
.hero.label-cell::after { display: none; }

.hero-keywords .chip { cursor: copy; font-family: inherit; line-height: 1.2; }
.hero-keywords .chip:hover { background: color-mix(in srgb, var(--accent) 30%, transparent); }
.hero-keywords .chip:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Auto AI polish (default-on after parse; never during parse) */
.label-edit.polishing { opacity: .65; }
button.undo-original {
  appearance: none; border: none; background: none; color: var(--accent);
  font: inherit; font-size: inherit; padding: 0; cursor: pointer; text-decoration: underline;
}
button.undo-original:hover { filter: brightness(1.15); }

.polish-badge {
  display: inline-block; font-size: .68rem; font-weight: 700; letter-spacing: .04em;
  text-transform: uppercase; padding: 1px 7px; border-radius: 999px; vertical-align: middle;
}
.polish-badge.ai {
  background: color-mix(in srgb, var(--accent) 22%, transparent);
  color: var(--accent); border: 1px solid color-mix(in srgb, var(--accent) 50%, transparent);
}
.polish-badge.ondevice {
  background: color-mix(in srgb, var(--muted) 18%, transparent);
  color: var(--muted); border: 1px solid var(--border);
}
