:root {
  --bg: #050607;
  --surface: #0d1012;
  --surface-raised: #12161a;
  --surface-soft: #171b1f;
  --line: #2a2f34;
  --line-strong: #3b4248;
  --ink: #f5f7f3;
  --muted: #7d838b;
  --lime: #baff27;
  --cyan: #43dcf6;
  --violet: #9d70ff;
  --amber: #ffb72d;
  --danger: #ff6d5d;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  min-height: 100%;
  background: #020303;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background: #020303;
  font-family: Inter, "PingFang SC", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
  letter-spacing: 0;
  -webkit-font-smoothing: antialiased;
}

button,
input {
  font: inherit;
}

button {
  color: inherit;
}

button:focus-visible,
a:focus-visible {
  outline: 2px solid var(--lime);
  outline-offset: 3px;
}

.app-shell {
  width: min(100%, 430px);
  min-height: 100dvh;
  margin: 0 auto;
  overflow: hidden;
  background: var(--bg);
  border-right: 1px solid #171a1d;
  border-left: 1px solid #171a1d;
  box-shadow: 0 0 60px rgba(0, 0, 0, 0.72);
}

.local-badge {
  padding: 5px 8px;
  border: 1px solid rgba(157, 112, 255, 0.55);
  border-radius: 4px;
  color: #c4aaff;
  background: #151020;
  font: 700 9px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
  letter-spacing: 0.08em;
}

main {
  width: calc(100% - 32px);
  margin: 0 auto;
  padding: 16px 0 max(24px, env(safe-area-inset-bottom));
}

.tool-heading p {
  margin: 0;
  color: var(--lime);
  font: 700 10px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace;
  letter-spacing: 0.14em;
}

.workspace {
  overflow: hidden;
  border: 1px solid #30353a;
  border-radius: 8px;
  background: var(--surface);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.02);
}

.tool-heading {
  min-height: 78px;
  padding: 14px 15px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid #24292d;
}

.tool-heading > div {
  min-width: 0;
  flex: 1;
}

.tool-heading p {
  margin-bottom: 5px;
  color: var(--violet);
  font-size: 9px;
}

.tool-heading h2 {
  margin: 0;
  font-size: 17px;
  line-height: 1.2;
}

.scan-symbol {
  position: relative;
  width: 48px;
  height: 48px;
  flex: 0 0 auto;
  display: block;
  border: 1px solid var(--violet);
  border-radius: 6px;
  background: #171321;
}

.scan-symbol::before,
.scan-symbol::after {
  position: absolute;
  content: "";
}

.scan-symbol::before {
  inset: 13px;
  border: 2px dashed var(--violet);
  border-radius: 4px;
}

.scan-symbol::after {
  top: 22px;
  left: 22px;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--cyan);
  box-shadow: 0 0 10px rgba(67, 220, 246, 0.85);
}

.local-badge {
  border-color: rgba(67, 220, 246, 0.4);
  color: var(--cyan);
  background: #0b171a;
}

.upload-panel {
  min-height: 0;
  padding: 14px;
}

