@font-face {
  font-family: "Open Sans";
  src: url("./fonts/OpenSans-Regular.ttf") format("truetype");
  font-weight: 400;
  font-display: swap;
}

@font-face {
  font-family: "Open Sans";
  src: url("./fonts/OpenSans-Semibold.ttf") format("truetype");
  font-weight: 600;
  font-display: swap;
}

:root {
  color-scheme: dark;
  --page: #121514;
  --panel: #1b201e;
  --tray: #101311;
  --line: #36413b;
  --text: #f1f5ed;
  --muted: #adb9af;
  --accent: #daf593;
  --accent-hover: #e8ffb9;
  --gutter: clamp(16px, 4vw, 60px);
  --font: "Open Sans", system-ui, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  background: var(--page);
  color: var(--text);
  font: 400 1rem / 1.6 var(--font);
}

img { display: block; max-width: 100%; }
a { color: inherit; }
button, select, input { font: inherit; }
button:enabled, select, input[type="range"] { cursor: pointer; }
h1, h2, p { margin: 0; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; }

.wrap { width: min(100% - 2 * var(--gutter), 1240px); margin-inline: auto; }
.skip-link {
  position: absolute;
  z-index: 5;
  left: var(--gutter);
  top: 8px;
  padding: 9px 14px;
  background: var(--panel);
  transform: translateY(-160%);
}
.skip-link:focus { transform: none; }

.masthead { border-bottom: 1px solid var(--line); }
.masthead-inner {
  min-height: 73px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  font-weight: 600;
  font-size: 1.05rem;
  letter-spacing: -0.035em;
  text-decoration: none;
  white-space: nowrap;
}

.button {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 10px;
  min-height: 46px;
  padding: 8px 15px;
  border: 1px solid transparent;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 600;
  transition: background-color 160ms, border-color 160ms;
}

.secondary { background: #212824; color: var(--text); border-color: var(--line); }
.secondary:hover { background: #2b352e; border-color: #627062; }
.primary { background: var(--accent); color: #17201a; }
.primary:hover:enabled { background: var(--accent-hover); }
.primary:disabled { opacity: 0.65; }

.intro { padding-block: clamp(26px, 4vw, 58px) 26px; }
.intro h1 {
  font-size: clamp(2rem, 5.4vw, 3.6rem);
  font-weight: 600;
  line-height: 1.08;
  letter-spacing: -0.075em;
}
.intro p { margin-top: 11px; color: var(--muted); font-size: 0.93rem; }

.editor {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  align-items: start;
  gap: 16px;
  padding-bottom: 36px;
}

.panel {
  min-width: 0;
  overflow: hidden;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 15px;
}

.panel-head, .stage-foot {
  min-height: 53px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 4px 17px;
}

.panel-head h2 { flex: 0 0 auto; font-size: 0.91rem; font-weight: 600; }
.source-name {
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--muted);
  font-size: 0.8rem;
  white-space: nowrap;
}

.stage {
  position: relative;
  aspect-ratio: 1.72;
  display: grid;
  place-items: center;
  min-height: 220px;
  overflow: hidden;
  background: var(--tray);
  border-block: 1px solid var(--line);
}

.stage.is-drop-target { box-shadow: inset 0 0 0 3px var(--accent); }
.stage.is-drop-target canvas { opacity: 0.58; }
.sample {
  width: 100%;
  height: 100%;
  position: absolute;
  object-fit: contain;
}

#crop-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: grab;
}
#crop-canvas:active { cursor: grabbing; }
#crop-canvas:focus-visible { outline-offset: -3px; }

.stage-foot { min-height: 46px; flex-wrap: wrap; color: var(--muted); font-size: 0.76rem; }
.dimensions { color: var(--text); font-size: 0.78rem; font-variant-numeric: tabular-nums; white-space: nowrap; }
.no-script { padding: 0 17px 14px; color: var(--muted); }

.control-panel .panel-head { border-bottom: 1px solid var(--line); }
.reset-button {
  border: none;
  padding-inline: 8px;
  min-height: 44px;
  border-radius: 5px;
  background: transparent;
  color: var(--muted);
  font-size: 0.82rem;
}
.reset-button:hover { color: var(--text); background: #28312c; }

.settings { padding: 17px; }
.control-group { min-width: 0; margin: 0; padding: 0; border: 0; }
.control-group legend, .zoom-group label, .export > label { font-size: 0.84rem; font-weight: 600; }
.ratios { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 7px; margin-top: 8px; }
.ratios label { position: relative; cursor: pointer; }
.ratios input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.ratios label span {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 46px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--tray);
  color: var(--muted);
  font-size: 0.76rem;
  white-space: nowrap;
}
.ratios label:hover span { border-color: #778976; color: var(--text); }
.ratios input:checked + span { background: #2a3828; color: var(--accent); border-color: #90aa73; }
.ratios input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.shape { flex: 0 0 auto; border: 1px solid; border-radius: 2px; opacity: 0.85; }
.shape.original { width: 15px; height: 11px; }
.shape.square { width: 12px; height: 12px; }
.shape.portrait { width: 10px; height: 13px; }
.shape.story { width: 8px; height: 14px; }
.shape.wide { width: 16px; height: 9px; }

.zoom-group { display: grid; grid-template-columns: 1fr auto; row-gap: 3px; margin-top: 17px; }
.zoom-group output { color: var(--accent); font-size: 0.8rem; font-variant-numeric: tabular-nums; }
.zoom-group input {
  grid-column: 1 / -1;
  min-height: 44px;
  margin: 0;
  width: 100%;
  accent-color: var(--accent);
}

.export {
  display: grid;
  gap: 7px;
  margin-top: 4px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}
.export select {
  min-height: 44px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--tray);
  color: var(--text);
  font-size: 0.84rem;
}
.export-size {
  display: flex;
  justify-content: space-between;
  gap: 6px;
  padding-block: 6px;
  color: var(--muted);
  font-size: 0.8rem;
}

.status:not(:empty) {
  margin: 0 17px 17px;
  border-top: 1px solid var(--line);
  padding-top: 9px;
  color: var(--muted);
  font-size: 0.82rem;
  overflow-wrap: anywhere;
}

.icon { width: 16px; height: 16px; border-bottom: 1px solid; flex: 0 0 auto; position: relative; }
.icon::before { content: ""; position: absolute; width: 1px; height: 10px; left: 7px; top: 1px; background: currentColor; }
.icon::after { content: ""; position: absolute; width: 7px; height: 7px; left: 4px; top: 5px; border: 1px solid; border-width: 0 1px 1px 0; transform: rotate(45deg); }
.icon-upload::after { top: 2px; transform: rotate(225deg); }

@media (max-width: 875px) {
  .editor { grid-template-columns: minmax(0, 1fr); }
  .ratios { grid-template-columns: repeat(auto-fit, minmax(73px, 1fr)); }
}

@media (max-width: 480px) {
  .masthead-inner { min-height: 65px; }
  .brand { font-size: 0.94rem; gap: 8px; }
  .brand img { width: 30px; height: 30px; }
  .secondary { padding-inline: 9px; font-size: 0.79rem; }
  .stage-foot { padding-block: 6px; }
  .stage { aspect-ratio: 1.17; }
}

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