:root {
  color-scheme: light;
  --bg: #f6f5f1;
  --panel: #ffffff;
  --panel-strong: #f0f5f7;
  --ink: #172026;
  --muted: #64717a;
  --line: #d9e0e2;
  --accent: #0f766e;
  --accent-dark: #115e59;
  --accent-soft: #d8f0ed;
  --danger: #b42318;
  --shadow: 0 18px 45px rgba(23, 32, 38, 0.11);
  --preview-card-width: 300px;
  --preview-card-height: 318px;
  --preview-image-height: 198px;
}

* {
  box-sizing: border-box;
}

html {
  height: 100%;
}

body {
  margin: 0;
  height: 100%;
  min-height: 100vh;
  overflow: hidden;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    linear-gradient(135deg, rgba(15, 118, 110, 0.09), transparent 32%),
    linear-gradient(315deg, rgba(184, 113, 49, 0.09), transparent 34%),
    var(--bg);
  color: var(--ink);
}

body.modal-open {
  overflow: hidden;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(360px, 480px) minmax(0, 1fr);
  gap: 18px;
  height: 100vh;
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
  padding: 18px;
}

.control-panel,
.result-panel {
  background: rgba(255, 255, 255, 0.86);
  border: 1px solid rgba(217, 224, 226, 0.9);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.control-panel {
  padding: 22px;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-gutter: stable;
}

.result-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  padding: 22px;
}

.app-header,
.preview-toolbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: 28px;
  line-height: 1.18;
}

h2 {
  font-size: 22px;
  line-height: 1.2;
}

.status-pill {
  flex: 0 0 auto;
  min-width: 76px;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel-strong);
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

.status-pill.ready {
  border-color: rgba(15, 118, 110, 0.26);
  background: var(--accent-soft);
  color: var(--accent-dark);
}

.status-pill.missing {
  border-color: rgba(180, 35, 24, 0.24);
  background: #fff0ee;
  color: var(--danger);
}

.mode-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: stretch;
  margin-bottom: 18px;
}

.mode-switch {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #edf2f3;
}

.mode-button,
.reverse-toggle-button {
  min-height: 38px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-weight: 700;
}

.mode-button.active {
  background: var(--panel);
  color: var(--ink);
  box-shadow: 0 1px 4px rgba(23, 32, 38, 0.12);
}

.reverse-toggle-button {
  padding: 0 12px;
  border: 1px solid rgba(15, 118, 110, 0.24);
  background: #fff;
  color: var(--accent-dark);
  white-space: nowrap;
}

.reverse-toggle-button.active {
  border-color: rgba(15, 118, 110, 0.38);
  background: var(--accent-soft);
  color: var(--accent-dark);
}

.settings-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: end;
  margin-bottom: 18px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fbfb;
}

.settings-card small {
  grid-column: 1 / -1;
  color: var(--muted);
  font-size: 12px;
}

.reverse-card {
  display: grid;
  gap: 12px;
  margin-bottom: 18px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fbfb;
}

.reverse-card-head,
.reverse-result-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.reverse-card-head h2 {
  font-size: 18px;
}

.reverse-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.reverse-actions input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.reverse-file-trigger {
  min-height: 42px;
  padding: 0 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.reverse-drop-zone {
  display: grid;
  gap: 12px;
  padding: 12px;
  border: 1px dashed #9fb2b7;
  border-radius: 8px;
  background: #fff;
  transition: background-color 140ms ease, border-color 140ms ease, box-shadow 140ms ease;
}

.reverse-drop-zone.drop-active {
  border-color: var(--accent);
  background: #e8f6f4;
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.14) inset;
}

