:root {
  --bg: #f6f8fa;
  --surface: #ffffff;
  --text: #1f2328;
  --muted: #656d76;
  --border: #d0d7de;
  --grid-line: #1f2328;
  --accent: #0969da;
  --accent-hover: #0550ae;
  --success: #1a7f37;
  --error: #cf222e;
  --warning-bg: #fff8c5;
  --given-bg: rgba(9, 105, 218, 0.12);
  --solved: #1a7f37;
  --shadow: 0 1px 3px rgba(27, 31, 36, 0.12);
  --radius: 12px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

.container {
  max-width: 1000px;
  margin: 0 auto;
  padding: 0 1.25rem;
}

.header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 1.5rem 0;
}

h1 {
  margin: 0;
  font-size: 1.75rem;
  font-weight: 700;
}

.subtitle {
  margin: 0.25rem 0 0;
  color: var(--muted);
}

.workspace {
  display: grid;
  grid-template-columns: minmax(280px, 360px) 1fr;
  gap: 2rem;
  align-items: start;
  padding-top: 2rem;
  padding-bottom: 2rem;
}

/* ---- Input column ---- */

.dropzone {
  position: relative;
  background: var(--surface);
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  box-shadow: var(--shadow);
  min-height: 180px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.dropzone:hover,
.dropzone.dragover,
.dropzone:focus-visible {
  border-color: var(--accent);
  background: #f0f6ff;
  outline: none;
}

.dropzone-icon {
  font-size: 2.25rem;
  margin-bottom: 0.5rem;
}

.dropzone-title {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
}

.dropzone-hint {
  margin: 0.35rem 0 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.preview {
  max-width: 100%;
  max-height: 320px;
  border-radius: 8px;
  display: block;
}

.actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 1rem;
}

.btn {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.6rem 1rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, opacity 0.15s;
}

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

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

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

.btn-ghost:hover:not(:disabled) {
  border-color: var(--error);
  color: var(--error);
}

.status {
  margin: 1rem 0 0;
  font-size: 0.95rem;
  min-height: 1.4em;
}

.status[data-type="success"] {
  color: var(--success);
  font-weight: 600;
}

.status[data-type="error"] {
  color: var(--error);
}

.status[data-type="loading"],
.status[data-type="info"] {
  color: var(--muted);
}

.warnings {
  margin-top: 0.75rem;
  padding: 0.6rem 0.85rem;
  background: var(--warning-bg);
  border-radius: 8px;
  font-size: 0.85rem;
}

.warnings p {
  margin: 0.2rem 0;
}

.legend {
  list-style: none;
  padding: 0;
  margin: 1.25rem 0 0;
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.legend li {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.swatch {
  width: 1rem;
  height: 1rem;
  border-radius: 4px;
  border: 1px solid var(--border);
  display: inline-block;
}

.swatch-given {
  background: var(--given-bg);
  backdrop-filter: blur(2px);
}

.swatch-solved {
  background: #fff;
}

.swatch-solved::after {
  content: "5";
  color: var(--solved);
  font-weight: 700;
  font-size: 0.8rem;
  line-height: 1;
  display: block;
  text-align: center;
}

.swatch-corrected {
  background: rgba(191, 135, 0, 0.16);
}

/* ---- Board column ---- */

.board-col {
  display: flex;
  justify-content: center;
}

.board {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  width: min(100%, 480px);
  aspect-ratio: 1 / 1;
  border: 3px solid var(--grid-line);
  border-radius: 6px;
  overflow: hidden;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.cell {
  width: 100%;
  height: 100%;
  min-width: 0;
  border: 1px solid var(--border);
  text-align: center;
  font-size: clamp(1rem, 4.2vw, 1.6rem);
  font-weight: 500;
  color: var(--text);
  padding: 0;
  background: var(--surface);
  font-family: inherit;
  transition: background 0.12s;
}

.cell:focus {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
  z-index: 1;
}

.cell.box-left {
  border-left: 2px solid var(--grid-line);
}

.cell.box-top {
  border-top: 2px solid var(--grid-line);
}

/* Extracted clues / user-entered givens: distinct frosted backdrop + bold dark */
.cell--given {
  background: var(--given-bg);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  font-weight: 700;
  color: var(--text);
}

/* Solver-filled digits: green, lighter weight, plain background — never overlaps */
.cell--solved {
  color: var(--solved);
  font-weight: 600;
  background: var(--surface);
}

/* Auto-corrected clue (OCR misread fixed via the unique-solution rule) */
.cell--corrected {
  background: rgba(191, 135, 0, 0.16);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  color: #9a6700;
  font-weight: 700;
}

.footer {
  padding: 1.5rem 0 2.5rem;
  text-align: center;
  color: var(--muted);
  font-size: 0.85rem;
}

@media (max-width: 760px) {
  .workspace {
    grid-template-columns: 1fr;
    gap: 1.5rem;
  }
  .board-col {
    order: -1;
  }
}
