:root {
  color-scheme: light;
  --bg: #f6f8fc;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --line: #dbe4f2;
  --primary: #2563eb;
  --primary-hover: #1e4fd8;
  --radius: 16px;
  --shadow: 0 18px 44px rgba(15, 23, 42, 0.08);
  --icon-card-size: 150px;
}

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

body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: linear-gradient(180deg, #f8faff 0%, var(--bg) 100%);
  color: var(--text);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.site-nav {
  position: sticky;
  top: 0;
  z-index: 40;
  border-bottom: 1px solid #e2e8f5;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(10px);
}

.nav-shell {
  width: min(1080px, 92vw);
  margin: 0 auto;
  padding: 10px 0 8px;
}

.nav-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: nowrap;
}

.nav-seo {
  margin: 8px 0 0;
  padding: 0;
  max-width: 100%;
  font-size: 0.72rem;
  line-height: 1.45;
  letter-spacing: 0.02em;
  color: #94a3b8;
  font-weight: 500;
}

.nav-brand {
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--text);
  text-decoration: none;
  letter-spacing: -0.02em;
}

.nav-brand:hover {
  color: var(--primary);
}

.lang-select-wrap {
  margin-inline-start: auto;
}

.lang-select {
  font-size: 0.85rem;
  font-weight: 500;
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid #d5deec;
  background: #fff;
  color: var(--text);
  cursor: pointer;
}

.app-shell {
  width: min(1080px, 92vw);
  margin: 22px auto 68px;
}

.card {
  margin-top: 20px;
  background: var(--card);
  border: 1px solid #e2e8f5;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.uploader-card {
  padding: 22px;
}

.is-hidden {
  display: none;
}

.drop-zone {
  position: relative;
  border: 2px dashed var(--line);
  border-radius: calc(var(--radius) - 6px);
  background: #f8faff;
  text-align: center;
  padding: 46px 16px;
  cursor: pointer;
  transition: border-color 0.2s ease, background 0.2s ease, transform 0.2s ease;
}

.drop-zone:hover,
.drop-zone:focus-visible,
.drop-zone.is-dragging {
  border-color: var(--primary);
  background: #eef4ff;
  transform: translateY(-1px);
  outline: none;
}

.file-input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}

.drop-title {
  font-size: 1.08rem;
  font-weight: 600;
  margin: 0;
}

.drop-subtitle,
.drop-note {
  margin: 6px 0 0;
  color: var(--muted);
}

.drop-note {
  font-size: 0.9rem;
}

.preview-card {
  padding: 22px;
}

.preview-grid {
  display: grid;
  gap: 16px;
  grid-template-columns: 1fr;
}

.preview-panel h2 {
  margin: 0 0 10px;
  font-size: 1.08rem;
}

.preview-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.preview-head h2 {
  margin: 0;
  flex: 1;
  min-width: 0;
}

.btn-remove-image {
  flex-shrink: 0;
  font-size: 0.82rem;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 9px;
  background: #fff;
  border: 1px solid #e2e8f0;
  color: #64748b;
}

.btn-remove-image:hover:enabled {
  color: #b91c1c;
  border-color: #fecaca;
  background: #fef2f2;
}

.image-meta-text {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 0.84rem;
}