.reverse-preview {
  display: grid;
  grid-template-columns: 92px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  min-height: 96px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.reverse-preview.is-empty {
  display: grid;
  place-items: center;
  grid-template-columns: 1fr;
  color: var(--muted);
  font-size: 13px;
}

.reverse-preview img {
  width: 92px;
  height: 76px;
  border: 1px solid var(--line);
  border-radius: 6px;
  object-fit: cover;
  background: #fff;
}

.reverse-preview-meta {
  display: grid;
  gap: 5px;
  min-width: 0;
}

.reverse-preview-meta strong,
.reverse-preview-meta span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.reverse-preview-meta strong {
  font-size: 13px;
}

.reverse-preview-meta span {
  color: var(--muted);
  font-size: 12px;
}

.reverse-copy-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.reverse-result-block {
  display: grid;
  gap: 7px;
  min-width: 0;
}

.reverse-result-head strong {
  color: var(--ink);
  font-size: 13px;
}

.reverse-result-head > div {
  display: flex;
  gap: 8px;
}

.copy-reverse-button {
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--accent-dark);
  font-size: 13px;
  font-weight: 800;
}

.copy-reverse-button:disabled {
  cursor: default;
  opacity: 0.38;
}

.reverse-result-block textarea {
  width: 100%;
  min-height: 112px;
  max-height: 220px;
  resize: vertical;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  font-size: 12px;
  line-height: 1.5;
}

.reverse-json-editor {
  display: block;
  height: min(58vh, 620px);
  min-height: 420px;
  overflow: auto;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  scrollbar-gutter: stable;
}

.reverse-json-empty {
  display: grid;
  place-items: center;
  min-height: 100%;
  border: 1px dashed #b9c8cb;
  border-radius: 8px;
  color: var(--muted);
  font-size: 13px;
}

.json-tree {
  display: grid;
  gap: 8px;
}

.json-edit-group {
  border: 0;
  border-radius: 0;
  background: transparent;
  overflow: visible;
}

.json-edit-group > summary,
.json-entity-card > summary {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  gap: 7px;
  cursor: pointer;
  min-height: 36px;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #eef5f5;
  color: var(--ink);
  font-size: 13px;
  font-weight: 800;
  list-style: none;
}

.json-edit-group > summary::-webkit-details-marker,
.json-entity-card > summary::-webkit-details-marker {
  display: none;
}

.json-edit-group:not([open]) > summary .folder-icon,
.json-entity-card:not([open]) > summary .folder-icon {
  transform: rotate(-90deg);
}

.folder-icon {
  display: inline-block;
  color: var(--accent-dark);
  transition: transform 120ms ease;
}

.json-edit-grid,
.json-entity-list {
  display: grid;
  gap: 9px;
  padding: 8px 0 10px 18px;
  border-left: 2px solid #dbe6e8;
  margin-left: 13px;
}

.json-edit-grid {
  grid-template-columns: minmax(0, 1fr);
}

.json-edit-field {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.json-edit-field span,
.json-entity-card h3 {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.json-edit-field input,
.json-edit-field select,
.json-edit-field textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  font-size: 12px;
  line-height: 1.45;
}

.json-edit-field input,
.json-edit-field select {
  height: 36px;
  padding: 0 9px;
}

.json-edit-field textarea {
  min-height: 92px;
  resize: vertical;
  padding: 8px 9px;
}

.json-edit-field input:focus,
.json-edit-field select:focus,
.json-edit-field textarea:focus {
  border-color: var(--accent);
  outline: none;
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.12);
}

.json-entity-card {
  display: block;
  border: 0;
  border-radius: 0;
  background: transparent;
}

.json-entity-card h3 {
  margin: 0;
  padding: 10px 12px 0;
  color: var(--accent-dark);
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.span-all {
  grid-column: 1 / -1;
}

.field {
  display: grid;
  gap: 7px;
}

.field span,
.upload-head span {
  color: var(--ink);
  font-size: 13px;
  font-weight: 700;
}

.prompt-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-width: 0;
}

.prompt-title-row > span {
  min-width: 0;
}

.prompt-optimize-button {
  flex: 0 0 auto;
  min-width: 0;
  min-height: 34px;
  padding: 0 11px;
  border-color: rgba(15, 118, 110, 0.24);
  color: var(--accent-dark);
  font-size: 13px;
}

.local-edit-head .prompt-optimize-button {
  margin-left: auto;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  outline: none;
  transition: border-color 140ms ease, box-shadow 140ms ease;
}

.field input,
.field select {
  height: 42px;
  padding: 0 11px;
}

.field textarea {
  min-height: 156px;
  resize: vertical;
  padding: 11px;
  line-height: 1.5;
}

