@font-face {
  font-family: "Dinasti";
  src: url("./fonts/DINASTI-Regular.otf") format("opentype");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

:root {
  color-scheme: light;
  --ink: #000;
  --muted: #4a4a4a;
  --accent: #000;
  --board: #fff;
  --cell: #fff;
  --line: #000;
  --grid: #444;
  --related: #f5f5f5;
  --selected: #e6e6e6;
  --same: #f0f0f0;
  --radius: 12px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Helvetica Neue", "Arial", sans-serif;
  color: var(--ink);
  background: #fff;
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: flex-start;
}

.wrap {
  width: min(1200px, 100%);
  padding: 32px clamp(18px, 4vw, 48px) 64px;
}

.hero {
  display: flex;
  flex-wrap: wrap;
  gap: 24px 32px;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 28px;
}

.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.2em;
  font-size: 0.7rem;
  color: var(--muted);
  margin: 0 0 6px;
}

h1 {
  font-family: "Dinasti", "Helvetica Neue", "Arial", sans-serif;
  font-size: clamp(1.8rem, 2.6vw, 2.6rem);
  font-weight: 400;
  margin: 0 0 8px;
}

.sub {
  margin: 0;
  color: var(--muted);
  max-width: 540px;
}

.status {
  display: grid;
  gap: 10px;
  justify-items: end;
}

.badge {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 0.85rem;
}

.timer {
  font-size: 1.4rem;
  font-weight: 700;
  letter-spacing: 0.08em;
}

.game {
  display: grid;
  grid-template-columns: minmax(280px, 1fr) minmax(240px, 340px);
  gap: clamp(24px, 4vw, 40px);
  align-items: start;
}

.board {
  width: min(92vw, 560px);
  aspect-ratio: 1;
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  grid-template-rows: repeat(9, 1fr);
  border-radius: var(--radius);
  background: var(--board);
  border: 2px solid var(--line);
  overflow: hidden;
  position: relative;
  animation: board-fade 400ms ease-out;
}

.board.loading {
  filter: grayscale(0.2);
  opacity: 0.8;
  cursor: progress;
}

.cell {
  border: 1px solid var(--grid);
  background: var(--cell);
  font-size: clamp(1rem, 4.2vw, 1.8rem);
  font-weight: 600;
  color: var(--ink);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  cursor: pointer;
  transition: background 140ms ease, color 140ms ease;
  user-select: none;
}

.cell:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: -3px;
}

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

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

.cell.fixed {
  color: var(--ink);
  font-weight: 700;
  background: #fff;
}

.cell.selected {
  background: var(--selected);
}

.cell.related {
  background: var(--related);
}

.cell.same {
  background: var(--same);
  color: var(--ink);
}

.cell.conflict {
  background: #fff;
  color: #d60000;
}

.cell,
.pill,
.action,
.icon-btn,
.numpad button {
  touch-action: manipulation;
}

.panel {
  background: #fff;
  border-radius: var(--radius);
  padding: 24px;
  border: 1px solid var(--line);
  display: grid;
  gap: 22px;
}

