:root {
  --bg: #eef3ff;
  --text: #0f172a;
  --muted: #4b5563;
  --surface: rgba(255, 255, 255, 0.72);
  --surface-strong: #ffffff;
  --border: rgba(148, 163, 184, 0.35);
  --brand: #4f46e5;
  --brand-2: #0ea5e9;
  --ok: #16a34a;
  --danger: #dc2626;
  --shadow: 0 12px 42px rgba(15, 23, 42, 0.12);
}

body.dark {
  --bg: #070b16;
  --text: #e5edff;
  --muted: #9db1d8;
  --surface: rgba(15, 23, 42, 0.75);
  --surface-strong: #0f172a;
  --border: rgba(96, 165, 250, 0.3);
  --brand: #60a5fa;
  --brand-2: #22d3ee;
  --ok: #4ade80;
  --danger: #f87171;
  --shadow: 0 18px 44px rgba(1, 4, 11, 0.68);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Segoe UI", Arial, sans-serif;
  background:
    radial-gradient(circle at 8% 12%, rgba(79, 70, 229, 0.16), transparent 32%),
    radial-gradient(circle at 90% 18%, rgba(14, 165, 233, 0.16), transparent 36%),
    var(--bg);
  color: var(--text);
  min-height: 100vh;
}

.app-shell {
  width: min(1380px, 96vw);
  margin: 18px auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.glass {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  backdrop-filter: blur(14px);
  box-shadow: var(--shadow);
}

.topbar {
  padding: 18px 20px;
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: center;
}

.topbar h1 {
  margin: 0;
  font-size: 1.35rem;
}

.subhead {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.topbar-actions {
  display: flex;
  gap: 10px;
}

.layout-grid {
  display: grid;
  grid-template-columns: 240px 1fr 320px;
  gap: 14px;
  min-height: calc(100vh - 144px);
}

.panel {
  padding: 16px;
}

.panel h2 {
  margin: 0;
  font-size: 1.03rem;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
  margin-bottom: 10px;
}

.panel-header small {
  color: var(--muted);
}

.actions-panel {
  position: sticky;
  top: 14px;
  height: fit-content;
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.divider {
  height: 1px;
  background: var(--border);
  margin: 6px 0;
}

.btn {
  border: 1px solid transparent;
  border-radius: 11px;
  padding: 10px 12px;
  cursor: pointer;
  font-weight: 700;
  color: #ffffff;
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  transition: transform 0.16s ease, opacity 0.2s ease, box-shadow 0.2s ease;
}

.btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 16px rgba(14, 165, 233, 0.2);
}

.btn.secondary {
  background: linear-gradient(135deg, #10b981, #22c55e);
}

.btn.ghost,
.btn.subtle {
  background: transparent;
  color: var(--text);
  border-color: var(--border);
}

.btn.subtle {
  color: var(--muted);
}

.btn.tiny {
  font-size: 0.74rem;
  padding: 6px 9px;
}

.main-panel {
  display: flex;
  flex-direction: column;
}

textarea {
  width: 100%;
  min-height: 260px;
  resize: vertical;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--surface-strong);
  color: var(--text);
  padding: 12px;
  font-family: Consolas, "Courier New", monospace;
  line-height: 1.45;
}

textarea:focus {
  outline: 1px solid var(--brand);
}

#embedCode {
  min-height: 130px;
}

.output-header {
  margin-top: 14px;
}

.output-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.output-empty {
  border: 1px dashed var(--border);
  border-radius: 12px;
  color: var(--muted);
  padding: 12px;
}

.link-card {
  background: var(--surface-strong);
  border: 1px solid var(--border);
  border-radius: 13px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.link-card h3 {
  margin: 0;
  font-size: 0.95rem;
}

.link-url {
  color: var(--brand);
  font-size: 0.88rem;
  overflow-wrap: anywhere;
  text-decoration: none;
}

.link-url:hover {
  text-decoration: underline;
}

.item-preview-image {
  width: 100%;
  max-height: 220px;
  object-fit: contain;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.03);
  padding: 6px;
}

.card-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.history-panel {
  display: flex;
  flex-direction: column;
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 9px;
  overflow: auto;
  max-height: calc(100vh - 250px);
  padding-right: 2px;
}

.history-item {
  background: var(--surface-strong);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px;
}

.history-head {
  display: flex;
  justify-content: space-between;
  font-size: 0.76rem;
  color: var(--muted);
}

.history-preview {
  margin-top: 6px;
  font-size: 0.8rem;
  color: var(--muted);
}

.history-thumb {
  margin-top: 8px;
  width: 100%;
  max-height: 110px;
  object-fit: contain;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.03);
}

.history-actions {
  margin-top: 8px;
  display: flex;
  gap: 7px;
}

.history-actions .btn {
  flex: 1;
  padding: 7px;
  font-size: 0.74rem;
}

.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 30;
  align-items: center;
  justify-content: center;
  background: rgba(2, 8, 23, 0.72);
  padding: 16px;
}

.modal-overlay.active {
  display: flex;
}

.modal {
  width: min(640px, 100%);
  padding: 16px;
  position: relative;
}

.modal-close {
  position: absolute;
  right: 12px;
  top: 10px;
  width: 30px;
  height: 30px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  cursor: pointer;
}

.similar-list {
  padding-left: 18px;
  margin-bottom: 0;
}

.similar-list li {
  margin-bottom: 9px;
}

.similar-list a {
  color: var(--brand);
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 16px;
  border-radius: 10px;
  padding: 9px 12px;
  background: rgba(15, 23, 42, 0.94);
  color: #fff;
  opacity: 0;
  pointer-events: none;
  transform: translateY(10px);
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 40;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.hidden {
  display: none !important;
}

@media (max-width: 1100px) {
  .layout-grid {
    grid-template-columns: 1fr;
  }

  .actions-panel {
    position: static;
  }

  .history-list {
    max-height: unset;
  }
}
