:root {
  color-scheme: light;
  --page-bg: #f3f4f6;
  --panel-bg: #ffffff;
  --text: #111827;
  --muted: #6b7280;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --border: #e5e7eb;
  --control-border: #d1d5db;
  --focus-ring: 0 0 0 3px rgb(37 99 235 / 20%);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  line-height: 1.5;
  color: var(--text);
  background: var(--page-bg);
}

* {
  box-sizing: border-box;
}

body {
  min-width: 320px;
  margin: 0;
  background: var(--page-bg);
  color: var(--text);
}

a {
  color: var(--accent);
}

a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
[role="button"]:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

.app-header {
  padding: 18px 24px;
  background: #111827;
  color: #ffffff;
}

.app-header h1 {
  margin: 0;
  font-size: 1.5rem;
  line-height: 1.25;
}

.back-link {
  display: inline-block;
  margin-bottom: 8px;
  color: #cbd5e1;
  font-size: 0.9rem;
  text-decoration: none;
}

.back-link:hover {
  color: #ffffff;
  text-decoration: underline;
}

.subtitle {
  max-width: 680px;
  margin: 5px 0 0;
  color: #cbd5e1;
  font-size: 0.95rem;
}

.tool-page {
  width: min(100% - 48px, 960px);
  margin: 0 auto;
  padding: 28px 0 56px;
}

.panel,
.result,
.tips {
  padding: 20px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--panel-bg);
  box-shadow: 0 3px 12px rgb(17 24 39 / 6%);
}

.panel h2,
.result h2,
.tips h2 {
  margin: 0 0 14px;
  font-size: 1.1rem;
}

.intro {
  margin: 0 0 18px;
  color: var(--muted);
}

.layout {
  display: grid;
  grid-template-columns: minmax(260px, 330px) minmax(0, 1fr);
  gap: 20px;
  align-items: start;
}

.controls {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 20px;
  margin: 22px 0;
}

label {
  display: block;
  margin-bottom: 7px;
  font-weight: 600;
}

input[type="text"],
input[type="number"],
input[type="email"],
input[type="url"],
input[type="password"],
select,
textarea {
  width: 100%;
  min-height: 42px;
  padding: 9px 11px;
  border: 1px solid var(--control-border);
  border-radius: 7px;
  background: #ffffff;
  color: var(--text);
  font: inherit;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

input[type="checkbox"],
input[type="radio"] {
  accent-color: var(--accent);
}

button {
  min-height: 42px;
  padding: 9px 14px;
  border: 1px solid var(--control-border);
  border-radius: 7px;
  background: #ffffff;
  color: var(--text);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

button:hover:not(:disabled) {
  background: #f9fafb;
}

button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

button.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: #ffffff;
}

button.primary:hover:not(:disabled) {
  border-color: var(--accent-hover);
  background: var(--accent-hover);
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.small,
.hint {
  color: var(--muted);
  font-size: 0.875rem;
}

#dropZone {
  padding: 34px 18px;
  border: 2px dashed #9ca3af;
  border-radius: 10px;
  background: #f9fafb;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}

#dropZone:hover,
#dropZone.dragover {
  border-color: var(--accent);
  background: #eff6ff;
}

#fileInput {
  display: none;
}

#fileList {
  margin: 18px 0 0;
  padding-left: 22px;
}

#fileList li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 6px;
  overflow-wrap: anywhere;
}

#fileList li > span {
  min-width: 0;
}

.crop-button {
  flex: 0 0 auto;
  min-height: 34px;
  padding: 5px 10px;
  font-size: 0.875rem;
}

#status {
  min-height: 1.5em;
  margin-top: 14px;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.crop-dialog {
  width: min(92vw, 900px);
  max-width: 900px;
  max-height: 90vh;
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--panel-bg);
  color: var(--text);
  box-shadow: 0 16px 48px rgb(17 24 39 / 24%);
}

.crop-dialog::backdrop {
  background: rgb(17 24 39 / 60%);
}

.crop-dialog-content {
  max-height: 90vh;
  padding: 20px;
  overflow-y: auto;
}

.crop-dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.crop-dialog-header h2 {
  min-width: 0;
  margin: 0;
  overflow-wrap: anywhere;
  font-size: 1.1rem;
}

.crop-dialog-content > .small {
  margin: 8px 0 14px;
}

.crop-stage {
  position: relative;
  width: fit-content;
  max-width: 100%;
  margin: 0 auto 16px;
  overflow: hidden;
  cursor: crosshair;
  touch-action: none;
  user-select: none;
}

#cropImage {
  display: block;
  max-width: 100%;
  max-height: 60vh;
  pointer-events: none;
}

.crop-selection {
  position: absolute;
  border: 2px solid #ffffff;
  outline: 2px solid var(--accent);
  background: rgb(37 99 235 / 20%);
  pointer-events: none;
}

.crop-selection[hidden] {
  display: none;
}

.crop-actions {
  display: flex;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 10px;
}

@media (max-width: 700px) {
  .tool-page {
    width: min(100% - 32px, 960px);
    padding-top: 20px;
  }

  .layout {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 560px) {
  .app-header {
    padding: 16px;
  }

  .app-header h1 {
    font-size: 1.35rem;
  }

  .tool-page {
    width: min(100% - 24px, 960px);
    padding-top: 16px;
  }

  .panel,
  .result,
  .tips {
    padding: 16px;
  }

  .crop-dialog-content {
    padding: 16px;
  }

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

  #fileList li {
    align-items: flex-start;
  }
}
