*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #f5f5f7;
  --card-bg: #fff;
  --text: #1d1d1f;
  --text-secondary: #6e6e73;
  --border: #d2d2d7;
  --primary: #0071e3;
  --primary-hover: #0077ed;
  --primary-bg: #e8f0fe;
  --danger: #ff3b30;
  --radius: 12px;
  --shadow: 0 2px 12px rgba(0,0,0,0.08);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

/* Header */
header {
  background: rgba(255,255,255,0.8);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}
.topbar {
  max-width: 1200px;
  margin: 0 auto;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.brand b { font-size: 18px; }
.brand span {
  font-size: 11px;
  color: var(--text-secondary);
  margin-left: 8px;
  letter-spacing: 1px;
}
.back-link {
  color: var(--primary);
  text-decoration: none;
  font-size: 14px;
}
.back-link:hover { text-decoration: underline; }

/* Main */
main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px 20px 60px;
}

.step { display: none; }
.step.active { display: block; }

.card {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 32px;
}

h2 { font-size: 22px; font-weight: 600; margin-bottom: 8px; }
.hint { color: var(--text-secondary); font-size: 14px; margin-bottom: 20px; }

/* Tabs */
.tabs { display: flex; gap: 4px; margin-bottom: 16px; }
.tab {
  padding: 8px 20px;
  border: 1px solid var(--border);
  background: var(--card-bg);
  border-radius: 8px 8px 0 0;
  cursor: pointer;
  font-size: 14px;
  color: var(--text-secondary);
  border-bottom: none;
}
.tab.active {
  background: var(--primary-bg);
  color: var(--primary);
  border-color: var(--primary);
  font-weight: 500;
}

.tab-content { display: flex; flex-direction: column; gap: 12px; }
.tab-content.hidden { display: none; }

/* Input */
#url-input {
  width: 100%;
  padding: 12px 16px;
  border: 2px solid var(--border);
  border-radius: 8px;
  font-size: 15px;
  outline: none;
  transition: border-color 0.2s;
}
#url-input:focus { border-color: var(--primary); }

/* File drop */
.file-drop {
  border: 2px dashed var(--border);
  border-radius: 8px;
  padding: 48px 20px;
  text-align: center;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s;
  position: relative;
}
.file-drop:hover, .file-drop.drag-over {
  border-color: var(--primary);
  background: var(--primary-bg);
  color: var(--primary);
}
.file-drop input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}
.file-drop .file-name {
  margin-top: 8px;
  font-size: 13px;
  color: var(--primary);
  font-weight: 500;
}

/* Buttons */
.btn {
  padding: 10px 20px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card-bg);
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}
.btn:hover { background: #f0f0f0; }
.btn.primary {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}
.btn.primary:hover { background: var(--primary-hover); }
.btn.primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.btn.large {
  padding: 14px 40px;
  font-size: 16px;
  font-weight: 600;
}

/* Status */
.status {
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 14px;
  margin-top: 8px;
}
.status.loading { background: #fef9e7; color: #b7950b; }
.status.error { background: #fde8e8; color: var(--danger); }
.status.hidden { display: none; }

/* Preview */
.preview-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 12px;
}
.preview-actions { display: flex; gap: 8px; }

.preview-container {
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: auto;
  max-height: 70vh;
  background: #e8e8ed;
  position: relative;
}
.selection-overlay {
  position: relative;
  display: inline-block;
  min-width: 100%;
  cursor: crosshair;
  -webkit-user-select: none;
  user-select: none;
}
.selection-overlay.selecting { cursor: crosshair; }
.selection-overlay.resizing { cursor: move; }

#preview-img {
  display: block;
  max-width: 100%;
  height: auto;
  pointer-events: none;
}

/* Crop box */
.crop-box {
  position: absolute;
  border: 2px dashed #0071e3;
  background: rgba(0, 113, 227, 0.08);
  pointer-events: none;
  z-index: 10;
}
.crop-box.hidden { display: none; }
.crop-box.active { pointer-events: auto; }

.crop-handle {
  position: absolute;
  width: 10px;
  height: 10px;
  background: #fff;
  border: 2px solid #0071e3;
  border-radius: 2px;
  pointer-events: auto;
}
.crop-handle.nw { top: -5px; left: -5px; cursor: nw-resize; }
.crop-handle.ne { top: -5px; right: -5px; cursor: ne-resize; }
.crop-handle.sw { bottom: -5px; left: -5px; cursor: sw-resize; }
.crop-handle.se { bottom: -5px; right: -5px; cursor: se-resize; }

/* Overlay mask */
.crop-mask {
  position: absolute;
  background: rgba(0,0,0,0.35);
  pointer-events: none;
  z-index: 5;
}

/* Crop info */
.crop-info {
  text-align: center;
  margin-top: 12px;
  font-size: 13px;
  color: var(--text-secondary);
}
.crop-info.hidden { display: none; }

/* Export */
#btn-export {
  display: block;
  margin: 20px auto 0;
}

/* Loading spinner */
@keyframes spin { to { transform: rotate(360deg); } }
.spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid #ccc;
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  vertical-align: middle;
  margin-right: 6px;
}

/* Responsive */
@media (max-width: 640px) {
  .card { padding: 20px; }
  .preview-header { flex-direction: column; }
  .preview-actions { width: 100%; }
  .topbar { padding: 10px 16px; }
  main { padding: 16px 12px 40px; }
}
