:root {
  --ink: #14151b;
  --ink-soft: #3b404d;
  --muted: #656c7a;
  --surface: #ece9de;
  --panel: #ffffff;
  --panel-border: rgba(20, 21, 27, 0.08);
  --accent: #e95145;
  --accent-2: #176f80;
  --shadow: 0 14px 32px rgba(17, 17, 22, 0.11);
  --grid-line: #1c1c22;
  --grid-light: #c7c9d1;
  --success: #1a7f5a;
  --warning: #c23b22;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Satoshi", "Manrope", "Avenir", "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at 8% -8%, #fff7e8 0%, rgba(255, 247, 232, 0) 42%),
    radial-gradient(circle at 92% 0%, #e9f2f9 0%, rgba(233, 242, 249, 0) 34%),
    linear-gradient(180deg, #f3f0e8 0%, #ebe7dc 52%, #e4dfd1 100%);
  color: var(--ink);
  min-height: 100vh;
  position: relative;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image: repeating-linear-gradient(
    135deg,
    rgba(20, 21, 27, 0.015) 0,
    rgba(20, 21, 27, 0.015) 2px,
    transparent 2px,
    transparent 14px
  );
}

.app {
  max-width: 1100px;
  margin: 0 auto;
  padding: 18px 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  position: relative;
  z-index: 1;
}

.boards-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 12px;
  align-items: start;
}

.hero {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 11px 14px;
  background: linear-gradient(145deg, #101319 0%, #1d2d3f 52%, #27344f 100%);
  color: #fef8f2;
  border-radius: 12px;
  box-shadow: 0 9px 22px rgba(17, 17, 22, 0.11);
  border: 1px solid rgba(254, 248, 242, 0.14);
  overflow: hidden;
  position: relative;
}

.hero::after {
  content: "";
  position: absolute;
  width: 150px;
  height: 150px;
  right: -34px;
  top: -58px;
  background: radial-gradient(circle, rgba(238, 240, 246, 0.18) 0%, rgba(238, 240, 246, 0) 70%);
  pointer-events: none;
}

.hero > div:first-child {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.hero h1 {
  margin: 0;
  font-size: 22px;
  line-height: 1.06;
  letter-spacing: 0.01em;
}

.hero .sub {
  margin: 0;
  font-size: 12px;
  color: rgba(254, 248, 242, 0.78);
  max-width: 40ch;
}

.status {
  padding: 6px 11px;
  border-radius: 999px;
  background: rgba(240, 84, 79, 0.17);
  border: 1px solid rgba(240, 84, 79, 0.44);
  font-weight: 600;
  font-size: 11px;
  box-shadow: inset 0 0 0 1px rgba(254, 248, 242, 0.08);
  white-space: nowrap;
  position: relative;
  z-index: 1;
}

.panel {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.95) 0%, rgba(255, 255, 255, 0.9) 100%);
  border-radius: 14px;
  padding: 13px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 10px;
  border: 1px solid var(--panel-border);
  backdrop-filter: blur(1.5px);
}

button {
  border: none;
  background: var(--accent);
  color: #fff;
  padding: 9px 14px;
  font-weight: 600;
  font-size: 13px;
  letter-spacing: 0.01em;
  border-radius: 999px;
  cursor: pointer;
  transition: transform 0.16s ease, opacity 0.15s ease, box-shadow 0.16s ease;
  box-shadow: 0 6px 16px rgba(20, 21, 27, 0.2);
}

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

button:hover:not(:disabled) {
  transform: translateY(-1px) scale(1.01);
}

button:active:not(:disabled) {
  transform: translateY(0);
}

button.ghost {
  background: rgba(255, 255, 255, 0.65);
  color: var(--ink);
  border: 1px solid rgba(20, 21, 27, 0.2);
  box-shadow: none;
}

button.ghost:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.95);
}

.progress {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
}

.progress-bar {
  height: 7px;
  flex: 1;
  background: #dfd9cd;
  border-radius: 999px;
  position: relative;
  overflow: hidden;
}

.progress-bar::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transform-origin: left;
  transform: scaleX(var(--progress, 0));
  transition: transform 0.2s ease;
}

.preview-panel,
.grid-panel {
  height: 100%;
}

.preview-panel {
  gap: 10px;
}

.preview-upload {
  display: block;
  cursor: pointer;
}

.preview-upload input {
  display: none;
}

.preview-upload.disabled {
  cursor: wait;
}

.canvas-wrap {
  background: linear-gradient(160deg, #0e1219 0%, #131c28 55%, #1c2636 100%);
  border-radius: 12px;
  padding: 8px;
  color: #fff;
  position: relative;
  min-height: 210px;
  border: 1px solid rgba(254, 248, 242, 0.13);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.03);
  transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
}

.canvas-wrap::after {
  content: "";
  position: absolute;
  inset: 8px;
  border-radius: 10px;
  background-image: linear-gradient(
    145deg,
    rgba(255, 255, 255, 0.06) 0%,
    rgba(255, 255, 255, 0.01) 36%,
    rgba(255, 255, 255, 0) 100%
  );
  pointer-events: none;
}

