.patches-page {
  font-family: 'Poppins', sans-serif;
  background: var(--bg-dark, #0a0a0f);
  color: var(--text-primary, #fff);
  min-height: 100vh;
  padding-bottom: 2rem;
}
.patches-header { text-align: center; padding: 1rem; }
.patches-back { display: inline-block; margin-bottom: 0.5rem; font-size: 0.9rem; color: var(--text-secondary); text-decoration: none; }
.patches-title { font-size: clamp(1.4rem, 4vw, 1.85rem); font-weight: 700; margin-bottom: 0.25rem; }
.patches-subtitle { font-size: 0.85rem; color: var(--text-secondary); }
.patches-main { max-width: min(480px, 100%); margin: 0 auto; padding: 0 1rem; }
.patches-legend {
  background: rgba(255, 255, 255, 0.05);
  border-radius: 14px;
  padding: 1rem;
  margin-bottom: 1rem;
  border: 1px solid rgba(255, 255, 255, 0.08);
  font-size: 0.82rem;
  color: var(--text-secondary);
}
.patches-legend-sample {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
}
.patches-legend-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  background: #f5d547;
  color: #1a1a24;
  font-weight: 800;
  border-radius: 8px;
  font-size: 1.1rem;
}
.patches-legend-grid {
  width: 48px;
  height: 48px;
  border: 2px dashed rgba(255, 255, 255, 0.35);
  border-radius: 6px;
  background: repeating-linear-gradient(90deg, transparent, transparent 11px, rgba(255,255,255,0.08) 11px, rgba(255,255,255,0.08) 12px),
    repeating-linear-gradient(0deg, transparent, transparent 11px, rgba(255,255,255,0.08) 11px, rgba(255,255,255,0.08) 12px);
}
.patches-legend-text { margin-bottom: 0.35rem; color: var(--text-primary); font-weight: 600; }
.patches-legend-shapes { margin: 0.25rem 0 0.5rem 1rem; padding: 0; }
.patches-legend-rule { margin: 0; line-height: 1.45; }
.patches-game-wrap { background: rgba(255, 255, 255, 0.04); border-radius: 16px; padding: 1rem; border: 1px solid rgba(255, 255, 255, 0.08); }
.patches-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.65rem 1rem;
  margin-bottom: 1rem;
  font-size: 0.82rem;
  color: var(--text-secondary);
}
.patches-toolbar-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex: 1 1 auto;
  min-width: 0;
}
.patches-select {
  flex: 1;
  max-width: 160px;
  padding: 0.45rem 0.65rem;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: #2a2a35;
  color: var(--text-primary);
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
}
.patches-toolbar-meta {
  flex: 1 1 100%;
  font-weight: 600;
  color: var(--text-primary);
  font-size: 0.88rem;
}
.patches-toolbar-stats {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}
.patches-stat strong { color: #f5d547; }
.patches-toolbar-nav {
  display: flex;
  gap: 0.35rem;
  margin-left: auto;
}
.patches-btn--icon {
  min-width: 2.5rem;
  padding: 0.45rem 0.65rem;
  font-size: 1.25rem;
  line-height: 1;
}
.patches-grid {
  display: grid;
  gap: 2px;
  width: min(320px, 92vw);
  margin: 0 auto 1rem;
  aspect-ratio: 1;
  background: #2a2a35;
  padding: 4px;
  border-radius: 12px;
  user-select: none;
  touch-action: none;
}
.patches-grid--medium {
  width: min(340px, 94vw);
}
.patches-grid--large {
  width: min(380px, 96vw);
}
.patches-cell {
  background: #3a3a48;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: clamp(0.85rem, 3.5vw, 1.15rem);
  color: #1a1a24;
  cursor: crosshair;
  position: relative;
  min-height: 0;
}
.patches-cell.has-region { color: #1a1a24; }
.patches-cell .patches-clue {
  position: absolute;
  top: 3px;
  left: 3px;
  font-size: clamp(0.65rem, 2.8vw, 0.85rem);
  font-weight: 800;
  color: #1a1a24;
  line-height: 1;
  background: rgba(255, 255, 255, 0.92);
  padding: 2px 5px;
  border-radius: 5px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.15);
}
.patches-cell.drag-preview { outline: 2px dashed rgba(255, 255, 255, 0.6); outline-offset: -2px; z-index: 2; }
.patches-cell.drag-preview-valid { outline-color: rgba(67, 233, 123, 0.85); }
.patches-cell.drag-preview-invalid { outline-color: rgba(245, 87, 108, 0.9); }
.patches-actions { display: flex; gap: 0.75rem; justify-content: center; margin-bottom: 0.75rem; }
.patches-btn {
  padding: 0.55rem 1.2rem;
  border-radius: 12px;
  font-weight: 600;
  font-size: 0.9rem;
  border: none;
  cursor: pointer;
  background: #3a3a48;
  color: var(--text-primary);
}
.patches-btn:disabled { opacity: 0.45; cursor: not-allowed; }
.patches-btn:hover:not(:disabled) { filter: brightness(1.1); }
.patches-submit {
  width: 100%;
  padding: 0.85rem;
  border-radius: 12px;
  font-weight: 700;
  font-size: 1rem;
  border: none;
  cursor: pointer;
  background: #1e1e28;
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.12);
}
.patches-submit:hover { background: #2a2a35; }
.patches-msg { text-align: center; font-size: 0.9rem; margin-top: 0.75rem; min-height: 1.4em; }
.patches-msg.err { color: #f5576c; }
.patches-msg.ok { color: #43e97b; }
.patches-win {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s, visibility 0.3s;
}
.patches-win.is-visible { opacity: 1; visibility: visible; }
.patches-win-box {
  background: #1a1a24;
  border-radius: 16px;
  padding: 2rem;
  text-align: center;
  max-width: 320px;
  border: 1px solid rgba(67, 233, 123, 0.35);
}
.patches-win-box h2 { color: #43e97b; margin-bottom: 0.5rem; }
.patches-win-box button {
  margin-top: 1rem;
  padding: 0.65rem 1.5rem;
  border-radius: 10px;
  font-weight: 600;
  background: #43e97b;
  color: #0a0a0f;
  border: none;
  cursor: pointer;
}