.prompt-composer {
  position: relative;
}

.prompt-composer textarea {
  display: block;
}

.mention-picker {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(100% + 8px);
  z-index: 20;
  display: grid;
  gap: 6px;
  max-height: 260px;
  overflow: auto;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 18px 42px rgba(23, 32, 38, 0.15);
}

.mention-item {
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  width: 100%;
  padding: 7px 9px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--ink);
  text-align: left;
}

.mention-item img {
  width: 48px;
  height: 48px;
  border: 1px solid var(--line);
  border-radius: 6px;
  object-fit: cover;
  background: #fff;
}

.mention-item strong,
.mention-item small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mention-item strong {
  font-size: 13px;
}

.mention-item small {
  margin-top: 3px;
  color: var(--muted);
  font-size: 11px;
}

.mention-item:hover,
.mention-item.active {
  border-color: rgba(15, 118, 110, 0.28);
  background: #e8f6f4;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.14);
}

.upload-grid {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.upload-panel {
  display: grid;
  gap: 10px;
  padding: 14px;
  border: 1px dashed #9fb2b7;
  border-radius: 8px;
  background: #f8fbfb;
  transition: background-color 140ms ease, border-color 140ms ease, box-shadow 140ms ease;
}

.upload-panel.drop-active {
  border-color: var(--accent);
  background: #e8f6f4;
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.14) inset;
}