.panel-section h2 {
  font-family: "Dinasti", "Helvetica Neue", "Arial", sans-serif;
  margin: 0 0 12px;
  font-size: 1rem;
  font-weight: 400;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.difficulty {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.pill {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 10px 14px;
  font-weight: 600;
  background: #fff;
  cursor: pointer;
  transition: background 120ms ease, color 120ms ease;
}

.pill.active {
  background: var(--accent);
  color: #fff;
}

.pill:hover {
  background: #f3f3f3;
}

.actions {
  display: grid;
  gap: 10px;
}

.manual-input {
  width: 100%;
  min-height: 180px;
  resize: vertical;
  border-radius: 16px;
  border: 1px solid var(--line);
  padding: 12px;
  font-family: "DINASTI", ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: clamp(14px, 3vw, 18px);
  line-height: 1.6;
  background: #fff;
  color: #000;
}

.manual-input:focus {
  outline: none;
  border-color: #000;
  box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.08);
}

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

.action {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px;
  font-weight: 600;
  background: #000;
  color: #fff;
  cursor: pointer;
  transition: background 120ms ease, color 120ms ease;
}

.action:hover {
  background: #1a1a1a;
}

.action:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.action.toggle.active {
  background: #fff;
  color: #000;
}

.action.ghost {
  background: #fff;
  color: #000;
}

.action.ghost:hover {
  background: #f3f3f3;
}

.numpad {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.numpad button {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 0;
  background: #fff;
  font-size: 1.1rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 120ms ease, color 120ms ease;
}

.numpad button:hover {
  background: #f3f3f3;
}

.numpad button:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.numpad button.is-hidden {
  visibility: hidden;
}

.mobile-top-bar,
.mobile-quick-actions,
.mobile-numpad-host,
.mobile-menu-overlay {
  display: none;
}

.icon-btn {
  width: 44px;
  height: 44px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  font-size: 1.2rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 120ms ease, color 120ms ease;
  padding: 0;
}

.icon-btn:active {
  background: #f0f0f0;
}

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

.icon-btn.toggle.active {
  background: var(--accent);
  color: #fff;
}

.mobile-top-bar {
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: #fff;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 6;
}

.mobile-timer {
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: 0.08em;
}

.mobile-actions {
  display: flex;
  gap: 8px;
}

.mobile-quick-actions {
  gap: 10px;
  justify-content: center;
  padding: 14px 12px 12px;
}

.mobile-quick-actions .icon-btn {
  flex: 1;
  max-width: 64px;
  height: 48px;
}

.mobile-numpad-host {
  position: sticky;
  bottom: 0;
  background: #f8f8f8;
  border-top: 1px solid var(--line);
  z-index: 5;
}

.mobile-menu-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 20;
  align-items: flex-end;
  justify-content: center;
}

.mobile-menu-overlay:not([hidden]) {
  display: flex;
}

.mobile-menu-content {
  width: min(100%, 540px);
  max-height: 85vh;
  background: #fff;
  border-radius: 20px 20px 0 0;
  padding: 20px;
  overflow-y: auto;
  animation: slide-up 240ms ease-out;
}

.mobile-menu-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.mobile-menu-header h2 {
  font-family: "Dinasti", "Helvetica Neue", "Arial", sans-serif;
  margin: 0;
  font-size: 1rem;
  font-weight: 400;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.mobile-menu-body {
  display: grid;
  gap: 18px;
}

.cell.notes {
  padding: 4px;
  align-items: stretch;
  justify-content: stretch;
}

.notes-grid {
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  font-size: 0.55em;
  color: #2a2a2a;
}

.notes-grid span {
  display: flex;
  align-items: center;
  justify-content: center;
}
.hint {
  color: var(--muted);
  font-size: 0.85rem;
  margin: 12px 0 0;
}

.toast {
  position: fixed;
  bottom: 32px;
  left: 50%;
  transform: translateX(-50%);
  background: #000;
  color: #fff;
  padding: 12px 20px;
  border-radius: 999px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease, transform 180ms ease;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(-6px);
}

.camera[hidden] {
  display: none;
}

.camera {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 10;
}

.camera-shell {
  width: min(92vw, 520px);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 12px;
  display: grid;
  gap: 12px;
}

#camera-video {
  width: 100%;
  aspect-ratio: 1;
  border-radius: 12px;
  background: #000;
  object-fit: cover;
}

.camera-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

@keyframes board-fade {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes slide-up {
  from {
    transform: translateY(100%);
  }
  to {
    transform: translateY(0);
  }
}

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

  .status {
    justify-items: start;
  }

  .board {
    width: min(95vw, 520px);
    margin: 0 auto;
  }
}

@media (max-width: 720px) {
  body.mobile-menu-open {
    overflow: hidden;
  }

  .wrap {
    padding: 0;
    max-width: 100%;
  }

  .hero {
    display: none;
  }

  .game {
    display: flex;
    flex-direction: column;
    gap: 0;
  }

  .board {
    width: 100%;
    max-width: 100%;
    margin: 0;
    border-radius: 0;
    border-left: none;
    border-right: none;
  }

  .cell {
    font-size: clamp(1.2rem, 8vw, 2rem);
  }

  .panel {
    display: none;
  }

  .mobile-top-bar {
    display: flex;
  }

  .mobile-quick-actions {
    display: flex;
  }

  .mobile-numpad-host {
    display: block;
  }

  .numbers-section {
    padding: 12px 12px 14px;
  }

  .numbers-section h2,
  .numbers-section .hint {
    display: none;
  }

  .numpad {
    grid-template-columns: repeat(9, minmax(0, 1fr));
    gap: 6px;
  }

  .numpad button {
    aspect-ratio: 1;
    min-height: 48px;
    border-radius: 10px;
    font-size: 1.15rem;
  }
}

@media (max-width: 600px) {
  .wrap {
    padding: 0;
  }
}

@media (max-width: 480px) {
  .manual-input {
    font-size: 16px;
    min-height: 200px;
    padding: 14px;
  }
}
