:root {
  --bg-color: #faf9f6;
  --text-color: #333;
  --grid-border: #333;
  --cell-bg: #fff;
  --cell-filled: #333;
  --cell-cross: #ccc;
  --clue-bg: #f0f0f0;
  --primary-color: #4a90e2;
  --primary-hover: #357abd;
}

*, *::before, *::after {
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background-color: var(--bg-color);
  color: var(--text-color);
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  margin: 0;
  width: 100vw;
  overflow-x: hidden;
}

.app-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 2rem;
  background: white;
  border-radius: 12px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
  width: 95%;
  max-width: 500px;
}

header {
  text-align: center;
  margin-bottom: 2rem;
  width: 100%;
}

h1 {
  margin: 0 0 0.5rem 0;
  font-size: 2.5rem;
}

.game-banner {
  display: block;
  width: min(100%, 430px);
  height: auto;
  margin: 0 auto 0.75rem;
}

p {
  margin: 0;
  color: #666;
}

.level-selector {
  margin-top: 1rem;
}

.level-selector label {
  font-weight: 600;
  margin-right: 0.5rem;
}

.level-selector select {
  padding: 6px 12px;
  font-size: 1rem;
  border-radius: 6px;
  border: 1px solid #ccc;
  outline: none;
  cursor: pointer;
}

.game-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2rem;
  width: 100%;
}

.nonogram-container {
  display: grid;
  gap: 1px;
  background-color: var(--grid-border);
  border: 2px solid var(--grid-border);
  max-width: 100%;
  overflow-x: auto;
  --cell-size: 40px;
  --clue-size: 60px;
}

.cell {
  background-color: var(--cell-bg);
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 0.8rem;
  user-select: none;
}

.clue-cell {
  background-color: var(--clue-bg);
  font-weight: bold;
  padding: 4px;
  text-align: center;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  gap: 2px;
  min-height: var(--clue-size);
}

.clue-row {
  flex-direction: row;
  justify-content: flex-end;
  padding-right: 8px;
  min-width: var(--clue-size);
  min-height: auto;
}

.corner-cell {
  justify-content: center;
  align-items: center;
}

.corner-ant {
  display: block;
  width: min(58px, 92%);
  height: min(58px, 92%);
  object-fit: contain;
  opacity: 0.86;
}

.playable-cell {
  cursor: pointer;
  width: var(--cell-size);
  height: var(--cell-size);
  transition: background-color 0.1s;
}

.playable-cell:hover {
  background-color: #f5f5f5;
}

.playable-cell.filled {
  background-color: var(--cell-filled);
}

.playable-cell.crossed {
  position: relative;
}

.playable-cell.crossed::before,
.playable-cell.crossed::after {
  content: '';
  position: absolute;
  width: 80%;
  height: 2px;
  background-color: var(--cell-cross);
  top: 50%;
  left: 10%;
}

.playable-cell.crossed::before {
  transform: rotate(45deg);
}

.playable-cell.crossed::after {
  transform: rotate(-45deg);
}

.playable-cell.dotted {
  position: relative;
}

.playable-cell.dotted::after {
  content: '';
  position: absolute;
  width: 25%;
  height: 25%;
  background-color: var(--cell-filled);
  border-radius: 50%;
  top: 37.5%;
  left: 37.5%;
}

.controls {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  justify-content: center;
}

button {
  padding: 10px 20px;
  border: none;
  border-radius: 6px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.2s;
}

.primary-button {
  background-color: var(--primary-color);
  color: white;
}

.primary-button:hover {
  background-color: var(--primary-hover);
}

.secondary-button {
  background-color: #eee;
  color: #333;
}

.secondary-button:hover {
  background-color: #ddd;
}

.message {
  font-weight: bold;
  font-size: 1.2rem;
  min-height: 1.5rem;
}

.success {
  color: #27ae60;
}

.error {
  color: #c0392b;
}

@media (max-width: 480px) {
  .app-container {
    padding: 1rem;
  }
  
  h1 {
    font-size: 2rem;
  }
  
  .playable-cell {
    width: 34px;
    height: 34px;
  }
  
  .controls {
    gap: 0.5rem;
  }
  
  button {
    padding: 8px 16px;
    font-size: 0.9rem;
  }
}

.print-view {
  display: none;
}

@media print {
  @page {
    size: letter portrait;
    margin: 0;
  }

  html,
  body {
    background: white;
    display: block;
    min-height: 11in;
    margin: 0;
    width: 8.5in;
    overflow-x: visible;
  }
  .app-container {
    display: none !important;
  }
  .print-view {
    display: block !important;
    padding: 0;
    width: 8.5in;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }
  .print-view * {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }
  .print-sheet {
    width: 8.5in;
    min-height: 11in;
    padding: 0.35in 0.45in;
  }
  .print-header {
    display: block;
    text-align: center;
    margin-bottom: 0.22in;
  }
  .print-header h2 {
    font-size: 20px;
    margin: 0 0 0.04in;
  }
  .print-header p {
    font-size: 12px;
    color: var(--muted);
    margin: 0;
  }
  .print-logo {
    display: block;
    width: 2.35in;
    height: auto;
    margin: 0 auto 0.03in;
  }
  .print-page {
    display: grid;
    grid-template-columns: repeat(2, max-content);
    justify-content: center;
    align-content: start;
    gap: 0.22in 0.35in;
    width: 7.6in;
  }
  .print-item {
    display: flex;
    justify-content: center;
    align-items: center;
    break-inside: avoid;
    page-break-inside: avoid;
  }
  .print-nonogram {
    --print-cell-size: 0.525in;
    --print-clue-size: 0.65in;
    --print-top-clue-size: 0.65in;
    background-color: transparent !important;
    gap: 0 !important;
    border: 2px solid #333 !important;
    overflow: visible;
  }
  .print-nonogram .cell {
    border-right: 1px solid #333;
    border-bottom: 1px solid #333;
  }
  .print-nonogram .playable-cell {
    width: var(--print-cell-size) !important;
    height: var(--print-cell-size) !important;
    background-color: white !important;
  }
  .print-nonogram .corner-ant {
    width: 0.52in !important;
    height: 0.52in !important;
    opacity: 0.9 !important;
  }
  .print-nonogram .clue-cell {
    width: var(--print-cell-size);
    min-height: var(--print-cell-size);
    height: var(--print-cell-size);
    padding: 2px;
    font-size: 0.82rem;
    background-color: #f2f2f2 !important;
  }
  .print-nonogram > .clue-cell:not(.clue-row) {
    min-height: var(--print-top-clue-size);
    height: var(--print-top-clue-size);
  }
  .print-nonogram > .corner-cell {
    width: var(--print-clue-size);
  }
  .print-nonogram .clue-row {
    width: var(--print-clue-size);
    min-width: var(--print-clue-size);
  }
}