.upload-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.upload-head > div {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.upload-head input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.upload-trigger {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  padding: 0 11px;
  border: 1px solid rgba(15, 118, 110, 0.24);
  border-radius: 8px;
  background: #fff;
  color: var(--accent-dark);
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
}

.upload-head small {
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.upload-note {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.upload-thumbs {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: 8px;
  align-items: start;
  max-height: 268px;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 2px 6px 2px 2px;
  scrollbar-gutter: stable;
}

.upload-thumbs.is-empty {
  display: none;
}

.upload-thumb {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.upload-thumb[draggable="true"] {
  cursor: grab;
}

.upload-thumb.dragging {
  opacity: 0.48;
}

.upload-thumb.drag-over {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.upload-thumb img {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  background: #fff;
}

.upload-thumb-meta {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 6px;
  align-items: center;
  min-height: 30px;
  padding: 6px 7px;
  color: var(--muted);
  font-size: 11px;
}

.upload-thumb-meta span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.upload-thumb-meta strong {
  color: var(--accent-dark);
  font-size: 11px;
}

.upload-remove {
  position: absolute;
  top: 6px;
  right: 6px;
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border: 1px solid rgba(23, 32, 38, 0.14);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.92);
  color: var(--danger);
  font-size: 18px;
  line-height: 1;
}

.local-edit-panel {
  display: grid;
  gap: 10px;
  padding: 14px;
  border: 1px dashed #9fb2b7;
  border-radius: 8px;
  background: #f8fbfb;
}

.local-edit-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.local-edit-head > div {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.local-edit-head span {
  color: var(--ink);
  font-size: 13px;
  font-weight: 700;
}

.local-edit-head small {
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.local-edit-head input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.local-edit-drop-zone {
  display: grid;
  gap: 0;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  transition: background-color 140ms ease, border-color 140ms ease, box-shadow 140ms ease;
}

.local-edit-drop-zone.drop-active {
  border-color: var(--accent);
  background: #e8f6f4;
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.14) inset;
}

.local-edit-stage {
  position: relative;
  display: grid;
  place-items: center;
  width: 100%;
  min-height: 240px;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  appearance: none;
  -webkit-appearance: none;
  padding: 0;
  background:
    linear-gradient(45deg, #eef3f4 25%, transparent 25%),
    linear-gradient(-45deg, #eef3f4 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #eef3f4 75%),
    linear-gradient(-45deg, transparent 75%, #eef3f4 75%);
  background-size: 20px 20px;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0;
  cursor: pointer;
}

.local-edit-stage img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  user-select: none;
  -webkit-user-drag: none;
}

.local-edit-stage img {
  position: absolute;
  inset: 0;
  display: block;
}

.local-edit-stage:not(.has-image) img {
  display: none;
}

.local-edit-empty {
  position: relative;
  z-index: 1;
  display: grid;
  place-items: center;
  width: 100%;
  min-height: 240px;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
  pointer-events: none;
}

.local-edit-tools {
  display: grid;
  align-content: start;
  gap: 10px;
  min-width: 0;
}

.local-edit-tools .field {
  gap: 5px;
}

.local-edit-tools .field span {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 12px;
}

.local-edit-tools .field strong {
  color: var(--accent-dark);
  font-size: 12px;
  font-weight: 800;
}

.local-edit-tools input[type="range"] {
  padding: 0;
}

.local-edit-modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 12px;
  padding: 16px;
  background: rgba(14, 20, 24, 0.88);
}

.local-edit-modal.hidden {
  display: none;
}

.local-edit-modal-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: end;
  padding: 12px;
  border: 1px solid rgba(255, 255, 255, 0.11);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
}

.local-edit-modal-toolbar .field {
  min-width: 140px;
  color: #fff;
}

.local-edit-modal-toolbar .field span {
  color: rgba(255, 255, 255, 0.86);
}

.local-edit-modal-toolbar .field strong {
  color: #fff;
}

.local-edit-range-field {
  min-width: 180px;
}

.local-edit-modal-toolbar .secondary-button {
  min-height: 40px;
  color: var(--ink);
}

.local-edit-modal-toolbar .secondary-button.hidden {
  display: none;
}

.local-edit-modal-viewport {
  position: relative;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  background:
    linear-gradient(45deg, rgba(255, 255, 255, 0.05) 25%, transparent 25%),
    linear-gradient(-45deg, rgba(255, 255, 255, 0.05) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, rgba(255, 255, 255, 0.05) 75%),
    linear-gradient(-45deg, transparent 75%, rgba(255, 255, 255, 0.05) 75%);
  background-size: 20px 20px;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0;
  cursor: grab;
  touch-action: none;
}

.local-edit-modal.is-panning .local-edit-modal-viewport {
  cursor: grabbing;
}

.local-edit-modal-layer {
  position: absolute;
  inset: 0 auto auto 0;
  transform-origin: 0 0;
  will-change: transform;
  pointer-events: auto;
}

.local-edit-modal-layer canvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  user-select: none;
  -webkit-user-drag: none;
  pointer-events: none;
}

#localEditMaskCanvas {
  cursor: crosshair;
  touch-action: none;
  pointer-events: auto;
  z-index: 2;
  user-select: none;
  -webkit-user-drag: none;
  opacity: 0.3;
}

#localEditImageCanvas {
  z-index: 1;
  pointer-events: none;
}

.local-edit-brush-cursor {
  position: absolute;
  z-index: 6;
  pointer-events: none;
  width: 1px;
  height: 1px;
}

.local-edit-brush-cursor.hidden {
  display: none;
}

.local-edit-feather-cursor,
.local-edit-core-cursor {
  position: absolute;
  left: 50%;
  top: 50%;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  box-sizing: border-box;
}

.local-edit-feather-cursor {
  border: 1px solid rgba(255, 68, 68, 0.58);
  background: rgba(255, 68, 68, 0.08);
}

.local-edit-core-cursor {
  border: 1px solid rgba(255, 68, 68, 0.92);
  background: rgba(255, 68, 68, 0.15);
}

.local-edit-modal-close {
  position: absolute;
  top: 18px;
  right: 18px;
  z-index: 7;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  font-size: 30px;
  line-height: 1;
}

.local-edit-modal-help {
  justify-self: center;
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.1);
  color: rgba(255, 255, 255, 0.86);
  font-size: 12px;
  z-index: 7;
}

.primary-button,
.secondary-button {
  min-height: 44px;
  border-radius: 8px;
  font-weight: 800;
}

.primary-button {
  border: 1px solid var(--accent-dark);
  background: var(--accent);
  color: #fff;
}

.primary-button:disabled {
  cursor: wait;
  opacity: 0.68;
}

.secondary-button {
  min-width: 74px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
}

.secondary-button:disabled {
  cursor: wait;
  opacity: 0.68;
}

.toolbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.message {
  margin-bottom: 14px;
  padding: 12px 13px;
  border: 1px solid rgba(180, 35, 24, 0.24);
  border-radius: 8px;
  background: #fff0ee;
  color: var(--danger);
  line-height: 1.45;
  white-space: pre-line;
}

.message[data-type="warning"] {
  border-color: rgba(184, 113, 49, 0.28);
  background: #fff7ed;
  color: #8a4b16;
}

.risk-hint {
  padding: 10px 12px;
  border: 1px solid rgba(184, 113, 49, 0.28);
  border-radius: 8px;
  background: #fff7ed;
  color: #8a4b16;
  font-size: 13px;
  line-height: 1.45;
}

.preview-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, var(--preview-card-width));
  gap: 14px;
  align-content: start;
  justify-content: start;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: auto;
  padding: 2px 8px 2px 2px;
  scrollbar-gutter: stable;
}

