:root {
  --bg: #111418;
  --surface: #1b1f26;
  --surface-2: #242a33;
  --border: #2e3540;
  --accent: #6ea9ff;
  --accent-hover: #8cbbff;
  --text: #e7ecf3;
  --muted: #9aa4b2;
  --error: #ff7a7a;
  --success: #7ed98a;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
}

main {
  max-width: 720px;
  margin: 0 auto;
  padding: 20px 16px 60px;
}

header { text-align: center; margin-bottom: 20px; }
h1 { margin: 0 0 4px; font-size: 28px; font-weight: 600; letter-spacing: -0.01em; }
.tagline { margin: 0; color: var(--muted); font-size: 14px; }
h2 { font-size: 14px; font-weight: 600; color: var(--muted); text-transform: uppercase;
     letter-spacing: 0.06em; margin: 0 0 10px; }

.difficulty {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.d-label { color: var(--muted); font-size: 13px; }
.d-buttons { display: flex; gap: 6px; background: var(--surface); padding: 4px;
             border: 1px solid var(--border); border-radius: 10px; }
.d-btn {
  background: transparent;
  color: var(--muted);
  border: none;
  border-radius: 7px;
  padding: 7px 14px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.d-btn:hover { color: var(--text); }
.d-btn.active {
  background: var(--accent);
  color: #0a1020;
  font-weight: 600;
}

.dropzone {
  border: 2px dashed var(--border);
  border-radius: 18px;
  background: var(--surface);
  padding: 40px 20px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  touch-action: manipulation;
}
.dropzone:hover, .dropzone:focus, .dropzone.dragover {
  border-color: var(--accent);
  background: var(--surface-2);
  outline: none;
}
.dz-icon {
  width: 56px; height: 56px; margin: 0 auto 14px;
  border-radius: 50%; background: var(--surface-2);
  display: flex; align-items: center; justify-content: center;
  font-size: 32px; color: var(--accent); font-weight: 300;
}
.dz-title { margin: 0 0 4px; font-size: 16px; font-weight: 500; }
.dz-sub { margin: 0 0 16px; color: var(--muted); font-size: 13px; }

.paste-target {
  margin-top: 14px;
  padding: 18px;
  border: 2px dashed var(--accent);
  border-radius: 10px;
  min-height: 56px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 14px;
  text-align: left;
  -webkit-user-select: text;
  user-select: text;
}
.paste-target:empty::before {
  content: attr(data-placeholder);
  color: var(--muted);
  font-style: italic;
}
.paste-target:focus { outline: none; border-color: var(--accent-hover); }
.paste-target img { max-width: 100%; height: auto; display: block; }

.paste-btn, .reset-btn {
  background: var(--accent);
  color: #0a1020;
  border: none;
  border-radius: 10px;
  padding: 10px 18px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
.paste-btn:hover, .reset-btn:hover { background: var(--accent-hover); }

.status {
  margin-top: 18px;
  padding: 12px 16px;
  border-radius: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 14px;
  display: flex; align-items: center; gap: 10px;
  white-space: pre-wrap;
}
.status.error { border-color: var(--error); color: var(--error); }
.status.working::before {
  content: ""; width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid var(--accent); border-top-color: transparent;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.preview, .result, .rescue {
  margin-top: 24px;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
}
.preview img, .result img {
  width: 100%;
  height: auto;
  border-radius: 8px;
  display: block;
}
.result { text-align: center; }
.result .reset-btn { margin-top: 14px; }

.solution-count {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 13px;
}
.solution-count.warn {
  color: #d9a23a;
  font-weight: 500;
}

.rescue-hint {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}
.rescue-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.rescue-btn {
  display: inline-flex;
  align-items: center;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 14px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.rescue-btn:hover { border-color: var(--accent); background: var(--surface); }

/* Glyphless-badge fill-in form */
.badge-form {
  margin: 0 0 14px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
}
.badge-form-title {
  margin: 0 0 10px;
  font-size: 13px;
  color: var(--text);
}
.badge-form-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
  font-size: 13px;
  color: var(--muted);
}
.badge-input {
  width: 90px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 9px;
  font-size: 14px;
}
.badge-input:focus { outline: none; border-color: var(--accent); }
.badge-form .rescue-btn { margin-top: 4px; }

/* Upload history */
.uploads {
  margin-top: 24px;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
}
.uploads-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.upload-entry {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
}
.upload-entry.upload-failed {
  border-color: color-mix(in srgb, var(--error) 40%, transparent);
}
.upload-thumb {
  width: 44px;
  height: 44px;
  object-fit: cover;
  border-radius: 6px;
  flex-shrink: 0;
  background: var(--bg);
}
.upload-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.upload-meta {
  font-size: 12px;
  color: var(--muted);
}
.upload-error-msg {
  font-size: 11px;
  color: var(--error);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.upload-actions {
  flex-shrink: 0;
  display: flex;
  gap: 6px;
}
.delete-btn {
  background: var(--surface);
  color: var(--error);
  border: 1px solid color-mix(in srgb, var(--error) 50%, transparent);
  border-radius: 7px;
  padding: 5px 12px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.delete-btn:hover {
  background: var(--error);
  color: #fff;
}
.delete-btn:disabled { opacity: 0.5; cursor: default; }
.retry-btn {
  background: var(--surface);
  color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 7px;
  padding: 5px 12px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.retry-btn:hover {
  background: var(--accent);
  color: #0a1020;
}
/* `.retry-btn` is also used as an <a> on the recent page. */
a.retry-btn { text-decoration: none; display: inline-block; }

/* Recent-uploads entry point (main page) */
.recent-link-section {
  margin-top: 24px;
  text-align: center;
}
.recent-link {
  display: inline-block;
  background: var(--surface);
  color: var(--accent);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 18px;
  font-size: 14px;
  font-weight: 500;
  text-decoration: none;
  transition: border-color 0.15s, color 0.15s;
}
.recent-link:hover {
  border-color: var(--accent);
  color: var(--accent-hover);
}

/* Recent-uploads page */
.back-link { color: var(--accent); text-decoration: none; }
.back-link:hover { color: var(--accent-hover); }
.uploads-day {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin: 14px 2px 4px;
}
.uploads-day:first-child { margin-top: 0; }
.uploads-day-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}
.uploads-day-count {
  font-size: 11px;
  color: var(--muted);
}
.uploads-empty {
  color: var(--muted);
  font-size: 13px;
  text-align: center;
  margin: 8px 0;
}

/* Puzzle archive */
.archive {
  margin-top: 24px;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  max-height: 360px;
  overflow-y: auto;
}
.archive-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.archive-entry {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.archive-date {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  min-width: 100px;
  font-variant-numeric: tabular-nums;
}
.archive-pills {
  display: flex;
  gap: 6px;
  flex: 1;
}
.archive-pill {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 4px 10px;
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}
.archive-pill:hover {
  border-color: var(--accent);
  color: var(--accent);
}
.archive-pill.archive-solved {
  color: var(--success);
  border-color: color-mix(in srgb, var(--success) 50%, transparent);
}
.archive-pill.archive-solved:hover {
  border-color: var(--success);
}
/* `.archive-pill` is also used as an <a> on the dedicated archive page. */
a.archive-pill { text-decoration: none; }

@media (max-width: 480px) {
  main { padding: 16px 12px 48px; }
  h1 { font-size: 24px; }
  .dropzone { padding: 32px 14px; }
}
