@font-face {
  font-family: 'Endfield UI';
  src: url('/assets/fonts/endfield-ui.woff2') format('woff2');
  font-weight: 100 900;
  font-display: swap;
}

@font-face {
  font-family: 'Endfield Title';
  src: url('/assets/fonts/endfield-title.woff2') format('woff2');
  font-weight: 900;
  font-display: swap;
}

:root {
  color-scheme: dark;
  font-family: 'Endfield UI', 'Noto Sans SC', 'Microsoft YaHei UI', 'PingFang SC', system-ui, sans-serif;
  --bg: #11120f;
  --panel: #1a1c17;
  --raised: #22251d;
  --line: #373b30;
  --text: #f3f4e9;
  --muted: #afb3a5;
  --accent: #e9f45d;
  --ink: #1b200c;
  --mono: 'Cascadia Mono', Consolas, ui-monospace, monospace;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  min-width: 280px;
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
}

h1, h2, h3, p { margin: 0; }
button, input, select { font: inherit; }
button, select, input[type='range'], input[type='checkbox'], input[type='color'] { cursor: pointer; }
button:disabled, input:disabled, select:disabled { cursor: default; }

button:focus-visible, input:focus-visible, select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.app-bar {
  min-height: 76px;
  border-bottom: 1px solid var(--line);
  padding: 12px clamp(16px, 3vw, 44px);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
}

.app-brand { display: flex; align-items: center; gap: 13px; }
.app-brand img { display: block; flex: none; }
.app-brand h1 { font-size: 18px; font-weight: 730; line-height: 1.28; }
.app-brand p { color: var(--muted); font-size: 11px; margin-top: 3px; }
.header-actions { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 8px 14px; }
.privacy { display: flex; align-items: center; gap: 8px; color: var(--muted); }
.privacy::before {
  content: '';
  height: 7px;
  width: 7px;
  border-radius: 50%;
  background: var(--accent);
}

.workspace {
  display: grid;
  grid-template-columns: 222px minmax(0, 1fr) 278px;
  width: min(100%, 1760px);
  height: calc(100dvh - 76px);
  min-height: 500px;
  margin-inline: auto;
  padding: clamp(12px, 1.7vw, 24px) clamp(12px, 3vw, 44px);
  gap: 12px;
}