.preview-item {
  display: grid;
  grid-template-rows: var(--preview-image-height) 74px minmax(0, 1fr);
  width: var(--preview-card-width);
  height: var(--preview-card-height);
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.preview-image-button {
  display: block;
  width: 100%;
  height: var(--preview-image-height);
  padding: 0;
  border: 0;
  background: transparent;
}

.preview-image-button img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background:
    linear-gradient(45deg, #eef3f4 25%, transparent 25%),
    linear-gradient(-45deg, #eef3f4 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #eef3f4 75%),
    linear-gradient(-45deg, transparent 75%, #eef3f4 75%);
  background-size: 20px 20px;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0;
}

.preview-actions {
  display: grid;
  grid-template-rows: auto auto;
  gap: 7px;
  min-width: 0;
  min-height: 74px;
  padding: 9px 10px 8px;
}

.preview-actions a {
  color: var(--accent-dark);
  font-size: 12px;
  font-weight: 800;
  text-decoration: none;
  white-space: nowrap;
}

.preview-actions code {
  display: block;
  min-width: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.25;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.preview-size-row {
  min-width: 0;
}

.preview-links {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 10px;
  min-width: 0;
  overflow: hidden;
}

.reuse-button,
.delete-image-button,
.local-edit-button {
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--accent-dark);
  font-size: 12px;
  font-weight: 800;
  line-height: 1.2;
  white-space: nowrap;
}

.delete-image-button {
  color: var(--danger);
}

.record-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  padding: 0 10px 9px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.25;
  align-content: start;
  min-height: 0;
  overflow: hidden;
}

.record-meta span {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.empty-state {
  grid-column: 1 / -1;
  display: grid;
  place-items: center;
  min-height: 420px;
  border: 1px dashed #b9c8cb;
  border-radius: 8px;
  background: rgba(248, 251, 251, 0.8);
  color: var(--muted);
  text-align: center;
}

.log-panel {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.log-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.log-header span {
  color: var(--muted);
  font-size: 12px;
}

.log-list {
  display: grid;
  gap: 10px;
  max-height: 260px;
  overflow: auto;
}

.log-empty,
.log-item {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.log-item.ok {
  border-color: rgba(15, 118, 110, 0.24);
}

.log-item.failed {
  border-color: rgba(180, 35, 24, 0.24);
  background: #fff8f7;
}

.log-title {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 6px;
}

.log-title strong {
  font-size: 13px;
}

.log-title span,
.log-item code,
.log-item p {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.log-item code {
  display: block;
  margin-bottom: 4px;
}

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  background: rgba(14, 20, 24, 0.88);
}

.lightbox-stage {
  width: calc(100vw - 32px);
  height: calc(100vh - 32px);
  overflow: hidden;
  display: grid;
  place-items: center;
  cursor: grab;
}

.lightbox.dragging .lightbox-stage {
  cursor: grabbing;
}

.lightbox-stage img {
  max-width: 100%;
  max-height: 100%;
  transform-origin: center center;
  user-select: none;
  -webkit-user-drag: none;
  will-change: transform;
}

.lightbox-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  font-size: 28px;
  line-height: 1;
}

.empty-icon {
  width: 68px;
  height: 68px;
  margin-bottom: 8px;
  border: 2px solid #adc1c5;
  border-radius: 8px;
  background:
    linear-gradient(135deg, transparent 54%, #adc1c5 55% 58%, transparent 59%),
    radial-gradient(circle at 68% 32%, #0f766e 0 7px, transparent 8px);
}

.hidden {
  display: none;
}

@media (max-width: 920px) {
  body {
    height: auto;
    overflow: auto;
  }

  .app-shell {
    grid-template-columns: 1fr;
    height: auto;
    min-height: 100vh;
    overflow: visible;
  }

  .control-panel {
    overflow: visible;
  }

  .result-panel {
    height: 680px;
    min-height: 0;
  }
}

@media (max-width: 560px) {
  :root {
    --preview-card-width: 288px;
    --preview-card-height: 310px;
    --preview-image-height: 190px;
  }

  .app-shell {
    padding: 10px;
  }

  .control-panel,
  .result-panel {
    padding: 16px;
  }

  .form-grid,
  .upload-grid,
  .settings-card,
  .mode-row,
  .reverse-copy-grid {
    grid-template-columns: 1fr;
  }

  .app-header,
  .preview-toolbar,
  .reverse-card-head {
    align-items: stretch;
    flex-direction: column;
  }

  .toolbar-actions,
  .reverse-actions {
    flex-wrap: wrap;
  }

  h1 {
    font-size: 24px;
  }
}

/* Portal visual theme alignment. Keep layout and JS-bound classes intact. */
:root {
  color-scheme: dark;
  --bg: #090b0d;
  --panel: rgba(17, 19, 22, 0.78);
  --panel-strong: rgba(20, 23, 27, 0.96);
  --line: rgba(255, 255, 255, 0.115);
  --line-strong: rgba(255, 255, 255, 0.2);
  --ink: #f5f6f2;
  --muted: #8f9894;
  --muted-strong: #c6cec9;
  --accent: #31e29b;
  --accent-dark: #31e29b;
  --accent-soft: rgba(49, 226, 155, 0.08);
  --danger: #f06b5d;
  --warn: #e6b65f;
  --shadow: 0 18px 56px rgba(0, 0, 0, 0.34);
  font-family: Inter, ui-sans-serif, "PingFang SC", "Microsoft YaHei", sans-serif;
}

body {
  position: relative;
  color: var(--ink);
  font-family: inherit;
  background:
    linear-gradient(115deg, rgba(49, 226, 155, 0.09), transparent 34%),
    linear-gradient(250deg, rgba(114, 167, 255, 0.1), transparent 42%),
    var(--bg);
}

body::before {
  position: fixed;
  inset: 0;
  z-index: 0;
  content: "";
  pointer-events: none;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.032) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.032) 1px, transparent 1px);
  background-size: 32px 32px;
  mask-image: linear-gradient(to bottom, #000 0%, rgba(0, 0, 0, 0.82) 62%, transparent 100%);
}

.app-shell {
  position: relative;
  z-index: 1;
}

.control-panel,
.result-panel,
.settings-card,
.reverse-card,
.upload-panel,
.local-edit-panel,
.preview-item,
.log-empty,
.log-item,
.message,
.risk-hint {
  border-color: var(--line);
  background: rgba(17, 19, 22, 0.78);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.settings-card,
.reverse-card,
.upload-panel,
.local-edit-panel,
.preview-item,
.log-empty,
.log-item {
  box-shadow: none;
}

.mode-switch,
.field input,
.field select,
.field textarea,
.reverse-result-block textarea,
.reverse-json-editor,
.json-edit-field input,
.json-edit-field select,
.json-edit-field textarea,
.reverse-preview,
.local-edit-drop-zone,
.upload-thumb,
.local-edit-modal-toolbar,
.local-edit-modal-footer {
  border-color: var(--line);
  background: rgba(255, 255, 255, 0.045);
  color: var(--ink);
}

.field input::placeholder,
.field textarea::placeholder,
.reverse-result-block textarea::placeholder {
  color: rgba(198, 206, 201, 0.58);
}

.mode-button,
.reverse-toggle-button,
.secondary-button,
.upload-trigger,
.copy-reverse-button,
.reuse-button,
.local-edit-button,
.preview-actions a {
  color: var(--accent);
}

.mode-button.active,
.reverse-toggle-button.active,
.secondary-button:hover,
.upload-trigger:hover {
  border-color: rgba(49, 226, 155, 0.32);
  background: rgba(49, 226, 155, 0.08);
  color: var(--accent);
}

.reverse-toggle-button,
.secondary-button,
.upload-trigger,
.prompt-optimize-button {
  border-color: rgba(49, 226, 155, 0.24);
  background: rgba(255, 255, 255, 0.055);
}

.primary-button {
  border: 1px solid rgba(49, 226, 155, 0.35);
  background: var(--accent);
  color: #04110c;
}

.status-pill {
  border-color: var(--line);
  background: rgba(255, 255, 255, 0.055);
  color: var(--muted-strong);
}

.status-pill.ready {
  border-color: rgba(49, 226, 155, 0.28);
  background: rgba(49, 226, 155, 0.08);
  color: var(--accent);
}

.status-pill.missing,
.message {
  border-color: rgba(240, 107, 93, 0.26);
  background: rgba(240, 107, 93, 0.1);
  color: #ffb1a8;
}

.message[data-type="warning"],
.risk-hint {
  border-color: rgba(230, 182, 95, 0.28);
  background: rgba(230, 182, 95, 0.1);
  color: #ffd89a;
}

.reverse-drop-zone,
.upload-panel,
.local-edit-panel {
  border-color: rgba(255, 255, 255, 0.16);
}

.reverse-drop-zone,
.empty-state {
  border-color: rgba(255, 255, 255, 0.16);
  background: rgba(17, 19, 22, 0.72);
}

.reverse-drop-zone.drop-active,
.upload-panel.drop-active,
.local-edit-drop-zone.drop-active {
  border-color: rgba(49, 226, 155, 0.4);
  background: rgba(49, 226, 155, 0.08);
  box-shadow: 0 0 0 3px rgba(49, 226, 155, 0.14) inset;
}

.mention-picker {
  border-color: var(--line);
  background: rgba(17, 19, 22, 0.98);
  box-shadow: 0 18px 42px rgba(0, 0, 0, 0.32);
}

.mention-item:hover,
.mention-item.active {
  border-color: rgba(49, 226, 155, 0.28);
  background: rgba(49, 226, 155, 0.08);
}

.field input:focus,
.field select:focus,
.field textarea:focus,
.json-edit-field input:focus,
.json-edit-field select:focus,
.json-edit-field textarea:focus {
  border-color: rgba(49, 226, 155, 0.5);
  box-shadow: 0 0 0 3px rgba(49, 226, 155, 0.14);
}

.json-edit-group > summary,
.json-entity-card > summary {
  border-color: var(--line);
  background: rgba(255, 255, 255, 0.055);
}

.folder-icon,
.json-entity-card h3,
.upload-thumb-meta strong {
  color: var(--accent);
}

.json-edit-grid,
.json-entity-list {
  border-left-color: rgba(255, 255, 255, 0.12);
}

.upload-thumb img,
.mention-item img,
.preview-image-button img,
.local-edit-stage {
  background:
    linear-gradient(45deg, rgba(255, 255, 255, 0.04) 25%, transparent 25%),
    linear-gradient(-45deg, rgba(255, 255, 255, 0.04) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, rgba(255, 255, 255, 0.04) 75%),
    linear-gradient(-45deg, transparent 75%, rgba(255, 255, 255, 0.04) 75%);
  background-size: 20px 20px;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0;
}

.upload-remove,
.lightbox-close,
.local-edit-modal-close {
  border-color: rgba(255, 255, 255, 0.14);
  background: rgba(17, 19, 22, 0.88);
  color: var(--ink);
}

.delete-image-button,
.upload-remove:hover,
.local-edit-modal-close:hover {
  color: var(--danger);
}

.log-item.failed {
  border-color: rgba(240, 107, 93, 0.24);
  background: rgba(240, 107, 93, 0.08);
}

.log-item.ok {
  border-color: rgba(49, 226, 155, 0.24);
}

.lightbox,
.local-edit-modal {
  background: rgba(9, 11, 13, 0.92);
}
