:root {
  --bg: #f3f4f8;
  --surface: #ffffff;
  --text: #1d2430;
  --muted: #5f6673;
  --accent: #1465b5;
  --accent-2: #0f4f8f;
  --line: #d4d9e2;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Avenir Next", "Helvetica Neue", Helvetica, Arial, sans-serif;
  background: linear-gradient(180deg, #ebeff7 0%, #f9fafc 100%);
  color: var(--text);
}

.app {
  max-width: 720px;
  margin: 0 auto;
  padding: 12px;
}

h1 {
  margin: 4px 0 8px;
  font-size: 1.5rem;
}

h2 {
  margin: 0 0 10px;
  font-size: 1.1rem;
}

h3 {
  margin: 12px 0 8px;
  font-size: 1rem;
}

.help {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 0.96rem;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px;
  margin-bottom: 12px;
}

.image-toolbar {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}

.search-input {
  width: 100%;
  min-width: 0;
  border: 2px solid var(--line);
  border-radius: 12px;
  font-size: 0.95rem;
  padding: 10px 12px;
}

.image-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  max-height: 300px;
  overflow: auto;
}

.image-item {
  border: 2px solid var(--line);
  border-radius: 10px;
  background: #fff;
  padding: 0;
  overflow: hidden;
  text-align: left;
}

.image-item.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px #cae3ff;
}

.image-item img {
  width: 100%;
  height: 120px;
  object-fit: cover;
  display: block;
}

.image-item span {
  display: block;
  font-size: 0.8rem;
  padding: 8px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.editor-wrap {
  width: min(100%, 360px);
  margin: 0 auto;
  border-radius: 14px;
  overflow: hidden;
  border: 2px solid #263244;
  background: #10161f;
}

canvas {
  width: 100%;
  height: auto;
  display: block;
  touch-action: none;
}

.controls {
  margin-top: 12px;
}

.row {
  display: grid;
  gap: 8px;
  grid-template-columns: 1fr 1fr;
}

.btn {
  appearance: none;
  border: 2px solid var(--line);
  border-radius: 12px;
  background: #fff;
  color: var(--text);
  font-size: 1rem;
  font-weight: 700;
  padding: 12px 10px;
  min-height: 52px;
}

.btn:disabled {
  opacity: 0.55;
}

.btn-small {
  min-height: auto;
  padding: 10px 12px;
  font-size: 0.88rem;
  white-space: nowrap;
}

.btn.active {
  border-color: var(--accent);
  background: #e8f2ff;
}

.btn.primary {
  width: 100%;
  margin-top: 14px;
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.btn.primary:active {
  background: var(--accent-2);
}

.label {
  display: block;
  font-size: 0.9rem;
  margin: 10px 0 6px;
  color: var(--muted);
}

input[type='range'] {
  width: 100%;
}

.status {
  text-align: center;
  color: var(--muted);
  font-weight: 600;
  margin: 10px 0 18px;
}

@media (min-width: 760px) {
  .image-list {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}