.preview-canvas {
  display: block;
  width: auto;
  max-width: 100%;
  height: auto;
  max-height: 360px;
  margin: 0 auto;
  border: 1px solid #e5ebf6;
  border-radius: 12px;
  background:
    linear-gradient(45deg, #eef3fc 25%, transparent 25%),
    linear-gradient(-45deg, #eef3fc 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #eef3fc 75%),
    linear-gradient(-45deg, transparent 75%, #eef3fc 75%);
  background-size: 18px 18px;
  background-position:
    0 0,
    0 9px,
    9px -9px,
    -9px 0;
}

.actions {
  display: flex;
  gap: 12px;
  margin-top: 16px;
}

button {
  border: 1px solid transparent;
  border-radius: 11px;
  padding: 10px 16px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s ease, border-color 0.2s ease, color 0.2s ease, transform 0.2s ease, opacity 0.2s ease;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}

.btn-primary.is-loading {
  opacity: 0.85;
  cursor: wait;
}

.btn-secondary {
  background: #f8fafc;
  border-color: #d7e1f1;
  color: #1e293b;
}

.btn-primary:hover:enabled {
  background: var(--primary-hover);
  transform: translateY(-1px);
}

.btn-secondary:hover:enabled {
  background: #eef2f8;
  transform: translateY(-1px);
}

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

.status-text {
  margin-top: 16px;
  border: 1px solid #dbe5f4;
  border-radius: 12px;
  padding: 10px 12px;
  background: #f8fbff;
  color: #334155;
}

.results-card {
  padding: 22px;
}

.results-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.results-left {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 12px;
  min-width: 0;
  flex: 1 1 auto;
}

.results-title {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.btn-download-all {
  flex-shrink: 0;
  font-size: 0.82rem;
  font-weight: 600;
  padding: 7px 12px;
  border-radius: 9px;
  background: #fff;
  border: 1px solid var(--primary);
  color: var(--primary);
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease, border-color 0.2s ease, opacity 0.2s ease;
}

.btn-download-all:hover:not(:disabled) {
  background: #eff6ff;
  border-color: var(--primary-hover);
  color: var(--primary-hover);
}

.btn-download-all:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-download-all.is-loading {
  opacity: 0.85;
  cursor: wait;
}

.results-card h2 {
  margin: 0;
  font-size: 1.08rem;
}

.count-badge {
  font-size: 0.78rem;
  font-weight: 600;
  color: #334155;
  border: 1px solid #d8e3f4;
  background: #f8fbff;
  border-radius: 999px;
  padding: 3px 9px;
}

.size-control {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #4e5f7b;
  font-size: 0.88rem;
}

.size-control input[type="range"] {
  width: 140px;
}

.icons-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(var(--icon-card-size), 1fr));
  gap: 12px;
}

.empty-state {
  border: 1px dashed #d5e0f0;
  border-radius: 12px;
  color: #64748b;
  background: #fbfdff;
  padding: 16px;
  margin-bottom: 12px;
  font-size: 0.9rem;
}

.empty-state.is-hidden {
  display: none;
}

.icon-item {
  border: 1px solid #e3e9f4;
  border-radius: 12px;
  background: #ffffff;
  padding: 12px;
  min-width: 0;
  overflow: hidden;
  box-sizing: border-box;
}

.icon-thumb {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-width: 0;
  min-height: 100px;
}

.icon-item canvas {
  display: block;
  width: auto;
  max-width: 100%;
  height: auto;
  max-height: 220px;
  border: 1px solid #ebf0f8;
  border-radius: 8px;
  background:
    linear-gradient(45deg, #eef3fc 25%, transparent 25%),
    linear-gradient(-45deg, #eef3fc 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #eef3fc 75%),
    linear-gradient(-45deg, transparent 75%, #eef3fc 75%);
  background-size: 18px 18px;
  background-position:
    0 0,
    0 9px,
    9px -9px,
    -9px 0;
}

.icon-meta {
  margin-top: 8px;
  font-size: 0.82rem;
  color: #4e5f7b;
}

.icon-actions {
  margin-top: 10px;
  display: flex;
  flex-direction: row;
  align-items: stretch;
  gap: 10px;
  width: 100%;
  min-width: 0;
  box-sizing: border-box;
}

.icon-actions button {
  margin-top: 0;
  flex: 1 1 0;
  min-width: 0;
  max-width: 100%;
  padding: 8px 8px;
  font-size: 0.78rem;
  line-height: 1.25;
  box-sizing: border-box;
  overflow-wrap: anywhere;
  word-break: break-word;
  hyphens: auto;
}

.btn-download {
  background: var(--primary);
  color: #fff;
  border: 1px solid transparent;
}

.btn-download:hover:enabled {
  background: var(--primary-hover);
}

.btn-adjust {
  background: #f8fafc;
  border-color: #d7e1f1;
  color: #1e293b;
}

.btn-adjust:hover:enabled {
  background: #eef2f8;
}

.skeleton-card {
  border: 1px solid #e3e9f4;
  border-radius: 12px;
  background: #ffffff;
  padding: 10px;
}

.skeleton-block {
  border-radius: 8px;
  background: linear-gradient(90deg, #eef3fb 25%, #f8fbff 45%, #eef3fb 65%);
  background-size: 220% 100%;
  animation: skeleton-shimmer 1.3s linear infinite;
}

.skeleton-canvas {
  width: 100%;
  aspect-ratio: 1 / 1;
}

.skeleton-meta {
  height: 12px;
  margin-top: 8px;
  width: 58%;
}

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

.skeleton-button {
  height: 34px;
  margin-top: 0;
}

.skeleton-button-secondary {
  opacity: 0.85;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.42);
}

.modal-panel {
  position: relative;
  box-sizing: border-box;
  width: min(860px, calc(100vw - 24px));
  max-width: 100%;
  max-height: min(92vh, 900px);
  margin: 6vh auto;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: #fff;
  border: 1px solid #dbe5f4;
  border-radius: 14px;
  box-shadow: 0 26px 60px rgba(15, 23, 42, 0.25);
  padding: 16px;
  unicode-bidi: isolate;
}

.modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
  min-width: 0;
}

.modal-head h3 {
  margin: 0;
  flex: 1 1 auto;
  min-width: 0;
  font-size: 1.05rem;
  line-height: 1.3;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.modal-head .btn-secondary {
  flex: 0 0 auto;
  max-width: 100%;
  white-space: nowrap;
}

.modal-hint {
  margin: 0 0 10px;
  font-size: 0.9rem;
  line-height: 1.5;
  color: #64748b;
  max-width: 100%;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.modal-controls {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 12px;
  width: 100%;
  min-width: 0;
}

.modal-controls label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.84rem;
  color: #475569;
  flex: 0 1 auto;
  min-width: 0;
}

.modal-controls input[type="number"] {
  width: 90px;
  max-width: 100%;
  min-width: 0;
  padding: 7px 8px;
  border-radius: 8px;
  border: 1px solid #d5deec;
  box-sizing: border-box;
}

.modal-controls .btn-primary {
  flex: 1 1 auto;
  min-width: min(100%, 8rem);
  max-width: 100%;
  white-space: normal;
  text-align: center;
  line-height: 1.25;
  padding: 10px 12px;
}

.modal-canvas-wrap {
  border: 1px solid #dde6f5;
  border-radius: 10px;
  padding: 10px;
  background: #f8fbff;
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
}

.modal-stage {
  position: relative;
  width: fit-content;
  max-width: 100%;
  margin: 0 auto;
  touch-action: none;
  min-width: 0;
}

.modal-canvas {
  display: block;
  width: auto;
  max-width: 100%;
  max-height: 58vh;
  margin: 0 auto;
  background:
    linear-gradient(45deg, #eef3fc 25%, transparent 25%),
    linear-gradient(-45deg, #eef3fc 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #eef3fc 75%),
    linear-gradient(-45deg, transparent 75%, #eef3fc 75%);
  background-size: 18px 18px;
  background-position:
    0 0,
    0 9px,
    9px -9px,
    -9px 0;
}

.crop-selection {
  position: absolute;
  border: 2px dashed #2563eb;
  background: rgba(37, 99, 235, 0.1);
  box-shadow: 0 0 0 9999px rgba(15, 23, 42, 0.22);
  cursor: move;
  pointer-events: auto;
  box-sizing: border-box;
}

.crop-handle {
  position: absolute;
  width: 14px;
  height: 14px;
  margin: 0;
  padding: 0;
  background: #fff;
  border: 2px solid #2563eb;
  border-radius: 3px;
  box-sizing: border-box;
  z-index: 2;
  pointer-events: auto;
  touch-action: none;
}

.crop-handle.nw {
  left: 0;
  top: 0;
  transform: translate(-50%, -50%);
  cursor: nwse-resize;
}

.crop-handle.n {
  left: 50%;
  top: 0;
  transform: translate(-50%, -50%);
  cursor: ns-resize;
}

.crop-handle.ne {
  left: 100%;
  top: 0;
  transform: translate(-50%, -50%);
  cursor: nesw-resize;
}

.crop-handle.e {
  left: 100%;
  top: 50%;
  transform: translate(-50%, -50%);
  cursor: ew-resize;
}

.crop-handle.se {
  left: 100%;
  top: 100%;
  transform: translate(-50%, -50%);
  cursor: nwse-resize;
}

.crop-handle.s {
  left: 50%;
  top: 100%;
  transform: translate(-50%, -50%);
  cursor: ns-resize;
}

.crop-handle.sw {
  left: 0;
  top: 100%;
  transform: translate(-50%, -50%);
  cursor: nesw-resize;
}

.crop-handle.w {
  left: 0;
  top: 50%;
  transform: translate(-50%, -50%);
  cursor: ew-resize;
}

@keyframes skeleton-shimmer {
  0% {
    background-position: 100% 0;
  }
  100% {
    background-position: -100% 0;
  }
}

@media (max-width: 860px) {
  .preview-grid {
    grid-template-columns: 1fr;
  }

  .results-toolbar {
    flex-direction: column;
    align-items: flex-start;
  }

  .results-left {
    width: 100%;
  }

  .btn-download-all {
    width: 100%;
    justify-content: center;
    text-align: center;
  }

  .preview-head {
    flex-direction: column;
    align-items: flex-start;
  }

  .lang-select-wrap {
    margin-inline-start: 0;
    width: auto;
  }
}

@media (max-width: 520px) {
  .modal-panel {
    margin: 3vh auto;
    padding: 12px;
    max-height: 94vh;
  }

  .modal-controls {
    flex-direction: column;
    align-items: stretch;
  }

  .modal-controls label {
    width: 100%;
  }

  .modal-controls input[type="number"] {
    width: 100%;
  }

  .modal-controls .btn-primary {
    width: 100%;
    flex: none;
  }
}