.photos, .preview, .editor {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 10px;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

.panel-header, .preview-toolbar {
  min-height: 62px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 15px;
}

.panel-header {
  border-bottom: 1px solid var(--line);
  flex: none;
}

.panel-header h2, .preview-heading h2 { font-size: 15px; font-weight: 730; }
.count { font: 12px var(--mono); font-variant-numeric: tabular-nums; color: var(--accent); }
.library-actions { display: grid; grid-template-columns: 1fr auto; gap: 6px; padding: 13px 12px 8px; }
.library-hint { color: var(--muted); font-size: 10.5px; padding: 0 13px 12px; }
.library-filter { padding-top: 0; }
.library-filter input { width: 100%; }
.button {
  min-height: 34px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--raised);
  color: var(--text);
  white-space: nowrap;
  transition: background-color .14s ease, border-color .14s ease;
}
.button:hover:not(:disabled) { background: #2e3226; border-color: #5b624e; }
.button.accent { color: var(--ink); background: var(--accent); border-color: var(--accent); font-weight: 750; }
.button.accent:hover:not(:disabled) { background: #f2ff7b; border-color: #f2ff7b; }
.button:disabled { opacity: .55; }
.button.accent:disabled { color: var(--muted); background: #292c22; border-color: var(--line); }
.button[aria-pressed='true']:not(:disabled) { color: var(--accent); border-color: #697344; background: #292e1c; }
.plus { margin-inline-end: 3px; font-size: 15px; font-weight: 500; }

.photo-list {
  flex: 1;
  min-height: 0;
  padding: 0 10px 10px;
  overflow: auto;
  display: grid;
  align-content: start;
  gap: 5px;
  scrollbar-color: #565c48 transparent;
}

.photo-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 4px;
  text-align: left;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  color: var(--text);
  min-width: 0;
}
.photo-item:hover { background: var(--raised); }
.photo-item[aria-selected='true'], .photo-item.active, .photo-item.selected {
  border-color: #727944;
  background: #2c301f;
}
.photo-item img {
  display: block;
  flex: none;
  width: 53px;
  height: 39px;
  background: #11130f;
  border-radius: 3px;
  object-fit: cover;
}
.photo-item-copy { display: grid; gap: 3px; min-width: 0; flex: 1; }
.photo-name { display: block; font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.photo-meta { display: block; color: var(--muted); font: 10px var(--mono); }

.preview-toolbar { flex: none; flex-wrap: wrap; }
.preview-heading { min-width: 0; }
.preview-heading h2 { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.photo-dimensions { color: var(--muted); font: 11px var(--mono); margin-top: 4px; }
.photo-dimensions:empty { display: none; }
.preview-tools, .segmented { flex: none; display: flex; align-items: center; gap: 6px; }
.preview-tools { flex-wrap: wrap; max-width: 100%; }
.segmented { gap: 2px; }
.preview-tools .button { min-height: 30px; font-size: 12px; padding-inline: 8px; }

.preview-stage {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  overflow: auto;
  border-block: 1px solid var(--line);
  background: conic-gradient(#151810 25%, #13150f 0 50%, #151810 0 75%, #13150f 0) 50% / 22px 22px;
  scrollbar-color: #565c48 transparent;
}
.preview-stage.dragging, .preview-stage[data-dragging='true'] { outline: 2px solid var(--accent); outline-offset: -3px; }
.preview-stage canvas { display: block; width: auto; height: auto; max-width: 100%; max-height: 100%; object-fit: contain; }
.preview-stage[data-zoom='actual'] { align-items: flex-start; justify-content: flex-start; }
.preview-stage[data-zoom='actual'] canvas { flex: none; max-width: none; max-height: none; margin: auto; }
.preview-stage[data-cropping='true'] { overflow: hidden; }
.preview-stage[data-cropping='true'] canvas { cursor: crosshair; touch-action: none; }
.crop-overlay { position: absolute; overflow: hidden; pointer-events: none; }
.crop-selection {
  position: absolute;
  border: 2px solid var(--accent);
  box-shadow: 0 0 0 200vmax #0b0d09a6;
}
.crop-actions, .recipe-actions, .dialog-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px; }

.empty-preview {
  display: grid;
  justify-items: center;
  text-align: center;
  gap: 9px;
  width: min(100%, 354px);
  padding: clamp(20px, 3vw, 37px) 16px;
  background: #1a1c17;
  border: 1px dashed #59614b;
  border-radius: 9px;
}
.empty-preview h3 { font-size: clamp(16px, 1.5vw, 21px); font-weight: 740; }
.empty-preview p { color: var(--muted); }
.empty-preview .button { min-height: 39px; margin-top: 9px; padding-inline: 15px; }
.empty-preview .button span { margin-inline-start: 6px; }
.drop-mark {
  position: relative;
  display: grid;
  place-items: center;
  width: 57px;
  height: 47px;
  margin-bottom: 5px;
  color: var(--accent);
}
.drop-mark::before, .drop-mark::after {
  content: '';
  position: absolute;
  width: 39px;
  height: 31px;
  border: 1px solid currentColor;
  border-radius: 4px;
}
.drop-mark::before { transform: translate(-4px, -4px); opacity: .35; }
.drop-mark::after { transform: translate(3px, 3px); background: #2a301f; }
.drop-mark div {
  z-index: 1;
  width: 20px;
  height: 13px;
  margin: 6px 0 0 6px;
  background: var(--accent);
  clip-path: polygon(0 100%, 33% 29%, 52% 69%, 72% 14%, 100% 100%);
}

.preview-status {
  min-height: 38px;
  flex: none;
  padding: 7px 13px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 7px;
  color: var(--muted);
  font-size: 12px;
}
#status[data-kind='error'], #status.error { color: #ffaba0; }
#status[data-kind='warning'], #status.warning { color: #f8d982; }
progress { flex: 0 1 120px; width: 120px; height: 7px; accent-color: var(--accent); }

.edit-controls {
  display: block;
  margin: 0;
  border: none;
  padding: 0 14px;
  flex: 1;
  min-inline-size: 0;
  min-height: 0;
  overflow: auto;
  scrollbar-color: #565c48 transparent;
}
.edit-controls:disabled { opacity: .59; }
.editor-group {
  display: grid;
  gap: 10px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}
.editor-group:last-child { border-bottom: none; }
.editor-group h3 { color: var(--accent); font-size: 12px; font-weight: 700; }
.field { display: grid; align-content: start; min-width: 0; gap: 5px; }
.check-field, .color-field, .control-heading, .export-format {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 7px;
}
.check-field { justify-content: flex-start; }
.check-field input { margin: 0; width: 15px; height: 15px; }
.control-heading { width: 100%; }
.control-heading output, .muted { color: var(--muted); font-size: 11px; }
output { font-variant-numeric: tabular-nums; }

select, input[type='text'], input[type='number'], input[type='color'], input[type='search'] {
  width: 100%;
  min-width: 0;
  min-height: 31px;
  padding: 4px 7px;
  border-radius: 4px;
  border: 1px solid var(--line);
  color: var(--text);
  background: #131610;
}
.trim-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 5px 8px; }
.trim-grid label { display: flex; align-items: center; gap: 7px; color: var(--muted); }
.trim-grid input { flex: 1; font-variant-numeric: tabular-nums; }
input[type='range'] { width: 100%; margin: 0; }
input[type='range'], input[type='checkbox'] { accent-color: var(--accent); }
.color-field input { width: 47px; padding: 3px; }
.template-options { display: grid; gap: 8px; }
.param-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.effect-settings { min-width: 0; border: 1px solid var(--line); border-radius: 6px; padding: 8px 9px; }
.effect-settings summary { cursor: pointer; font-weight: 650; }
.effect-settings > :not(summary) { margin-top: 8px; }
.recipe-actions { justify-content: stretch; }
.recipe-actions .button { flex: 1; }
.help-dialog { width: min(460px, calc(100% - 24px)); color: var(--text); background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 0; }
.help-dialog::backdrop { background: #0a0b08bb; }
.help-dialog ol { margin: 0; padding: 14px 20px 18px 36px; line-height: 1.65; }
.help-dialog li + li { margin-top: 6px; }
.help-dialog p, .dialog-actions { padding: 12px 15px; line-height: 1.6; }
.editor-export { flex: none; display: grid; gap: 6px; border-top: 1px solid var(--line); padding: 10px 13px 12px; }
.export-format span { flex: none; color: var(--muted); font-size: 11px; }
.export-format select { width: auto; flex: 1; }

@media (max-width: 1040px) {
  .workspace { grid-template-columns: 182px minmax(0, 1fr) 230px; padding-inline: 14px; gap: 8px; }
  .preview-toolbar { min-height: 62px; padding-inline: 10px; }
  .panel-header { padding-inline: 12px; }
}

@media (max-width: 810px) {
  .workspace { grid-template-columns: minmax(0, 1fr) 226px; height: auto; min-height: calc(100dvh - 76px); align-items: stretch; }
  .photos { grid-column: 1 / -1; display: grid; grid-template-columns: auto 1fr; }
  .photos .panel-header { min-height: 48px; justify-content: flex-start; gap: 8px; border-bottom: 0; }
  .library-actions { grid-template-columns: auto auto; justify-content: end; padding: 8px 10px; }
  .library-hint { grid-column: 1 / -1; }
  .library-actions.library-filter { grid-column: 1 / -1; grid-template-columns: minmax(0, 1fr) auto; justify-content: stretch; }
  .photo-list { grid-column: 1 / -1; display: flex; padding: 0 10px 8px; overflow: auto; }
  .photo-list:empty { display: none; }
  .photo-item { flex: 0 0 162px; }
  .preview { height: min(75dvh, 680px); min-height: 430px; }
  .preview-stage { min-height: 300px; }
  .editor { max-height: max(430px, min(75dvh, 680px)); }
}

@media (max-width: 570px) {
  .app-bar { min-height: 67px; padding: 10px 12px; align-items: flex-start; }
  .app-brand { gap: 8px; }
  .app-brand img { width: 30px; height: 30px; }
  .app-brand h1 { font-size: 15px; }
  .privacy { font-size: 10px; gap: 4px; align-self: center; }
  .privacy::before { width: 5px; height: 5px; }
  .header-actions { gap: 4px 8px; }
  .header-actions .button { min-height: 26px; padding: 2px 6px; font-size: 11px; }
  .workspace { display: flex; flex-direction: column; padding: 8px; min-height: auto; }
  .preview { height: auto; min-height: 0; }
  .preview-stage { min-height: 280px; height: min(56dvh, 380px); flex: none; padding: 12px; }
  .preview-toolbar { flex-wrap: wrap; }
  .editor { max-height: none; }
  .edit-controls { overflow: visible; }
}

@media (max-width: 340px) {
  .photos { display: flex; }
  .library-actions { justify-content: stretch; grid-template-columns: 1fr auto; }
}

@media (prefers-reduced-motion: reduce) {
  .button { transition: none; }
}