.empty-state {
  min-height: 438px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.drop-zone {
  width: 100%;
  min-height: 326px;
  padding: 30px 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border: 1px dashed #454b51;
  border-radius: 6px;
  background: #090b0d;
  cursor: pointer;
  transition: border-color 160ms ease, background 160ms ease;
}

.drop-zone:hover,
.drop-zone.is-dragging {
  border-color: var(--violet);
  background: #100d17;
}

.upload-symbol {
  position: relative;
  width: 72px;
  height: 72px;
  margin-bottom: 23px;
  display: grid;
  place-items: center;
  border: 1px solid var(--violet);
  border-radius: 7px;
  background: #171321;
  color: var(--violet);
  box-shadow: 0 0 0 7px rgba(157, 112, 255, 0.04);
}

.upload-symbol::before,
.upload-symbol::after {
  position: absolute;
  content: "";
}

.upload-symbol::before {
  width: 28px;
  border-top: 2px solid var(--cyan);
}

.upload-symbol::after {
  height: 28px;
  border-left: 2px solid var(--cyan);
}

.upload-symbol span {
  display: none;
}

.drop-title {
  margin-bottom: 7px;
  font-size: 20px;
  font-weight: 750;
}

.drop-subtitle {
  margin-bottom: 24px;
  color: #686e76;
  font: 600 10px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace;
  letter-spacing: 0.08em;
}

.primary-action {
  width: min(100%, 210px);
  min-height: 48px;
  padding: 0 20px;
  display: inline-grid;
  place-items: center;
  border-radius: 5px;
  background: var(--lime);
  color: #081000;
  font-size: 14px;
  font-weight: 800;
  box-shadow: 0 10px 24px rgba(186, 255, 39, 0.09);
}

.camera-action,
.change-image {
  min-height: 42px;
  border: 0;
  background: transparent;
  color: var(--cyan);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}

.camera-action {
  margin-top: 9px;
  padding: 8px 12px;
}

.target-ratios {
  margin: 3px 0 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.target-ratios > span {
  height: 27px;
  padding: 0 9px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border: 1px solid #33383e;
  border-radius: 4px;
  background: #101316;
  color: #a4a9af;
  font: 700 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
}

.target-ratios > span:first-child {
  border-color: rgba(157, 112, 255, 0.45);
  color: #c2a8fb;
}

.target-ratios > span:last-child {
  border-color: rgba(67, 220, 246, 0.38);
  color: #91e9f8;
}

.ratio-shape {
  display: inline-block;
  border: 1px solid currentColor;
}

.portrait-shape { width: 6px; height: 11px; }
.landscape-shape { width: 11px; height: 6px; }

.empty-state > p {
  margin: 0;
  color: #555b62;
  font-size: 10px;
}

.preview-state {
  min-height: 0;
}

.preview-toolbar {
  min-height: 54px;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.file-heading {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
}

.status-dot {
  width: 8px;
  height: 8px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--cyan);
  box-shadow: 0 0 0 5px rgba(67, 220, 246, 0.09);
}

.file-heading div {
  min-width: 0;
}

.file-heading strong,
.file-heading span {
  display: block;
}

.file-heading strong {
  max-width: 245px;
  overflow: hidden;
  color: var(--ink);
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-heading span:not(.status-dot) {
  margin-top: 4px;
  color: var(--muted);
  font: 600 9px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace;
}

.icon-button {
  width: 38px;
  height: 38px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border: 1px solid #353b40;
  border-radius: 5px;
  background: #111417;
  color: #8c9298;
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
}

.image-stage {
  --stage-height: clamp(280px, 52vh, 410px);
  position: relative;
  height: var(--stage-height);
  padding: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  border: 1px solid #282d31;
  background-color: #0a0d0f;
  background-image:
    linear-gradient(45deg, #13171a 25%, transparent 25%),
    linear-gradient(-45deg, #13171a 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #13171a 75%),
    linear-gradient(-45deg, transparent 75%, #13171a 75%);
  background-position: 0 0, 0 8px, 8px -8px, -8px 0;
  background-size: 16px 16px;
}

.crop-entry-button {
  appearance: none;
  -webkit-appearance: none;
  width: 100%;
  min-height: 52px;
  margin-top: 8px;
  padding: 0 13px;
  display: flex;
  align-items: center;
  gap: 10px;
  border: 1px solid rgba(186, 255, 39, 0.55);
  border-radius: 6px;
  background: var(--lime);
  color: #081000;
  font-size: 14px;
  font-weight: 850;
  cursor: pointer;
  box-shadow: 0 8px 20px rgba(186, 255, 39, 0.08);
}

.crop-entry-button small {
  margin-left: auto;
  font: 700 9px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
  letter-spacing: 0.05em;
}

.crop-entry-button:disabled {
  opacity: 0.6;
  cursor: wait;
}

.crop-button-icon {
  position: relative;
  width: 20px;
  height: 20px;
  flex: 0 0 auto;
  border: solid #081000;
  border-width: 0 0 2px 2px;
}

.crop-button-icon::before {
  position: absolute;
  top: -4px;
  left: 6px;
  width: 15px;
  height: 15px;
  border: solid #081000;
  border-width: 2px 2px 0 0;
  content: "";
}

.image-stage img {
  width: auto;
  height: auto;
  min-width: 0;
  min-height: 0;
  display: block;
  max-width: 100%;
  max-height: calc(var(--stage-height) - 28px);
  flex: 0 1 auto;
  object-fit: contain;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
}

.crop-guide {
  position: absolute;
  z-index: 2;
  border: 2px dashed var(--violet);
  box-shadow:
    0 0 0 1px rgba(5, 6, 7, 0.82),
    inset 0 0 18px rgba(157, 112, 255, 0.12);
  pointer-events: none;
}

.crop-guide > span {
  position: absolute;
  top: 7px;
  left: 7px;
  padding: 5px 7px;
  border-radius: 3px;
  background: var(--violet);
  color: #0b0713;
  font: 800 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
  white-space: nowrap;
  box-shadow: 0 3px 12px rgba(0, 0, 0, 0.35);
}

.compact-result {
  min-height: 58px;
  margin-top: 12px;
  padding: 11px 12px;
  display: flex;
  align-items: center;
  gap: 11px;
  border: 1px solid rgba(157, 112, 255, 0.48);
  border-radius: 6px;
  background: #13101a;
}

.compact-result-dot {
  width: 9px;
  height: 9px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--violet);
  box-shadow: 0 0 0 5px rgba(157, 112, 255, 0.1);
}

.compact-result strong,
.compact-result small {
  display: block;
}

.compact-result strong {
  color: #c7adff;
  font-size: 13px;
}

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

.compact-result.is-matched {
  border-color: rgba(186, 255, 39, 0.5);
  background: #101708;
}

.compact-result.is-matched .compact-result-dot {
  background: var(--lime);
  box-shadow: 0 0 0 5px rgba(186, 255, 39, 0.09);
}

.compact-result.is-matched strong {
  color: var(--lime);
}

.change-image {
  width: 100%;
  min-height: 46px;
  margin-top: 8px;
  border: 1px solid #30363b;
  border-radius: 5px;
  background: #101316;
}

.toast {
  position: fixed;
  z-index: 20;
  left: 50%;
  bottom: max(24px, env(safe-area-inset-bottom));
  max-width: min(calc(100% - 32px), 398px);
  padding: 11px 15px;
  border: 1px solid #3b4248;
  border-radius: 5px;
  background: #13171a;
  color: var(--ink);
  font-size: 12px;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 10px);
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

body.is-cropping {
  overflow: hidden;
}

.crop-modal {
  position: fixed;
  z-index: 30;
  inset: 0;
  width: min(100%, 430px);
  height: 100dvh;
  margin: 0 auto;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  overflow: hidden;
  background: #050607;
  box-shadow: 0 0 70px rgba(0, 0, 0, 0.85);
}

.crop-modal-header {
  min-height: 68px;
  padding: 10px 14px;
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid #272c31;
  background: #090b0d;
}

.crop-modal-close {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border: 1px solid #353b40;
  border-radius: 5px;
  background: #111417;
  color: #a2a8ae;
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
}

.crop-modal-header div {
  min-width: 0;
}

.crop-modal-header small,
.crop-modal-header h2 {
  display: block;
}

.crop-modal-header small {
  margin-bottom: 3px;
  color: var(--violet);
  font: 700 8px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
  letter-spacing: 0.1em;
}

.crop-modal-header h2 {
  margin: 0;
  overflow: hidden;
  font-size: 15px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.crop-modal-header > span {
  color: var(--cyan);
  font: 700 9px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
  white-space: nowrap;
}

.crop-workspace {
  min-height: 0;
  padding: 12px;
  overflow: hidden;
  background: #020303;
}

.crop-workspace > img {
  display: block;
  max-width: 100%;
}

.crop-workspace .cropper-container {
  width: 100% !important;
  height: 100% !important;
}

.crop-workspace .cropper-view-box {
  outline: 2px solid var(--violet);
  outline-color: var(--violet);
}

.crop-workspace .cropper-line,
.crop-workspace .cropper-point {
  background-color: var(--violet);
}

.crop-workspace .cropper-dashed {
  border-color: rgba(255, 255, 255, 0.28);
}

.crop-workspace .cropper-modal {
  background-color: #020303;
  opacity: 0.76;
}

.crop-workspace .cropper-bg {
  background-image:
    linear-gradient(45deg, #161a1d 25%, transparent 25%),
    linear-gradient(-45deg, #161a1d 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #161a1d 75%),
    linear-gradient(-45deg, transparent 75%, #161a1d 75%);
  background-color: #0b0e10;
}

.crop-controls {
  padding: 13px 16px max(16px, env(safe-area-inset-bottom));
  border-top: 1px solid #272c31;
  background: #0a0d0f;
}

.crop-ratio-control {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.crop-ratio-control button {
  min-height: 40px;
  border: 1px solid #343a40;
  border-radius: 5px;
  background: #111519;
  color: #8c9299;
  font-size: 12px;
  font-weight: 750;
  cursor: pointer;
}

.crop-ratio-control button.is-active {
  border-color: var(--violet);
  background: #181222;
  color: #c6acff;
}

.quick-controls {
  margin-top: 8px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.quick-controls button {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border: 1px solid #343a40;
  border-radius: 5px;
  background: #111519;
  color: #aeb4ba;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

.quick-controls button:active {
  border-color: var(--cyan);
  color: var(--cyan);
}

.quick-controls span {
  font-size: 18px;
  line-height: 1;
}

.zoom-control {
  min-height: 46px;
  margin-top: 9px;
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr);
  align-items: center;
  gap: 9px;
  color: #9ca1a8;
  font-size: 11px;
}

.zoom-control input {
  width: 100%;
  accent-color: var(--violet);
}

.move-controls {
  min-height: 40px;
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr);
  align-items: center;
  gap: 9px;
  color: #9ca1a8;
  font-size: 11px;
}

.move-controls > div {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}

.move-controls button {
  height: 36px;
  display: grid;
  place-items: center;
  border: 1px solid #343a40;
  border-radius: 5px;
  background: #111519;
  color: #b6bbc1;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
}

.move-controls button:active {
  border-color: var(--violet);
  background: #181222;
  color: #c6acff;
}

.crop-drag-hint {
  margin: 5px 0 9px;
  color: #696f76;
  font-size: 10px;
  text-align: center;
}

.export-button {
  width: 100%;
  min-height: 50px;
  padding: 7px 16px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 5px;
  background: var(--lime);
  color: #081000;
  cursor: pointer;
  box-shadow: 0 10px 24px rgba(186, 255, 39, 0.09);
}

.export-button > span,
.export-button > small {
  display: block;
}

.export-button > span {
  font-size: 14px;
  font-weight: 850;
}

.export-button > small {
  margin-top: 2px;
  font: 700 9px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
}

.export-button:disabled {
  opacity: 0.55;
  cursor: wait;
}

.save-modal {
  position: fixed;
  z-index: 40;
  inset: 0;
  width: min(100%, 430px);
  height: 100dvh;
  margin: 0 auto;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  overflow: hidden;
  background: #050607;
  box-shadow: 0 0 70px rgba(0, 0, 0, 0.9);
}

.save-modal-header {
  min-height: 66px;
  padding: 10px 14px;
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid #272c31;
  background: #090b0d;
}

.save-modal-header button {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border: 1px solid #353b40;
  border-radius: 5px;
  background: #111417;
  color: #a2a8ae;
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
}

.save-modal-header small,
.save-modal-header h2 {
  display: block;
}

.save-modal-header small {
  margin-bottom: 3px;
  color: var(--lime);
  font: 700 8px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
  letter-spacing: 0.1em;
}

.save-modal-header h2 {
  margin: 0;
  font-size: 15px;
}

.save-image-stage {
  min-height: 0;
  padding: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background-color: #090c0e;
  background-image:
    linear-gradient(45deg, #15191c 25%, transparent 25%),
    linear-gradient(-45deg, #15191c 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #15191c 75%),
    linear-gradient(-45deg, transparent 75%, #15191c 75%);
  background-position: 0 0, 0 8px, 8px -8px, -8px 0;
  background-size: 16px 16px;
}

.save-image-stage img {
  display: block;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.55);
  -webkit-user-select: auto;
  user-select: auto;
  -webkit-touch-callout: default;
}

.save-actions {
  padding: 14px 16px max(16px, env(safe-area-inset-bottom));
  border-top: 1px solid #272c31;
  background: #0a0d0f;
  text-align: center;
}

.save-actions strong {
  display: block;
  color: var(--lime);
  font-size: 15px;
}

.save-actions p {
  margin: 5px 0 12px;
  color: #858b92;
  font-size: 11px;
  line-height: 1.6;
}

.save-actions a {
  min-height: 44px;
  display: grid;
  place-items: center;
  border: 1px solid #343a40;
  border-radius: 5px;
  background: #111519;
  color: var(--cyan);
  font-size: 13px;
  font-weight: 750;
  text-decoration: none;
}

[hidden] {
  display: none !important;
}

@media (max-width: 360px) {
  main {
    width: calc(100% - 24px);
  }

  .tool-heading {
    padding-right: 12px;
    padding-left: 12px;
  }

  .upload-panel {
    padding: 11px;
  }

  .drop-zone {
    min-height: 306px;
  }

  .file-heading strong {
    max-width: 200px;
  }
}

@media (orientation: landscape) and (max-height: 500px) {
  .crop-modal {
    width: min(100%, 760px);
    grid-template-columns: minmax(0, 1fr) 294px;
    grid-template-rows: 58px minmax(0, 1fr);
  }

  .crop-modal-header {
    min-height: 58px;
    grid-column: 1 / -1;
    padding-top: 7px;
    padding-bottom: 7px;
  }

  .crop-workspace {
    grid-column: 1;
    grid-row: 2;
  }

  .crop-controls {
    grid-column: 2;
    grid-row: 2;
    overflow-y: auto;
    border-top: 0;
    border-left: 1px solid #272c31;
  }

  .zoom-control {
    min-height: 38px;
  }

  .move-controls {
    min-height: 36px;
  }

  .move-controls button {
    height: 32px;
  }

  .crop-drag-hint {
    margin-top: 3px;
    margin-bottom: 7px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition-duration: 0.01ms !important;
  }
}
