:root {
  --bg: #f4f1ea;
  --panel: #fffdf7;
  --ink: #1d1a16;
  --muted: #70675b;
  --line: #d8d0c2;
  --accent: #0b6f68;
  --accent-dark: #084d49;
  --error: #a32828;
  --success: #16724a;
  --shadow: 0 24px 80px rgba(33, 27, 18, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(90deg, rgba(29, 26, 22, 0.035) 1px, transparent 1px),
    linear-gradient(180deg, rgba(29, 26, 22, 0.035) 1px, transparent 1px),
    var(--bg);
  background-size: 32px 32px;
  color: var(--ink);
  font-family: ui-serif, "Songti SC", "Noto Serif CJK SC", Georgia, serif;
}

button,
input {
  font: inherit;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  max-width: 1120px;
  margin: 0 auto;
  padding: 34px 24px 20px;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--accent);
  font: 700 12px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(32px, 6vw, 64px);
  line-height: 0.95;
  letter-spacing: 0;
}

.workspace {
  display: grid;
  gap: 20px;
  max-width: 1120px;
  margin: 0 auto;
  padding: 10px 24px 48px;
}

.tool-panel,
.results-shell,
.login-panel {
  border: 1px solid var(--line);
  background: rgba(255, 253, 247, 0.94);
  box-shadow: var(--shadow);
}

.tool-panel {
  padding: 22px;
}

.parse-form label,
.login-form label {
  display: block;
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 14px;
}

.input-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
}

input {
  width: 100%;
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #fffaf0;
  color: var(--ink);
  padding: 0 14px;
  outline: none;
}

input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(11, 111, 104, 0.12);
}

button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  border: 1px solid var(--accent-dark);
  border-radius: 4px;
  background: var(--accent);
  color: white;
  padding: 0 18px;
  text-decoration: none;
  cursor: pointer;
}

button:disabled {
  cursor: wait;
  opacity: 0.64;
}

.ghost-button {
  border-color: var(--line);
  background: transparent;
  color: var(--ink);
}

.status-text {
  margin: 12px 0 0;
  color: var(--muted);
}

.status-text:empty {
  display: none;
}

.status-text[data-tone="success"] {
  color: var(--success);
}

.status-text[data-tone="error"] {
  color: var(--error);
}

.results-shell {
  padding: 22px;
}

.section-title {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: center;
  border-bottom: 1px solid var(--line);
  padding-bottom: 14px;
}

.section-title h2 {
  margin: 0;
  font-size: 22px;
}

.section-title span {
  color: var(--muted);
  font-size: 14px;
}

.batch-controls {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 8px;
}

.batch-controls[hidden] {
  display: none;
}

.compact-button {
  min-height: 36px;
  padding: 0 12px;
  font-size: 14px;
  white-space: nowrap;
}

.empty-state {
  display: grid;
  min-height: 220px;
  place-items: center;
  color: var(--muted);
  text-align: center;
}

.error-state {
  color: var(--error);
}

.results-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 14px;
  padding-top: 18px;
}

.media-card {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fffaf0;
}

.select-media {
  position: absolute;
  top: 8px;
  left: 8px;
  z-index: 2;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 26px;
  border: 1px solid rgba(29, 26, 22, 0.22);
  border-radius: 4px;
  background: rgba(255, 253, 247, 0.92);
  color: var(--ink);
  padding: 0 8px;
  font-size: 12px;
  cursor: pointer;
}

.select-media input.media-checkbox {
  flex: 0 0 12px;
  width: 12px;
  height: 12px;
  min-width: 12px;
  min-height: auto;
  border-radius: 2px;
  margin: 0;
  padding: 0;
  accent-color: var(--accent);
}

.preview {
  display: grid;
  aspect-ratio: 16 / 9;
  place-items: center;
  background: #e9dfcf;
}

.preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.media-info {
  padding: 14px;
}

.media-info h3 {
  margin-bottom: 6px;
  font-size: 18px;
}

.media-info p {
  min-height: 20px;
  color: var(--muted);
  font-size: 14px;
}

.action-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.action-row button {
  min-width: 0;
  min-height: 40px;
  padding: 0 10px;
}

.copy-button {
  border-color: var(--line);
  background: transparent;
  color: var(--ink);
}

#toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 20;
  max-width: min(320px, calc(100vw - 48px));
  border: 1px solid var(--accent-dark);
  border-radius: 6px;
  background: var(--accent);
  color: white;
  box-shadow: var(--shadow);
  opacity: 0;
  padding: 12px 16px;
  pointer-events: none;
  transform: translateY(12px);
  transition: opacity 160ms ease, transform 160ms ease;
}

#toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

#toast[data-tone="error"] {
  border-color: #7f1d1d;
  background: var(--error);
}

.login-body {
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-shell {
  width: min(100%, 420px);
}

.login-panel {
  padding: 30px;
}

.login-panel h1 {
  margin-bottom: 12px;
}

.muted {
  color: var(--muted);
}

.login-form {
  margin-top: 26px;
}

.login-form button {
  width: 100%;
  margin-top: 12px;
}

.error-message {
  margin: 10px 0 0;
  color: var(--error);
}

@media (max-width: 680px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .input-row {
    grid-template-columns: 1fr;
  }

  .section-title {
    align-items: flex-start;
    flex-direction: column;
  }

  .batch-controls {
    justify-content: flex-start;
    width: 100%;
  }
}