.canvas-wrap canvas {
  display: block;
  width: min(100%, 680px);
  height: auto;
  aspect-ratio: 1 / 1;
  margin: 0 auto;
  border-radius: 10px;
  background: #0d1117;
  border: 1px solid rgba(255, 255, 255, 0.08);
  transition: opacity 0.2s ease;
}

.canvas-label {
  position: absolute;
  top: 8px;
  left: 12px;
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  opacity: 0.9;
  background: rgba(15, 16, 20, 0.6);
  padding: 3px 7px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.16);
}

.canvas-help {
  position: absolute;
  left: 12px;
  bottom: 8px;
  margin: 0;
  font-size: 11px;
  color: rgba(254, 248, 242, 0.86);
  background: rgba(15, 16, 20, 0.52);
  padding: 3px 7px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.14);
}

.preview-upload-copy {
  position: absolute;
  inset: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 2px;
  border: 2px dashed rgba(254, 248, 242, 0.45);
  border-radius: 12px;
  background: rgba(14, 18, 25, 0.54);
  color: #fef8f2;
  text-align: center;
  pointer-events: none;
  transition: opacity 0.2s ease, border-color 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease;
}

.preview-upload-copy h2 {
  margin: 0;
  font-size: 24px;
}

.preview-upload-copy p {
  margin: 0;
  color: rgba(254, 248, 242, 0.86);
}

.preview-upload.has-image .preview-upload-copy {
  opacity: 0;
}

.preview-upload:not(.has-image):hover .canvas-wrap,
.preview-upload.drag-active .canvas-wrap {
  transform: translateY(-1px);
  border-color: rgba(233, 81, 69, 0.55);
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.03),
    0 10px 24px rgba(20, 21, 27, 0.2);
}

.preview-upload:not(.has-image):hover .preview-upload-copy,
.preview-upload.drag-active .preview-upload-copy {
  border-color: rgba(233, 81, 69, 0.9);
  transform: scale(1.01);
  box-shadow: 0 8px 20px rgba(20, 21, 27, 0.24);
}

.preview-upload:not(.has-image) .canvas-wrap canvas {
  opacity: 0.26;
}

.hidden-canvas {
  display: none;
}

.grid-panel {
  gap: 10px;
}

.grid-header {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.grid-header h2,
.grid-header p {
  margin: 0;
}

.grid-header p {
  color: var(--ink-soft);
  font-size: 13px;
}

.workflow-controls {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  padding: 8px;
  border: 1px solid rgba(20, 21, 27, 0.11);
  border-radius: 10px;
  background: linear-gradient(135deg, #fff8eb 0%, #f7f2e7 100%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.6);
}

.workflow-controls button {
  width: 100%;
}

#scanBtn {
  background: linear-gradient(135deg, #23798a 0%, #176f80 100%);
}

#solveBtn {
  background: linear-gradient(135deg, #ee5b4f 0%, #e95145 100%);
}

.sudoku-grid {
  display: grid;
  grid-template-columns: repeat(9, minmax(0, 1fr));
  grid-template-rows: repeat(9, minmax(0, 1fr));
  gap: 0;
  border: 2px solid var(--grid-line);
  border-radius: 12px;
  overflow: hidden;
  width: min(100%, 680px);
  aspect-ratio: 1 / 1;
  margin: 0 auto;
  background: #f4f0e8;
}

.cell {
  border: 1px solid var(--grid-light);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 17px;
  font-weight: 600;
  background: #fdfbf7;
  min-width: 0;
  min-height: 0;
}

.cell input {
  width: 100%;
  height: 100%;
  border: none;
  text-align: center;
  font-size: 19px;
  font-weight: 600;
  background: transparent;
  color: var(--ink);
}

.cell input:focus {
  outline: 2px solid rgba(23, 111, 128, 0.4);
  outline-offset: -2px;
}

.cell.given input {
  color: var(--accent-2);
  font-weight: 700;
}

.cell.given {
  background: #e8f3f6;
}

.cell.solved input {
  color: var(--success);
}

.cell.solved {
  background: #edf6ef;
}

.cell.invalid {
  background: #fbe6df;
}

.cell.invalid input {
  color: var(--warning);
}

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

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

.footer {
  text-align: center;
  padding: 0 16px 14px;
  font-size: 12px;
  color: #5e6675;
  text-wrap: balance;
}

@media (max-width: 900px) {
  .boards-layout {
    grid-template-columns: 1fr;
  }

  .hero h1 {
    font-size: 20px;
  }

  .workflow-controls {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 720px) {
  .app {
    padding: 12px 10px 16px;
  }

  .hero {
    flex-direction: column;
    align-items: flex-start;
    padding: 10px 11px;
  }

  .hero h1 {
    font-size: 19px;
  }

  .status {
    align-self: flex-start;
  }

  .canvas-wrap canvas {
    width: min(100%, 560px);
  }

  .panel {
    padding: 11px;
  }

  .preview-upload-copy {
    inset: 20px;
  }

  .preview-upload-copy h2 {
    font-size: 21px;
  }
}

@media (max-width: 560px) {
  button {
    padding: 9px 12px;
  }

  .workflow-controls {
    grid-template-columns: 1fr;
  }

  .canvas-help {
    font-size: 10px;
  }

  .preview-upload-copy h2 {
    font-size: 18px;
  }

  .preview-upload-copy p {
    font-size: 13px;
  }
}
